WDPA — comparing protected areas across countries¶
Fetch protected areas for several countries and compare how many each has, then map them together. Builds on the quickstart by looping the facade over a list of countries.
Token. Needs a Protected Planet v4 token in
WDPA_TOKEN(https://api.protectedplanet.net/request). See Authentication.
Setup¶
In [ ]:
Copied!
import matplotlib.pyplot as plt
from earthlens import EarthLens
import matplotlib.pyplot as plt
from earthlens import EarthLens
Fetch a few East-African countries¶
A small set of neighbouring countries (you can pass friendly names too). Each download() returns a polygon FeatureCollection.
In [ ]:
Copied!
countries = ["KEN", "TZA", "UGA"]
areas = {}
for iso3 in countries:
areas[iso3] = EarthLens(
data_source="wdpa",
variables=[iso3],
start="2024-01-01",
end="2024-12-31",
lat_lim=[-90.0, 90.0],
lon_lim=[-180.0, 180.0],
path="out/wdpa",
).download()
print(f"{iso3}: {len(areas[iso3])} protected areas")
countries = ["KEN", "TZA", "UGA"]
areas = {}
for iso3 in countries:
areas[iso3] = EarthLens(
data_source="wdpa",
variables=[iso3],
start="2024-01-01",
end="2024-12-31",
lat_lim=[-90.0, 90.0],
lon_lim=[-180.0, 180.0],
path="out/wdpa",
).download()
print(f"{iso3}: {len(areas[iso3])} protected areas")
Compare counts¶
In [ ]:
Copied!
counts = {iso3: len(fc) for iso3, fc in areas.items()}
ax = plt.bar(list(counts), list(counts.values()), color="forestgreen")
plt.title("Protected-area count by country (WDPA)")
plt.ylabel("protected areas")
plt.show()
counts = {iso3: len(fc) for iso3, fc in areas.items()}
ax = plt.bar(list(counts), list(counts.values()), color="forestgreen")
plt.title("Protected-area count by country (WDPA)")
plt.ylabel("protected areas")
plt.show()
Map them together¶
In [ ]:
Copied!
colors = ["forestgreen", "steelblue", "darkorange"]
ax = None
for (iso3, fc), color in zip(areas.items(), colors):
ax = fc.plot(ax=ax, facecolor=color, edgecolor="black", alpha=0.5, label=iso3)
ax.set_title("Protected areas — Kenya, Tanzania, Uganda")
ax.legend()
plt.show()
colors = ["forestgreen", "steelblue", "darkorange"]
ax = None
for (iso3, fc), color in zip(areas.items(), colors):
ax = fc.plot(ax=ax, facecolor=color, edgecolor="black", alpha=0.5, label=iso3)
ax.set_title("Protected areas — Kenya, Tanzania, Uganda")
ax.legend()
plt.show()
Licensing¶
WDPA carries the custom UNEP-WCMC license (commercial use needs written permission; redistribution restricted), so every download raises a LicenseWarning.