Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. >>> p1=Polygon([(0,0),(10,0),(10,10),(0,10)])
  2. >>> p2=Polygon([(10,10),(20,10),(20,20),(10,20)])
  3. >>> p3=Polygon([(10,10),(10,20),(0,10)])
  4. >>>
  5. >>> p4=Polygon([(40,40),(50,40),(50,30),(40,30)])
  6. >>> p5=Polygon([(40,40),(50,40),(50,50),(40,50)])
  7. >>> p6=Polygon([(40,40),(40,50),(30,50)])
  8. >>>
  9. >>> df=gpd.GeoDataFrame(geometry=[p1,p2,p3,p4,p5,p6])
  10. >>> df
  11. geometry
  12. 0 POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))
  13. 1 POLYGON ((10 10, 20 10, 20 20, 10 20, 10 10))
  14. 2 POLYGON ((10 10, 10 20, 0 10, 10 10))
  15. 3 POLYGON ((40 40, 50 40, 50 30, 40 30, 40 40))
  16. 4 POLYGON ((40 40, 50 40, 50 50, 40 50, 40 40))
  17. 5 POLYGON ((40 40, 40 50, 30 50, 40 40))
  18. >>>
  19. >>> df.plot()
  20.  
  21. >>> SepIslands=gpd.GeoDataFrame(geometry=list(df.unary_union))
  22. >>> SepIslands.plot()
  23.  
  24. >>> SepIslands['IslandID']=SepIslands.index+1
  25.  
  26. >>> Final=gpd.tools.sjoin(df, SepIslands, how='left').drop('index_right',1)
  27. >>> Final
  28. geometry IslandID
  29. 0 POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)) 1
  30. 1 POLYGON ((10 10, 20 10, 20 20, 10 20, 10 10)) 1
  31. 2 POLYGON ((10 10, 10 20, 0 10, 10 10)) 1
  32. 3 POLYGON ((40 40, 50 40, 50 30, 40 30, 40 40)) 2
  33. 4 POLYGON ((40 40, 50 40, 50 50, 40 50, 40 40)) 2
  34. 5 POLYGON ((40 40, 40 50, 30 50, 40 40)) 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement