Hi, I’m using Julia’s GeometryBasics
package, and in particular the Polygon class. I can create a square polygon by
p=Polygon([ [0,0],[1,0],[1,1],[0,1],[0,0] ])
where p.exterior
is a 4-element LineString
object containing the four edges of the square. But there is also a field p.interiors
, which seem to be an empty LineString
.
Can someone explain to me what is the interiors
field referring to? How can I generate a polygon with nonempty interiors
, and in particular, more than one interiors ?
I think interiors are typically used to describe holes in the polygon, see the image on this page: shape types
The docstring for Polygon
says you can construct one with Polygon(exterior::AbstractVector{<:Point}, interiors::Vector{<:AbstractVector{<:AbstractPoint}})
, but it seems that’s wrong: there’s no such constructor. The tests in test/runtests.jl
show a working example:
pts_ext = Point{2, Int}[(5, 1), (3, 3), (4, 8), (1, 2), (5, 1)]
ls_ext = LineString(pts_ext)
pts_int1 = Point{2, Int}[(2, 2), (3, 8),(5, 6), (3, 4), (2, 2)]
ls_int1 = LineString(pts_int1)
pts_int2 = Point{2, Int}[(3, 2), (4, 5),(6, 1), (1, 4), (3, 2)]
ls_int2 = LineString(pts_int2)
poly_ext = Polygon(ls_ext)
poly_ext_int = Polygon(ls_ext, [ls_int1, ls_int2])
Try plotting this in Makie…