This document is archived and information here might be outdated. Recommended version. |
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
Use a srID from the esriSRProjCSType or esriSRGeoCSType enumerations to create a particular predefined spatial reference.
E_INVALIDARG is returned if the srID is not a valid geographic or projected coordinate system.
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.
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");
}
}
}