基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码

空间参考是地理空间要素的重要属性,也是地理信息数据处理的关键要素;本文将对Arcengine中与地图投影相关的接口及方法进行系统而全面的分析,希望能为大家的工作和学习提供一定的帮助。

主要介绍IGeographicCoordinateSystem,IProjectedCoordinateSystem和ISpatialReferenceFactory三个接口的成员及示例代码

几点总结:

类别 坐标系统名称 工厂代码 说明
投影坐标系 CGCS2000_3_Degree_GK_CM_75E  4534 2000坐标系下3度分带75度分带坐标,横坐标前不加带号
CGCS2000_3_Degree_GK_Zone_25 4513 2000坐标系下3度分带25带,横坐标前加带号
CGCS2000_GK_Zone_13 4491 2000坐标系下6度分带13带,横坐标前加带号
CGCS2000_GK_CM_75E  4502 2000坐标系下6度分带75度分带坐标,横坐标前不加带号
地理坐标系 GCS_China_Geodetic_Coordinate_System_2000  4490 2000地理坐标

 

1 地理坐标系与投影坐标系

地理坐标系是以经纬度表示地面目标信息的坐标系统,投影坐标系是有XY表示地面坐标信息的坐标系统

1.1 IGeographicCoordinateSystem

地理坐标,使用经纬度地理信息

该接口在10.1版本中已被IGeographicCoordinateSystem2接口替换,它提供了所有与地理坐标系统相关的属性。

属性/方法 英文描述 中文注释
Abbreviation The abbreviated name of this spatial reference component. 此空间引用组件的名称缩写
Alias The alias of this spatial reference component. 此空间引用组件的别名
Changed Notify this object that some of its parts have changed (parameter values, z unit, etc.).  
CoordinateUnit The angular unit of this geographic coordinate system. 地理坐标系统的角度单位
Datum The horizontal datum of this geographic coordinate system. 地理坐标系统的水平基准
FactoryCode The factory code (WKID) of the spatial reference.

投影引擎对象类型的唯一整数标识符,自定义投影坐标系该参数默认为0;具体整数值参见ISpatialReferenceFactory::CreateProjectedCoordinateSystem

方法

GetDomain The XY domain extent. 得到XY的区域范围
GetFalseOriginAndUnits Get the false origin and units. 得到XY域的最小坐标和分辨率的倒数
GetMDomain The measure domain extent. 得到XY域的最小坐标
GetMFalseOriginAndUnits Get the measure false origin and units.  
GetZDomain The Z domain extent.  
GetZFalseOriginAndUnits Get the Z false origin and units. 得到Z坐标方向上的最小值和单位
HasMPrecision Returns true when m-value precision information has been defined. 定义M值精度时,使用该参数
HasXYPrecision Returns true when (x,y) precision information has been defined. 定义(x,y)值精度时,使用该参数
HasZPrecision Returns true when z-value precision information has been defined.  
IsPrecisionEqual Returns TRUE when the precision information for the two spatial references is the same.  
Name The name of this spatial reference component.  
PrimeMeridian The prime meridian of this geographic coordinate system.  
Remarks The comment string of this spatial reference component.  
SetDomain The XY domain extent.  
SetFalseOriginAndUnits Set the false origin and units.  
SetMDomain The measure domain extent.  
SetMFalseOriginAndUnits Set the measure false origin and units.  
SetZDomain The Z domain extent.  
SetZFalseOriginAndUnits Set the Z false origin and units.  
Usage The usage notes of this geographic coordinate system.  
ZCoordinateUnit The unit for the Z coordinate.  

1.2 IProjectedCoordinateSystem

投影坐标系,目前已经升级到IProjectedCoordinateSystem5

Member Description
Abbreviation The abbreviated name of this spatial reference component.
Alias The alias of this spatial reference component.
Azimuth The azimuth of a projected coordinate system.
CentralMeridian The central meridian (Lambda0) of a projected coordinate system.
CentralParallel The central parallel (Phi 0) of a projected coordinate system.
Changed Notify this object that some of its parts have changed (parameter values, z unit, etc.).
ConvergenceAngle Returns the grid convergence angle .
CoordinateUnit The linear unit of a projected coordinate system.
FactoryCode The factory code (WKID) of the spatial reference.
FalseEasting The false easting (X0) of a projected coordinate system.
FalseNorthing The false northing (Y0) of a projected coordinate system.
Forward Projects points from geographic to planar coordinates.
GeographicCoordinateSystem The geographic coordinate system of a projected coordinate system.
GetCentralLongitude Returns CentralLongitude of the projected coordinate system. Always defined, unlike CentralMeridian or LongitudeOfCenter.
GetDomain The XY domain extent.
GetFalseOriginAndUnits Get the false origin and units.
GetGCSParams Returns 180 degrees and horizon delta in proper GCS units.
GetHorizon Returns the standard horizon polygon, its envelope, and whether it is inclusive or exclusive; the horizon polygon may be 0.
GetMDomain The measure domain extent.
GetMFalseOriginAndUnits Get the measure false origin and units.
GetNorthPole Returns the north pole in projected coordinates, or an empty point if the north pole is outside the PCS horizon.
GetNorthPoleGeometry Returns type of north pole geometry.
GetNorthPoleLocation Returns type of location of north pole with respect to the PCS horizon.
GetParameters Gets the map projection parameters of a projected coordinate system.
GetPCSHorizon Returns PCS horizon polygon, its envelope and whether it is inclusive or exclusive; the horizon polygon may be 0.
GetShiftedHorizon Returns the horizon polygon, shifted once or twice, west/east of the standard horizon for a negative/positive shift.
GetSouthPole Returns the south pole in projected coordinates, or an empty point if the south pole is outside the PCS horizon.
GetSouthPoleGeometry Returns type of south pole geometry.
GetSouthPoleLocation Returns type of location of south pole with respect to the PCS horizon.
GetZDomain The Z domain extent.
GetZFalseOriginAndUnits Get the Z false origin and units.
HasMPrecision Returns true when m-value precision information has been defined.
HasXYPrecision Returns true when (x,y) precision information has been defined.
HasZPrecision Returns true when z-value precision information has been defined.
Height The height above the sphere in projected coordinate system units.
Horizon The mathematical limits of a projected coordinate system.
HorizonCount The number of shapes that describe the limits of a ProjCS.
Inverse Projects points from planar to geographic coordinates.
InverseWithShift Projects points from planar to geographic coordinates. Deals with geographic coordinates in ranges other than +-180.
IsCentralLongitudeVertical Returns true if central meridian is a straight vertical line.
IsEqualNoNames Compares to projected coordinate systems for equality but ignores their names.
IsHorizonConvexHull Returns true if PCS horizon is convex.
IsHorizonEdgeDuplicated Returns true if some edges of PCS horizon project inversely to identical lines.
IsHorizonEntireWorld Returns true if PCS horizon contains the entire world.
IsPrecisionEqual Returns TRUE when the precision information for the two spatial references is the same.
LatitudeOf1st The latitude of the first point (Phi 1) of a projected coordinate system.
LatitudeOf2nd The latitude of the second point (Phi 2) of a projected coordinate system.
LatitudeOfCenter The latitude of center (Phi C) of a projected coordinate system.
LatitudeOfOrigin The latitude of the origin (Phi 0) of a projected coordinate system.
LongitudeOf1st The longitude of the first point (Lambda 1) of a projected coordinate system.
LongitudeOf2nd The longitude of the second point (Lambda 2) of a projected coordinate system.
LongitudeOfCenter The longitude of center (Lam C) of a projected coordinate system.
LongitudeOfOrigin The longitude of origin (Lambda0) of a projected coordinate system.
Name The name of this spatial reference component.
Projection The map projection of a projected coordinate system.
PseudoStandardParallel1 The latitude on an oblique spheroid that defines the oblique cone for a Krovak projected coordinate system.
PutLinearAndAngularUnits Modify linear unit of projected coordinates and angular unit of associated geographic coordinates.
Remarks The comment string of this spatial reference component.
Rotation The rotation value used to change the axis directions in a Krovak projected coordinate system.
ScaleFactor The scale factor (K0) of a projected coordinate system.
SetDomain The XY domain extent.
SetFalseOriginAndUnits Set the false origin and units.
SetMDomain The measure domain extent.
SetMFalseOriginAndUnits Set the measure false origin and units.
SetZDomain The Z domain extent.
SetZFalseOriginAndUnits Set the Z false origin and units.
StandardParallel1 The first parallel (Phi 1) of a projected coordinate system.
StandardParallel2 The second parallel (Phi 2) of a projected coordinate system.
Usage The usage notes of a projected coordinate system.
XScaleFactor The X axis scale value used to flip the axis direction in a Krovak projected coordinate system.
YScaleFactor The Y axis scale value used to flip the axis direction in a Krovak projected coordinate system.
ZCoordinateUnit The unit for the Z coordinate.

 

 

