This document is archived and information here might be outdated.  Recommended version.


ISpatialReferenceFactory2.CreateSpatialReference Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IS > ISpatialReferenceFactory2 Interface > ISpatialReferenceFactory2.CreateSpatialReference Method
ArcGIS Developer Help

ISpatialReferenceFactory2.CreateSpatialReference Method

Creates a predefined spatial reference from an srID.

[Visual Basic .NET]
Public Function CreateSpatialReference ( _
    ByVal srID As Integer _
) As ISpatialReference
[C#]
public ISpatialReference CreateSpatialReference (
    int srID
);
[C++]
HRESULT CreateSpatialReference(
  long srID
);
[C++]
Parameters
srID 

srID is a parameter of type long

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

Use a srID from the esriSRProjCSType or esriSRGeoCSType enumerations to create a particular predefined spatial reference.

Errors Returned

E_INVALIDARG is returned if the srID is not a valid geographic or projected coordinate system.

Remarks

The CreateSpatialReference method creates a valid SpatialReference, either a projected or geographic coordinate system, depending on the supplied FactoryCode (here called an srID). The method returns an ISpatialReference. The example code illustrates how to test for what type of SpatialReference has been created. This method will raise an error (E_INVALIDARG) if the FactoryCode number supplied is not valid.

[C#]

    private void CreateSpatialReference(int spatialReferenceID)
    {
        // use activator class with SpatialReferenceEnvironment singleton
        Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
        System.Object obj = Activator.CreateInstance(factoryType);
        ISpatialReferenceFactory2 spatialReferenceFactory = obj as ISpatialReferenceFactory2;

        //Some examples of spatialReferenceIDs are:
        //esriSRProjCS_ColombiaBogota = 21892
        //esriSRGeoCS_Australian = 4003
        ISpatialReference spatialReference = spatialReferenceFactory.CreateSpatialReference(spatialReferenceID);
        if (spatialReference is IProjectedCoordinateSystem)
        {
            System.Windows.Forms.MessageBox.Show("You have a Projected Coordinate System");
        }
        else
        {
            if (spatialReference is IGeographicCoordinateSystem)
            {
                System.Windows.Forms.MessageBox.Show("You have a Geographic Coordinate System");
            }
        }
    }

See Also

ISpatialReferenceFactory2 Interface

.NET Samples

Create a raster catalog using the geoprocessor Create a custom raster type from the ground up for DMCII data Creating a toolbar of globe tools