MakieOrg / AlgebraOfGraphics.jl

An algebraic spin on grammar-of-graphics data visualization in Julia. Powered by the Makie.jl plotting ecosystem.
https://aog.makie.org
MIT License
443 stars 45 forks source link

Plotting maps using GeoTables.jl, Meshes.jl and MeshViz.jl #259

Open greimel opened 3 years ago

greimel commented 3 years ago

This is just to report that there might be an alternative way to support plotting maps.

Advantage:

Issues:

import GeoTables
using MeshViz: Viz
using DataFrames: DataFrame
using CairoMakie, AlgebraOfGraphics

import Meshes
const AoG = AlgebraOfGraphics
AoG.scientific_type(::Type{<:Meshes.Geometry}) = AoG.geometrical

t = GeoTables.gadm("AUT", children=true)
df = DataFrame(t)
df.color = 1:size(df, 1)

data(df) * visual(Viz, decimation = 0.01) * mapping(:geometry, elementcolor = :color) |> draw

image

cc @juliohm

juliohm commented 3 years ago

Thank you for pinging @greimel , you are correct that we need decimation with the GADM dataset because it is extremely refined. Most other polygons in the wild are simplified versions already. What we plan to do in MeshViz.jl is set a more sensible default for decimation instead of no decimation. I may actually fix this in the following weeks because of a workshop we are doing at our institute.

The default I have in mind is a binary search until the number of vertices is smaller than a pre-specified threshhold. I am open to suggestions.

greimel commented 3 years ago

Automatic decimation would be great!

Could you make it dependent on the size of the bounding box? Say, skip points unless they are more than box_size .* 0.01 away from the previous one?

Ideally you would use the size of the union of bounding boxes. (Is that possible?)

juliohm commented 3 years ago

Ideally we would set the decimation as a function of the visualization zoom level as well so that the geometries within the visualization window at a given zoom level get the necessary level of detail. That requires more advanced Makie knowledge, which I don't have unfortunately.

If you have ideas on the default decimation method, please feel free to submit a PR, the code should be super simple to read. We need a function default_decimation(geometry) that does something clever and returns a reasonable threshold. Maybe in the future it becomes default_decimation(geometry, scene). This threshold is passed to the simplify function from Meshes.jl before plotting.