Configure Spatial Reference Systems (SRS)¶
A spatial reference system (SRS) or coordinate reference system (CRS) is a framework used to precisely measure locations on, or relative to, the Earth's surface. GeoKit offers a variety of options for specifying these systems, which are introduced here. If you are new to spatial reference system you could start here: https://en.wikipedia.org/wiki/Spatial_reference_system
Load required libraries¶
In [1]:
Copied!
import geokit.core.srs
import geokit.core.srs
Common Spatial Reference System (SRS)¶
Commonly used SRS:
- Basic latitude and longitude - EPSG4326
- Lambert azimuthal equal area (LAEA) - EPSG3035
- Mercator - EPSG3857
In [2]:
Copied!
print(type(geokit.core.srs.EPSG4326))
print(type(geokit.core.srs.EPSG4326))
<class 'osgeo.osr.SpatialReference'>
In [3]:
Copied!
print(geokit.core.srs.EPSG4326)
print(geokit.core.srs.EPSG3035)
print(geokit.core.srs.EPSG3857)
print(geokit.core.srs.EPSG4326)
print(geokit.core.srs.EPSG3035)
print(geokit.core.srs.EPSG3857)
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Latitude",NORTH],
AXIS["Longitude",EAST],
AUTHORITY["EPSG","4326"]]
PROJCS["ETRS89-extended / LAEA Europe",
GEOGCS["ETRS89",
DATUM["European_Terrestrial_Reference_System_1989",
SPHEROID["GRS 1980",6378137,298.257222101,
AUTHORITY["EPSG","7019"]],
AUTHORITY["EPSG","6258"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4258"]],
PROJECTION["Lambert_Azimuthal_Equal_Area"],
PARAMETER["latitude_of_center",52],
PARAMETER["longitude_of_center",10],
PARAMETER["false_easting",4321000],
PARAMETER["false_northing",3210000],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Northing",NORTH],
AXIS["Easting",EAST],
AUTHORITY["EPSG","3035"]]
PROJCS["WGS 84 / Pseudo-Mercator",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Mercator_1SP"],
PARAMETER["central_meridian",0],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"],
AUTHORITY["EPSG","3857"]]
In [4]:
Copied!
print(geokit.core.srs.loadSRS(2004))
print(geokit.core.srs.loadSRS(2004))
PROJCS["Montserrat 1958 / British West Indies Grid",
GEOGCS["Montserrat 1958",
DATUM["Montserrat_1958",
SPHEROID["Clarke 1880 (RGS)",6378249.145,293.465,
AUTHORITY["EPSG","7012"]],
AUTHORITY["EPSG","6604"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4604"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",-62],
PARAMETER["scale_factor",0.9995],
PARAMETER["false_easting",400000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
AUTHORITY["EPSG","2004"]]
Proj4 string¶
Otherwise, SRS can be loaded from their Proj4 string:
In [5]:
Copied!
poland_special_srs = geokit.core.srs.loadSRS(
'PROJCS["PUWG_42_Strefa_4",GEOGCS["GCS_Pulkovo_1942",DATUM["Pulkovo_1942",SPHEROID["Krasovsky_1940",6378245,298.3]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",4500000],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",21],PARAMETER["Scale_Factor",1],PARAMETER["Latitude_Of_Origin",0],UNIT["Meter",1]]'
)
print(poland_special_srs)
poland_special_srs = geokit.core.srs.loadSRS(
'PROJCS["PUWG_42_Strefa_4",GEOGCS["GCS_Pulkovo_1942",DATUM["Pulkovo_1942",SPHEROID["Krasovsky_1940",6378245,298.3]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",4500000],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",21],PARAMETER["Scale_Factor",1],PARAMETER["Latitude_Of_Origin",0],UNIT["Meter",1]]'
)
print(poland_special_srs)
PROJCS["PUWG_42_Strefa_4",
GEOGCS["Pulkovo 1942",
DATUM["Pulkovo_1942",
SPHEROID["Krassowsky 1940",6378245,298.3,
AUTHORITY["EPSG","7024"]]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",21],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",4500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]
Center the SRS to Coordinate¶
SRS can be centered to a coordinate, for example centered to Aachen:
In [6]:
Copied!
aachen_centered_srs = geokit.core.srs.centeredLAEA(6.083, 50.775)
print(aachen_centered_srs)
aachen_centered_srs = geokit.core.srs.centeredLAEA(6.083, 50.775)
print(aachen_centered_srs)
PROJCS["unnamed_m",
GEOGCS["GRS 1980(IUGG, 1980)",
DATUM["unknown",
SPHEROID["GRS80",6378137,298.257222101],
TOWGS84[0,0,0,0,0,0,0]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433]],
PROJECTION["Lambert_Azimuthal_Equal_Area"],
PARAMETER["latitude_of_center",50.775],
PARAMETER["longitude_of_center",6.083],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["Meter",1],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]
Transformation Between Coordinate Systems¶
In [7]:
Copied!
# transforming points between SRS's
new_points = geokit.core.srs.xyTransform(
[
(6.083, 50.775),
(6.083, 50.875),
(6.083, 50.975),
(7.083, 50.175),
(7.583, 50.775),
],
fromSRS=geokit.core.srs.EPSG4326,
toSRS=aachen_centered_srs,
outputFormat="xy",
)
# transforming points between SRS's
new_points = geokit.core.srs.xyTransform(
[
(6.083, 50.775),
(6.083, 50.875),
(6.083, 50.975),
(7.083, 50.175),
(7.583, 50.775),
],
fromSRS=geokit.core.srs.EPSG4326,
toSRS=aachen_centered_srs,
outputFormat="xy",
)
In [8]:
Copied!
for x, y in zip(new_points.x, new_points.y):
print(x, y)
for x, y in zip(new_points.x, new_points.y):
print(x, y)
0.0 0.0 0.0 11124.480318935728 0.0 22249.12252108337 71432.80781956235 -66262.41755972906 105796.52244980003 1069.9939140465938
Export the SRS¶
The coordinate systems can be exported. File formats for that are: WKT or Proj4
In [9]:
Copied!
# Export as WKT
aachen_centered_srs.ExportToWkt()
# Export as WKT
aachen_centered_srs.ExportToWkt()
Out[9]:
'PROJCS["unnamed_m",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101],TOWGS84[0,0,0,0,0,0,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["latitude_of_center",50.775],PARAMETER["longitude_of_center",6.083],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1],AXIS["Easting",EAST],AXIS["Northing",NORTH]]'
In [10]:
Copied!
# Export to Proj4
aachen_centered_srs.ExportToProj4()
# Export to Proj4
aachen_centered_srs.ExportToProj4()
Out[10]:
'+proj=laea +lat_0=50.775 +lon_0=6.083 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
Load SRS¶
In [11]:
Copied!
geokit.core.srs.loadSRS(aachen_centered_srs.ExportToWkt())
geokit.core.srs.loadSRS(aachen_centered_srs.ExportToWkt())
Out[11]:
<osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7e451c5872a0> >