CoordinateReferenceSystem Class
A coordinate reference system (CRS): what the two numbers of a position mean. The library works with longitudes and latitudes on WGS 84 (EPSG:4326); a CRS converts its coordinates to and from them, so a position can go from any CRS to any other one through WGS 84.
public abstract class CoordinateReferenceSystemRemarks
A GeoPosition holds the coordinates of any CRS in the GIS order: GeoPosition.Longitude is the longitude or the easting (x), and GeoPosition.Latitude is the latitude or the northing (y), whatever the order of the axes in the definition of the CRS. The altitude is kept by the projections, and changed by the datum shifts, as an ellipsoidal height. The built-in systems keep the GeoPosition.Measure and the GeoPosition.Time of the positions.
Derive from this class to plug a coordinate system that the library does not support: implement CoordinateReferenceSystem.ToWgs84 and CoordinateReferenceSystem.FromWgs84, for instance with a call to another library.
Constructors
| Name | Description |
|---|---|
| CoordinateReferenceSystem(string) | Initializes a new instance of the CoordinateReferenceSystem class. |
CoordinateReferenceSystem(string)
CoordinateReferenceSystem.csInitializes a new instance of the CoordinateReferenceSystem class.
protected CoordinateReferenceSystem(string name)Parameters
namestring- The name of the coordinate reference system.
Properties
| Name | Description |
|---|---|
| EpsgCode | Gets the code of the coordinate reference system in the EPSG dataset, such as 4326 or 2154, or null when it is not known. |
| IsGeographic | Gets a value that indicates whether the coordinates are a longitude and a latitude, rather than an easting and a northing. |
| Lambert93 | Gets the Lambert 93 projection of metropolitan France, in meters (RGF93 v1 / Lambert-93, EPSG:2154). |
| Name | Gets the name of the coordinate reference system. |
| WebMercator | Gets the Web Mercator projection of web maps, in meters (WGS 84 / Pseudo-Mercator, EPSG:3857). |
| Wgs84 | Gets the longitudes and latitudes of WGS 84, in degrees (EPSG:4326): the coordinates of GPS devices, of GeoJSON and of the library. |
EpsgCode
CoordinateReferenceSystem.csIsGeographic
Lambert93
CoordinateReferenceSystem.csGets the Lambert 93 projection of metropolitan France, in meters (RGF93 v1 / Lambert-93, EPSG:2154).
public static ProjectedCoordinateSystem Lambert93 { get; }Property value
Remarks
RGF93 is taken as equal to WGS 84, as PROJ does without a grid: the difference is below a meter.
WebMercator
CoordinateReferenceSystem.csGets the Web Mercator projection of web maps, in meters (WGS 84 / Pseudo-Mercator, EPSG:3857).
public static ProjectedCoordinateSystem WebMercator { get; }Property value
Gets the longitudes and latitudes of WGS 84, in degrees (EPSG:4326): the coordinates of GPS devices, of GeoJSON and of the library.
public static GeographicCoordinateSystem Wgs84 { get; }Property value
Methods
| Name | Description |
|---|---|
| FromEpsg(int) | Gets a built-in coordinate reference system by its EPSG code, such as 4326, 3857, 2154 or 32631, as the SRID of EWKT and EWKB gives it. |
| FromWgs84(GeoPosition) | Converts a longitude and a latitude of WGS 84 to a position of this coordinate reference system. |
| ParseWkt(string) | Reads the definition of a coordinate reference system in the Well-Known Text of the OGC (WKT 1) or of ESRI, as in the .prj file of a shapefile, such as PROJCS["RGF_1993_Lambert_93",GEOGCS[...],PROJECTION["Lambert_Conformal_Conic"],...]. |
| ToString() | Returns a string that represents the current object. |
| ToWgs84(GeoPosition) | Converts a position of this coordinate reference system to a longitude and a latitude of WGS 84. |
| Transform(GeoPosition, CoordinateReferenceSystem) | Converts a position of this coordinate reference system to another one, through WGS 84. |
| Utm(int, bool) | Gets the UTM zone of WGS 84 (EPSG:32601 to 32660 in the northern hemisphere, 32701 to 32760 in the southern one). |
FromEpsg(int)
CoordinateReferenceSystem.csGets a built-in coordinate reference system by its EPSG code, such as 4326, 3857, 2154 or 32631, as the SRID of EWKT and EWKB gives it.
public static CoordinateReferenceSystem? FromEpsg(int code)Parameters
codeint- The EPSG code. The codes 900913, 3785 and 102100 also give Web Mercator.
Returns
CoordinateReferenceSystem? The coordinate reference system, or null when the library does not know the code.
Remarks
The built-in codes are: 4326 (WGS 84), 4258 (ETRS89), 4171 (RGF93 v1), 4269 (NAD83), 4275 (NTF), 4277 (OSGB36), 3857 (Web Mercator), 3395 (World Mercator), 32601 to 32660 and 32701 to 32760 (UTM on WGS 84), 25828 to 25838 (UTM on ETRS89), 26901 to 26923 (UTM on NAD83), 2154 (Lambert 93), 3942 to 3950 (the conic conformal zones CC42 to CC50 of France), 27572 (NTF (Paris) / Lambert zone II, the "Lambert II étendu") and 27700 (British National Grid). ETRS89, RGF93 and NAD83 are taken as equal to WGS 84 (the difference is below a meter or two); NTF and OSGB36 are shifted with the Helmert transformation of the EPSG dataset, accurate to a few meters.
FromWgs84(GeoPosition)
Converts a longitude and a latitude of WGS 84 to a position of this coordinate reference system.
public abstract GeoPosition FromWgs84(GeoPosition position)Parameters
positionGeoPosition- The longitude and the latitude on WGS 84, in degrees.
Returns
GeoPosition The position, in this coordinate reference system.
ParseWkt(string)
CoordinateReferenceSystem.csReads the definition of a coordinate reference system in the Well-Known Text of the OGC (WKT 1) or of ESRI, as in the .prj file of a shapefile, such as PROJCS["RGF_1993_Lambert_93",GEOGCS[...],PROJECTION["Lambert_Conformal_Conic"],...].
public static CoordinateReferenceSystem ParseWkt(string wkt)Parameters
wktstring- The definition.
Returns
CoordinateReferenceSystem The coordinate reference system.
Exceptions
FormatException- The text is not valid WKT, or it is not the definition of a coordinate reference system.
NotSupportedException- The projection of the definition is not supported.
Remarks
A definition with an EPSG code (AUTHORITY["EPSG","2154"], or ID["EPSG",2154] in WKT 2) that CoordinateReferenceSystem.FromEpsg knows gives that built-in system. Otherwise the system is built from the definition: a GEOGCS or a PROJCS whose projection is a transverse Mercator, a Lambert conformal conic (1SP or 2SP) or a Mercator (1SP, 2SP, or the pseudo-Mercator of web maps), with its ellipsoid, its TOWGS84 datum shift, its prime meridian and its units. As GDAL and ESRI write them, the prime meridian is read in degrees, and the angles of the parameters in the angular unit of the GEOGCS. A COMPD_CS gives its horizontal system.
A datum without TOWGS84 is taken as equal to WGS 84, except the NTF and OSGB 1936 datums of ESRI definitions, which get the shifts of CoordinateReferenceSystem.FromEpsg.
ToString()
CoordinateReferenceSystem.csToWgs84(GeoPosition)
Converts a position of this coordinate reference system to a longitude and a latitude of WGS 84.
public abstract GeoPosition ToWgs84(GeoPosition position)Parameters
positionGeoPosition- The position, in this coordinate reference system.
Returns
GeoPosition The longitude and the latitude on WGS 84, in degrees, the longitude from -180 to 180.
Transform(GeoPosition, CoordinateReferenceSystem)
CoordinateReferenceSystem.csConverts a position of this coordinate reference system to another one, through WGS 84.
public GeoPosition Transform(GeoPosition position, CoordinateReferenceSystem target)Parameters
positionGeoPosition- The position, in this coordinate reference system.
targetCoordinateReferenceSystem- The coordinate reference system to convert the position to.
Returns
GeoPosition The position, in target. The position itself when target is this instance.
Utm(int, bool)
CoordinateReferenceSystem.csGets the UTM zone of WGS 84 (EPSG:32601 to 32660 in the northern hemisphere, 32701 to 32760 in the southern one).
public static ProjectedCoordinateSystem Utm(int zone, bool isNorthernHemisphere)Parameters
zoneint- The number of the zone, from 1 (180°W to 174°W) to 60.
isNorthernHemispherebooltruefor the northern hemisphere, whose northings start at 0 at the equator;falsefor the southern one, whose northings start at 10,000,000 meters.
Returns
ProjectedCoordinateSystem The coordinate reference system, in meters.
Exceptions
ArgumentOutOfRangeExceptionzoneis not between 1 and 60.