2. ISpatialReferenceFactory

此接口已被ISpatialReferenceFactory3所代替,

2.1 接口方法概览

AllPropertiesMethods Description 备注
CreateDatum Creates a predefined datum. 创建一个预定义椭球
CreateESRISpatialReference Creates a spatial reference system and defines it from the specified ESRISpatialReference buffer. 创建一个由ESRISpatialReference定义的空间参考系统
CreateESRISpatialReferenceFromPRJ Creates a spatial reference from a PRJ string. 根据一个投影字符串创建一个空间参考
CreateESRISpatialReferenceFromPRJFile Creates a spatial reference from a PRJ file. 根据投影文件创建空间参考
CreateGeographicCoordinateSystem Creates a predefined geographic coordinate system. 创建预定义的地理坐标系统
CreateGeoTransformation Creates a predefined transformation between geographic coordinate systems. 在两个地理坐标系之间创建一个预定变换
CreateParameter Creates a predefined parameter. 创建一个预定义参数 
CreatePredefinedAngularUnits Creates a list of predefined angular units. 创建预定义角度单位列表
CreatePredefinedDatums Creates a list of a list of predefined datums. 创建预定义基准列表
CreatePredefinedLinearUnits Creates a list of predefined linear units. 创建预定义的长度单位列表
CreatePredefinedPrimeMeridians Creates a list of predefined prime meridians. 创建预定义基本子午线列表
CreatePredefinedProjections Creates a list of predefined projections. 创建预定义的投影列表
CreatePredefinedSpheroids Creates a list of predefined spheroids. 创建预定义椭球列表
CreatePrimeMeridian Creates a predefined prime meridian. 创建基本子午线
CreateProjectedCoordinateSystem Creates a predefined projected coordinate system. 创建投影坐标系统
CreateProjection Creates a predefined projection. 创建预定义投影
CreateSpheroid Creates a predefined spheroid. 创建预定义椭球
CreateUnit Creates a predefined unit of measure. 创建预定义测度dan
ExportESRISpatialReferenceToPRJFile Exports a spatial reference to a PRJ file. 输出ESRI空间参考到投影文件

2.2 ISpatialReferenceFactory.CreateGeographicCoordinateSystem

public IGeographicCoordinateSystem CreateGeographicCoordinateSystem (int gcsType);

其参数由 esriSRGeoCSType, esriSRGeoCS2Type, or esriSRGeoCS3Type枚举器提供

使用代码示例

 ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create a geographic coordinate system using the available geographic
//coordinate systems. These can be found in the esriGeometry esriSRGeoCSType
//enumeration.
IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

2.2.1 Creating a predefined geographic coordinate system

ISpatialReferenceFactory 可以创建一个被 esriSRGeoCSType, esriSRGeoCS2Type, and esriSRGeoCS3Type枚举列表中包含的地理坐标系统

