2.3.4 ISpatialReferenceFactory.CreateParameter
public IParameter CreateParameter (int parameterType);
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
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