I'm having a problem transforming a point from the Australian MGA UTM datum (eg MGA Zone 51 http://spatialreference.org/ref/epsg/28351/) to WGS84 using GeoDjango. I've narrowed that down to a problem where PostGIS can not select a Spatial Reference System using Proj4 text.

One of the main limitations is that I'm dealing with many geospatial locations, and I don't actually know which CRS I'm working with for each one; I only know that they're using the MGA UTM datum, they're located in Australia, and they have a northing, easting and zone which I am given.

I figure I should be able to use the Proj4 text string in order to get the correct CRS like this, because the Proj4 string is consistent for these CRSs except for the zone:

from django.contrib.gis.gdal import SpatialReference
proj = "+proj=utm +zone=%d +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" % zone
srs = SpatialReference(proj)

Is this a reasonable approach? If not, that would at least answer the question.

However, if so, it's not working as I think it should, because srs.srid gives nothing.

>>> srs.srid

Doing it the other way works fine:

>>> srs = SpatialReference(28351)
>>> srs.srid
>>> srs.proj4
u'+proj=utm +zone=51 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs '

Digging deeper, I went into the database to check things out.

database=> SELECT proj4text FROM spatial_ref_sys WHERE srid = 928351;
 +proj=utm +zone=51 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
(1 row)

That works fine. But going back the other way doesn't:

database=> SELECT * FROM spatial_ref_sys WHERE proj4text = '+proj=utm +zone=51 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
 srid | auth_name | auth_srid | srtext | proj4text 
(0 rows)

I've tried updating the spatial reference table with the insert statements from http://spatialreference.org/.

Any ideas about this?


You can cheat, because the EPSG numbers for UTM zones have a pattern than incorporates the zone number.

  • 269ZZ for UTM north zones, where ZZ is the zone number
  • 327ZZ for UTM south zones, where ZZ is the zone number

And, since PostGIS uses the EPSG number for the SRID, you're all set.

  • Thanks Paul. I came up with this solution too, although the EPSG numbers for the datums I'm interested in use a 283ZZ pattern. I'd still like to know why the PostGIS lookups are failing. – ChidG Jul 3 '14 at 3:01

The proj4text strings have been saved with a single trailing whitespace, which is why your query returns nothing. Use the trim operator:

SELECT * FROM spatial_ref_sys WHERE trim(proj4text) = '+proj=utm +zone=51 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
  • Adding the trailing whitespace to your own definition might work too. I have not tested that myself. – AndreJ Feb 8 '15 at 7:25
  • Thanks Allie - looking back at the text I posted, it seems pretty obvious! I won't have a chance to test this in the near future but I look forward to doing so - will accept your answer then. – ChidG Feb 8 '15 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.