[GIS] GeoDjango Changing My Coordinates

geodjangopython

I'm running into a problem when saving a coordinate into one of my models in (Geo)Django. My point field is setup as:

location = PointField(blank=True, null = True)

So while running some tests in the django shell I noticed my coordinates were changing…

obj.location = 'POINT(-120.18444970926208 50.65664762026928)'
obj.save()
print(obj.location.x)

-120.1840742

print(obj.location.y)

50.6569673

Another thing I've noticed If I set the point using an UPDATE in postgres and then…

print(obj.location.y)

50.65664762026928

but if I run a save and check the coordinate again I get…

obj.save()
print(obj.location.y)

50.6569673

Anybody have any ideas where I can start looking to sort this out or any suggestions what may be causing this.

Thanks,
Dustin

Software:

  • Django 1.3.1
  • GDAL 1.9.1
  • Python 2.7.2
  • PostGIS 1.5.3
  • GEOS 3.3.3
  • PostgreSQL 9.1.4

Best Answer

try to add your srid to your point for a more detailed explanation.

>>> from django.contrib.gis.geos import GEOSGeometry
>>> point_loc = GEOSGeometry('POINT(-120.18444970926208 50.65664762026928)', srid=3084)  
>>> z = Object(location = point_loc)
>>> z.save()

i hope it helps you..

Related Question