
AE中及坐标系统转换.doc
8页AE 中的坐标系统转换ArcEngine 开发总结 2008-09-04 22:47:33 阅读 405 评论 0 字号:大中小 在搞 AE 开发的时候,经常碰到的一个问题就是不同坐标系统之间的转换,AE 中 IGlobeControl 控件中提供了 IGlobeViewUtil 类实现了大地坐标、屏幕坐标和地理坐标三者之间的转换,IMapControl 中则提供了 ToMapPoint 和 FromMapPoint 两种方法实现屏幕坐标和地理坐标之间的转换,但在实际开发中,这些转换还不够,比如当我们需要实现地理坐标转换到自定义格式的大地坐标时,上述方法则不能解决这些问题,最好的解决方法是使用 IGeometry 对象的 Project 方法,实现不同空间参照系之间的相互转换以下以地理坐标转为自定义的 Albers 坐标系统为例予以说明,其主要用到的接口有ISpatialReferenceFactory、IProjectedCoordinateSystem 、IProjectedCoordinateSystemEdit 、ISpatialReferenceFactory、IGeographicCoordinateSystem 、ISpatialReference 等:其 C#代码如下://将任意坐标系统转换为自定义 Albers 大地坐标(米)public static IPoint GeoToGra(IPoint point){IPoint pt = new PointClass();pt.PutCoords(point.X,point.Y);ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass();//定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSTypeIGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass();pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode);//自定义投影方式IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass();IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit;//定义投影方式,参考: esriSRProjectionTypeIProjection pProjection = new ProjectionClass();pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers);//定义投影单位,参考:esriSRUnitTypeILinearUnit pUnit = new LinearUnitClass();pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;//定义其他参数,参考:esriSRParameterTypeIParameter[] pParm = new IParameter[6];pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting);pParm[0].Value = 0;pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing);pParm[1].Value = 0;pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian);pParm[2].Value = 110;pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1);pParm[3].Value = 25;pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2);pParm[4].Value = 47;pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin);pParm[5].Value = 0;//设置投影相关信息object name = "User_Defined_Albers";object alias = "Albers";object abbreviation = "Albers";object remarks = "User_Defined_Albers is the projection";object usage = "";object gcs = pGCS;object projectedUnit = pUnit;object projection = pProjection;object parameters = pParm;pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref projectedUnit, ref projection, ref parameters);//获取自定义空间参考ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference;IGeometry pGeometry = (IGeometry)pt;pGeometry.SpatialReference = pGCS as ISpatialReference;//重投影处理pGeometry.Project(pSpatialRef);return pt;} //将平面坐标转换为地理坐标 WGS1984(经纬度)public static IPoint GetGeo(IGeometry pg){IPoint pt = new PointClass();pt.PutCoords(pg.Envelope.XMax, pg.Envelope.YMax); //这里 IGeometry 对象可换成 IPoint 等对象ISpatialReferenceFactory2 spatialReferenceFact = new SpatialReferenceEnvironmentClass();IGeometry geo = (IGeometry)pt;geo.SpatialReference = spatialReferenceFact.CreateProjectedCoordinateSystem(pg.SpatialReference.FactoryCode);ISpatialReference pSR = spatialReferenceFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);geo.Project(pSR); return pt;}以上实现可以参考 ESRI 提供的相关帮助示例文档:IProjectedCoordinateSystemEdit_Define_Example、CreateParameter_Example 、ISpatialReferenceFactory_Example、CreateProjection_Example、CreateUnit_ExampleCreateGeographicCoordinateSystem_Example、CreateProjectedCoordinateSystem_Example自定义不同的坐标系统,需要设置不同的参数,所有的地图投影都必须有 FalseEasting 和 FalseNorthing 两个参数,每种不同投影的其他参数的参数如下所示,具体参照:IProjectedCoordinateSystemEdit InterfaceAitoffCentralMeridian AlbersCentralMeridian StandardParallel1StandardParallel2LatitudeOfOrigin Azimuthal_EquidistantCentralMeridian LatitudeOfOrigin BehrmannCentralMeridian BonneCentralMeridian StandardParallel1CassiniCentralMeridian ScaleFactor LatitudeOfOrigin Craster_ParabolicCentralMeridian Cylindrical_Equal_AreaCentralMeridian StandardParallel1Double_StereographicCentralMeridian ScaleFactor LatitudeOfOrigin Eckert_ICentralMeridian Eckert_IICentralMeridian Eckert_IIICentralMeridian Eckert_IVCentralMeridian Eckert_VCentralMeridian Eckert_VICentralMeridian Equidistant_ConicCentralMeridian StandardParallel1StandardParallel2LatitudeOfOrigin Equidistant_CylindricalCentralMeridian StandardParallel1Flat_Polar_QuarticCentralMeridian Gall_StereographicCentralMeridian Gauss_KrugerCentralMeridian ScaleFactor LatitudeOfOrigin GnomonicLongitudeOfCenter LatitudeOfCenter Hammer_AitoffCentralMeridian Hotine_Oblique_Mercator_Azimuth_CenterScaleFactor Azimuth LongitudeOfCenter LatitudeOfCenter Hotine_Oblique_Mercator_Azimuth_Natural_OriginScaleFactor Azimuth LongitudeOfCenter LatitudeOfCenter Hotine_Oblique_Mercator_Two_Point_CenterLatitudeOf1stLatitudeOf2ndScaleFactor Lon。












