码迷,mamicode.com
首页 > 其他好文 > 详细

空间参考及坐标转换

时间:2019-09-30 16:21:44      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:beijing   htm   ted   地球   接口   arcgis   war   cal   direction   

 转自:https://www.cnblogs.com/lonelyxmas/p/5784699.html

同一基准面的坐标转换 

对于同一基准面,我们可以肯定一点就是同一位置经纬度坐标是一样的,而不同的就是计算成平面坐标的时候可能有所不同,因为算法不一样,在这里我只是将经纬度坐标转成平面的坐标。

技术图片
技术图片
 private IPoint GetpProjectPoint(IPoint pPoint, bool pBool)         
 {             
     ISpatialReferenceFactory pSpatialReferenceEnvironemnt = new SpatialReferenceEnvironment();             
     ISpatialReference pFromSpatialReference = pSpatialReferenceEnvironemnt.CreateGeographicCoordinateSystem((int)esriSRGeoCS3Type .esriSRGeoCS_Xian1980);//西安80 
     ISpatialReference pToSpatialReference = pSpatialReferenceEnvironemnt.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type .esriSRProjCS_Xian1980_3_Degree_GK_Zone_34);//西安80             
     if (pBool == true)//球面转平面            
        {                   
            Geometry pGeo = (IGeometry)pPoint;                 
            pGeo.SpatialReference = pFromSpatialReference;               
            pGeo.Project(pToSpatialReference);                 
            return pPoint;             
        }             
        else //平面转球面             
        {  
        IGeometry pGeo = (IGeometry)pPoint;                 
        pGeo.SpatialReference = pToSpatialReference;                
        pGeo.Project(pFromSpatialReference);                 
        return pPoint;             
        }         
} 
技术图片

不同基准面的坐标转换 

通过前面的介绍,我们知道地球上同一位置的坐标在不同的基准面上是不一样的,而基准面是构成坐标系的一个部分,因为基准面在定位的时候牵扯到了相对地心的平移或旋转等,所以对于这样的转换我们无法直接进行,需要一个转换参数,而这些参数也是基于不同的模型的,常用的有三参数和 7 参数,三参数是比较简单的也是比较容易理解的,三参数是在两个基准面之间进行了 X,Y,Z 轴的平移,通过下面的图我们很清楚的看到三参数之间两个基准面的关系:

而 7 参数的模型比较复杂,这种复杂的同时让精度大为提高,7参数不仅仅考虑了两个基准面之间的平移,还考虑了旋转外加一个比例因子(椭球体的大小可能不一样).

对于不同基准面之间的转换,ArcGIS Engine 提供了一个用来控制转换参数的接口 IGeoTransformation,该接口被以下类实现;

着每一个接口对应了一种转换方法,比如 GeocentricTranslationClass类就实现了三参数,而CoordinateFrameTransformationClass 类实现了7 参数,要实现 3 参数或者 7 参数需要 IGeometry2 或更新接口的ProjectEx 方法,下面我们用代码实现一个不同基准面之间的坐标转换。 

public void ProjectExExample()        
 {                          
            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();  // ISpatialReference pFromCustom = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(@"E:\arcgis\Engine\z idingyi.prj");  
            IPoint pFromPoint = new PointClass();  
            pFromPoint.X = 518950.788;  
            pFromPoint.Y = 4335923.97;  
            IZAware pZAware = pFromPoint as IZAware;  
            pZAware.ZAware = true;  
            pFromPoint.Z = 958.4791;  
           // ((IGeometry)pFromPoint).SpatialReference = pFromCustom; 
           //自定义投影WGS84下的北京6度19带。             ((IGeometry)pFromPoint).SpatialReference = CreateCustomProjectedCoordinateSystem();             //目标投影             IProjectedCoordinateSystem projectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esr iSRProjCS_Xian1980_GK_Zone_19);             //因为目标基准面和原始基准面不在同一个上,所以牵扯到参数转换,我用7参数 转换             ICoordinateFrameTransformation   pCoordinateFrameTransformation = new CoordinateFrameTransformationClass();  
            pCoordinateFrameTransformation.PutParameters(-112.117, 4.530, 21.89, -0.00058702, -0.00476421, 0.00009358, 0.99998006411);   
            pCoordinateFrameTransformation.PutSpatialReferences(CreateCustomProjectedCoordinate System(), projectedCoordinateSystem as ISpatialReference);                       
            //投影转换             IGeometry2 pGeometry = pFromPoint as IGeometry2;  
            pGeometry.ProjectEx(projectedCoordinateSystem as ISpatialReference, esriTransformDirection.esriTransformForward, pCoordinateFrameTransformation, false, 0, 0);  
                }   
private IProjectedCoordinateSystem CreateCustomProjectedCoordinateSystem()         
{  
            ISpatialReferenceFactory2 pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();  
            IProjectionGEN pProjection = pSpatialReferenceFactory.CreateProjection((int) esriSRProjectionType.esriSRProjection_GaussKruger) as IProjectionGEN;IGeographicCoordinateSystem pGeographicCoordinateSystem = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);             
            ILinearUnit pUnit = pSpatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;  
            IParameter[] pParameters = pProjection.GetDefaultParameters();  
            IProjectedCoordinateSystemEdit pProjectedCoordinateSystemEdit = new ProjectedCoordinateSystemClass();   
            object pName = "WGS-BeiJing1954";             
            object pAlias = "WGS-BeiJing1954";             
            object pAbbreviation = "WGS-BeiJing1954";             
            object pRemarks = "WGS-BeiJing1954";             
            object pUsage = "Calculate Meter From lat and lon";             
            object pGeographicCoordinateSystemObject = pGeographicCoordinateSystem as object;             
            object pUnitObject = pUnit as object;             
            object pProjectionObject = pProjection as object;             
            object pParametersObject = pParameters as object;  
            pProjectedCoordinateSystemEdit.Define(ref pName, ref pAlias, ref pAbbreviation, ref  pRemarks, ref pUsage, ref pGeographicCoordinateSystemObject, ref pUnitObject,ref pProjectionObject, ref pParametersObject);  
            IProjectedCoordinateSystem5 pProjectedCoordinateSystem = pProjectedCoordinateSystemEdit as IProjectedCoordinateSystem5;  
            pProjectedCoordinateSystem.FalseEasting = 500000;  
            pProjectedCoordinateSystem.LatitudeOfOrigin = 0;  
            pProjectedCoordinateSystem.set_CentralMeridian(true,111);  
            pProjectedCoordinateSystem.ScaleFactor=1;            
            pProjectedCoordinateSystem.FalseNorthing=0;  
            return pProjectedCoordinateSystem;  
}

 

空间参考及坐标转换

标签:beijing   htm   ted   地球   接口   arcgis   war   cal   direction   

原文地址:https://www.cnblogs.com/leebokeyuan/p/11613124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!