0% found this document useful (0 votes)
65 views

Geospatial Data: Instructors

This document provides an overview of working with geospatial data in Python. It discusses what geospatial data is, how the real world is recorded through raster and vector data formats. It also explains how to import geospatial data into GeoPandas, which allows users to work with geospatial data in a pandas DataFrame. GeoPandas enables spatial operations and visualization of data on maps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Geospatial Data: Instructors

This document provides an overview of working with geospatial data in Python. It discusses what geospatial data is, how the real world is recorded through raster and vector data formats. It also explains how to import geospatial data into GeoPandas, which allows users to work with geospatial data in a pandas DataFrame. GeoPandas enables spatial operations and visualization of data on maps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Geospatial Data

W O R K I N G W I T H G E O S PAT I A L D ATA I N P Y T H O N

Instructors
Joris Van den Bossche & Dani Arribas-
Bel
What is Geospatial Data?
Geospatial data are data with location information

WORKING WITH GEOSPATIAL DATA IN PYTHON


What is Geospatial Data?
Geospatial data are data with location information

WORKING WITH GEOSPATIAL DATA IN PYTHON


WORKING WITH GEOSPATIAL DATA IN PYTHON
WORKING WITH GEOSPATIAL DATA IN PYTHON
How we record the real world

WORKING WITH GEOSPATIAL DATA IN PYTHON


Raster versus vector data

WORKING WITH GEOSPATIAL DATA IN PYTHON


Vector features
"Discrete" representations that turn the world into:

WORKING WITH GEOSPATIAL DATA IN PYTHON


Vector features
"Discrete" representations that turn the world into:

WORKING WITH GEOSPATIAL DATA IN PYTHON


Vector features
"Discrete" representations that turn the world into:

Feature consisting of multiple geometries: eg MultiPolygon

WORKING WITH GEOSPATIAL DATA IN PYTHON


WORKING WITH GEOSPATIAL DATA IN PYTHON
WORKING WITH GEOSPATIAL DATA IN PYTHON
WORKING WITH GEOSPATIAL DATA IN PYTHON
Vector attribute data
Vector features can have information associated that describe them: a ributes

Tabular vector data:

WORKING WITH GEOSPATIAL DATA IN PYTHON


Let's practice!
W O R K I N G W I T H G E O S PAT I A L D ATA I N P Y T H O N
Introduction to
GeoPandas
W O R K I N G W I T H G E O S PAT I A L D ATA I N P Y T H O N

Joris Van den Bossche


Open source so ware developer and
teacher, GeoPandas maintainer
Spatial specific data formats
restaurants = pd.read_csv("datasets/paris_restaurants.csv")
restaurants.head()

type x y
0 Restaurant européen 259641.6 6251867.4
1 Restaurant traditionnel français 259572.3 6252030.2
2 Restaurant traditionnel français 259657.2 6252143.8
3 Restaurant indien, pakistanais et Moyen Orient 259684.4 6252203.6
4 Restaurant traditionnel français 259597.9 6252230.0

In the rest of the course:

spatial le formats (Shape les, GeoJSON, GeoPackage, ...)

GeoPandas: pandas dataframes with support for spatial data

WORKING WITH GEOSPATIAL DATA IN PYTHON


Importing geospatial data with GeoPandas
import geopandas

countries = geopandas.read_file("countries.geojson")

countries.head()

name continent gdp geometry


0 Afghanistan Asia 64080.0 POLYGON ((61.21 35.65, 62.23 35...
1 Angola Africa 189000.0 MULTIPOLYGON (((23.90 -11.72, 2...
2 Albania Europe 33900.0 POLYGON ((21.02 40.84, 21.00 40...
4 Argentina South America 879400.0 MULTIPOLYGON (((-66.96 -54.90, ...
5 Armenia Asia 26300.0 POLYGON ((43.58 41.09, 44.97 41...

WORKING WITH GEOSPATIAL DATA IN PYTHON


Quickly visualizing spatial data with GeoPandas
countries.plot()

WORKING WITH GEOSPATIAL DATA IN PYTHON


The GeoDataFrame
countries.head()

name continent gdp geometry


0 Afghanistan Asia 64080.0 POLYGON ((61.21 35.65, 62.23 35...
1 Angola Africa 189000.0 MULTIPOLYGON (((23.90 -11.72, 2...
2 Albania Europe 33900.0 POLYGON ((21.02 40.84, 21.00 40...
...

type(countries)

geopandas.geodataframe.GeoDataFrame

WORKING WITH GEOSPATIAL DATA IN PYTHON


The GeoDataFrame
countries.head()

name continent gdp geometry


0 Afghanistan Asia 64080.0 POLYGON ((61.21 35.65, 62.23 35...
1 Angola Africa 189000.0 MULTIPOLYGON (((23.90 -11.72, 2...
2 Albania Europe 33900.0 POLYGON ((21.02 40.84, 21.00 40...
...

A GeoDataFrame represents a tabular, geospatial vector dataset:

a 'geometry' column: that holds the geometry information

other columns: a ributes describe each of the geometries

WORKING WITH GEOSPATIAL DATA IN PYTHON


The 'geometry' attribute
countries.geometry

0 POLYGON ((61.21 35.65, 62.23 35...


1 MULTIPOLYGON (((23.90 -11.72, 2...
...
175 POLYGON ((23.22 -17.52, 22.56 -...
176 POLYGON ((29.43 -22.09, 28.79 -...
Name: geometry, Length: 176, dtype: object

type(countries.geometry)

geopandas.geoseries.GeoSeries

WORKING WITH GEOSPATIAL DATA IN PYTHON


Spatial aware DataFrame
countries.geometry.area

0 63.593500
1 103.599439
2 3.185163
...
174 112.718524
175 62.789498
176 32.280371
Length: 177, dtype: float64

WORKING WITH GEOSPATIAL DATA IN PYTHON


Summary
A GeoDataFrame is like a pandas DataFrame:

all features of normal pandas DataFrames still work

but supercharged with spatial functionality:

plot() method

geometry a ribute (GeoSeries)

spatial-speci c a ributes and methods (e.g. area )

WORKING WITH GEOSPATIAL DATA IN PYTHON


Let's practice!
W O R K I N G W I T H G E O S PAT I A L D ATA I N P Y T H O N
Exploring and
visualizing spatial
data and its
attributes
W O R K I N G W I T H G E O S PAT I A L D ATA I N P Y T H O N

Joris Van den Bossche


Open source so ware developer and
teacher, GeoPandas maintainer
Filtering data
countries.head()

name continent gdp geometry


0 Afghanistan Asia 64080.0 POLYGON ((61.21 35.65, 62.23 35...
1 Angola Africa 189000.0 MULTIPOLYGON (((23.90 -11.72, 2...
...

countries['continent'] == 'Africa'

0 False
1 True
...
175 True
176 True
Name: continent, Length: 177, dtype: bool

WORKING WITH GEOSPATIAL DATA IN PYTHON


Filtering data
countries_africa = countries[countries['continent'] == 'Africa']

countries_africa.plot()

WORKING WITH GEOSPATIAL DATA IN PYTHON


Visualizing spatial data
countries.plot()

WORKING WITH GEOSPATIAL DATA IN PYTHON


Adjusting the color: uniform color
countries.plot(color="red")

WORKING WITH GEOSPATIAL DATA IN PYTHON


Adjusting the color: based on attribute values
countries.plot(column='gdp_per_cap')

WORKING WITH GEOSPATIAL DATA IN PYTHON


Multi-layered plot
fig, ax = plt.subplots(figsize=(12, 6))
countries.plot(ax=ax)
cities.plot(ax=ax, color='red', markersize=10)
ax.set_axis_off()

WORKING WITH GEOSPATIAL DATA IN PYTHON


Let's practice!
W O R K I N G W I T H G E O S PAT I A L D ATA I N P Y T H O N

You might also like