Skip to content

Coloring

GeoGrids.color_greedy Function
julia
color_greedy(points::AbstractVector{<:Union{LatLon,Point{🌐,<:LatLon{WGS84Latest}}}}, radius::Number, count::Int; cutoff_dist::Number=radius * 10.0, min_dist::Number=radius * 2)

Color a set of points with n colors with an extended greedy algorithm. The algorithm makes sure no points closer than min_dist share the same color. Additionally, it tries to optimize the total spatial distribution of colors.

Arguments

  • points: A vector of points.
  • radius: The radius of the individual cells.
  • count: The number of colors to use.
  • cutoff_dist: The cutoff distance for the greedy algorithm. A low value will result in a faster but less optimal coloring.
  • min_dist: The minimum distance for the greedy algorithm. If the minimum distance between two colors is not met, the coloring will fail.

Returns

  • A vector of integers where each entry represents the "color" of the cell with the same index.

source

Example

julia
region = GeoRegion(admin="Italy")
centers, tiles = generate_tesselation(region, 50e3, HEX(), EO())
colors = color_greedy(centers, 50e3, 4)
plot = plot_geo_cells(centers, tiles; colors, title="Hexagonal Tessellation with Colors of Italy", kwargs_layout=(;geo_fitbounds="locations"))

Alternatively, the contours of the colors of the cells can be limited to simply the number of the cells by passing the keyword argument color_contours=false.

julia
plot = plot_geo_cells(centers, tiles; colors, color_contours=false, title="Hexagonal Tessellation with Colors of Italy", kwargs_layout=(;geo_fitbounds="locations"))