I'm trying to classify island in an AOI. For the moment I haven't the final real AOI so i'm working on a sample of world nations polygons. To detect islands, I use geopandas.GeoSeries.touches. It works not so bad but have some mistakes and some details I want to precise.
My code for the moment:
p_path = "world/Light_GS_REF_MONDE_PAYS_V1_for_tests.shp"
gdf = gpd.read_file(p_path)
gdf = gdf.to_crs("EPSG:3857")
exploded = gdf.explode()
exploded = exploded.reset_index().drop(columns=['level_0', 'level_1'], axis=1)
for index, row in exploded.iterrows():
neighbors = exploded[exploded.geometry.touches(row['geometry'], align=False)].PAYS.tolist()
if len(neighbors) > 0:
exploded.at[index, "island"] = "False"
else:
exploded.at[index, "island"] = "True"
exploded.at[index, "neighbors"] = len(neighbors)
Here is visual results:
- We can see that Switzerland is consider as an island. I don't understand why...
- Some little islands have 1 neighbors because of 1 common node due to drawing precision. It would be better to need more than 2 nodes in common to define 2 neighbors.
Does anybody have an idea to improve my process?