class: center, middle # Introduction to geospatial data analysis with GeoPandas and the PyData stack Joris Van den Bossche, GeoPython conference, May 7, 2018 https://github.com/jorisvandenbossche/geopandas-tutorial --- # About me Joris Van den Bossche - Background: PhD bio-science engineer, air quality research - Open source enthusiast: pandas core dev, geopandas maintainer, scikit-learn contributor - Currently working at the Université Paris-Saclay Center for Data Science (Inria) https://github.com/jorisvandenbossche Twitter: [@jorisvdbossche](https://twitter.com/jorisvdbossche)
.affiliations[   ] --- # Raster vs vector data   -- count: false .right[ ### -> in this tutorial: focus on vector data ] -- count: false .right[ ### -> simple features (points, linestrings, polygons) with attributes ] ??? Two major families of geospatial data raster: grid based (topology lacking, difficult to link to tabular data) vector: coordinate based objects, topological here: vector vector -> common abstraction model in many software Open Geospatial consortium standard Attributes : each vector feature can have a record in attribute table and that is where geopandas comes into play but before talking about geopandas, first a bit more general about open source geospatial software # geospatial software This presentation: in python but everything I will present -> builds upon widely used open source libraries --- class: middle, center # Open source geospatial software .center[  ] ??? Open Source Geospatial Foundation OSGeo was created to support the collaborative development of open source geospatial software, and promote its widespread use. --- # GDAL / OGR ### Geospatial Data Abstraction Library.
* The swiss army knife for geospatial. * Read and write Raster (GDAL) and Vector (OGR) datasets * More than 200 (mainly) geospatial formats and protocols. .center[  ] .credits[ Slide from "GDAL 2.2 What's new?" by Even Rouault (CC BY-SA) ] ??? GDAL is a translator library for raster and vector geospatial data formats. As a library, it presents a single raster abstract data model and single vector abstract data model to the calling application for all supported formats. It also comes with a variety of useful command line utilities for data translation and processing. --- # GEOS
## Geometry Engine Open Source * C/C++ port of a subset of Java Topology Suite (JTS) * Most widely used geospatial C++ geometry library * Implements geometry objects (simple features), spatial predicate functions and spatial operations Used under the hood by many applications (QGIS, PostGIS, MapServer, GRASS, GeoDjango, ...) [geos.osgeo.org](http://geos.osgeo.org) --- # Python geospatial packages -- count:false Interfaces to widely used libraries: - Python bindings to GDAL/OGR (`from osgeo import gdal, ogr`) - [`pyproj`](https://jswhit.github.io/pyproj/): python interface to PROJ.4. - Pythonic binding to GDAL/OGR: - [`rasterio`](https://mapbox.github.io/rasterio/) for GDAL - [`fiona`](http://toblerity.org/fiona/README.html) for OGR - [`shapely`](https://shapely.readthedocs.io/en/latest/): python package based on GEOS. --- # Shapely Python package for the manipulation and analysis of geometric objects
Pythonic interface to GEOS -- count:false .mmedium[ ```python >>> from shapely.geometry import Point, LineString, Polygon >>> point = Point(1, 1) >>> line = LineString([(0, 0), (1, 2), (2, 2)]) >>> poly = line.buffer(1) ``` ]
.mmedium[ ```python >>> poly.contains(point) True ``` ] -- count: false Nice interface to GEOS, but: single objects, no attributes ??? # Shapely typical predicates and operations (images from shapely docs) ---  One of the packages driving the growing popularity of Python for data science, machine learning and academic research * High-performance, easy-to-use data structures and tools * Suited for tabular data (e.g. columnar data, spread-sheets, database tables) ```python import pandas as pd df = pd.read_csv("myfile.csv") subset = df[df['value'] > 0] subset.groupby('key').mean() ``` --- # GeoPandas Make working with geospatial data in python easier * Started by Kelsey Jordahl in 2013 * Extends the pandas data analysis library to work with geographic objects and spatial operations * Combines the power of whole ecosystem of (geo) tools (pandas, geos, shapely, gdal, fiona, pyproj, rtree, ...) Documentation: http://geopandas.readthedocs.io/ ??? make working with geospatial data like working with any other kind of data in python (data stack, numpy, pandas and other tools around those) analysis for which you otherwise would need desktop GIS applications (QGIS, ArcGIS) or geospatial databases (PostGIS) makes pandas objects geometry aware --- # Summary * Read and write variety of formats (fiona, GDAL/OGR) * Familiar manipulation of the attributes (pandas dataframe) * Element-wise spatial predicates (intersects, within, ...) and operations (intersection, union, difference, ..) (shapely) * Re-project your data (pyproj) * Quickly visualize the geometries (matplotlib, descartes) * More advanced spatial operations: spatial joins and overlays (rtree) -- count:false **-> Interactive exploration and analysis of geospatial data** --- # Ecosystem [geoplot](http://www.residentmar.io/geoplot/index.html) (high-level geospatial visualization), [cartopy](http://scitools.org.uk/cartopy/) (projection aware cartographic library) [folium](https://github.com/python-visualization/folium) (Leaflet.js maps) [OSMnx](http://geoffboeing.com/2016/11/osmnx-python-street-networks/) (python for street networks) [PySAL](http://pysal.readthedocs.io/en/latest/index.html) (Python Spatial Analysis Library) [rasterio](https://mapbox.github.io/rasterio/) (working with geospatial raster data) ... --- class: middle http://geopandas.readthedocs.io # Thanks for listening! ## Thanks to all contributors! ## Those slides: - https://github.com/jorisvandenbossche/talks/ - [jorisvandenbossche.github.io/talks/2018_FOSDEM_geopandas]( http://jorisvandenbossche.github.io/talks/2018_FOSDEM_geopandas) http://geopandas.readthedocs.io