This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IS > ISpatialReferenceFactory2 Interface > ISpatialReferenceFactory2.CreateSpatialReference Method (ArcObjects .NET 10.5 SDK) |
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
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");
}
}
}