This document is archived and information here might be outdated.  Recommended version.


Make Spatial Reference Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Make Spatial Reference Snippet

Generate a SpatialReference by setting it's default projection.

[C#]
///<summary>
///Generate a SpatialReference by setting it's default projection.
///</summary>
///<param name="coordinateSystem">An ESRI.ArcGIS.Geometry.esriSRProjCSType projection. Example: ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_World_WinkelI</param>
///<returns>A newly created ESRI.ArcGIS.Geometry.ISpatialReference interface.</returns>
///<remarks>You need a SpatialReference in order to draw graphics and geometric objects in the correct location in the Map.</remarks>
public ESRI.ArcGIS.Geometry.ISpatialReference MakeSpatialReference(ESRI.ArcGIS.Geometry.esriSRProjCSType coordinateSystem)
{

ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatialReferenceFactory=new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();

//Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
ESRI.ArcGIS.Geometry.ISpatialReferenceResolution spatialReferenceResolution=spatialReferenceFactory.CreateProjectedCoordinateSystem(System.Convert.ToInt32(coordinateSystem)) as ESRI.ArcGIS.Geometry.ISpatialReferenceResolution;
spatialReferenceResolution.ConstructFromHorizon();
ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance spatialReferenceTolerance=spatialReferenceResolution as ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance;
spatialReferenceTolerance.SetDefaultXYTolerance();
ESRI.ArcGIS.Geometry.ISpatialReference spatialReference=spatialReferenceResolution as ESRI.ArcGIS.Geometry.ISpatialReference;

return spatialReference;

}
[Visual Basic .NET]
'''<summary>
'''Generate a SpatialReference by setting it's default projection.
'''</summary>
'''<param name="coordinateSystem">An ESRI.ArcGIS.Geometry.esriSRProjCSType projection. Example: ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_World_WinkelI</param>
'''<returns>A newly created ESRI.ArcGIS.Geometry.ISpatialReference interface.</returns>
'''<remarks>You need a SpatialReference in order to draw graphics and geometric objects in the correct location in the Map.</remarks>
Public Function MakeSpatialReference(ByVal coordinateSystem As ESRI.ArcGIS.Geometry.esriSRProjCSType) As ESRI.ArcGIS.Geometry.ISpatialReference

  Dim spatialReferenceFactory As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory=New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass

  'Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
  Dim spatialReferenceResolution As ESRI.ArcGIS.Geometry.ISpatialReferenceResolution=TryCast(spatialReferenceFactory.CreateProjectedCoordinateSystem(CInt(coordinateSystem)), ESRI.ArcGIS.Geometry.ISpatialReferenceResolution)
  spatialReferenceResolution.ConstructFromHorizon()
  Dim spatialReferenceTolerance As ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance=TryCast(spatialReferenceResolution, ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance)
  spatialReferenceTolerance.SetDefaultXYTolerance()
  Dim spatialReference As ESRI.ArcGIS.Geometry.ISpatialReference=TryCast(spatialReferenceResolution, ESRI.ArcGIS.Geometry.ISpatialReference)

  Return spatialReference

End Function

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