compare spatial references

178
2
10-26-2018 02:55 AM
CarstenSchumann
Occasional Contributor

In order to compare the spatial reference of my map and this of my database I use the following code:

var mapSR = myMap.ActiveView.SpatialReference;
var gdbSR = ((IGeoDataset)myFeatureClass).SpatialReference;

bool areSame = ((IClone)mapSR).IsEqual((IClone)gdbSR);
if(areSame)  // also compare map-resolution as suggested here: https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#ISpatialReference_IsPrecisionEqual....
    mapSR.IsPrecisionEqual(gdbSR, out areSame);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

After calling IsPrecisionEqual areSame will be false (I ensured the method was called by setting a breakpoint), which I don´t understand. When I dive into the spatial references, e.g. using a watch, I can´t see any (meaningful) differences:

(ISpatialReferenceResolution)mapSR
COM Object
    [System.__ComObject]: COM Object
    Abbreviation: ""
    Alias: ""
    FactoryCode: 0
    MResolution: 0.0001
    MResolution: 0.0001
    MTolerance: 0.001
    MToleranceValid: esriSRToleranceOK
    Name: "ETRS89_UTM32"
    PrecisionExImpl: 1529763776
    PrecisionImpl: 1533456216
    Remarks: ""
    SpatialReferenceImpl: 689094056
    VerticalCoordinateSystem: null
    XYTolerance: 0.0001
    XYToleranceValid: esriSRToleranceOK
    ZCoordinateUnit: null
    ZTolerance: 0.001
    ZToleranceValid: esriSRToleranceOK
(ISpatialReferenceResolution)gdbSR
COM Object
    [System.__ComObject]: COM Object
    Abbreviation: null
    Alias: null
    FactoryCode: 0
    MResolution: 0.0001
    MResolution: 0.0001
    MTolerance: 0.001
    MToleranceValid: esriSRToleranceOK
    Name: "ETRS89_UTM32"
    PrecisionExImpl: 1103993808
    PrecisionImpl: 1100159248
    Remarks: null
    SpatialReferenceImpl: 689094056
    VerticalCoordinateSystem: null
    XYTolerance: 0.0001
    XYToleranceValid: esriSRToleranceOK
    ZCoordinateUnit: null
    ZTolerance: 0.001
    ZToleranceValid: esriSRToleranceOK
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Also get_XYResolution(false) returns 0.00001 (which is 10times the XYTolerance, as seen above) for both the maps and the databases spatial reference.

I also tried to use ISpatialReference3.IsXYResolutionEqual, because I´m only interested in plane resolution and tolerance. However this also returns false when comparing the two spatial references. So what do IsXYResolutionEqual and IsResolutionEqual compare asside from the above properties? Are those Impl- and ExImp-properties considered as well (which is not documented)?

0 Kudos
2 Replies
GintautasKmieliauskas
Regular Contributor

Hi Carsten,

Do you need to check are spatial references are exactly the same? If yes, you could use IClone method IsEqual. I also tried to use IsXYPrecisionEqual, but without success. 

0 Kudos
CarstenSchumann
Occasional Contributor

As you see in my code I already use IClone.IsEqual. However as of the docs this does not consider any information about precision and tolerance, which is why I use IsPrecisionEqual

0 Kudos