Spatial reference and coordinate conversion

 Transfer: https: //www.cnblogs.com/lonelyxmas/p/5784699.html

The same datum coordinate conversion 

For the same plane, we can be sure it is the same location as latitude and longitude coordinates, and the difference is calculated as the plane coordinates of time may be different, because the algorithm is not the same, here I will just turn into latitude and longitude coordinates of the coordinate plane .

Copy the code
 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; } } 
Copy the code

Different datum coordinate conversion 

By the previous description, we know the coordinates of the same position on the earth surface at a different reference are not the same, and a part constituting the reference surface of the coordinate system, because when the reference surface positioned relative translation involves the center of the earth, or rotation, so for this conversion we can not directly requires a conversion parameters, and these parameters are also based on different models, commonly used three parameters and 7 parameters, the three parameters is relatively simple but also relatively easy to understand, the three parameters is a X, Y, Z axis translation between the two reference plane, the following figure we clearly see the relationship between the two reference plane three parameters:

7 while the model parameters is more complex, this complex while allowing precision is improved, considering not only the parameter 7 of the translation between the two reference plane, also considered a scale factor rotation plus (the size may be different ellipsoid ).

For conversion between different plane, ArcGIS Engine provides an interface for controlling a IGeoTransformation conversion parameters, the interface is implemented following classes;

Each interface corresponds with a conversion method, such GeocentricTranslationClass class implements three parameters, the parameters CoordinateFrameTransformationClass class implements 7, ProjectEx method parameters or 3 or 7 IGeometry2 update interface parameters need to be achieved, we use the following code to achieve a conversion between different coordinate plane. 

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 = to true ;   
            pFromPoint.Z = 958.4791 ;  
            // ((IGeometry) pFromPoint) .SpatialReference = pFromCustom; 
            // custom Beijing 6 degrees with the projection 19 WGS84. ((IGeometry) pFromPoint) .SpatialReference CreateCustomProjectedCoordinateSystem = ();              // target projection projectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem IProjectedCoordinateSystem ((int) esriSRProjCS4Type.esr iSRProjCS_Xian1980_GK_Zone_19);              // Since the original target plane and not on the same plane, it involves the conversion parameters, the conversion parameters I 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) is 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;             
            objectpParametersObject = pParameters as object ;  
            pProjectedCoordinateSystemEdit.Define ( ref pName, ref Palia, 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;  
}

 

Guess you like

Origin www.cnblogs.com/leebokeyuan/p/11613124.html