ISpatialReferenceFactory Interface

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

Members

Name Description
Method CreateDatum Creates a predefined datum.
Method CreateESRISpatialReference Creates a spatial reference system and defines it from the specified ESRISpatialReference buffer.
Method CreateESRISpatialReferenceFromPRJ Creates a spatial reference from a PRJ string.
Method CreateESRISpatialReferenceFromPRJFile Creates a spatial reference from a PRJ file.
Method CreateGeographicCoordinateSystem Creates a predefined geographic coordinate system.
Method CreateGeoTransformation Creates a predefined transformation between geographic coordinate systems.
Method CreateParameter Creates a predefined parameter.
Method CreatePredefinedAngularUnits Creates a list of predefined angular units.
Method CreatePredefinedDatums Creates a list of a list of predefined datums.
Method CreatePredefinedLinearUnits Creates a list of predefined linear units.
Method CreatePredefinedPrimeMeridians Creates a list of predefined prime meridians.
Method CreatePredefinedProjections Creates a list of predefined projections.
Method CreatePredefinedSpheroids Creates a list of predefined spheroids.
Method CreatePrimeMeridian Creates a predefined prime meridian.
Method CreateProjectedCoordinateSystem Creates a predefined projected coordinate system.
Method CreateProjection Creates a predefined projection.
Method CreateSpheroid Creates a predefined spheroid.
Method CreateUnit Creates a predefined unit of measure.
Method ExportESRISpatialReferenceToPRJFile Exports a spatial reference to a PRJ file.

ISpatialReferenceFactory.CreateDatum Method

Creates a predefined datum.

Public Function CreateDatum ( _
    ByVal datumType As Integer _
) As IDatum
public IDatum CreateDatum (
    int datumType
);

Description

Use an element from the esriSRDatumType, esriSRDatum2Type, or esriSRDatum3Type enumerations as the datumType to create a particular predefined horizontal datum.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

//Create the datum using the available datums. These can be

//found in the esriGeometry esriSRDatumType enumeration.

IDatum datum = spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_NAD1983);

ISpatialReferenceFactory.CreateESRISpatialReference Method

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

Public Sub CreateESRISpatialReference ( _
    ByVal spatRefInfo As String, _
    ByRef SpatialReference As ISpatialReference, _
    ByRef cBytesRead As Integer _
)
public void CreateESRISpatialReference (
    string spatRefInfo,
    ref ISpatialReference SpatialReference,
    ref int cBytesRead
);

ISpatialReferenceFactory.CreateESRISpatialReferenceFromPRJ Method

Creates a spatial reference from a PRJ string.

Public Function CreateESRISpatialReferenceFromPRJ ( _
    ByVal prj As String _
) As ISpatialReference
public ISpatialReference CreateESRISpatialReferenceFromPRJ (
    string prj
);

Description

Not implemented for GeographicCoordinateSystem and ProjectedCoordinateSystem. Use the CreateESRISpatialReference or CreateESRISpatialReferenceFromPRJFile methods instead.

ISpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile Method

Creates a spatial reference from a PRJ file.

Public Function CreateESRISpatialReferenceFromPRJFile ( _
    ByVal prjFile As String _
) As ISpatialReference
public ISpatialReference CreateESRISpatialReferenceFromPRJFile (
    string prjFile
);

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.

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");

    }
'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")

ISpatialReferenceFactory.CreateGeographicCoordinateSystem Method

Creates a predefined geographic coordinate system.

Public Function CreateGeographicCoordinateSystem ( _
    ByVal gcsType As Integer _
) As IGeographicCoordinateSystem
public IGeographicCoordinateSystem CreateGeographicCoordinateSystem (
    int gcsType
);

Description

Use an element from the esriSRGeoCSType, esriSRGeoCS2Type, or esriSRGeoCS3Type enumerations as the gcsType to create a particular predefined geographic coordinate system.

Remarks

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

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);
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)

ISpatialReferenceFactory.CreateGeoTransformation Method

Creates a predefined transformation between geographic coordinate systems.

Public Function CreateGeoTransformation ( _
    ByVal gTransformationType As Integer _
) As ITransformation
public ITransformation CreateGeoTransformation (
    int gTransformationType
);

Description

Use an element from the esriSRGeoTransformationType, esriSRGeoTransformation2Type, or esriSRGeoTransformation3Type enumerations as the gTransformationType to create a particular predefined geographic (datum) transformation.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            //Create a geographic (datum) transformation using the predefined geographic 

            //transformations. These can be found in the esriGeometry esriSRGeoTransformationType

            //and esriSRGeoTransformation2Type enumerations.

            IGeoTransformation geoTransformation = spatialReferenceFactory.CreateGeoTransformation((int)esriSRGeoTransformation2Type.esriSRGeoTransformation_NAD_1983_TO_HARN_MO) as IGeoTransformation;
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 pGeoTran As ESRI.ArcGIS.Geometry.IGeoTransformation

        'Create a geographic (datum) transformation using the predefined geographic 

        'transformations. These can be found in the esriGeometry esriSRGeoTransformationType

        'and esriSRGeoTransformation2Type enumerations. 

        pGeoTran = pSpatRefFact.CreateGeoTransformation(ESRI.ArcGIS.Geometry.esriSRGeoTransformation2Type.esriSRGeoTransformation_NAD_1983_TO_HARN_MO)

ISpatialReferenceFactory.CreateParameter Method

Creates a predefined parameter.

Public Function CreateParameter ( _
    ByVal parameterType As Integer _
) As IParameter
public IParameter CreateParameter (
    int parameterType
);

Description

Use an element from the esriSRParameterType, esriSRParameter2Type, esriSRParameter3Type, or esriSRParameter4Type enumerations as the ParameterType to create a particular predefined parameter.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); // Declare an array of IParameters, and for each, create the required Parameter object 

            // by using ISpatialReferenceFactory::CreateParamater. Then assign the parameter 

            // a value. Below is an example used for a Transverse Mercator projection

            IParameter[] parameterArray = new IParameter[5];

            parameterArray[0] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting);

            parameterArray[0].Value = 500000;

            parameterArray[1] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing);

            parameterArray[1].Value = 0;

            parameterArray[2] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian);

            parameterArray[2].Value = -123;

            parameterArray[3] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin);

            parameterArray[3].Value = 0;

            parameterArray[4] = spatialReferenceFactory.CreateParameter((int)esriSRParameterType.esriSRParameter_ScaleFactor);

            parameterArray[4].Value = 0.9996;
'This example shows you how to declare a safe array of IParameter, 

        'and for each, create the required Parameter object by using 

        'ISpatialReferenceFactory::CreateParameter and assign each parameter a value.

        'Parameter types can be found in the esriGeometry esriSRParameterType 

        'enumeration.  Below is an example used for a Transverse Mercator projection.



        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory

        pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment

        Dim aParamArray(5) As ESRI.ArcGIS.Geometry.IParameter

        aParamArray(0) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_FalseEasting)

        aParamArray(0).Value = 500000

        aParamArray(1) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_FalseNorthing)

        aParamArray(1).Value = 0

        aParamArray(2) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_CentralMeridian)

        aParamArray(2).Value = -123

        aParamArray(3) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_LatitudeOfOrigin)

        aParamArray(3).Value = 0

        aParamArray(4) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_ScaleFactor)

        aParamArray(4).Value = 0.9996



        'Below is an example for an Albers projection:



        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory

        pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment

        Dim aParamArray(6) As ESRI.ArcGIS.Geometry.IParameter

        aParamArray(0) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_FalseEasting)

        aParamArray(0).Value = 0

        aParamArray(1) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_FalseNorthing)

        aParamArray(1).Value = 0

        aParamArray(2) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_CentralMeridian)

        aParamArray(2).Value = -96

        aParamArray(3) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_StandardParallel1)

        aParamArray(3).Value = 29.5

        aParamArray(4) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_StandardParallel2)

        aParamArray(4).Value = 45.5

        aParamArray(5) = pSpatRefFact.CreateParameter(ESRI.ArcGIS.Geometry.esriSRParameterType.esriSRParameter_CentralParallel)

        aParamArray(5).Value = 37.5

