Importing or exporting a spatial reference
This article shows how to create a predefined projected coordinate system (PCS), define its coordinate grid and tolerance values, then export and import it two different ways. First, it exports the coordinate system to a .prj file, then uses the contents of the .prj file to create a second PCS.
At the end of this process, you might expect that both PCSs will be identical, but they are not. PRJ files do not store coordinate grid information, so re-creating a spatial reference from a PRJ file will lose any coordinate grid and tolerance information that might have been defined for it.
Complete equality of spatial references (equal coordinate systems and equal coordinate grids) cannot be checked with one method. IClone.IsEqual compares coordinate systems but not coordinate grids. You need to use other methods to do the latter. See the following:
[Java]
static void importExportSR_Example()throws Exception{
//Instantiate a predefined spatial reference and set its coordinate grid information.
ISpatialReferenceFactory spatialReferenceFactory = new
SpatialReferenceEnvironment();
IProjectedCoordinateSystem projectedCoordinateSystem =
spatialReferenceFactory.createProjectedCoordinateSystem((int)
esriSRProjCSType.esriSRProjCS_WGS1984UTM_10N);
ISpatialReferenceResolution spatialReferenceResolution =
(ISpatialReferenceResolution)projectedCoordinateSystem;
ISpatialReferenceTolerance spatialReferenceTolerance =
(ISpatialReferenceTolerance)projectedCoordinateSystem;
spatialReferenceResolution.constructFromHorizon();
spatialReferenceTolerance.setDefaultXYTolerance();
//Export the PCS to a .prj file.
String fileName = "c:\\temp\\utm10.prj";
spatialReferenceFactory.exportESRISpatialReferenceToPRJFile(fileName,
projectedCoordinateSystem);
//Rehydrate it as a new spatial reference object.
ISpatialReference projectedCoordinateSystem2 =
spatialReferenceFactory.createESRISpatialReferenceFromPRJFile(fileName);
//See if they are equal.
IClone comparison = (IClone)projectedCoordinateSystem;
//Should be true, but coordinate grid information has not been checked.
System.out.println(comparison.isEqual((IClone)projectedCoordinateSystem2));
ISpatialReference2 comparePrecisions = (ISpatialReference2)
projectedCoordinateSystem;
//Should be false, PRJ files do not persist coordinate grid information.
System.out.println(comparePrecisions.isXYPrecisionEqual
(projectedCoordinateSystem2));
}
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |