0

Why does buffering one of my geometries have an unexpected hole in it?

from shapely import LineString
from geopandas import GeoDataFrame

l = LineString([
  (250,447),
  (319,446),
  (325,387),
  (290,374),
  (259,378),
  (254,385),
  (240,409),
  (244,440),
  (250,447),
])

assert l.is_valid
assert l.is_simple

GeoDataFrame({'geometry': [
  l,
  l.buffer(80),
]}).plot(column='geometry')

holey buffered geometry

  • By removing a pair of coordinates, it doesn't have a hole.
  • When using Sedona's ST_Buffer this happened in more cases.
A. West
  • 571
  • 5
  • 12
  • It fills the hole when using this LineRing: `l = LineString([(250,447),(319,446),(325,387),(290,374),(259,378),(254,385),(240,409),(250,447)])` – A. West Jan 16 '23 at 09:25
  • I expect there to be a hole when I buffer less: `l.buffer(40)` – A. West Jan 16 '23 at 09:25
  • My hack solution is to buffer a tiny amount to make a polygon: `l.buffer(1e-6).buffer(80)` – A. West Jan 17 '23 at 12:33

1 Answers1

0
from shapely import LineString
from geopandas import GeoDataFrame

l = LineString([
  (250,447),
  (319,446),
  (325,387),
  (290,374),
  (259,378),
  (254,385),
  (240,409),
  (244,440),
  (250,447),
])

l = l.simplify(tolerance=1e-6)

buffered_geometry = l.buffer(80, cap_style=3, join_style=2)

GeoDataFrame({'geometry': [l, buffered_geometry]}).plot(column='geometry')

which is basically what you did.

enter image description here

  • However `l.is_valid == True`, and there is no self-intersection expect starting and ending in the same point, which simplify doesn't alter. In fact simplifying at 1 drops one pair of coordinates which I have already tested to work. And simplifying lower does not work. – A. West Jan 17 '23 at 12:32
  • My apologies. I updated my answer. – Serge de Gosson de Varennes Jan 17 '23 at 13:45
  • Is this expected behaviour? I wasn't expecting it, and it doesn't happen with many similar geometries. How can we predict this? – A. West Feb 03 '23 at 11:01
  • 1
    As you write, it doesn't happen very often. The times it has, I have tried to understand why but not found the source of it....and then I let it go. – Serge de Gosson de Varennes Feb 03 '23 at 11:37
  • This is a known JTS bug: https://github.com/locationtech/jts/issues/876 – A. West Feb 14 '23 at 10:20