4

I am creating an ArcMap 10.2 extension is VS 2012 and C#. I want to give the user the option to select a spatial reference to be applied to a layer - planning to use the Dialog for that.

But then, I want to be able to save the name of the SR the user selected to an custom XML settings file so that when they come back to the same section it will be set by default (and they can use the Dialog to change it if needed). This is where I am stuck.

My plan was to use that string name and recreate the SR object by see no option for it in something like ISpatialReferenceFactory3.

As an example, if I run this code on an mxd using a New Jersey projected coordinate system:

ISpatialReference SR = new UnknownCoordinateSystemClass();
IMxDocument Mxd =  (IMxDocument)WestonGISExtension.ExtensionApplicationHook.Document;
ESRI.ArcGIS.Carto.IMap Map = Mxd.FocusMap;
if (Map.SpatialReference != null)
    SR = Map.SpatialReference;

then, the SR.Name would produce, say, "NAD_1983_StatePlane_New_Jersey_FIPS_2900_Feet". So, how do I later come back with that string and reproduce the SpatialReferenceClass?


Thanks guys. Ya, I think you are right in going with the WKID. Here is what I settled on:

ISpatialReferenceFactory3 SpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference SpatialReference = SpatialReferenceFactory.CreateSpatialReference(SpatialReferenceCode);

Ernie

  • 3
    I am afraid the Name only will not suffice for reconstructing the spatial reference. Would you be willing to persist the whole WKT/PRJ definition as a string? – Petr Krebs Dec 5 '13 at 20:16
4

Check for the FactoryCode on ISpatialReferenceInfo instead. ArcPy might have a method to create a spatial reference from the name, but ArcObjects doesn't have one.

FactoryCode is the same as the EPSG or Esri well-known ID. Ex. The Geographic Coordinate Reference System (2D) WGS 1984 is 4326 (EPSG).

Std Disclaimer: I work for Esri and am on the subcommittee that maintains the EPSG Geodetic Parameter Dataset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.