3

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:

islands detection 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?

5
  • 1
    Can you tell us, how you decide what is an island and what isn't? How does your code reflect that logic?
    – Erik
    Commented Sep 2, 2021 at 8:54
  • I forget this, an island is a polygon without neighbors. I'll filter by size after, I think .
    – Tim
    Commented Sep 2, 2021 at 9:03
  • 1
    So Ireland isn't an island? Why not dissolve first, then explode and define an Island as everything smaller than some threshold
    – JonasV
    Commented Sep 2, 2021 at 9:07
  • Because it's a amazing idea I didn't have :D
    – Tim
    Commented Sep 2, 2021 at 9:35
  • Why isn't Great Britain or the Shetlands defined as island? And wouldn't the answer below return Ireland and Northern Ireland as false? Completely surrounded or contained by water should work for everything except Ireland and Northern Ireland. That is a tough situation. Switzerland? Maybe the geometry of that polygon is such that is does not touch neighbors but you can't tell because of the scale of the polygons?
    – GBG
    Commented Sep 2, 2021 at 15:28

1 Answer 1

2

I dont know if this is any better but another way. For each polygon, if there's another at 0 distance, it is not an island.

import geopandas as gpd

df = gpd.read_file(r'C:\GIS\data\testdata\ak_riks_mod.shp')
indices = df.index.tolist()

for i in indices:
    L = [df.iloc[i].geometry.distance(df.iloc[j].geometry) for j in indices if i!=j] #List all distances
    if L.count(0)>0:
        df.at[i,'island']=0
    else:
        df.at[i,'island']=1
        
df.to_file(r'C:\GIS\data\testdata\ak_riks_mod_island.shp')

enter image description here

1
  • 1
    Good idea too !
    – Tim
    Commented Sep 2, 2021 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.