Coordinate Reference System
We can check our current Coordinate System using Geopandas CRS i.e Coordinates Reference System. Also, we can change it to a projection coordination system. The Coordinate Reference System (CRS) is represented as a pyproj.CRS object. We can check current CRS using the following syntax.
Syntax:
GeoDataFrame.crs
to_crs() method transform geometries to a new coordinate reference system. Transform all geometries in an active geometry column to a different coordinate reference system. The CRS attribute on the current GeoSeries must be set. Either CRS or epsg may be specified for output. This method will transform all points in all objects. It has no notion or projecting entire geometries. All segment joining points are assumed to be lined in the current projection, not geodesics. Objects crossing the dateline (or another projection boundary) will have undesirable behavior.
Syntax: GeoDataFrame.to_crs(crs=None, epsg=None, inplace=False)
Parameters
- crs: pyproj.CRS, optional if epsg is specified. The value can be anything accepted by pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.
- epsg: int, optional if crs is specified. EPSG code specifying output projection.
- inplace: bool, optional, default: False. Whether to return a new GeoDataFrame or do the transformation in place.
Example:
Python3
import geopandas as gpd # Reading the world shapefile world_data = gpd.read_file(r 'world.shp' ) world_data = world_data[[ 'NAME' , 'geometry' ]] # Calculating the area of each country world_data[ 'area' ] = world_data.area # Removing Antarctica from GeoPandas GeoDataframe world_data = world_data[world_data[ 'NAME' ] ! = 'Antarctica' ] # Changing the projection current_crs = world_data.crs world_data.to_crs(epsg = 3857 , inplace = True ) world.plot() |
Output:
Working with Geospatial Data in Python
Spatial data, also known as geospatial data, GIS data, or geodata, is a type of numeric data that defines the geographic location of a physical object, such as a building, a street, a town, a city, a country, or other physical objects, using a geographic coordinate system. You may determine not just the position of an object, but also its length, size, area, and shape using spatial data.
To work with geospatial data in python we need the GeoPandas & GeoPlot library
GeoPandas is an open-source project to make working with geospatial data in python easier. GeoPandas extends the data types used by pandas to allow spatial operations on geometric types. Geometric operations are performed shapely. Geopandas further depends on fiona for file access and matplotlib for plotting. GeoPandas depends on its spatial functionality on a large geospatial, open-source stack of libraries (GEOS, GDAL, and PROJ). See the Dependencies section below for more details.
Required dependencies:
- numpy
- pandas (version 0.24 or later)
- shapely (interface to GEOS)
- fiona (interface to GDAL)
- pyproj (interface to PROJ; version 2.2.0 or later)
Further, optional dependencies are:
- rtree (optional; spatial index to improve performance and required for overlay operations; interface to libspatialindex)
- psycopg2 (optional; for PostGIS connection)
- GeoAlchemy2 (optional; for writing to PostGIS)
- geopy (optional; For plotting, these additional for geocoding)
packages may be used:
- matplotlib (>= 2.2.0)
- mapclassify (>= 2.2.0)
Geoplot is a geospatial data visualization library for data scientists and geospatial analysts that want to get things done quickly. Below we’ll cover the basics of Geoplot and explore how it’s applied. Geoplot is for Python 3.6+ versions only.
Note: Please install all the dependencies and modules for the proper functioning of the given codes.
Contact Us