How to use the SpatialReferenceEnvironment

Using the spatial reference environment

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 for more information.
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.
The next type of function on the ISpatialReferenceFactory interface returns a complete set of objects. For example, the CreatePredefinedProjections function returns a set that contains all the available projection objects. These type of functions are useful for developers who want to populate a pull-down selection list of available SpatialReference objects. See the following code example:
static void printPreDefinedProjections()throws Exception{
    ISpatialReferenceFactory spatialReferenceFactory = new
    ISet projectionSet = spatialReferenceFactory.createPredefinedProjections();

    System.out.println("Number of predefined Projections = " +

    for (int i = 0; i < projectionSet.getCount(); i++){
        IProjection projection = (IProjection);
The third type of function supported by ISpatialReferenceFactory deals with PRJ files and strings. CreateESRISpatialReferenceFromPRJFile takes an old- or new-style PRJ file and creates either a geographic or projected coordinate system from it, depending on the file contents. The old-style PRJ is used with coverages, triangulated irregular networks (TINs), and grids.
CreateESRISpatialReferenceFromPRJ is used to create a SpatialReference based on the string buffer of an old-style PRJ file. While CreateESRISpatialReference is similar, the string buffer must be in the format of a new PRJ file. The following code sample shows how to create a SpatialReference coordinate system directly from a PRJ file (both old- and new-style files are supported).
static IProjectedCoordinateSystem loadProjectedCoordinateSystem()throws Exception{
    ISpatialReferenceFactory spatialReferenceFactory = new
    IProjectedCoordinateSystem projectedCoordinateSystem = 
        "C:\\Program Files\\ArcGIS\\Coordinate Systems\\Projected Coordinate Systems\\World\\Mollweide (world).prj");
    return projectedCoordinateSystem;
The ISpatialReferenceFactory3 interface has two methods that are useful when working with low- and high-precision spatial references. ConstructHighPrecisionSpatialReference creates a high-precision spatial reference from a low-precision spatial reference. Using this method ensures that coordinate values will fit exactly into the new, denser grid mesh. Each intersection of the original grid is an intersection of the new grid.
ConstructLowPrecisionSpatialReference will create a low-precision spatial reference from an existing high-precision one. You can require that the new resolution value be maintained, possibly at the expense of the x,y domain extent.
In addition, ISpatialReferenceFactory3 provides access to predefined vertical coordinate systems and datums via the CreateVerticalCoordinateSystem and CreateVerticalDatum methods. The predefined vertical datums and coordinate systems are listed in the esriSRVerticalDatumType and esriSRVerticalCSType enumerations.

Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine