dimanche 7 mars 2021

How to loop through a multipolygon and return the area of the largest one

I am trying to figure out how I could extract mainland Great Britain from the uk MultiPolygon.

I got the coastline of Great Britain out of the countries dataset

from shapely.geometry import LineString

from geopandas import read_file, GeoSeries

from matplotlib_scalebar.scalebar import ScaleBar

from matplotlib.pyplot import subplots, savefig, Line2D

from rtree import index

get the proj string definition for British National Grid (OSGB)

osgb = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs"

open a dataset of all countries in the world

world = read_file("../data/natural-earth/ne_10m_admin_0_countries.shp")

extract the UK, project, and extract the geometry (a multipolygon)

uk = world.loc[(world.ISO_A3 == 'GBR')].to_crs(osgb).geometry.iloc[0]

report geometry type

print(f"geometry type: {uk.geom_type}")

But I'm not really sure how to progress. We've been tasked with looping through the polygon list using an if statement but I'm getting really confused over the terminology as I'm new to this. I can't return the value inside the polygon only the name.

Does anyone have any suggestions?

Thank you

Aucun commentaire:

Enregistrer un commentaire