JuliaGeo / LibGEOS.jl

Julia package for manipulation and analysis of planar geometric objects
MIT License
72 stars 24 forks source link

buffering a polygon results in an empty polygon #200

Open pilifly opened 7 months ago

pilifly commented 7 months ago

buffering a polygon by -0.05 created an empty polygon.

libgeos_error
using LibGEOS
points = 
[[-1.980000000392857, -1.1200595222536243], 
[-1.9707179676972442, -1.1547005387729528], 
[1.9600000000000004, -1.1547005387729532], 
[1.9853589842420483, -1.1293415545453502], 
[0.020000000340954713, 2.274760060803972], 
[-0.014641016121955817, 2.284042093302481], 
[-1.980000000392857, -1.1200595222536243]]
poly = LibGEOS.Polygon([points])
dist = -0.05
buffered_poly = LibGEOS.buffer(poly, dist, 40)
@test !LibGEOS.isEmpty(buffered_poly)

Note: test passed when reducing dist to -0.005
dist = -0.005
buffered_poly = LibGEOS.buffer(poly, dist, 40)
@test !LibGEOS.isEmpty(buffered_poly)
jaakkor2 commented 5 months ago

Depending on your requirements, you could consider simplifying the poly before buffering

buffered_poly = LibGEOS.buffer(simplify(poly, abs(dist)), dist, 40)