Geospatial Data and 7 Python Libraries to Visualize Them🗺️
Tags: machinelearning, datascience, python
Published: 2020-12-05 07:07:23

## Geospatial Data

> Geospatial data means data that has geographic components for locational information like coordinates, address, ZIP code, etc. 

Analysis and Visualization of Geospatial data is one of the recent branches of Data Science. It can be used for many purposes like - coffee chains like Starbucks, Dunkin' or CCD determine where to make there next outlet, determining earthquake-prone areas in countries like Japan to provide extra reinforcement in those areas, it can be used determine areas with most pollution or areas where certain wildlife can find their natural shelter.  In the present time, it can be used for tracking the spread of COVID-19 and determining red-zones or containment zones.

## Representation of Geospatial Data
There are many types of geospatial data file formats like **shapefile**, **GeoJSON**, **KML**, and **GPKG**. These type of file formats can be used to store geospatial data. 

**Shapefile** is the most common format for storing geospatial data. It represents the data in the form of points, lines, and polygons along with certain attributes like name, temperature, etc. These shapes along with the attributes form geographic components like rivers, roads, landmarks, etc. It contains three mandatory files **.shp** - representing the shape or geometry, **.shx** - representing the index of the shapes for easier navigation, **.dbf** - storing the attributes associated with the shapes. Along with these mandatory files some other files like .prj,.ixs,.mxs,etc. can also be present. 

**GeoJSON** represents the geospatial data in JSON like format *eg-* 
```javascript
{
"type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [105.6, 110.1]
  },
  "properties": {
    "name": "Andaman Islands"
} 
}
```
It can represent data in the following geometry types: `Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon`. 

**KML** stands for Keyhole Markup Language and is used to represent data in Google Earth. It is based on XML notation. They are distributed in zipped formats with .kmz as an extension.

**GPKG** or GeoPackage is an open format that can represent geospatial data in both raster and vector forms. It is an extended SQLite database file that is lightweight and contained in a single ready-to-use file.

## Visualization of Geospatial Data
There are many Python libraries to visualize geospatial data and draw interesting maps some of the most famous of them are:-

* [Folium](https://python-visualization.github.io/folium/)
* [GeoPandas](https://geopandas.org/)
* [Basemap](https://basemaptutorial.readthedocs.io/en/latest/)
* [GeoViews](https://geoviews.org/)
* [KeplerGL](https://kepler.gl/)
* [IpyLeaflet](https://ipyleaflet.readthedocs.io/en/latest/)
* [Cartopy](https://scitools.org.uk/cartopy/docs/latest/)

## Folium 
It is based on Leaflet.js. It makes visualization with the help of interactive leaflet map data manipulated in python. It supports the GeoJSON file type along with some other file types.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/r2mxn9sr9rterws93n14.PNG)
<hr>
## GeoPandas
It extends the datatypes used by Pandas to represent geospatial data. It uses descartes and matplotlib for plotting. It is based on shapely for geometric operations. It supports GPKG, shapefile, and GeoJSON data formats.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/kohn0k81kixcr42nm1gy.png)
<hr>
## BaseMap
It is a great tool to make interactive maps and is an extension of matplotlib. It supports shapefile type data.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b86o3ylphalr53ib126j.png)
<hr>
## GeoViews
It is built on Holoviews library. It uses Cartopy python package and for visualization uses matplotlib or Bokeh. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0gon0xleah4vtf1th2gy.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/s1mu8m936wvg8b8t3tvk.png)
<hr>
## KeplerGL
It is based on WebGL. Kepler.gl is also a React component that uses Redux to manage its state and data flow. It can be embedded into other React-Redux applications and is highly customizable.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fztfh3ayqafl1ceg3qsi.png)
<hr>
## IpyLeaflet
It is used to embed maps in Jupyter notebooks. It acts as a bridge between leaflet.js and Jupyter.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5ufkm30moz3219m1x3wb.PNG)
<hr>
## Cartopy
Cartopy is a Python package for geospatial data processing, produce maps and geospatial data analyses. Cartopy makes use of powerful PROJ.4, NumPy and Shapely libraries and uses Matplotlib for the creation of maps.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2xhhx8c2upl3udnsv5l4.png)