Question

Good day everyone.

I'm using Django 1.6 with GeoDjango and Postgresql+PostGIS backend. I want to use LineStringField to save some routes. But I can't find any documentation about how to do it. I have model, have LineStringField attribute - but what to do next?

Here https://docs.djangoproject.com/en/1.6/ref/contrib/gis/model-api/#linestringfield are only class names, nothing else. I also tried to google some examples, but it wasn't successful. Can you please point me where to search for it? And also I'll highly appreciate some examples of code - like creating object of model with LineStringField, saving it to DB and then getting points from it (to display on the map).

P.s. Please sorry for my english.

Was it helpful?

Solution

Finally I found it myself. We need just to use coords property of LineStringField, like this:

>>> event.route.coords
((15.732421875, 8.5775756835938), (10.986328125, 3.3041381835938), (3.779296875, 10.862731933594), (-1.58203125, 7.8744506835938), (-4.74609375, 14.114685058594))
>>> event.route.x
[15.732421875, 10.986328125, 3.779296875, -1.58203125, -4.74609375]
>>> event.route.y
[8.5775756835938, 3.3041381835938, 10.862731933594, 7.8744506835938, 14.114685058594]
>>> event.route.json
'{ "type": "LineString", "coordinates": [ [ 15.732421875, 8.5775756835938 ], [ 10.986328125, 3.3041381835938 ], [ 3.779296875, 10.862731933594 ], [ -1.58203125, 7.8744506835938 ], [ -4.74609375, 14.114685058594 ] ] }'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top