[postgis-users] Comparing two WKT... howto?

Frank Warmerdam warmerdam at pobox.com
Thu Nov 18 07:11:08 PST 2004


Luigi Pirelli wrote:
> Hi,
> 
> I've this problem, I've to compare two WKT strings (first extracted bye 
> spatial_ref_sys PostGis table and second from g.proj -wf Grass commad).
> 
> They differ in format but they refer to the same projection (e.g 
> ellipsoy could expressed by symbolic name or geometric parameters)
> 
> There's applications of library that help to compare them?
> 
> could be simplest to compare PROJ4 strings (+format)?

Luigi,

Good question(s)!  In general comparing coordinate systems can be challenging.

Comparing PROJ.4 strings will often be easier than comparing WKT but if the PROJ.4
representations are produced by different software (or by hand!) then arguments
are likely to be in different orders and one definition may contain parameters
that are just the defaults, and omitted from the other.   Ideally PROJ.4 itself
would have a comparison function but currently it does not.

If comparing WKT strings you pretty much have to have an "in depth" comparitor
since lots stuff, such as coordinate system names, can differ with no real
significance.  Likewise there are lots of optional elements in WKT that may
appear in one representation and not another with no real significance.

If both definitions include an AUTHORITY definition on the root level object,
you have a short cut available to compare the authority codes.  If those match
you aren't required to check everything else.

In the GDAL/OGR library, the OGRSpatialReference class includes an IsSame()
method that can be used to compare two coordinate systems generated from
WKT.  But to be honest, the implementation is far from complete.  If within
the context of what you are doing you know you will have OGR available I
would suggest using that method, and then we can cooperate to make it better
if/when you run into limitations.

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    | Geospatial Programmer for Rent




More information about the postgis-users mailing list