ISpatialReferenceFactory.CreatePredefinedAngularUnits Method

Creates a list of predefined angular units.

Public Function CreatePredefinedAngularUnits ( _
) As ISet
public ISet CreatePredefinedAngularUnits (
);

Description

Returns a list of all predefined angular units. The list has two columns: the factory code and the name.

ISpatialReferenceFactory.CreatePredefinedDatums Method

Creates a list of a list of predefined datums.

Public Function CreatePredefinedDatums ( _
) As ISet
public ISet CreatePredefinedDatums (
);

Description

Returns a list of all predefined horizontal datums. The list has two columns: the factory code and the name.

ISpatialReferenceFactory.CreatePredefinedLinearUnits Method

Creates a list of predefined linear units.

Public Function CreatePredefinedLinearUnits ( _
) As ISet
public ISet CreatePredefinedLinearUnits (
);

Description

Returns a list of all predefined linear units. The list has two columns: the factory code and the name.

ISpatialReferenceFactory.CreatePredefinedPrimeMeridians Method

Creates a list of predefined prime meridians.

Public Function CreatePredefinedPrimeMeridians ( _
) As ISet
public ISet CreatePredefinedPrimeMeridians (
);

Description

Returns a list of all predefined prime meridians. The list has two columns: the factory code and the name.

private void PrintPrimeMeridian()

    {

        // use activator class with SpatialReferenceEnvironment singleton

        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

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

        ISpatialReferenceFactory spatialReferenceFactory = obj as ISpatialReferenceFactory;

        ISet primeMeridiansSet = spatialReferenceFactory.CreatePredefinedPrimeMeridians();

        System.Windows.Forms.MessageBox.Show("Number of projections = " + primeMeridiansSet.Count);

        for (int i = 0; i < primeMeridiansSet.Count; i++)

        {

            IPrimeMeridian primeMeridian = primeMeridiansSet.Next() as IPrimeMeridian;

            System.Windows.Forms.MessageBox.Show(primeMeridian.Name);

        }

    }

ISpatialReferenceFactory.CreatePredefinedProjections Method

Creates a list of predefined projections.

Public Function CreatePredefinedProjections ( _
) As ISet
public ISet CreatePredefinedProjections (
);

Description

Create a set of all predefined map projection objects.

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.

//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.
'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

ISpatialReferenceFactory.CreatePredefinedSpheroids Method

Creates a list of predefined spheroids.

Public Function CreatePredefinedSpheroids ( _
) As ISet
public ISet CreatePredefinedSpheroids (
);

Description

Returns a list of all predefined spheroids. The list has two columns: the factory code and the name.

ISpatialReferenceFactory.CreatePrimeMeridian Method

Creates a predefined prime meridian.

Public Function CreatePrimeMeridian ( _
    ByVal primeMeridianType As Integer _
) As IPrimeMeridian
public IPrimeMeridian CreatePrimeMeridian (
    int primeMeridianType
);

Description

Use an element from the esriSRPrimeMType or esriSRPrimeM2Type enumerations as the primeMeridianType to create a particular predefined prime meridian.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            //Create the prime meridian using the available prime meridians. These can be

            //found in the esriGeometry esriSRPrimeMType enumeration.

            IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich);
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 pPrimeM As ESRI.ArcGIS.Geometry.IPrimeMeridian

        'Create the prime meridian using the available prime meridians. These can be

        'found in the esriGeometry esriSRPrimeMType enumeration.

        pPrimeM = pSpatRefFact.CreatePrimeMeridian(ESRI.ArcGIS.Geometry.esriSRPrimeMType.esriSRPrimeM_Greenwich)

ISpatialReferenceFactory.CreateProjectedCoordinateSystem Method

Creates a predefined projected coordinate system.

Public Function CreateProjectedCoordinateSystem ( _
    ByVal pcsType As Integer _
) As IProjectedCoordinateSystem
public IProjectedCoordinateSystem CreateProjectedCoordinateSystem (
    int pcsType
);

Description

Use an element from the esriSRProjCSType, esriSRProjCS2Type, esriSRProjCS3Type, or esriSRProjCS4Type enumerations as the pcsType to create a particular predefined projected coordinate system.

private void CreateProjectedCoordinateSystem()

        {

            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            //Create a projected coordinate system using the available projected coordinate systems 

            IProjectedCoordinateSystem projectedCoordinateSystem1 = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_World_Mercator);

            //Here is an more detailed example for creating a pre-defined projected coordinate 

            //system for a new Shapefile using the 'ISpatialReferenceFactory::CreateProjectedCoordinateSystem method 

            //Create the pre-defined projected coordinate system object 

            IProjectedCoordinateSystem projectedCoordinateSystem2 = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983SPCS_TXSouthCentFT);

            ISpatialReference spatialReference = projectedCoordinateSystem2 as ISpatialReference;

            //Set the false origin and units for the spatial reference.

            //You can use either the Domain or the FalseOriginAndUnits methods.

            // spatialReference.SetFalseOriginAndUnits(0, 0, 0); 

            spatialReference.SetDomain(-1000000, 10000000, -1000000, 10000000);

            // spatialReference.SetMDomain(0, 1); 

            spatialReference.SetMFalseOriginAndUnits(1, 1);

            // spatialReference.SetZDomain(0, 1);

            spatialReference.SetZFalseOriginAndUnits(1, 1);

            // Create a new SDE workspace 

            IWorkspaceFactory sdeWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();

            IWorkspace workspace = sdeWorkspaceFactory.OpenFromFile("C:\\Documents and Settings\\bast5010\\Application Data\\ESRI\\ArcCatalog\\Connection to Vampire.sde", 0);

            IFeatureWorkspace sdeFeatureWorkspace = workspace as IFeatureWorkspace;

            //Create the fields for the feature dataset 

            IFields fields = new FieldsClass();

            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            IField field = new FieldClass();

            IFieldEdit fieldEdit = field as IFieldEdit;

            fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;

            fieldEdit.IsNullable_2 = false;

            fieldEdit.Name_2 = "OID";

            fieldsEdit.AddField(fieldEdit);

            IGeometryDefEdit geometryDefEdit = new GeometryDefClass();

            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;

            geometryDefEdit.GridCount_2 = 1;

            geometryDefEdit.set_GridSize(0, 1000);

            geometryDefEdit.SpatialReference_2 = spatialReference;

            fieldEdit = new FieldClass();

            fieldEdit.Name_2 = "Shape";

            fieldEdit.IsNullable_2 = true;

            fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            fieldEdit.GeometryDef_2 = geometryDefEdit;

            fieldsEdit.AddField(fieldEdit);

            fieldEdit = new FieldClass();

            fieldEdit.Name_2 = "Test_Field";

            fieldEdit.IsNullable_2 = true;

            fieldEdit.Editable_2 = true;

            fieldEdit.Length_2 = 25;

            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;

            fieldsEdit.AddField(fieldEdit);

            //Create a UID for the CreateFeatureClass method 

            UID uid = new UIDClass();

            uid.Generate();

            //Create ExtCLSID as for CreateFeatureClass method 

            UID uidExt = new UIDClass();

            uidExt.Generate();

            //Create the feature class for the feature dataset

            IFeatureClass featureClass = sdeFeatureWorkspace.CreateFeatureClass("PreDef_StateNAD83", fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            System.Windows.Forms.MessageBox.Show("Data Creation Complete", "Program Status");

        }
