2

GeoSeries.boundary() finds the entire object's perimeter, so I supposed that wouldn't work. I made my GeoSeries donut-like shape using unary_union of smaller GeoSeries objects.

7

Use exterior method.

from shapely.geometry import Point
from geopandas import GeoSeries

donut = Point(5 ,5).buffer(5, 2).difference(Point(5, 5).buffer(3, 2))
print(donut)

# OUTPUT
# POLYGON ((10 5, 8.535.. 1.464..., 5.000... 0, 1.464... 1.464..., 0 4.999..., 1.464... 8.535..., 5 10, 8.535... 8.535..., 10 5), #exterior
#          (8 5, 7.121... 7.121..., 5 8, 2.878... 7.121..., 2 5, 2.878... 2.878..., 5. 2, 7.121... 2.878..., 8 5)) # interior

enter image description here

donut_gs = GeoSeries(donut)
print(donut_gs.exterior)

# OUTPUT
# 0    LINEARRING (10 5, 8.535.. 1.464..., ....
# dtype: geometry

enter image description here

| improve this answer | |
  • Thanks for the answer and edit. Just one question: what does the '[0]' passed in donut_gs.exterior[0] do? I only see that I get the printed object in one case (when passing [0]) and only the object's description ('linearring') in the other. – Samia Zaman Jun 12 at 16:09
  • @SamiaZaman My mistake. Without [0]you get all rows in the GeoSeries( it has 1 row here). donut_gs.exterior gives each row's exterior. donut_gs.exterior[0] is used get first row exterior. – Kadir Şahbaz Jun 12 at 20:22
  • I initially wasn't understanding why there should be 1 row; it took me a while before I finally noticed that even though the entries in the linear ring (10.00000 5.00000, 8.53553 1.46447,...) are not separated nicely by commas the way we usually expect [e.g. (10,5) (8.53,1.46), ..] each entry is still representing a single point - just space separated instead! Thanks again! – Samia Zaman Jun 13 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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