private void CreateGeographicCoordinateSystem()
{
    // Set up the SpatialReferenceEnvironment.
    // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.

    Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
    System.Object obj = Activator.CreateInstance(t);
    ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory;

    // Use the enumeration to create an instance of the predefined object.

    IGeographicCoordinateSystem geographicCS =
        srFact.CreateGeographicCoordinateSystem((int)
        esriSRGeoCSType.esriSRGeoCS_NAD1983);
}

2.2.2 Creating a custom geographic coordinate system

一个基本的地理坐标系统包括名称、角度单位、基准基本子午线,他是一个描述三维地球模型的坐标系统;我们可以通过IGeographicCoordinateSystem 接口获取主要的属性和方法,以及IGeographicCoordinateSystem2定义的额外属性;虽然我们不需要创建地理坐标系,但是IGeographicCoordinateSystemEdit 接口包含Define 和DefineEx 方法。

A GCS includes a name, angular unit of measure, datum (which includes a spheroid), and a prime meridian. It is a model of the earth in a three-dimensional (3D) coordinate system. Latitude-longitude or lat/lon data is in a GCS. You can access the majority of the properties and methods through the IGeographicCoordinateSystem interface with additional properties that are available in IGeographicCoordinateSystem2. Although most developers will not need to create a custom GCS, IGeographicCoordinateSystemEdit contains the Define and DefineEx methods.

下面是如何使用Define 方法创建用户定义GCS的示例,ISpatialReferenceFactory 允许创建基准、本初子午线、角度三维等要素

The following code example shows how to use the Define method to create a user-defined GCS. The ISpatialReferenceFactory interface allows you to create the Datum, PrimeMeridian, and AngularUnit component parts. These components can also be created using a similar Define method available on their classes.

private IGeographicCoordinateSystem CreateGeographicCoordinateSystem()
{
    // Set up the SpatialReferenceEnvironment.
    // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
    Type factoryType = Type.GetTypeFromProgID(
        "esriGeometry.SpatialReferenceEnvironment");
    System.Object obj = Activator.CreateInstance(factoryType);
    ISpatialReferenceFactory3 spatialReferenceFactory = obj as
        ISpatialReferenceFactory3;

    // Create the datum, prime meridian, and angular unit from existing definitions.
    IDatum datum = spatialReferenceFactory.CreateDatum((int)
        esriSRDatumType.esriSRDatum_OSGB1936);
    IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)
        esriSRPrimeMType.esriSRPrimeM_Greenwich);
    IUnit unit = spatialReferenceFactory.CreateUnit((int)
        esriSRUnitType.esriSRUnit_Degree);

    IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new
        GeographicCoordinateSystemClass();

    object name = "UserDefined Geographic Coordinate System";
    object alias = "UserDefined GCS";
    object abbreviation = "UserDefined";
    object remarks = "User Defined Geographic Coordinate System based on OSGB1936";
    object usage = "Suitable for the UK";
    object datumObject = datum as object;
    object primeMeridianObject = primeMeridian as object;
    object unitObject = unit as object;

    geographicCoordinateSystemEdit.Define(ref name, ref alias, ref abbreviation, ref
        remarks, ref usage, ref datumObject, ref primeMeridianObject, ref unitObject)
        ;

    IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem =
        geographicCoordinateSystemEdit as IGeographicCoordinateSystem;
    return userDefinedGeographicCoordinateSystem;

}

下面是使用DefineEx 创建定义投影的例子,它使用 SpatialReferenceEnvironment  接口创建基准、本初子午线和单位

The following code example shows how the DefineEx method can be used. It uses SpatialReferenceEnvironment to create the Datum, PrimeMeridian, and Unit components:

private IGeographicCoordinateSystem CreateGeographicCoordinateSystemEx()
{

    // Set up the SpatialReferenceEnvironment.
    // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
    Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
    System.Object obj = Activator.CreateInstance(t);
    ISpatialReferenceFactory3 spatialReferenceFactory = obj as
        ISpatialReferenceFactory3;

    // Create the datum, prime meridian, and angular unit from existing definitions.

    IDatum datum = spatialReferenceFactory.CreateDatum((int)
        esriSRDatumType.esriSRDatum_OSGB1936);
    IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)
        esriSRPrimeMType.esriSRPrimeM_Greenwich);
    IUnit unit = spatialReferenceFactory.CreateUnit((int)
        esriSRUnitType.esriSRUnit_Degree);

    IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new
        GeographicCoordinateSystemClass();

    String name = "UserDefined Geographic Coordinate System";
    String alias = "UserDefined GCS";
    String abbreviation = "UserDefined";
    String remarks = "User Defined Geographic Coordinate System based on OSGB1936";
    String usage = "Suitable for the UK";

    geographicCoordinateSystemEdit.DefineEx(name, alias, abbreviation, remarks,
        usage, datum, primeMeridian, unit as IAngularUnit);

    IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem =
        geographicCoordinateSystemEdit as IGeographicCoordinateSystem;

    return userDefinedGeographicCoordinateSystem;

}

2.2.3 esriSRGeoCS3Type 

几个常见的椭球编码:WGS-84(4326), Xian-80(4610), GCS-2000(4490)

更为详细的编码,参见文章:https://www.cnblogs.com/liweis/p/5951032.html

2.3 其他方法

2.3.1 ISpatialReferenceFactory.CreateDatum

public IDatum CreateDatum (int datumType);

参数由 esriSRDatumType, esriSRDatum2Type, or esriSRDatum3Type 枚举器提供

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); 
//Create the datum using the available datums. These can be 
//found in the esriGeometry esriSRDatumType enumeration. 
IDatum datum = spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_NAD1983);

2.3.2 ISpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile

public ISpatialReference CreateESRISpatialReferenceFromPRJFile (stringprjFile);
    public void CreateESRISpatialReferenceFromPRJFileExample()
    {
        //The ISpatialReferenceFactory::CreateESRISpatialReferenceFromPRJFile
        //method requires that you specify the path and filename of the PRJ
        //file you wish to import to create a spatial reference from.
        // use activator class with SpatialReferenceEnvironment singleton
        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        System.Object obj = Activator.CreateInstance(factoryType);
        ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;
        ISpatialReference spatialReference = spatialReferenceFactory.
        CreateESRISpatialReferenceFromPRJFile("C:\\Program Files\\ArcGIS\\Coordinate Systems\\Geographic Coordinate Systems\\World\\WGS 1984.prj");
    }

2.3.3 ISpatialReferenceFactory.CreateGeoTransformation

public ITransformation CreateGeoTransformation (
    intgTransformationType);

 参数由esriSRGeoTransformationType, esriSRGeoTransformation2Type, or esriSRGeoTransformation3Type枚举器指定的变换类型,以创建特定的地理变换

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create a geographic (datum) transformation using the predefined geographic
//transformations. These can be found in the esriGeometry esriSRGeoTransformationType and esriSRGeoTransformation2Type enumerations.
IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation((int)esriSRGeoTransformation2Type.esriSRGeoTransformation_NAD_1983_TO_HARN_MO) as IGeoTransformation;

2.3.4 ISpatialReferenceFactory.CreateParameter

public IParameter CreateParameter (int parameterType);

从 esriSRParameterType, esriSRParameter2Type, esriSRParameter3Type, or esriSRParameter4Type 枚举器指定的参数类型,来创建指定的参数

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); // Declare an array of IParameters, and for each, create the required Parameter object
// by using ISpatialReferenceFactory::CreateParamater. Then assign the parameter a value. Below is an example used for a Transverse Mercator projection
IParameter[] parameterArray = new IParameter[5];
parameterArray[0] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting);
parameterArray[0].Value = 500000;
parameterArray[1] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing);
parameterArray[1].Value = 0;
parameterArray[2] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian);
parameterArray[2].Value = -123;
parameterArray[3] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin);
parameterArray[3].Value = 0;
parameterArray[4] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_ScaleFactor);
parameterArray[4].Value = 0.9996;

