Coordinate Reference S y stems W OR K IN G W ITH G E OSPATIAL - - PowerPoint PPT Presentation

coordinate reference s y stems
SMART_READER_LITE
LIVE PREVIEW

Coordinate Reference S y stems W OR K IN G W ITH G E OSPATIAL - - PowerPoint PPT Presentation

Coordinate Reference S y stems W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON Joris Van den Bossche Open so u rce so w are de v eloper and teacher , GeoPandas maintainer Coordinate Reference S y stem ( CRS ) Location of the Ei el To w


slide-1
SLIDE 1

Coordinate Reference Systems

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

Joris Van den Bossche

Open source soware developer and teacher, GeoPandas maintainer

slide-2
SLIDE 2

WORKING WITH GEOSPATIAL DATA IN PYTHON

Coordinate Reference System (CRS)

Location of the Eiel Tower:

POINT (2.2945 48.8584)

→ The Coordinate Reference System (CRS) relates the coordinates to a specic location on earth.

slide-3
SLIDE 3

WORKING WITH GEOSPATIAL DATA IN PYTHON

Geographic coordinates

Degrees of latitude and longitude. E.g. 48°51′N, 2°17′E Used in GPS, web mapping applications... Aention! in Python we use (lon, lat) and not (lat, long) Longitude: [-180, 180] Latitude: [-90, 90]

slide-4
SLIDE 4

WORKING WITH GEOSPATIAL DATA IN PYTHON

Maps are 2D

slide-5
SLIDE 5

WORKING WITH GEOSPATIAL DATA IN PYTHON

Projected coordinates

(x, y) coordinates are usually in meters or feet

slide-6
SLIDE 6

WORKING WITH GEOSPATIAL DATA IN PYTHON

Projected coordinates - Examples

Albers Equal Area projection

slide-7
SLIDE 7

WORKING WITH GEOSPATIAL DATA IN PYTHON

Projected coordinates - Examples

Mercator projection

slide-8
SLIDE 8

WORKING WITH GEOSPATIAL DATA IN PYTHON

Projected coordinates - Examples

Projected size vs actual size (Mercator projection)

slide-9
SLIDE 9

WORKING WITH GEOSPATIAL DATA IN PYTHON

Specifying a CRS

proj4 string

Example: +proj=longlat +datum=WGS84 +no_defs Dict representation:

{'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True}

EPSG code Example:

EPSG:4326 = WGS84 geographic CRS (longitude, latitude)

slide-10
SLIDE 10

WORKING WITH GEOSPATIAL DATA IN PYTHON

CRS in GeoPandas

The .crs aribute of a GeoDataFrame/GeoSeries:

import geopandas gdf = geopandas.read_file("countries.shp") print(gdf.crs) {'init': 'epsg:4326'}

slide-11
SLIDE 11

WORKING WITH GEOSPATIAL DATA IN PYTHON

Summary

"geographic" (long, lat) versus "projected" (x, y) coordinates Coordinates Reference System (CRS) in GeoPandas: .crs aribute Most used geographic CRS: WGS84 or EPSG:4326

slide-12
SLIDE 12

Let's practice

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

slide-13
SLIDE 13

Working with coordinate systems in GeoPandas

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

Joris Van den Bossche

Open source soware developer and teacher, GeoPandas maintainer

slide-14
SLIDE 14

WORKING WITH GEOSPATIAL DATA IN PYTHON

CRS information in GeoPandas

The .crs aribute of a GeoDataFrame/GeoSeries:

import geopandas gdf = geopandas.read_file("countries.shp") print(gdf.crs) {'init': 'epsg:4326'}

slide-15
SLIDE 15

WORKING WITH GEOSPATIAL DATA IN PYTHON

Setting a CRS manually

gdf_noCRS = geopandas.read_file("countries_noCRS.shp") print(gdf_noCRS.crs) {}

Add CRS information to crs :

# Option 1 gdf.crs = {'init': 'epsg:4326'} # Option 2 gdf.crs = {'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True}

slide-16
SLIDE 16

WORKING WITH GEOSPATIAL DATA IN PYTHON

Transforming to another CRS

import geopandas gdf = geopandas.read_file("countries_web_mercator.shp") print(gdf.crs) {'init': 'epsg:3857', 'no_defs': True}

The to_crs() method:

# Option 1 gdf2 = gdf.to_crs({'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True}) # Option 2 gdf2 = gdf.to_crs(epsg=4326)

slide-17
SLIDE 17

WORKING WITH GEOSPATIAL DATA IN PYTHON

Why converting the CRS?

1) Sources with a dierent CRS

