ArcGis 获取地理、平面坐标系

 1 IProjectedCoordinateSystem LoadProjectedCoordinateSystem( string shpfile)
 2         {
 3              /*   IFeatureClass从中获取地理坐标、平面坐标
 4              string shpDir = System.IO.Path.GetDirectoryName(shpfile);
 5              string shpfilename = System.IO.Path.GetFileName(shpfile);
 6              IWorkspaceFactory wsFactory = new ShapefileWorkspaceFactoryClass();
 7              IWorkspace ws = wsFactory.OpenFromFile(shpDir, 0);
 8              IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)ws;
 9              IFeatureClass featureCls = featureWorkspace.OpenFeatureClass(shpfilename);
10              IGeoDataset pGeoDataset = featureCls as IGeoDataset;
11              var spatialReference = pGeoDataset.SpatialReference;
12 
13              IProjectedCoordinateSystem pProCoordSys = spatialReference as IProjectedCoordinateSystem;//平面
14              IGeographicCoordinateSystem pGeographCoordinateSys = pProCoordSys.GeographicCoordinateSystem;//地理
15               */
16 
17 
18              // 1、从文件中获取
19              ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatialRefFactory =  new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
20             ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = spatialRefFactory.CreateESRISpatialReferenceFromPRJFile(shpfile.ToLower().Replace( " .shp "" .prj "));
21 
22              // 2、自定义
23              IProjectedCoordinateSystem geographicCoordinateSystem = spatialRefFactory.CreateProjectedCoordinateSystem(( int)ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_World_Mercator);
24 
25              // 3、从文件中获取
26              Type factoryType = Type.GetTypeFromProgID( " esriGeometry.SpatialReferenceEnvironment ");
27             System.Object obj = Activator.CreateInstance(factoryType);
28             ISpatialReferenceFactory spatialReferenceFactory = obj  as ISpatialReferenceFactory;
29 
30             IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(shpfile.ToLower().Replace( " .shp "" .prj "))  as IProjectedCoordinateSystem;
31              return projectedCoordinateSystem;
32 
33         }

你可能感兴趣的:(arcgis)