ArcObjects Library Reference

Get Spatial Reference from Dataset Snippet

Get the spatial reference information of a dataset that is supplied.

[C#]

///<summary>Get the spatial reference information of a dataset that is supplied.</summary>
///  
///<param name="dataset">An IDataset, this could be a table, feature class, feature dataset, workspace etc.</param>
///   
///<returns>An ISpatialReference interface if successful, nothing otherwise.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Geometry.ISpatialReference GetSpatialReferenceFromDataset(ESRI.ArcGIS.Geodatabase.IDataset dataset)
{
  //If the dataset supports IGeoDataset
  if (dataset is ESRI.ArcGIS.Geodatabase.IGeoDataset)
  {
    //then grab the spatial reference information and return it.
    ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)dataset;
    return geoDataset.SpatialReference;
  }
  else
  {
    return null; //otherwise return null
  }
}
[Visual Basic .NET]

'''<summary>Get the spatial reference information of a dataset that is supplied.</summary>
'''  
'''<param name="dataset">An IDataset, this could be a table, feature class, feature dataset, workspace etc.</param>
'''   
'''<returns>An ISpatialReference interface if successful, nothing otherwise.</returns>
'''   
'''<remarks></remarks>
Public Function GetSpatialReferenceFromDataset(ByVal dataset As ESRI.ArcGIS.Geodatabase.IDataset) As ESRI.ArcGIS.Geometry.ISpatialReference

  'If the dataset supports IGeoDataset
  If TypeOf dataset Is ESRI.ArcGIS.Geodatabase.IGeoDataset Then
    'then grab the spatial reference information and return it.
    Dim geoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset = CType(dataset, ESRI.ArcGIS.Geodatabase.IGeoDataset)

    Return geoDataset.SpatialReference

  Else

    Return Nothing 'otherwise return nothing

  End If

End Function


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.System