Private Sub CreateProjectedCoordinateSystem()

        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 pProjCoordSys As ESRI.ArcGIS.Geometry.IProjectedCoordinateSystem

        'Create a projected coordinate system using the available projected coordinate systems

        pProjCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_World_Mercator)

        'Here is an more detailed example for creating a pre-defined projected coordinate

        'system for a new Shapefile using the 'ISpatialReferenceFactory::CreateProjectedCoordinateSystem method



        'Create the pre-defined projected coordinate system object

        pProjCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_NAD1983SPCS_TXSouthCentFT)

        Dim pSpatRef As ESRI.ArcGIS.Geometry.ISpatialReference

        pSpatRef = pProjCoordSys

        'Set the domain extents for the new dataset

        pSpatRef.SetDomain(-10000000, 10000000, -10000000, 10000000)

        'pSpatRef.SetFalseOriginAndUnits 0, 0, 0

        pSpatRef.SetMDomain(1, 1)

        'pSpatRef.SetMFalseOriginAndUnits 1, 1

        pSpatRef.SetZDomain(0, 1)

        'pSpatRef.SetZFalseOriginAndUnits 1, 1

        'Create a new SDE workspace

        Dim pSdeWorkspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory

        pSdeWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactory

        Dim pWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace

        pWorkspace = pSdeWorkspaceFactory.OpenFromFile("C:\\Documents and Settings\\bast5010\\Application Data\\ESRI\\ArcCatalog\\Connection to Vampire.sde", 0)

        Dim pSdeFeatureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace

        pSdeFeatureWorkspace = pWorkspace

        'Creat the fields for new dataset

        Dim pFlds As ESRI.ArcGIS.Geodatabase.IFields

        pFlds = New ESRI.ArcGIS.Geodatabase.Fields

        Dim pFldsEdit As ESRI.ArcGIS.Geodatabase.IFieldsEdit

        pFldsEdit = pFlds

        Dim pFld As ESRI.ArcGIS.Geodatabase.IField

        pFld = New ESRI.ArcGIS.Geodatabase.Field

        Dim pFldEdit As ESRI.ArcGIS.Geodatabase.IFieldEdit

        pFldEdit = pFld

        With pFldEdit

            .Type_2 = 6

            .IsNullable_2 = False

            .Name_2 = "OID"

        End With

        pFldsEdit.AddField(pFldEdit)

        Dim pGeodef As ESRI.ArcGIS.Geodatabase.IGeometryDefEdit

        pGeodef = New ESRI.ArcGIS.Geodatabase.GeometryDef

        With pGeodef

            .GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon

            .GridCount_2 = 1

            .GridSize_2(0) = 1000



            .SpatialReference_2 = pSpatRef

        End With

        pFldEdit = New ESRI.ArcGIS.Geodatabase.Field

        With pFldEdit

            .Name_2 = "Shape"

            .IsNullable_2 = True

            .Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry

            .GeometryDef_2 = pGeodef

        End With

        pFldsEdit.AddField(pFldEdit)

        pFldEdit = New ESRI.ArcGIS.Geodatabase.Field

        With pFldEdit

            .Name_2 = "Test_Field"

            .Editable_2 = True

            .Length_2 = 25

            .Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString

        End With

        pFldsEdit.AddField(pFldEdit)

        Dim pUID As New ESRI.ArcGIS.esriSystem.UID

        pUID.Generate()

        Dim pEXTCLSID As New ESRI.ArcGIS.esriSystem.UID

        pEXTCLSID.Generate()

        Dim shapeFieldName As String

        shapeFieldName = "Shape"

        Dim pOutputFeatureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass

        'Create the feature class

        pOutputFeatureClass = pSdeFeatureWorkspace.CreateFeatureClass("PreDef_StateNAD83", pFlds, Nothing, Nothing, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, "Shape", "")

        MsgBox("Data Creation Complete", vbOKOnly, "Program ")

    End Sub

ISpatialReferenceFactory.CreateProjection Method

