[gdal-dev] Testing if two spatial references are the same

Simon Perkins sy at perkins.net
Wed Dec 26 15:23:43 EST 2007


I have a file, which is giving me some strange results with the 
OGRSpatialReference.IsSame() method. Here's a short test program:

#include "gdal_priv.h"
#include "ogr_spatialref.h"
#include "ogr_core.h"
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    GDALAllRegister();
    const char* filename = argv[1];
    GDALDataset* dataset = (GDALDataset*) GDALOpen(filename, GA_ReadOnly);
    cout << "Opened file: " << filename << "\n";
    const char* projWkt = dataset->GetProjectionRef();
    cout << "Raw Projection WKT: " << projWkt << "\n";
    OGRSpatialReference* spatialRef = new OGRSpatialReference(projWkt);
    char* prettyWkt = new char[4096];
    spatialRef->exportToPrettyWkt(&prettyWkt, 0);
    cout << "Pretty Projection WKT:\n" << prettyWkt << "\n";
    cout << "Result from s.IsSame(s): " << 
spatialRef->IsSame(spatialRef) << "\n";
    return 0;
}


Basically, the code opens a raster file, grabs the projection Well Known 
Text string, constructs an OGRSpatialReference using that string, and 
then compares that spatial reference to itself using the IsSame() 
method. One would expect that a spatial reference is the same as itself, 
so this method should return 1.

Here's the output from a particular file:

Opened file: C:/Images/Demo/K10.tif
Raw Projection WKT: 
PROJCS["unnamed",GEOGCS["NAD83",DATUM["North_American_Datum_
1983",SPHEROID["GRS 
1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AU
THORITY["EPSG","6269"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4269"]],UNIT["US survey 
foot",0.3048006096012192,AUTHORITY["EP
SG","9003"]],AUTHORITY["EPSG","26942"]]
Pretty Projection WKT:
PROJCS["unnamed",
    GEOGCS["NAD83",
        DATUM["North_American_Datum_1983",
            SPHEROID["GRS 1980",6378137,298.2572221010002,
                AUTHORITY["EPSG","7019"]],
            AUTHORITY["EPSG","6269"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4269"]],
    UNIT["US survey foot",0.3048006096012192,
        AUTHORITY["EPSG","9003"]],
    AUTHORITY["EPSG","26942"]]
Result from s.IsSame(s): 0

Any ideas what's going on here? Is it something specific to this 
particular projection string? Is there a better way of checking 
equivalence of projected coordinate systems, e.g. using the EPSG code? 
What would I have to check to ensure equivalency?

Regards,

Simon




More information about the gdal-dev mailing list