ST_LENGTH SPHEROID

120 views
Skip to first unread message

seko

unread,
Dec 5, 2009, 11:15:57 PM12/5/09
to geodjango
Hi,

i have a geodjango model that represents tracks as LineStrings in
WGS84. Now I want to calculate their length in meters without
transforming the geometry into an other SRID.
I was trying to do ST_LENGTH_SPHEROID selects on PostGIS, which worked
perfectly.
Now I want to integrate that funktion in my Django-Model so that I may
call "track.length_spheroid()" on python.
Is this possible and if so, how? :)

thanks

Sebastian

cka...@googlemail.com

unread,
Dec 6, 2009, 5:11:03 AM12/6/09
to geodjango
Hm, interesting question, I would like to know that too!

Chris

Tyler Erickson

unread,
Dec 6, 2009, 7:52:24 AM12/6/09
to geodjango
I'm not aware of any current support for spheroid calculations in
geodjango, but you could try constructing raw sql and running it
against PostGIS. If that works you could include it in a custom method
for your model.
See: http://docs.djangoproject.com/en/dev/topics/db/sql/

- Tyler

Justin Bronn

unread,
Dec 6, 2009, 12:25:49 PM12/6/09
to geod...@googlegroups.com
Tyler Erickson wrote:
> I'm not aware of any current support for spheroid calculations in
> geodjango, but you could try constructing raw sql and running it
> against PostGIS. If that works you could include it in a custom method
> for your model.
> See: http://docs.djangoproject.com/en/dev/topics/db/sql/

`ST_Length_Spheroid` is used automatically when you try to calculate the
length of a geometry that has a geographic coordinate system. For
example, if you had the following model:

class GeoModel(models.Model):
line = models.LineStringField()
objects = models.GeoManager()

Then the following queryset would use `ST_Length_Spheroid` in its SQL
(because the default SRID is 4326, a geographic coordinate system):

qs = GeoModel.objects.length()

-Justin
Reply all
Reply to author
Forward
0 new messages