import pandas as pd
import shapely as sp
import contextily as ctx
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import rasterio
import rasterio.plot
import requests
import requests
import tempfileGeographic data manipulation
Geographic data
Outline for this part: - Vector data - Raster data - CRS - Vector / Raster interactions - Recap Exercise
Vector data
Introduction
# "https://datacatalogfiles.worldbank.org/ddh-published/0038272/5/DR0095370/World Bank Official Boundaries (GeoPackage)/World Bank Official Boundaries - Admin 0.gpkg"
world = gpd.read_file("./data/countries.gpkg")
world| ISO_A3 | ISO_A2 | WB_A3 | HASC_0 | GAUL_0 | WB_REGION | WB_STATUS | SOVEREIGN | NAM_0 | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | CHN | CN | CHN | CN | 147295 | EAP | Member State | CHN | China | MULTIPOLYGON (((117.58675 38.59517, 117.58909 ... |
| 1 | JPN | JP | JPN | JP | 126 | Other | Member State | JPN | Japan | MULTIPOLYGON (((137.48411 34.67386, 137.46683 ... |
| 2 | KOR | KR | KOR | KR | 202 | EAP | Member State | KOR | Republic of Korea | MULTIPOLYGON (((126.05363 36.19852, 126.05372 ... |
| 3 | PRK | KP | PRK | KP | 67 | Other | Non Member State | PRK | D. P. R. of Korea | MULTIPOLYGON (((126.95508 38.16282, 126.95184 ... |
| 4 | RUS | RU | RUS | RU | 204 | ECA | Member State | RUS | Russian Federation | MULTIPOLYGON (((130.61904 48.88019, 130.60659 ... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 259 | UMI | UM | UMI | UM | 129 | Other | Territory | USA | U.S. Minor Outlying Islands (U.S.) | MULTIPOLYGON (((-169.51424 16.75948, -169.5177... |
| 260 | UMI | UM | UMI | UM | 190 | Other | Territory | USA | U.S. Minor Outlying Islands (U.S.) | MULTIPOLYGON (((-162.05749 5.87833, -162.05696... |
| 261 | URY | UY | URY | UY | 260 | LCR | Member State | URY | Uruguay | MULTIPOLYGON (((-56.65825 -30.20105, -56.65254... |
| 262 | WLF | WF | WLF | WF | 266 | Other | Territory | FRA | Wallis and Futuna (Fr.) | MULTIPOLYGON (((-176.24899 -13.30266, -176.247... |
| 263 | WSM | WS | WSM | WS | 212 | EAP | Member State | WSM | Samoa | MULTIPOLYGON (((-172.40519 -13.45112, -172.400... |
264 rows × 10 columns
- Attribute data, like the name of a country in the
NAM_0column- this is plain tabular data like used before in this course
- Geometry data, which describes the shape & location of objects in the
geometrycolumn- the shape and location of country borders in this case
- this is new and what this session is about
We’ll be using GeoPandas which is an extension of Pandas - GeoDataFrame is an extension of DataFrame, which works exactly like a standard dataframe for the non-geometry variables
world_viz = world.copy()
world_viz.geometry = world_viz.geometry.simplify(0.1, preserve_topology=True)
world_viz[["NAM_0", "geometry"]].explore() Make this Notebook Trusted to load map: File -> Trust Notebook