Using UTM with geodjango
Question
I'm looking into using the UTM coordinate system with geodjango. And I can't figure out how to get the data in properly.
I've been browsing the documentation and it seems that the "GEOSGeometry(geo_input, srid=None)" or "OGRGeometry" could be used with an EWKT, but I can't figure out how to format the data.
It looks like the UTM SRID is: 2029
From the wikipedia article the format is written like this:
[UTMZone][N or S] [easting] [northing]
17N 630084 4833438
So I tried the following with no luck:
>>> from django.contrib.gis.geos import *
>>> pnt = GEOSGeometry('SRID=2029;POINT(17N 630084 4833438)')
GEOS_ERROR: ParseException: Expected number but encountered word: '17N'
>>>
>>> from django.contrib.gis.gdal import OGRGeometry
>>> pnt = OGRGeometry('SRID=2029;POINT(17N 630084 4833438)')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\django\contrib\gis\gdal\geometries.py", line 106, in __init__
ogr_t = OGRGeomType(geom_input)
File "C:\Python26\lib\site-packages\django\contrib\gis\gdal\geomtype.py", line 31, in __init__
raise OGRException('Invalid OGR String Type "%s"' % type_input)
django.contrib.gis.gdal.error.OGRException: Invalid OGR String Type "srid=2029;point(17n 630084 4833438)"
Are there any example available to show how this is done?
May be I should just do any necessary calulations in UTM and convert to decimal degrees?
In this case does GEOS or other tools in geodjango provide convertion utitilites?
Solution
The UTM zone (17N) is already specified by the spatial reference system -- SRID 2029, so you don't need to include it in the WKT you pass to the GEOSGeometry
constructor.
>>> from django.contrib.gis.geos import *
>>> pnt = GEOSGeometry('SRID=2029;POINT(630084 4833438)')
>>> (pnt.x, pnt.y)
(630084.0, 4833438.0)
>>> pnt.srid
2029
Then, for example:
>>> pnt.transform(4326) # Transform to WGS84
>>> (pnt.x, pnt.y)
(-79.387137066054038, 43.644504290860461)
>>> pnt.srid
4326