除了ISpatialReferenceFactory接口,AE还提供ISpatialReferenceFactory3接口实现了创建垂直坐标系、构建高精度坐标系和低精度坐标系的系列方法。
private void ConstructCoordinateSystem(bool highPrecision)
{
ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference3 spatialReference = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile("D://ArcGIS//Coordinate Systems//Geographic Coordinate Systems//World//WGS 1984.prj") as ISpatialReference3;
IControlPrecision2 controlPrecision = spatialReference as IControlPrecision2;
//Determines whether you are constructing a high or low.
controlPrecision.IsHighPrecision = highPrecision;
ISpatialReferenceResolution spatialReferenceResolution = spatialReference as ISpatialReferenceResolution;
//These three methods are the keys, construct horizon, then set the default x,y resolution and tolerance.
spatialReferenceResolution.ConstructFromHorizon();
//Set the default x,y resolution value.
spatialReferenceResolution.SetDefaultXYResolution();
//Set the default x,y tolerance value.
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReference as ISpatialReferenceTolerance;
spatialReferenceTolerance.SetDefaultXYTolerance();
double xMin;
double xMax;
double yMin;
double yMax;
spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax);
System.Windows.Forms.MessageBox.Show("Domain : " + xMin + ", " + xMax + ", " + yMin + ", " + yMax);
}
IControlPrecision2.IsHighPrecision 用来判断是否对数据采用高精度坐标,后面的设置空间参考的方法将根据这个判断来决定各种参数的精确程度。 highPrecision 等于 true 或 false 时,返回的 Domain 分别是:
highPrecision=true -400 9006799.25474099 -400 9006799.25474099
highPrecision=false -400 793.04646944444426 -400 793.04646944444426
可以看出两者之间精度差别的大小。
我们可以创建一个新的投影坐标系并保存为prj文件,同时可以利用这个prj生成一个新的投影坐标系。
private void ImportExportSR_Example()
{
//Instantiate a predefined spatial reference and set its coordinate grid information.
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_10N);
ISpatialReferenceResolution spatialReferenceResolution = projectedCoordinateSystem as ISpatialReferenceResolution;
ISpatialReferenceTolerance spatialReferenceTolerance = projectedCoordinateSystem as ISpatialReferenceTolerance;
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 = projectedCoordinateSystem as IClone;
//Should be true, but coordinate grid information has not been checked.
System.Windows.Forms.MessageBox.Show((comparison.IsEqual(projectedCoordinateSystem2 as IClone)).ToString());
ISpatialReference2 comparePrecisions = projectedCoordinateSystem as ISpatialReference2;
//Should be false, PRJ files do not persist coordinate grid information.
System.Windows.Forms.MessageBox.Show((comparePrecisions.IsXYPrecisionEqual(projectedCoordinateSystem2)).ToString());
}