How to create a predefined spatial reference


Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime

Additional Requirements
  • This article assumes your project includes references to the ESRI Geometry assembly.

Creating a predefined spatial reference

ArcObjects includes a vast array of predefined spatial reference systems and building blocks for spatial reference systems. Each predefined object is identified by a factory code. Factory codes are defined enumeration sets that begin with esriSR. Use the enumeration macro rather than the integer value it represents.
 
Occasionally, the code value an enumeration stands for may change. This is because many of the values are from the European Petroleum Survey Group (EPSG) database, which is becoming an industry standard. See http://www.epsg.org for more information.
 
The following code example shows how to create predefined spatial reference objects and use them as input to geodatabase operations:

[C#]
private IProjectedCoordinateSystem LoadProjectedCoordinateSystem()
{
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile("C:\\Program Files\\ArcGIS\\Coordinate Systems\\Projected Coordinate Systems\\World\\Mollweide (world).prj") as IProjectedCoordinateSystem;
return projectedCoordinateSystem;
}

[VB.NET]
Private Function LoadProjectedCoordinateSystem() As IProjectedCoordinateSystem
  Dim spatialReferenceFactory As ISpatialReferenceFactory = New SpatialReferenceEnvironmentClass()
  Dim projectedCoordinateSystem As IProjectedCoordinateSystem = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile _
  ("C:\\ArcGIS\\Coordinate Systems\\Projected Coordinate Systems\\World\\Mollweide (world).prj")
  Return projectedCoordinateSystem
End Function
The ISpatialReferenceFactory interface provides methods that use the FactoryCode to generate predefined factory spatial reference objects. There are three types of functions on this interface:
 
For example, the CreateGeographicCoordinateSystem function takes as its only parameter an integer that represents the FactoryCode of a predefined geographic coordinate system (GCS). The function returns a fully instantiated GCS object that can then be queried for its properties and classes.
 
Thousands of coordinate system related objects are available through macros. The enumerations all begin with esriSR. Use the enumeration macro rather than the integer value it represents. Many of the FactoryCode values are based on an external standard, and the values may change.
 
The next type of function on the ISpatialReferenceFactory interface returns a complete set of objects. For example, the following code 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 types of functions are useful for developers who want to populate a pull-down selection list of available Spatial Reference objects. See the following code example:
 

[C#]
private void PrintPreDefinedProjections()
{
 ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); 
  ISet projectionSet = spatialReferenceFactory.CreatePredefinedProjections();

 System.Windows.Forms.MessageBox.Show("Number of predefined Projections = " + projectionSet.Count);

 projectionSet.Reset();
 for(int i = 0; i < projectionSet.Count; i++)
 {
   IProjection projection = projectionSet.Next() as IProjection;
   System.Windows.Forms.MessageBox.Show(projection.Name);
 }
} 

[VB.NET]
Private Sub PrintPreDefinedProjections()
  Dim spatialReferenceFactory As ISpatialReferenceFactory = New SpatialReferenceEnvironmentClass()
  Dim projectionSet As ISet = spatialReferenceFactory.CreatePredefinedProjections()
  
  System.Windows.Forms.MessageBox.Show("Number of predefined Projections = " & projectionSet.Count)
  projectionSet.Reset()

  For i As Integer = 0 To projectionSet.Count Step 1
    Dim projection As IProjection = projectionSet.Next()
    System.Windows.Forms.MessageBox.Show(projection.Name)
  Next
End Sub