Assign SpatialReference to Map

473
1
12-03-2019 07:19 AM
CarstenSchumann
Occasional Contributor

I have a map containign some layers in a user-defined spatial-reference (some version of the German DE_DHDN_3GK2). As of the docs my map gets the spatial-reference of ther very first layer, which is identical to the mentioned one. 

However when I assign another reference-sytem to my map, nothing happens:

var myMap = ((IMxDocument)myApp.Document).FocusMap;
myMap.SpatialReference = anotherWorkspace.SpatialReference;‍‍‍‍

In particular when I query the properties of the maps spatial-reference I get its old values:

((ISpatialReferenceResolution)myMap.SpatialReference).get_XYResolution(false);‍‍

The same applies when I use this:

((ISpatialReference)myMap.SpatialReference).GetFalseOriginAndUnits(out var falseX, out var falseY, out var xyUnits);‍‍‍

So I wonder if assigning a spatial-reference to a map has any purpose at all.

When I compare the spatial references using 

var transformEqual = ((IClone)myMap.SpatialReference).IsEqual((IClone)anotherWorkspace.SpatialReference);
myMap.SpatialReference.IsPrecisionEqual(anothrWorkspace.SpatialReference, out var precisionEqual);

I get true for transformEqual and false for precisionEqual, which makes me assume that the setter for IMap.SpatialReference checks for IClone.IsEqual first and does nothing in case of true.

The above code runs in an AddIn on ArcMap 10.6.1.

0 Kudos
1 Reply
CarstenSchumann
Occasional Contributor

Seems we can´t assign a new spatial-reference, but modify the existing to fit the parameters of the provided one:

((IClone)myMap.SpatialReference).Assign((IClone)anotherWorkspace.SpatialReference);
0 Kudos