Interface ISpatialReferenceFactory

Namespace
ESRI.ArcGIS.Geometry
Assembly
ESRI.Server.Geometry.dll

Provides access to members that create different kinds of spatial reference components.

[Guid("6CD10B60-C4F6-11D1-BC92-0000F875BCCE")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISpatialReferenceFactory

Remarks

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: those that return single objects, those that return a set of objects of the same type, and those that are used to import and export SpatialReference objects to and from a PRJ file or a PRJ string representation. For example, the CreateGeographicCoordinateSystem function takes as its only parameter an integer that represents the FactoryCode of a predefined geographic coordinate system. The function returns a GCS whose coordinate system has been defined. Its coordinate grids and tolerance, though, have not yet been defined.

Thousands of coordinate system related objects are available through the esriSR... enumerations. To maintain compatibility between versions, each object, such as a geographic coordinate system, will have more than one enumeration. Use the enumeration elements (for example, esriSRGeoCS_WGS1984) 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. These type of functions are useful for developers who may wish to populate a pulldown selection list of available SpatialReference objects.

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, 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. Conversely, the ExportESRISpatialReferenceToPRJFile function provides a mechanism to take a SpatialReference object and create a new style PRJ file from it. These four functions provide you with a way to take advantage of existing routines that involve the use of PRJ files. They also provide an easy and effective way to exchange spatial reference information through the use of text files. If you plan to work with vertical coordinate systems, use the ISpatialReferenceFactory3 versions of these methods.

Methods

CreateDatum(int)

Creates a predefined datum.

IDatum CreateDatum(int datumType)

Parameters

datumType int

Returns

IDatum

CreateESRISpatialReference(string, out ISpatialReference, out int)

Creates a spatial reference system and defines it from the specified ESRISpatialReference buffer.

void CreateESRISpatialReference(string spatRefInfo, out ISpatialReference SpatialReference, out int cBytesRead)

Parameters

spatRefInfo string
SpatialReference ISpatialReference
cBytesRead int

CreateESRISpatialReferenceFromPRJ(string)

Creates a spatial reference from a PRJ string.

ISpatialReference CreateESRISpatialReferenceFromPRJ(string prj)

Parameters

prj string

Returns

ISpatialReference

CreateESRISpatialReferenceFromPRJFile(string)

Creates a spatial reference from a PRJ file.

ISpatialReference CreateESRISpatialReferenceFromPRJFile(string prjFile)

Parameters

prjFile string

Returns

ISpatialReference

Remarks

Both old style (workstation) and new style (ArcGIS for Desktop Basic) prj files can be used with this method to create spatial reference system objects.

[C#]

    public void CreateESRISpatialReferenceFromPRJFileExample()
    {
        //The ISpatialReferenceFactory::CreateESRISpatialReferenceFromPRJFile
        //method requires that you specify the path and filename of the PRJ
        //file you wish to import to create a spatial reference from.



        // use activator class with SpatialReferenceEnvironment singleton
        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        System.Object obj = Activator.CreateInstance(factoryType);
        ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;


        ISpatialReference spatialReference = spatialReferenceFactory.
            CreateESRISpatialReferenceFromPRJFile("C:\\Program Files\\ArcGIS\\Coordinate Systems\\Geographic Coordinate Systems\\World\\WGS 1984.prj");
    }

[Visual Basic .NET]

        'The ISpatialReferenceFactory::CreateESRISpatialReferenceFromPRJFile
        'method requires that you specify the path and filename of the PRJ
        'file you wish to import to create a spatial reference from.

        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory
        pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment

        Dim pSpatRef As ESRI.ArcGIS.Geometry.ISpatialReference
        pSpatRef = pSpatRefFact.CreateESRISpatialReferenceFromPRJFile("c:\geodata\prj_import.prj")

CreateGeoTransformation(int)

Creates a predefined transformation between geographic coordinate systems.

ITransformation CreateGeoTransformation(int gTransformationType)

Parameters

gTransformationType int

Returns

ITransformation

CreateGeographicCoordinateSystem(int)

Creates a predefined geographic coordinate system.

IGeographicCoordinateSystem CreateGeographicCoordinateSystem(int gcsType)

Parameters

gcsType int

Returns

IGeographicCoordinateSystem

Remarks

The example code shows how to create an object that represents the WGS 1984 geographic coordinate system.

[C#]

            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            //Create a geographic coordinate system using the available geographic
            //coordinate systems. These can be found in the esriGeometry esriSRGeoCSType
            //enumeration.
            IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);




[Visual Basic .NET]

        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory
        'Set the spatial reference factory to a new spatial reference environment
        pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment

        Dim pGCS As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem

        'Create a geographic coordinate system using the available geographic
        'coordinate systems. These can be found in the esriGeometry esriSRGeoCSType
        'enumeration.

        pGCS = pSpatRefFact.CreateGeographicCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)

CreateParameter(int)

Creates a predefined parameter.

IParameter CreateParameter(int parameterType)

Parameters

parameterType int

Returns

IParameter

CreatePredefinedAngularUnits()

Creates a list of predefined angular units.

ISet CreatePredefinedAngularUnits()

Returns

ISet

CreatePredefinedDatums()

Creates a list of a list of predefined datums.

ISet CreatePredefinedDatums()

Returns

ISet

CreatePredefinedLinearUnits()

Creates a list of predefined linear units.

ISet CreatePredefinedLinearUnits()

Returns

ISet

CreatePredefinedPrimeMeridians()

Creates a list of predefined prime meridians.

ISet CreatePredefinedPrimeMeridians()

Returns

ISet

CreatePredefinedProjections()

Creates a list of predefined projections.

ISet CreatePredefinedProjections()

Returns

ISet

Remarks

A Projection object encapsulates the mathematics needed to convert geographic coordinates between two different coordinate systems. A projection is a component of a projected coordinate system and is not usually used directly. Rather, a projected cooordinate system is defined and used to project cooordinates.

[C#]

//This example 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 

//type of functions are useful for developers who may wish to populate a

//pulldown selection list of available SpatialReference objects.

private void PrintProjections() { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

ISet projectionSet = spatialReferenceFactory.CreatePredefinedProjections(); System.Windows.Forms.MessageBox.Show("Number of projections = " + projectionSet.Count); for (int i = 0; i < projectionSet.Count; i++) { IProjection projection = projectionSet.Next() as IProjection; System.Windows.Forms.MessageBox.Show(projection.Name); } }

[Visual Basic .NET]

'This example 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 

'type of functions are useful for developers who may wish to populate a

'pulldown selection list of available SpatialReference objects.

        Dim pProjection As ESRI.ArcGIS.Geometry.IProjection
        Dim pProjectionSet As ESRI.ArcGIS.esriSystem.ISet
        Dim pSpatialRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory
        pSpatialRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment
        pProjectionSet = pSpatialRefFact.CreatePredefinedProjections
        Debug.Print(pProjectionSet.Count)
        Dim i As Integer
        pProjectionSet.Reset()
        For i = 0 To pProjectionSet.Count - 1
            pProjection = pProjectionSet.Next
            Debug.Print(pProjection.Name)
        Next i











CreatePredefinedSpheroids()

Creates a list of predefined spheroids.

ISet CreatePredefinedSpheroids()

Returns

ISet

CreatePrimeMeridian(int)

Creates a predefined prime meridian.

IPrimeMeridian CreatePrimeMeridian(int primeMeridianType)

Parameters

primeMeridianType int

Returns

IPrimeMeridian

CreateProjectedCoordinateSystem(int)

Creates a predefined projected coordinate system.

IProjectedCoordinateSystem CreateProjectedCoordinateSystem(int pcsType)

Parameters

pcsType int

Returns

IProjectedCoordinateSystem

CreateProjection(int)

Creates a predefined projection.

IProjection CreateProjection(int projectionType)

Parameters

projectionType int

Returns

IProjection

CreateSpheroid(int)

Creates a predefined spheroid.

ISpheroid CreateSpheroid(int spheroidType)

Parameters

spheroidType int

Returns

ISpheroid

CreateUnit(int)

Creates a predefined unit of measure.

IUnit CreateUnit(int unitType)

Parameters

unitType int

Returns

IUnit

ExportESRISpatialReferenceToPRJFile(string, ISpatialReference)

Exports a spatial reference to a PRJ file.

void ExportESRISpatialReferenceToPRJFile(string prjFile, ISpatialReference SpatialReference)

Parameters

prjFile string
SpatialReference ISpatialReference

Remarks

To convert a spatialreference into an ArcGIS for Desktop Advanced workstation format (for TINs, GRIDs, or coverages), use  IPRJSpatialReferenceGEN_ExportSpatialReferenceToPRJ.

[C#]

    public void ExportESRISpatialReferenceToPRJFileExample()
    {
        //The ISpatialReferenceFactory::ExportESRISpatialReferenceToPRJFile
        //method requires that you specify the path and filename of the output
        //PRJ file you wish to create with the export. A valid spatial reference
        //object containing spatial reference information is also required.




        // use activator class with SpatialReferenceEnvironment singleton
        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

System.Object obj = Activator.CreateInstance(factoryType);

ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;


        IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_10N);

//Export the pcs to a prj file
String fileName = "c:\temp\utm10.prj";

spatialReferenceFactory.ExportESRISpatialReferenceToPRJFile(fileName, projectedCoordinateSystem);
}



[Visual Basic .NET]

        'The ISpatialReferenceFactory::ExportESRISpatialReferenceToPRJFile
        'method requires that you specify the path and filename of the output
        'PRJ file you wish to create with the export. A valid spatial reference
        'object containing spatial reference information is also required.


        'pSpatRefFact represents an ISpatialReferenceFactory object
        'pSpatRef represents an ISpatialReference object

        pSpatRefFact.ExportESRISpatialReferenceToPRJFile("c:\geodata\prj_export", pSpatRef)