About creating a custom geographic coordinate system
A GCS includes a name, angular unit of measure, datum (which includes a spheroid), and a prime meridian. It is a model of the earth in a three-dimensional (3D) coordinate system. Latitude-longitude or lat/lon data is in a GCS. You can access the majority of the properties and methods through the IGeographicCoordinateSystem interface with additional properties that are available in IGeographicCoordinateSystem2. Although most developers will not need to create a custom GCS, IGeographicCoordinateSystemEdit contains the Define and DefineEx methods.
The following code example shows how to use the Define method to create a user-defined GCS. The ISpatialReferenceFactory interface allows you to create the Datum, PrimeMeridian, and AngularUnit component parts. These components can also be created using a similar Define method available on their classes.
[C#]
private IGeographicCoordinateSystem CreateGeographicCoordinateSystem()
{
// Set up the SpatialReferenceEnvironment.
// SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
Type factoryType = Type.GetTypeFromProgID(
"esriGeometry.SpatialReferenceEnvironment");
System.Object obj = Activator.CreateInstance(factoryType);
ISpatialReferenceFactory3 spatialReferenceFactory = obj as
ISpatialReferenceFactory3;
// Create the datum, prime meridian, and angular unit from existing definitions.
IDatum datum = spatialReferenceFactory.CreateDatum((int)
esriSRDatumType.esriSRDatum_OSGB1936);
IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)
esriSRPrimeMType.esriSRPrimeM_Greenwich);
IUnit unit = spatialReferenceFactory.CreateUnit((int)
esriSRUnitType.esriSRUnit_Degree);
IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new
GeographicCoordinateSystemClass();
object name = "UserDefined Geographic Coordinate System";
object alias = "UserDefined GCS";
object abbreviation = "UserDefined";
object remarks = "User Defined Geographic Coordinate System based on OSGB1936";
object usage = "Suitable for the UK";
object datumObject = datum as object;
object primeMeridianObject = primeMeridian as object;
object unitObject = unit as object;
geographicCoordinateSystemEdit.Define(ref name, ref alias, ref abbreviation, ref
remarks, ref usage, ref datumObject, ref primeMeridianObject, ref unitObject)
;
IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem =
geographicCoordinateSystemEdit as IGeographicCoordinateSystem;
return userDefinedGeographicCoordinateSystem;
}
[VB.NET]
Private Function CreateGeographicCoordinateSystem() As IGeographicCoordinateSystem
' Set up the SpatialReferenceEnvironment.
' SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
Dim factoryType As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
Dim spatialReferenceFactory As ISpatialReferenceFactory3 = CType(Activator.CreateInstance(factoryType), ISpatialReferenceFactory3)
' Create the datum, prime meridian, and angular unit from existing definitions.
Dim datum As IDatum = spatialReferenceFactory.CreateDatum(CInt(esriSRDatumType.esriSRDatum_OSGB1936))
Dim primeMeridian As IPrimeMeridian = spatialReferenceFactory.CreatePrimeMeridian(CInt(esriSRPrimeMType.esriSRPrimeM_Greenwich))
Dim unit As IUnit = spatialReferenceFactory.CreateUnit(CInt(esriSRUnitType.esriSRUnit_Degree))
Dim geographicCoordinateSystemEdit As IGeographicCoordinateSystemEdit = New GeographicCoordinateSystemClass()
Dim Name As Object = "UserDefined Geographic Coordinate System"
' Note: Alias is a reserved keyword in VB .NET. To use it as a variable name, encase it in brackets [ ].
Dim [Alias] As Object = "UserDefined GCS"
Dim abbreviation As Object = "UserDefined"
Dim remarks As Object = "User Defined Geographic Coordinate System based on OSGB1936"
Dim usage As Object = "Suitable for the UK"
Dim datumObject As Object = TryCast(datum, Object)
Dim primeMeridianObject As Object = TryCast(primeMeridian, Object)
Dim unitObject As Object = TryCast(unit, Object)
geographicCoordinateSystemEdit.Define(Name, [Alias], abbreviation, remarks, usage, datumObject, primeMeridianObject, unitObject)
Dim userDefinedGeographicCoordinateSystem As IGeographicCoordinateSystem = TryCast(geographicCoordinateSystemEdit, IGeographicCoordinateSystem)
Return userDefinedGeographicCoordinateSystem
End Function
The following code example shows how the DefineEx method can be used. It uses SpatialReferenceEnvironment to create the Datum, PrimeMeridian, and Unit components:
[C#]
private IGeographicCoordinateSystem CreateGeographicCoordinateSystemEx()
{
// Set up the SpatialReferenceEnvironment.
// SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
System.Object obj = Activator.CreateInstance(t);
ISpatialReferenceFactory3 spatialReferenceFactory = obj as
ISpatialReferenceFactory3;
// Create the datum, prime meridian, and angular unit from existing definitions.
IDatum datum = spatialReferenceFactory.CreateDatum((int)
esriSRDatumType.esriSRDatum_OSGB1936);
IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)
esriSRPrimeMType.esriSRPrimeM_Greenwich);
IUnit unit = spatialReferenceFactory.CreateUnit((int)
esriSRUnitType.esriSRUnit_Degree);
IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new
GeographicCoordinateSystemClass();
String name = "UserDefined Geographic Coordinate System";
String alias = "UserDefined GCS";
String abbreviation = "UserDefined";
String remarks = "User Defined Geographic Coordinate System based on OSGB1936";
String usage = "Suitable for the UK";
geographicCoordinateSystemEdit.DefineEx(name, alias, abbreviation, remarks,
usage, datum, primeMeridian, unit as IAngularUnit);
IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem =
geographicCoordinateSystemEdit as IGeographicCoordinateSystem;
return userDefinedGeographicCoordinateSystem;
}
[VB.NET]
Private Function CreateGeographicCoordinateSystemEx() As IGeographicCoordinateSystem
' Set up the SpatialReferenceEnvironment.
' SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
Dim t As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
Dim obj As System.Object = Activator.CreateInstance(t)
Dim spatialReferenceFactory As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 = obj
' Create the datum, prime meridian, and angular unit from existing definitions.
Dim datum As IDatum = spatialReferenceFactory.CreateDatum(CInt(esriSRDatumType.esriSRDatum_OSGB1936))
Dim primeMeridian As IPrimeMeridian = spatialReferenceFactory.CreatePrimeMeridian(CInt(esriSRPrimeMType.esriSRPrimeM_Greenwich))
Dim unit As IUnit = spatialReferenceFactory.CreateUnit(CInt(Fix(esriSRUnitType.esriSRUnit_Degree)))
Dim geographicCoordinateSystemEdit As IGeographicCoordinateSystemEdit = New GeographicCoordinateSystemClass()
Dim Name As String = "UserDefined Geographic Coordinate System"
' Note: Alias is a reserved keyword in VB .NET. To use it as a variable name, encase it in brackets [ ].
Dim [Alias] As String = "UserDefined GCS"
Dim abbreviation As String = "UserDefined"
Dim remarks As String = "User Defined Geographic Coordinate System based on OSGB1936"
Dim usage As String = "Suitable for the UK"
geographicCoordinateSystemEdit.DefineEx(Name, [Alias], abbreviation, remarks, usage, datum, primeMeridian, TryCast(unit, IAngularUnit))
Dim userDefinedGeographicCoordinateSystem As IGeographicCoordinateSystem = TryCast(geographicCoordinateSystemEdit, IGeographicCoordinateSystem)
Return userDefinedGeographicCoordinateSystem
End Function
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
ESRI.ArcGIS.Geometry System
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |