简体   繁体   中英

GeoDjango - LineStringField - how to use it? Where do I find documentation?

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).

Ps Please sorry for my english.

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 ] ] }'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM