How to create a predefined spatial reference


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:
[Java]
static IProjectedCoordinateSystem loadProjectedCoordinateSystem()throws Exception{
    ISpatialReferenceFactory spatialReferenceFactory = new
        SpatialReferenceEnvironment();
    IProjectedCoordinateSystem projectedCoordinateSystem = 
        (IProjectedCoordinateSystem)
        spatialReferenceFactory.createESRISpatialReferenceFromPRJFile(
        "C:\\Program Files\\ArcGIS\\Coordinate Systems\\Projected Coordinate Systems\\World\\Mollweide (world).prj");
    return projectedCoordinateSystem;
}
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:
[Java]
static void printPreDefinedProjections()throws Exception{
    ISpatialReferenceFactory spatialReferenceFactory = new
        SpatialReferenceEnvironment();
    ISet projectionSet = spatialReferenceFactory.createPredefinedProjections();

    System.out.println("Number of predefined Projections = " +
        projectionSet.getCount());

    projectionSet.reset();
    for (int i = 0; i < projectionSet.getCount(); i++){
        IProjection projection = (IProjection)projectionSet.next();
        System.out.println(projection.getName());
    }
}






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