5

Similar to this question: How to test if two GDAL datasets are in the same projection?

However, the above does not cover cases where an SRID is not available. It can often be the case that an SRID is not specified and the WKT between 2 datasets of the same projection does not precisely match.

What is your strategy for determining whether 2 datasets are of the same projection (using python) in this case?

It is annoying to go through the whole process of reprojecting a dataset just because the WKT strings do not exactly match, even though they are in the same projection.

osr's Spatial Reference class can allow us toe get the projection information in a number of formats, and I often find that comparing the results of ExportToProj4() rather than ExportToWkt() to be more reliable in matching projections. However, I do not know if it is 'bullet-proof'?

Another method could be to parse the WKT strings and match the 'important' parts. This has 2 questions: 1. Does anyone know an efficient method (in python) of breaking a WKT string into it's constituent parts which can be easily compared? 2. What are the relevant parts of a WKT string, or how can you determine this?

James
  • 2,248
  • 2
  • 22
  • 27

2 Answers2

4

Read before asking:

Buried in the OGR/OSR/GDAL documentation:

http://www.gdal.org/ogr/classOGRSpatialReference.html#a17fd82b2f58a976a30358b076a2fc966

It seems the SpatialReference() class has a method called IsSame which returns true if it and another srs describe the same system.

There is also IsSameGeogCS.

How they work I don't know. I also dont know why a seperate method is needed for the GeogCS. Surely calling IsSame would also work for GCS?

James
  • 2,248
  • 2
  • 22
  • 27
  • If two projections share the same GCS (that is lat/lon), you don't need to do any datum shift. The transformation is pretty much like a planar transformation. – AndreJ Aug 08 '14 at 14:08
  • This is the best answer, although the link is broken. You can find info on this in the gdal python docs under the osgeo.osr-Class SpatialReference – Devin Cairns Nov 16 '16 at 03:18
1

There is no automated bullet-proof method to guess the SRID correctly. Sometimes QGIS creates a custom CRS even in cases when a well known projection is used without giving a EPSG code.

Most fail cases are due to naming of WKT fields, like Longitude of Origin vs. Central longitude or Center Longitude

This site offers a comparison service: http://prj2epsg.org/search

but I have not tested it to be bullet proof.

To compare two WKT's, you have to go through all parameters and see if they match.

For LCC with two standard parallels, you also have to check if first and second parallel are swapped. The result is the same, but automated guessing might fail.

AndreJ
  • 76,698
  • 5
  • 86
  • 162