Flyingis]ArcEngine中的Spatial Refrence (3)

 

除了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());
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值