How to create a custom projected coordinate system


Summary
This article shows how to create a custom projected coordinate system (PCS) and manipulate the projection parameters.

Creating a custom projected coordinate system

The parts of a PCS, such as the projection, linear unit, and geographic coordinate system, are objects. All support ISpatialReference2 and ISpatialReferenceFactory. When defining a custom projected coordinate system, make use of the predefined objects available in the various esriSR* enumerations.
You can access the majority of the properties and methods through the IProjectedCoordinateSystem2 interface, although a few more properties are available in IProjectedCoordinateSystem3 and IProjectedCoordinateSystem4.
The IProjectedCoordinateSystemEdit contains the Define method, which allows you to define a custom projected coordinate system. To access the hundreds of predefined projected coordinate systems, ISpatialReferenceFactory has the CreateProjectedCoordinateSystem method. The predefined projected coordinate systems are listed in the esriSRProjCSType, esriSRProjCS2Type, esriSRProjCS3Type, and esriSRProjCS4Type enumerations.
The IProjectedCoordinateSystemEdit interface provides you with the Define method to create your own PCS object based on parameters such as Name, GeographicCoordinateSystem, projectedUnit, Projection, and if necessary, projection Parameters. See the following:
[Java]
static IProjectedCoordinateSystem createProjectedCoordinateSystem()throws Exception{

    ISpatialReferenceFactory2 spatialReferenceFactory = new
        SpatialReferenceEnvironment();

    //Create a projection, GeographicCoordinateSystem, and unit using the factory.
    IProjectionGEN projection = (IProjectionGEN)
        spatialReferenceFactory.createProjection((int)
        esriSRProjectionType.esriSRProjection_Sinusoidal);
    IGeographicCoordinateSystem geographicCoordinateSystem =
        spatialReferenceFactory.createGeographicCoordinateSystem((int)
        esriSRGeoCSType.esriSRGeoCS_WGS1984);
    ILinearUnit unit = (ILinearUnit)spatialReferenceFactory.createUnit((int)
        esriSRUnitType.esriSRUnit_Meter);

    //Get the default parameters from the projection.
    IParameter[] parameters = projection.getDefaultParameters();

    //Create a projected coordinate system using the Define method.
    IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = new
        ProjectedCoordinateSystem();

    Object name = "Newfoundland";
    Object alias = "NF_LAB";
    Object abbreviation = "NF";
    Object remarks = "Most Eastern Province in Canada";
    Object usage = "When making maps of Newfoundland";
    Object geographicCoordinateSystemObject = geographicCoordinateSystem;
    Object unitObject = unit;
    Object projectionObject = projection;
    Object parametersObject = parameters;

    projectedCoordinateSystemEdit.define(name, alias, abbreviation, remarks, usage,
        geographicCoordinateSystemObject, unitObject, projectionObject,
        parametersObject);

    return (IProjectedCoordinateSystem)projectedCoordinateSystemEdit;
}
Parameter requirements
Parameters are required by both projected coordinate systems and geographic transformations. For example, to define a Lambert Azimuthal Equal Area projected coordinate system, only the central meridian and latitude of origin parameters are required by the mathematical algorithm that actually performs the projection.
The IParameter interface has an index and a value. The value is self-explanatory and refers to the internal array that holds the parameters for a projected coordinate system or a geographic transformation. The ISpatialReferenceFactory can be used to create new parameters. The following is an example of how to use the CreateParameter method and the esriSR_ParameterType enumeration. The SpatialReferenceFactory provides default values for each type of parameter. The values can easily be changed.
[Java]
static void printParameter()throws Exception{
    ISpatialReferenceFactory2 spatialReferenceFactory = new
        SpatialReferenceEnvironment();
    IParameter parameter = spatialReferenceFactory.createParameter((int)
        esriSRParameterType.esriSRParameter_LatitudeOfOrigin);

    System.out.println(parameter.getName());
    System.out.println(parameter.getIndex());
    System.out.println(parameter.getValue());
    parameter.setValue(45);
    System.out.println(parameter.getValue());
}
The following code demonstrates how to get the parameters from a projected coordinate system. It assumes that the projected coordinate is already defined. These parameters are passed to the client by reference; it is then possible to modify the value of the parameters directly. If this is done, the Changed method on the ProjectedCoordinateSystem must be called.
[Java]
static void printParameters(IProjectedCoordinateSystem4GEN projectedCoordinateSystem)
    throws Exception{
    //Create an array of IParameters with 16 elements.
    IParameter[][] parameters = new IParameter[1][16];

    //Get the parameters.
    projectedCoordinateSystem.getParameters(parameters);

    //Iterate through the array of parameters. 
    for (int i = 0; i < parameters[0].length; i++){
        IParameter currentParameter = parameters[0][i];
        if (currentParameter != null)
            System.out.println(currentParameter.getName() + ", " +
                currentParameter.getIndex() + ", " + currentParameter.getValue());

    }
}
The following code shows how to change a parameter using the same variables:
[Java]
private void SetParameter(IProjectedCoordinateSystem4GEN projectedCoordinateSystem){

    //Create an array of IParameters with 16 elements.
    IParameter[] parameters = new IParameter[16];

    //Get the parameters.
    projectedCoordinateSystem.GetParameters(ref parameters);

    //Get the Central Meridian Parameter, you know that it is the 3rd element (remember, arrays are 0-based).
    //A safer and more intuitive way would be to use the methods:
    //IProjectedCoordinateSystem4GEN.get_CentralMeridian or to set it
    //IProjectedCoordinateSystem4GEN.set_CentralMeridian.
    IParameter centralMeridian = parameters[2];

    //Set the new value. 
    centralMeridian.Value = 123;

    //Tell the projected coordinate system that it has changed. 
    projectedCoordinateSystem.Changed();

}
The following example uses the GetDefaultParameters method on the IProjection interface to retrieve a set of the required parameters for a projection. Next, set some values and create a new projected coordinate system using these parameters, then make a call to IProjectedCoordinateSystem4GEN::GetParameters to verify that the parameters have been set.
[Java]
static void setProjectionParameters()throws Exception{
    //Create a factory.
    ISpatialReferenceFactory2 spatialReferenceFactory = new
        SpatialReferenceEnvironment();

    //Create a projection, GeographicCoordinateSystem, and unit using the factory.
    IProjectionGEN projection = (IProjectionGEN)
        spatialReferenceFactory.createProjection((int)
        esriSRProjectionType.esriSRProjection_Sinusoidal);
    IGeographicCoordinateSystem geographicCoordinateSystem =
        spatialReferenceFactory.createGeographicCoordinateSystem((int)
        esriSRGeoCSType.esriSRGeoCS_WGS1984);
    ILinearUnit unit = (ILinearUnit)spatialReferenceFactory.createUnit((int)
        esriSRUnitType.esriSRUnit_Meter);

    //Get the default parameters from the projection.
    IParameter[] parameters = projection.getDefaultParameters();

    //Iterate through the parameters and print out their name and value.
    for (int i = 0; i < parameters.length; i++){
        IParameter currentParameter = parameters[i];
        if (currentParameter != null)
            System.out.println(currentParameter.getName() + ", " +
                currentParameter.getIndex() + ", " + currentParameter.getValue());
    }

    //Reset one of the parameter values.
    IParameter parameter = parameters[2];
    parameter.setValue(45);

    //Create a projected coordinate system using the Define method.
    IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = new
        ProjectedCoordinateSystem();
    Object name = "Newfoundland";
    Object alias = "NF_LAB";
    Object abbreviation = "NF";
    Object remarks = "Most Eastern Province in Canada";
    Object usage = "When making maps of Newfoundland";
    Object geographicCoordinateSystemObject = geographicCoordinateSystem;
    Object unitObject = unit;
    Object projectionObject = projection;
    Object parametersObject = parameters;

    projectedCoordinateSystemEdit.define(name, alias, abbreviation, remarks, usage,
        geographicCoordinateSystemObject, unitObject, projectionObject,
        parametersObject);

    IProjectedCoordinateSystem4GEN projectedCoordinateSystem = 
        (IProjectedCoordinateSystem4GEN)projectedCoordinateSystemEdit;

    //Get the parameters from your new projected coordinate system and verify
    //that the parameter value was changed.
    //Create an array of IParameters with 16 elements.
    IParameter[][] newParameters = new IParameter[1][16];

    //Get the parameters.
    projectedCoordinateSystem.getParameters(newParameters);

    //Iterate through the parameters and print out their name and value.
    for (int i = 0; i < newParameters[0].length; i++){
        IParameter currentNewParameter = newParameters[0][i];
        if (currentNewParameter != null)
            System.out.println(currentNewParameter.getName() + ", " +
                currentNewParameter.getIndex() + ", " + currentNewParameter.getValue
                ());

    }
}






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