A
A
AlexWinner2014-03-06 19:45:25
PostgreSQL
AlexWinner, 2014-03-06 19:45:25

GeoDjango - LineStringField - how to use and where is the documentation?

Good afternoon!
I am using Django 1.6 + GeoDjango + PostgreSQL + PostGIS.
I want to store routes (well, ordered collections of points) in a LineStringField.
However, I can't find examples of how to do this anywhere.
I fill the usual PointField like this: How can
location='POINT(%s %s)' % (lng, lat)
I do the same for LineString?
And how to get the coordinates in the opposite direction?
For PointField I do:

lng = location.x
lat = location.y

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexWinner, 2014-03-07
@AlexWinner

I figured it out myself, geo-fields have a coords property, which can be pulled.
In the Python console it looks like this (where event is an object, and route is a property of type LineStringField:

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question