Spatial analysis with geopandas
Spatial analysis with geopandas
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
type(world), world.shape
world.head()
world.continent.value_counts()
world.crs
southern_world = world.cx[:, :0]
southern_world.plot(figsize=(10,6))
southern_world.crs
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
cities = gpd.read_file(gpd.datasets.get_path("naturalearth_cities"))
world.head()
world.plot()
cities.head()
cities.plot()
ax = world.plot()
cities.plot(ax=ax)
world = world[(world.pop_est>0) & (world.name!="Antarctica")]
world.shape
world['gdp_per_cap'] = world.gdp_md_est/world.pop_est
world.plot(column="gdp_per_cap", figsize=(10,6))
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig, ax = plt.subplots(1, 1)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.1)
world.plot(column='pop_est', ax=ax, legend=True, cax=cax, figsize=(10,6))
world.boundary.plot()
cities.plot(marker="*", color="green", markersize=5)
cities.crs, world.crs
cities = cities.to_crs(world.crs)
base = world.plot(color="white", edgecolor="black")
cities.plot(ax=base, marker="o", color="red", markersize=5)
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_aspect("equal")
world.plot(ax=ax, color="white", edgecolor="black")
cities.plot(ax=ax, marker="o", color="red", markersize=5)
plt.show()