36 Creating proj.crs.crs.CRS Objects for GemGIS
Contents
36 Creating proj.crs.crs.CRS Objects for GemGIS#
proj.crs.crs.CRS
can be used in GemGIS
to define the coordinate reference system (CRS) of GeoDataFrames
or to specify the target CRS for coordinate transformations. The underlying pyproj
package (https://pyproj4.github.io/pyproj/dev/index.html) is a Python interface to the PROJ
package/library for cartographic projections and coordinate transformations (https://proj.org/).
Set File Paths and download Tutorial Data#
If you downloaded the latest GemGIS
version from the Github repository, append the path so that the package can be imported successfully. Otherwise, it is recommended to install GemGIS
via pip install gemgis
and import GemGIS
using import gemgis as gg
. In addition, the file path to the folder where the data is being stored is set. The tutorial data is downloaded using Pooch (https://www.fatiando.org/pooch/latest/index.html) and stored in the specified folder. Use
pip install pooch
if Pooch is not installed on your system yet.
[1]:
file_path ='data/36_creating_proj_crs_object_for_gemgis/'
Creating CRS Objects#
CRS objects/the CRS class can easily be initiated from a variety of inputs. The following shows a selection of these inputs. These objects can then be passed to functions that take a proj.crs.crs.CRS
object as argument.
[2]:
from pyproj import CRS
From Authority#
Making a CRS from an authority name and authority code.
[3]:
CRS.from_authority(auth_name='EPSG', code=4647)
[3]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
[4]:
CRS.from_authority(auth_name='EPSG', code='4647')
[4]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
From a dict#
Making a CRS from a dictionary of PROJ parameters. The parameters were created using the to_dict
function in the first place. You will likely lose important projection information when converting to a PROJ dict from another format!
[5]:
CRS.from_dict({'proj': 'tmerc',
'lat_0': 0,
'lon_0': 9,
'k': 0.9996,
'x_0': 32500000,
'y_0': 0,
'ellps': 'GRS80',
'units': 'm',
'no_defs': None,
'type': 'crs'})
[5]:
<Projected CRS: +proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=32500 ...>
Name: unknown
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- undefined
Coordinate Operation:
- name: unknown
- method: Transverse Mercator
Datum: Unknown based on GRS80 ellipsoid
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
From EPSG Code#
Making a CRS from an EPSG code.
[6]:
CRS.from_epsg(4647)
[6]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
[7]:
CRS.from_epsg('4647')
[7]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
From User Input#
Initialize a CRS class instance with: - PROJ string - Dictionary of PROJ parameters - PROJ keyword arguments for parameters - JSON string with PROJ parameters - CRS WKT string - An authority string [i.e. ‘epsg:4326’] - An EPSG integer code [i.e. 4326] - A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)] - An object with a to_wkt
method. - A :class:pyproj.crs.CRS
class
[8]:
CRS.from_user_input('EPSG:4647')
[8]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
[9]:
CRS.from_user_input(('EPSG', '4647'))
[9]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
[10]:
CRS.from_user_input(4647)
[10]:
<Projected CRS: EPSG:4647>
Name: ETRS89 / UTM zone 32N (zE-N)
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Germany - 6°E to 12°E
- bounds: (6.0, 47.27, 12.0, 55.47)
Coordinate Operation:
- name: UTM zone 32N with prefix
- method: Transverse Mercator
Datum: European Terrestrial Reference System 1989
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
[11]:
crs = CRS.from_user_input('EPSG:4647')
type(crs)
[11]:
pyproj.crs.crs.CRS