2.3.5 ISpatialReferenceFactory.CreatePredefinedPrimeMeridians

private void PrintPrimeMeridian()
    {
        // use activator class with SpatialReferenceEnvironment singleton
        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        System.Object obj = Activator.CreateInstance(factoryType);
        ISpatialReferenceFactory spatialReferenceFactory = obj as ISpatialReferenceFactory;
        ISet primeMeridiansSet = spatialReferenceFactory.CreatePredefinedPrimeMeridians();
        System.Windows.Forms.MessageBox.Show("Number of projections = " + primeMeridiansSet.Count);
        for (int i = 0; i < primeMeridiansSet.Count; i++)
        {
            IPrimeMeridian primeMeridian = primeMeridiansSet.Next() as IPrimeMeridian;
            System.Windows.Forms.MessageBox.Show(primeMeridian.Name);
        }
    }

2.3.6 ISpatialReferenceFactory.CreatePredefinedProjections

//This example shows how the CreatePredefinedProjections function returns a 
//set that contains all the available Projection objects. The set is iterated 
//through, and the name of each Projection with the set is obtained. These  
//type of functions are useful for developers who may wish to populate a 
//pulldown selection list of available SpatialReference objects. 

private void PrintProjections()
{
  ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
  ISet projectionSet = spatialReferenceFactory.CreatePredefinedProjections();
  System.Windows.Forms.MessageBox.Show("Number of projections = " + projectionSet.Count);
  for (int i = 0; i < projectionSet.Count; i++)
  {
    IProjection projection = projectionSet.Next() as IProjection;
    System.Windows.Forms.MessageBox.Show(projection.Name);
  }
}

2.3.7 ISpatialReferenceFactory.CreatePrimeMeridian

public IPrimeMeridian CreatePrimeMeridian (int primeMeridianType);

Use an element from the esriSRPrimeMType or esriSRPrimeM2Type enumerations as the primeMeridianType to create a particular predefined prime meridian.

 ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create the prime meridian using the available prime meridians. These can be
//found in the esriGeometry esriSRPrimeMType enumeration.
IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich);

2.3.8 ISpatialReferenceFactory.CreateProjection

public IProjection CreateProjection (int projectionType);

Use an element from the esriSRProjectionType, esriSRProjection2Type, esriSRProjection3Type, or esriSRProjection4Type enumerations as the projectionType to create a particular predefined map projection.

            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create a projections using the available projections. These can be
            //found in the esriGeometry esriSRProjectionType, esriSRProjection2Type,
            //esriSRProjection3Type, and esriSRProjection4Type enumerations.
            IProjection projection = spatialReferenceFactory.CreateProjection((int)esriSRProjectionType.esriSRProjection_LambertConformalConic);

2.3.9 ISpatialReferenceFactory.CreateSpheroid

public ISpheroid CreateSpheroid (int spheroidType);

Use an element from the esriSRSpheroidType or esriSRSpheroid2Type enumerations as the spheroidType to create a particular predefined spheroid.

            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create the spheroid using the available spheroids. These can be
            //found in the esriGeometry esriSRSpheroidType enumeration.
            ISpheroid spheroid = spatialReferenceFactory.CreateSpheroid((int)esriSRSpheroidType.esriSRSpheroid_Clarke1866);

2.3.10 ISpatialReferenceFactory.CreateUnit

public IUnit CreateUnit (int unitType);

Use an element from the esriSRUnitType or esriSRUnit2Type enumerations as the unitType to create a particular predefined unit of measure.

Use an element from the esriSRUnitType or esriSRUnit2Type enumerations as the unitType to create a particular predefined unit of measure.
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create the unit using the available units.  These can be
//found in the esriGeometry esriSRUnitType enumeration.
ILinearUnit linearUnit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Foot) as ILinearUnit;

2.3.11 ISpatialReferenceFactory.ExportESRISpatialReferenceToPRJFile