df1 = geopandas.read_file(...) df2 = geopandas.read_file(...) df2 = df2.to_crs(df1.crs)

slide-18
SLIDE 18

WORKING WITH GEOSPATIAL DATA IN PYTHON

Why converting the CRS?

1) Sources with a dierent CRS 2) Mapping (distortion of shape and distances)

slide-19
SLIDE 19

WORKING WITH GEOSPATIAL DATA IN PYTHON

Why converting the CRS?

1) Sources with a dierent CRS 2) Mapping (distortion of shape and distances) 3) Distance / area based calculations

slide-20
SLIDE 20

WORKING WITH GEOSPATIAL DATA IN PYTHON

How to choose which CRS to use?

Tips: Use projection specic to the area of your data Most countries have a standard CRS Useful sites: hp://spatialreference.org/ hps://epsg.io/

slide-21
SLIDE 21

WORKING WITH GEOSPATIAL DATA IN PYTHON

Summary

To convert to another CRS: the to_crs() method Make sure dierent datasets have the same CRS When calculating distance, area, ... -> use a projected CRS Useful sites: hp://spatialreference.org/ hps://epsg.io/

slide-22
SLIDE 22

Let's practice!

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

slide-23
SLIDE 23

Spatial operations: creating new geometries

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

Joris Van den Bossche

Open source soware developer and teacher, GeoPandas maintainer

slide-24
SLIDE 24

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations

slide-25
SLIDE 25

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations: intersection

slide-26
SLIDE 26

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations: union

slide-27
SLIDE 27

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations: difference

slide-28
SLIDE 28

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations with GeoPandas

africa.head() name geometry 0 Angola (POLYGON ((23.90... 1 Burundi POLYGON ((29.339... 2 Benin POLYGON ((2.6917... 3 Burkina Faso POLYGON ((2.1544... 4 Botswana POLYGON ((29.432...

slide-29
SLIDE 29

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations with GeoPandas

print(box) POLYGON ((60 10, 60 -10, -20 -10, -20 10))

slide-30
SLIDE 30

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations with GeoPandas

africa.intersection(box)

slide-31
SLIDE 31

WORKING WITH GEOSPATIAL DATA IN PYTHON

Spatial operations with GeoPandas

africa.head() name geometry 0 Angola (POLYGON ((23.90415368011818 -11.7222815894063... 1 Burundi POLYGON ((29.33999759290035 -4.499983412294092... 2 Botswana POLYGON ((29.43218834810904 -22.09131275806759... ... africa.intersection(box) 0 (POLYGON ((13.22332255001795 -10, 13.120987583... 1 POLYGON ((29.33999759290035 -4.499983412294092... 2 () ... dtype: object

slide-32
SLIDE 32

Let's practice!

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

slide-33
SLIDE 33

Overlaying spatial datasets

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON

Joris Van den Bossche

Open source soware developer and teacher, GeoPandas maintainer

slide-34
SLIDE 34

WORKING WITH GEOSPATIAL DATA IN PYTHON

Intersection with a polygon

countries.intersection(circle)

slide-35
SLIDE 35

WORKING WITH GEOSPATIAL DATA IN PYTHON

Intersection with a polygon

Limitations of countries.intersection(circle) : Only intersecting a GeoSeries with a single polygon Does not preserve aribute information

slide-36
SLIDE 36

WORKING WITH GEOSPATIAL DATA IN PYTHON

Overlaying two datasets

countries.plot() geologic_regions.plot()

slide-37
SLIDE 37

WORKING WITH GEOSPATIAL DATA IN PYTHON

Overlaying two datasets

geopandas.overlay(countries, geologic_regions, how='intersection')

slide-38
SLIDE 38

WORKING WITH GEOSPATIAL DATA IN PYTHON

Overlay vs intersection

Intersection method (with single polygon)

countries.intersection(geologic_region_A) 0 () 1 POLYGON ((-1.661 48.803... 2 POLYGON ((1.201 51.145,... dtype: object

Overlay method

geopandas.overlay(countries, geologic_regions, how='intersection') name geologic_region geometry 1 France C POLYGON ((2.5 51.... 2 UK C POLYGON ((0.7 52 ... 3 France B POLYGON ((-1.7 46... .. ... ... ...

slide-39
SLIDE 39

Let's practice!

W OR K IN G W ITH G E OSPATIAL DATA IN P YTH ON