Creates a predefined projection.

Public Function CreateProjection ( _
    ByVal projectionType As Integer _
) As IProjection
public IProjection CreateProjection (
    int projectionType
);

Description

Use an element from the esriSRProjectionType, esriSRProjection2Type, esriSRProjection3Type, or esriSRProjection4Type enumerations as the projectionType to create a particular predefined map projection.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            //Create a projections using the available projections. These can be 

            //found in the esriGeometry esriSRProjectionType, esriSRProjection2Type, 

            //esriSRProjection3Type, and esriSRProjection4Type enumerations.

            IProjection projection = spatialReferenceFactory.CreateProjection((int)esriSRProjectionType.esriSRProjection_LambertConformalConic);
'Set the spatial reference factory to a new spatial reference environment

        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory

        pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment

        'Create a projections using the available projections. These can be 

        'found in the esriGeometry esriSRProjectionType, esriSRProjection2Type, 

        'esriSRProjection3Type, and esriSRProjection4Type enumerations.

        Dim pProj As ESRI.ArcGIS.Geometry.IProjection

        pProj = pSpatRefFact.CreateProjection(ESRI.ArcGIS.Geometry.esriSRProjectionType.esriSRProjection_LambertConformalConic)

ISpatialReferenceFactory.CreateSpheroid Method

Creates a predefined spheroid.

Public Function CreateSpheroid ( _
    ByVal spheroidType As Integer _
) As ISpheroid
public ISpheroid CreateSpheroid (
    int spheroidType
);

Description

Use an element from the esriSRSpheroidType or esriSRSpheroid2Type enumerations as the spheroidType to create a particular predefined spheroid.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            //Create the spheroid using the available spheroids. These can be 

            //found in the esriGeometry esriSRSpheroidType enumeration. 

            ISpheroid spheroid = spatialReferenceFactory.CreateSpheroid((int)esriSRSpheroidType.esriSRSpheroid_Clarke1866);
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 pSpher As ESRI.ArcGIS.Geometry.ISpheroid 'Create the spheroid using the available spheroids. These can be 

        'found in the esriGeometry esriSRSpheroidType enumeration. 

        pSpher = pSpatRefFact.CreateSpheroid(ESRI.ArcGIS.Geometry.esriSRSpheroidType.esriSRSpheroid_Clarke1866)

ISpatialReferenceFactory.CreateUnit Method

Creates a predefined unit of measure.

Public Function CreateUnit ( _
    ByVal unitType As Integer _
) As IUnit
public IUnit CreateUnit (
    int unitType
);

Description

Use an element from the esriSRUnitType or esriSRUnit2Type enumerations as the unitType to create a particular predefined unit of measure.

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); 

//Create the unit using the available units.  These can be

//found in the esriGeometry esriSRUnitType enumeration.

ILinearUnit linearUnit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Foot) as ILinearUnit;
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 pUnit As ESRI.ArcGIS.Geometry.ILinearUnit

        'Create the unit using the available units.  These can be

        'found in the esriGeometry esriSRUnitType enumeration.

        pUnit = pSpatRefFact.CreateUnit(ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Foot)

ISpatialReferenceFactory.ExportESRISpatialReferenceToPRJFile Method

Exports a spatial reference to a PRJ file.

Public Sub ExportESRISpatialReferenceToPRJFile ( _
    ByVal prjFile As String, _
    ByVal SpatialReference As ISpatialReference _
)
public void ExportESRISpatialReferenceToPRJFile (
    string prjFile,
    ISpatialReference SpatialReference
);

Description

ExportESRISpatialReferenceToPRJFile converts an ArcGIS style spatial reference into the well-known text string. Here is an example (reformatted):

GEOGCS["GCS_North_American_1983", DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]]

``

Remarks

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

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);

     }
'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)

Classes that implement ISpatialReferenceFactory

Classes Description
SpatialReferenceEnvironment Creates various spatial reference objects.

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.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.