ArcGIS Engine provides a series of objects for developers to manage Coordinate Systems of GIS systems.
For most developers, understanding ProjectedCoordinateSysteM, GeographicCoordinateSystEm,
SpatialReference Environment is necessary for the three component classes,
For advanced developers, you may need to use a custom coordinate system.
These objects include Projection, Datum, AngularUnit, Spheriod, PrimeMeridian, and
GeoTransformation.
1. ISpatialReference geographical coordinate system object
(The setting of spatial reference mainly refers to the geographic coordinate system object. After setting it, assign it to the desired object)
// Create a geographic coordinate system object
ISpatialReferenceFactorySpatialReferenceFactory = new SpatialReferenceEnvironmEntClass ();
ISpatialReference spatialReference = spatialReferenceFactory. CreateGeographicCoordinaTeSystem (int) esriSRGeoCSType. esriSRGeoCS_WGS1984 );
2. Spatial Change reference
The AlterSpatialReference method of the IGeoDatasetSchemaEdit interface can be used to change the spatial reference.Attribute to see if it can be changed
PGeoDatasetSchemaEdit. AlterSpatialReference (pSpatialReference );
Instance:
/// <Summary>
/// Reference for changing the space of a Layer
/// </Summary>
/// <Param name = "pFeatureLayer"> layer </param>
/// <Param name = "pGeoType"> spatial reference type </param>
Private void ChangeLayerRef (IFeatureLayer pFeatureLayer, int gcsType)
{
Try
{
IFeatureClass pFeatureClass = pFeatureLayer. FeatureClass;
// QI to IGeoDataset
IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
// QI to IGeoDatasetSchemaEdit
IGeoDatasetSchemaEdit pGeoDatasetSchemaEdit = pGeoDataset as IGeoDatasetSchemaEdit;
If (pGeoDatasetSchemaEdit. CanAlterSpatialReference= True)
{
// Create SpatialReferenceEnvironmEntClass object
ISpatialReferenceFactory2 pspareffacloud = new SpatialReferenceEnvironmEntClass ();
// Create a geographic coordinate system object
IGeographicCoordinateSysTem pNewGeoSys = pspareffacloud. CreateGeographicCoordinaTeSystem (gcsType); // 4214 stands for Beijing1954
PGeoDatasetSchemaEdit. AlterSpatialReference (pNewGeoSys );
}
}
Catch (Exception Err)
{
MessageBox. Show (Err. Message, "prompt", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
}
3. Spatial coordinate Enumeration
EsriSRGeoCSType
EsriSRProjCSType
4. Custom Coordinate System
Use ArcMap to define the coordinate system and export it to a prj file. Use ISpatialReferenceFactory. createesrispatialreferencefromp1_file to create a coordinate system.