[FWTools] Comparing SRS objects

David Fawcett david.fawcett at gmail.com
Mon Nov 20 11:22:15 EST 2006


Thanks guys.

Since I am really only looking at two potential SRS's, I think that I will
end up dumping the SRS to wkt and using the find() method to see if the wkt
contains 'NAD_1983_UTM_Zone_15N' or even just 'UTM' or 'WGS', depending on
which one I am looking for.

I was hoping to write something that was more extensible, but don't really
need to.  When I came up with the idea for this script, I had just assumed
that there was a exportToEPSG() function  ; /

Ed, I appreciate your comments on how there really is no good way to do
this.  With the relatively small community of people writing Python GDAL and
MapScript code, it is hard to get a feeling for best practices or most
efficient ways of doing things.

David.

On 11/20/06, Ed McNierney <ed at topozone.com> wrote:
>
> David -
>
> In my (limited) experience I have found this an exceptionally difficult
> thing to do.  I found it hard enough that I gave up!
>
> We used to offer an ArcIMS interface to our WMS image services.  We
> created an ArcIMS emulator that, in essence, translated ArcIMS image
> requests to WMS image requests.  This worked fine until ESRI changed the
> ArcGIS client interface so it specified the image SRS in WKT format
> rather than with an EPSG index.  Since the WMS interface required an
> EPSG index, we needed to translate arbitrary WKT descriptions (esp.
> ESRI-flavored ones) into EPSG codes.  Oy!  Since there is a reasonable
> degree of flexibility in a WKT description, it is quite easy to come up
> with two WKT projections that are, in practice, "the same projection"
> but which look different.
>
> Fortunately, that was the same release in which ESRI added real OGC WMS
> client support to ArcGIS, so we simply surrendered and discontinued
> ArcIMS support, and provided support exclusively for our OGC WMS
> interface.
>
> This is one of the chief benefits, IMHO, of the EPSG or any other
> catalog-style system.  EPSG:4326 is the same as EPSG:4326 and is not the
> same as EPSG:26915 and that's pretty darn easy to figure out.
>
>         - Ed
>
> Ed McNierney
> President and Chief Mapmaker
> TopoZone.com / Maps a la carte, Inc.
> 73 Princeton Street, Suite 305
> North Chelmsford, MA  01863
> ed at topozone.com
> (978) 251-4242
>
> -----Original Message-----
> From: fwtools-bounces at lists.maptools.org
> [mailto:fwtools-bounces at lists.maptools.org] On Behalf Of Frank Warmerdam
> Sent: Monday, November 20, 2006 4:26 PM
> To: David Fawcett
> Cc: fwtools at lists.maptools.org
> Subject: Re: [FWTools] Comparing SRS objects
>
> 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
>
> _______________________________________________
> FWTools mailing list
> FWTools at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/fwtools
> http://fwtools.maptools.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20061120/a7c86847/attachment.html


More information about the FWTools mailing list