[FWTools] Comparing SRS objects
Frank Warmerdam
warmerdam at pobox.com
Mon Nov 20 16:26:14 EST 2006
David Fawcett wrote:
> In a Python script, I want to compare spatial reference systems. For
> context, I am creating a map image with Python MapScript, the map SRS is
> UTM, the layer SRS for one of the layers could sometimes be in UTM or
> sometimes in Lat/Long. The extent of the map will be based on this layer.
>
> As I build the layer, I want to check to see what SRS it is in, if it is
> in Lat/Long, I am planning to grab it's extent in lat/long, create a
> rectObj, and then project this rectObj to UTM so I can use the
> coordinates for my map extent.
>
> Assuming that this is a reasonable way to approach the problem, I am
> curious how to use OGR, OSR, or MapScript to compare SRS's. If I create
> SRS objects, can I just check that they are equal, as below, or do I
> need to dump them to WKT or proj Defs and do a string comparison?
>
> e.g.
>
> srs_one = osr.SpatialReference()
> srs_two = osr.SpatialReference()
>
> srs_one .ImportFromEPSG(4326)
> srs_two .ImportFromEPSG(26915)
>
> if srs_one == srs_two:
> print "they are the same"
> else:
> print "they are different"
David,
I think this will only determine if they are the same object, not if
the coordinate system description is the same. There is an IsSame()
method on the osr.SpatialReference, so you could instead do:
if srs_one.IsSame(srs_two):
...
that said, the IsSame() method is not really very robust.
Another approach would be to convert them both to WKT and compare those
strings, though you will get a lot of apparent differences which are
not actually significant to the underlying definition.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
More information about the FWTools
mailing list