Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> p1=Polygon([(0,0),(10,0),(10,10),(0,10)])
- >>> p2=Polygon([(10,10),(20,10),(20,20),(10,20)])
- >>> p3=Polygon([(10,10),(10,20),(0,10)])
- >>>
- >>> p4=Polygon([(40,40),(50,40),(50,30),(40,30)])
- >>> p5=Polygon([(40,40),(50,40),(50,50),(40,50)])
- >>> p6=Polygon([(40,40),(40,50),(30,50)])
- >>>
- >>> df=gpd.GeoDataFrame(geometry=[p1,p2,p3,p4,p5,p6])
- >>> df
- geometry
- 0 POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))
- 1 POLYGON ((10 10, 20 10, 20 20, 10 20, 10 10))
- 2 POLYGON ((10 10, 10 20, 0 10, 10 10))
- 3 POLYGON ((40 40, 50 40, 50 30, 40 30, 40 40))
- 4 POLYGON ((40 40, 50 40, 50 50, 40 50, 40 40))
- 5 POLYGON ((40 40, 40 50, 30 50, 40 40))
- >>>
- >>> df.plot()
- >>> SepIslands=gpd.GeoDataFrame(geometry=list(df.unary_union))
- >>> SepIslands.plot()
- >>> SepIslands['IslandID']=SepIslands.index+1
- >>> Final=gpd.tools.sjoin(df, SepIslands, how='left').drop('index_right',1)
- >>> Final
- geometry IslandID
- 0 POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)) 1
- 1 POLYGON ((10 10, 20 10, 20 20, 10 20, 10 10)) 1
- 2 POLYGON ((10 10, 10 20, 0 10, 10 10)) 1
- 3 POLYGON ((40 40, 50 40, 50 30, 40 30, 40 40)) 2
- 4 POLYGON ((40 40, 50 40, 50 50, 40 50, 40 40)) 2
- 5 POLYGON ((40 40, 40 50, 30 50, 40 40)) 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement