GeoSpatial Analysis using GeoPandas in python

GeoSpatial Analysis using GeoPandas in python

In this tuorial, we will do geospatial analysis using python on UK Accidents and UK Administrative datasets.

Geopandas is a library for working with geospatial data in Python. It builds on the popular Pandas library and extends its functionality to handle geospatial data. Some of the key features of Geopandas include:

  • Handling of shapefiles, geojson, and other geospatial data formats
  • Integration with other popular Python libraries such as Matplotlib and Scikit-learn
  • Easy handling and manipulation of geospatial data, including operations like merging, grouping, and transforming data
  • Support for spatial join operations, spatial indexing, and other geospatial analysis tasks

Here are some examples of tasks you can perform using Geopandas:

  • Visualizing and plotting geospatial data on maps
  • Performing spatial join operations to combine data from different sources
  • Calculating summary statistics for spatial data, such as mean, median, or standard deviation
  • Performing spatial analysis tasks, such as proximity analysis or spatial clustering

First, we will set up conda environment and install required python GIS packages for this task. Make sure conda is installed on your system. Use following commands to create a conda environment and to install python libraries.

Geospatial analysis using GeoPandas on UK Accidents and UK Administrative datasets

Click here to get source code and datasets used in this tutorial.

The below code reads in two datasets: a dataset of UK accidents, and a shapefile of administrative regions in the UK. The following steps are performed on the accidents dataset:

  • Convert the longitude and latitude columns to numeric data types.
  • Convert the longitude and latitude columns into Point geometries.
  • Set the coordinate reference system (CRS) to EPSG:4326 (WGS 84) for the accidents dataset.
  • Filter out any invalid geometries or empty geometries.
  • Convert the CRS to EPSG:3857 (Web Mercator) for the accidents dataset.

1. A sample point is then created and a buffer of 1000 meters is created around it. The code then filters the accidents dataset to find all accidents within this buffer.

2. Next, the shapefile of UK administrative regions is read in and its CRS is also converted to EPSG:3857. A spatial join is then performed between the accidents dataset and the administrative regions shapefile, resulting in a merged GeoDataFrame. This GeoDataFrame contains all the accidents point with region based value from UK administrative regions. Using spatial join, ADMIN_REGI column is added to uk_accidents data set.

3. Finally, the merged GeoDataFrame is grouped by the administrative region and the number of accidents in each region is counted. The result is a series of the number of accidents in each administrative region.

I hope this tutorial will create a good foundation for you. If you want tutorials on another GIS topic or you have any queries, please send an email at

We also offer freelancing services. Please email us at for any query.

Leave a ReplyCancel reply