Get Coordinate System Information Of Feature Class Using ArcObject

In GIS, whenever we start any work, we have to specify the spatial reference or coordinate system of data. Without Coordinate System, we can't find the exact location of data so all our analysis will be wrong. In ArcGIS, we have the facility to set or get the spatial reference related information using ArcObject. ArcObject provides us all the facilities we need when using ArcGIS Application. The below code describes how we can get the information of spatial reference using ArcObject.

Suppose, we have shapefiles and we want to get the coordinate system information programmaticaly; so the below given code is very useful to get the details of Coordinate System. First, we create an object of workspacefactory and after that, we use the method OpenFromFile and get the object of the workspace. Once we get the object of workspace, we need to cast that object in ifeatureworkspace and use method OpenFeatureclass. We will get the object of feature class. If we check the Object Model Diagram which is provided by ESRI at the time of installation, there, we will get the list of all interfaces to which we can cast the featureclass. Once we cast featureclass to IGeoDataset, we will get property SpatialReference and in that property, we will get the information of Spatial reference.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using ESRI.ArcGIS.DataSourcesFile;  
  9. using ESRI.ArcGIS.DataSourcesGDB;  
  10. using ESRI.ArcGIS.Geodatabase;  
  11. using ESRI.ArcGIS.esriSystem;  
  12. using ESRI.ArcGIS.Geometry;  
  13. using System.Collections;  
  14. namespace WindowsApp {  
  15.     public partial class Form1: Form {  
  16.         public Form1() {  
  17.             InitializeComponent();  
  18.         }  
  19.         private void button1_Click(object sender, EventArgs e) {  
  20.             IWorkspaceFactory pwsf = new ShapefileWorkspaceFactory();  
  21.             IWorkspace pws = pwsf.OpenFromFile(@ "D:\YS\ShapeFiles", 0);  
  22.             IFeatureWorkspace pfeatWs = (IFeatureWorkspace) pws;  
  23.             IFeatureClass pfc = pfeatWs.OpenFeatureClass("LandUseA.shp");  
  24.             IGeoDataset pGeoDs = (IGeoDataset) pfc;  
  25.             ISpatialReference pspatialRef = pGeoDs.SpatialReference;  
  26.             string spatialrefName = pspatialRef.Name;  
  27.         }  
  28.     }  
  29. }  

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now