public void ExportESRISpatialReferenceToPRJFile (
    stringprjFile,
    ISpatialReferenceSpatialReference);

ExportESRISpatialReferenceToPRJFile converts an ArcGIS style spatial reference into the well-known text string. Here is an example (reformatted):

GEOGCS["GCS_North_American_1983", DATUM["D_North_American_1983", SPHEROID["GRS_1980",6378137,298.257222101]], PRIMEM["Greenwich",0], UNIT["Degree",0.0174532925199433]]

public void ExportESRISpatialReferenceToPRJFileExample()
    {
        //The ISpatialReferenceFactory::ExportESRISpatialReferenceToPRJFile
        //method requires that you specify the path and filename of the output
        //PRJ file you wish to create with the export. A valid spatial reference
        //object containing spatial reference information is also required.
        // use activator class with SpatialReferenceEnvironment singleton
        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        System.Object obj = Activator.CreateInstance(factoryType);
        ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;
        IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_10N);
        //Export the pcs to a prj file
        String fileName = "c:\\temp\\utm10.prj";
        spatialReferenceFactory.ExportESRISpatialReferenceToPRJFile(fileName, projectedCoordinateSystem);
    }

2.4 ISpatialReferenceFactory.CreateProjectedCoordinateSystem

2.4.1 创建投影坐标系

示例代码1:

private void CreateProjectedCoordinateSystem()
        {
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create a projected coordinate system using the available projected coordinate systems
            IProjectedCoordinateSystem projectedCoordinateSystem1 = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_World_Mercator);
            //Here is an more detailed example for creating a pre-defined projected coordinate system for a new Shapefile using the 'ISpatialReferenceFactory::CreateProjectedCoordinateSystem method
            //Create the pre-defined projected coordinate system object
            IProjectedCoordinateSystem projectedCoordinateSystem2 = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983SPCS_TXSouthCentFT);
            ISpatialReference spatialReference = projectedCoordinateSystem2 as ISpatialReference;
            //Set the false origin and units for the spatial reference.
            //You can use either the Domain or the FalseOriginAndUnits methods.
            // spatialReference.SetFalseOriginAndUnits(0, 0, 0);
            spatialReference.SetDomain(-1000000, 10000000, -1000000, 10000000);
            // spatialReference.SetMDomain(0, 1);
            spatialReference.SetMFalseOriginAndUnits(1, 1);
            // spatialReference.SetZDomain(0, 1);
            spatialReference.SetZFalseOriginAndUnits(1, 1);
            // Create a new SDE workspace
            IWorkspaceFactory sdeWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
            IWorkspace workspace = sdeWorkspaceFactory.OpenFromFile("C:\\Documents and Settings\\bast5010\\Application Data\\ESRI\\ArcCatalog\\Connection to Vampire.sde", 0);
            IFeatureWorkspace sdeFeatureWorkspace = workspace as IFeatureWorkspace;
            //Create the fields for the feature dataset
            IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;
            IField field = new FieldClass();
            IFieldEdit fieldEdit = field as IFieldEdit;
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Name_2 = "OID";
            fieldsEdit.AddField(fieldEdit);
            IGeometryDefEdit geometryDefEdit = new GeometryDefClass();
            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.GridCount_2 = 1;
            geometryDefEdit.set_GridSize(0, 1000);
            geometryDefEdit.SpatialReference_2 = spatialReference;
            fieldEdit = new FieldClass();
            fieldEdit.Name_2 = "Shape";
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDefEdit;
            fieldsEdit.AddField(fieldEdit);
            fieldEdit = new FieldClass();
            fieldEdit.Name_2 = "Test_Field";
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Editable_2 = true;
            fieldEdit.Length_2 = 25;
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(fieldEdit);
            //Create a UID for the CreateFeatureClass method
            UID uid = new UIDClass();
            uid.Generate();
            //Create ExtCLSID as for CreateFeatureClass method
            UID uidExt = new UIDClass();
            uidExt.Generate();
            //Create the feature class for the feature dataset
            IFeatureClass featureClass = sdeFeatureWorkspace.CreateFeatureClass("PreDef_StateNAD83", fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            System.Windows.Forms.MessageBox.Show("Data Creation Complete", "Program Status");
        }

