Skip to content

Polylabel

Gujarat

This package implements an algorithm to find the pole of inaccessibility of a polygon, the most distant internal point from the polygon outline. This algorithm was originally written (and taken from) mapbox/polylabel - you can find a lot more information there! To summarize, the algorithm is basically a quad-tree search across the polygon which finds the point which is most distant from any edge.

In the plot above, this point is shown in orange, while the input polygon (multipolygon in this case) is shown in blue.

The package is built on top of GeoInterface.jl and GeometryOps.jl, and works with any polygon or multipolygon object which implements the GeoInterface geointerface_geomtype API for reverse conversion.

The main entry point is the polylabel(input [; atol = nothing, rtol = 0.01]) function. It returns a 2-Tuple of floats, representing the x and y coordinates of the found pole of inaccessibility.

# Polylabel.CellType.
julia
Cell(x, y, half_size, polygon)

Comparison operators operate on the max_distance field.

source


# Polylabel.polylabelMethod.
julia
polylabel(polygon::Polygon; rtol::Real = 0.01, atol::Union{Nothing, Real} = nothing)::Tuple{Float64, Float64}
polylabel(multipoly::MultiPolygon; rtol::Real = 0.01, atol::Union{Nothing, Real} = nothing)::Tuple{Float64, Float64}

polylabel finds the pole of inaccessibility of the given polygon or multipolygon, and returns its coordinates as a 2-Tuple of (x, y). Tolerances can be specified.

Any geometry which expresses the GeoInterface.jl polygon or multipolygon traits can be passed to this method, so long as it implements the GeoInterface methods extent, contains, and centroid, in addition to the polygon coordinates, getexterior, and gethole interfaces.

rtol is relative tolerance, atol is absolute tolerance (in the same vein as Base.isapprox). When atol is provided, it overrides rtol.

Warning

The performance of this function is still being actively improved; specifically the signed distance function needs some optimization. Until then, this will be much slower than the equivalent in Python/JS.

source