Get geometries for named countries¶
This example illustrates how to get a list of coordinates which describes the boundary of one or more countries. Country polygons are derived from Natural Earth’s shapefiles.
[1]:
import earthkit.geo.cartography
countries = ["France", "Italy", "Spain"]
shapes = earthkit.geo.cartography.country_polygons(countries, resolution=50e6)
# Print the truncated result
print(str(shapes)[:100] + "...")
[[[27.761474609375, -18.160546874999994], [27.768115234374996, -18.043359374999994], [27.85014648437...
The result is a list of lists of coordinates, where each sublist represents a polygon.
We can plot this result on a map using earthkit-plots:
[2]:
import earthkit.plots
chart = earthkit.plots.Map(domain=countries)
chart.coastlines(color="#DDDDDD")
for shape in shapes:
longitudes = [point[1] for point in shape]
latitudes = [point[0] for point in shape]
chart.line(x=longitudes, y=latitudes, color="red")
chart.gridlines()
chart.show()