代码示例2:

private void CreateProjectedCoordinateSystem()
{
    // Set up the SpatialReferenceEnvironment.
    // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
    Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
    System.Object obj = Activator.CreateInstance(t);
    ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory;
    // Use the enumeration to create an instance of the predefined object.
    IProjectedCoordinateSystem projectedCS = srFact.CreateProjectedCoordinateSystem(
        (int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N);
}

2.4.2  创建一个自定义的投影坐标系

private IProjectedCoordinateSystem CreateProjectedCoordinateSystem()
{

    // Set up the SpatialReferenceEnvironment.
    // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
    Type factoryType = Type.GetTypeFromProgID(
        "esriGeometry.SpatialReferenceEnvironment");
    System.Object obj = Activator.CreateInstance(factoryType);
    ISpatialReferenceFactory3 spatialReferenceFactory = obj as
        ISpatialReferenceFactory3;

    // Create a projection, GeographicCoordinateSystem, and unit using the factory.
    IProjectionGEN projection = spatialReferenceFactory.CreateProjection((int)
        esriSRProjectionType.esriSRProjection_Sinusoidal)as IProjectionGEN;
    IGeographicCoordinateSystem geographicCoordinateSystem =
        spatialReferenceFactory.CreateGeographicCoordinateSystem((int)
        esriSRGeoCSType.esriSRGeoCS_WGS1984);
    ILinearUnit unit = spatialReferenceFactory.CreateUnit((int)
        esriSRUnitType.esriSRUnit_Meter)as ILinearUnit;

    // Get the default parameters from the projection.
    IParameter[] parameters = projection.GetDefaultParameters();

    // Create a PCS using the Define method.
    IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = new
        ProjectedCoordinateSystemClass();
    object name = "Newfoundland";
    object alias = "NF_LAB";
    object abbreviation = "NF";
    object remarks = "Most Eastern Province in Canada";
    object usage = "When making maps of Newfoundland";
    object geographicCoordinateSystemObject = geographicCoordinateSystem as object;
    object unitObject = unit as object;
    object projectionObject = projection as object;
    object parametersObject = parameters as object;


    projectedCoordinateSystemEdit.Define(ref name, ref alias, ref abbreviation, ref
        remarks, ref usage, ref geographicCoordinateSystemObject, ref unitObject,
        ref projectionObject, ref parametersObject);
    return projectedCoordinateSystemEdit as IProjectedCoordinateSystem;
}

3 其它接口

3.1 IPRJSpatialReference 

  方法 描述 备注
  ExportSpatialReferenceToPRJ Exports the spatial reference to a buffer. 导出参考信息
  ImportSpatialReferenceFromPRJ Defines the spatial reference from the specified ESRISpatialReference buffer. 从prj文件导入参考信息
  PRJSpatialReferenceSize The number of bytes required to hold the persistant representation of the spatial reference. pdj文件所需的字节数

A sample represetation (reformatted for display) is below.

Projection    UTM   
Zone          10  
Datum         NAD83     
Zunits        NO     
Units         METERS     
Spheroid      GRS1980     
Xshift        0.0000000000     
Yshift        0.0000000000  
Parameters  

3.2 ISpatialReferenceInfo 

属性/方法 描述 备注
Abbreviation The abbreviated name of this spatial reference component. 该空间参考组件的缩写名称
Alias The alias of this spatial reference component. 该空间参考组件的缩写别名
FactoryCode The factory code (WKID) of the spatial reference. 该空间参考组件的工厂代码
Name The name of this spatial reference component. 该空间参考组件的名称
Remarks The comment string of this spatial reference component. 该空间参考组件的建议字符串

 

你可能感兴趣的:(基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码)