Reading Shapefile
First, we will import the geopandas library and then read our shapefile using the variable “world_data”. Geopandas can read almost any vector-based spatial data format including ESRI shapefile, GeoJSON files and more using the command:
Syntax: geopandas.read_file()
Parameters
- filename: str, path object, or file-like object. Either the absolute or relative path to the file or URL to be opened or any object with a read() method (such as an open file or StringIO)
- bbox: tuple | GeoDataFrame or GeoSeries | shapely Geometry, default None. Filter features by given bounding box, GeoSeries, GeoDataFrame or a shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with mask.
- mask: dict | GeoDataFrame or GeoSeries | shapely Geometry, default None. Filter for features that intersect with the given dict-like geojson geometry, GeoSeries, GeoDataFrame or shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with bbox.
- rows: int or slice, default None. Load in specific rows by passing an integer (first n rows) or a slice() object.
- **kwargs : Keyword args to be passed to the open or BytesCollection method in the fiona library when opening the file. For more information on possible keywords, type: import fiona; help(fiona.open)
Example:
Python3
import geopandas as gpd # Reading the world shapefile world_data = gpd.read_file(r 'world.shp' ) world_data |
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