2. ISpatialReferenceFactory
此接口已被ISpatialReferenceFactory3所代替,
2.1 接口方法概览
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;