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


ISpatialReferenceFactory2.CreateSpatialReference Method (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference (Geometry)  

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,
  ISpatialReference** SR
);
[C++]

Parameters srID srID is a parameter of type long SR [out, retval]
SR is a parameter of type ISpatialReference

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 Snippets

Get Azimuth from Two Points

.NET Samples

Create a raster catalog using the geoprocessor (Code Files: CreateRasterCatalog_GP) | Create a custom raster type from the ground up for DMCII data (Code Files: DMCIIRasterType) | Creating a toolbar of globe tools (Code Files: SpatialReference)

.NET Related Topics

Writing .NET code using properties