evetion/GeoDataFrames.jl

Convenience plotting method for use with GeoMakie?

ConnectedSystems opened this issue · 3 comments

Is there any interest in an extension package to support plotting GeoDataFrames with GeoMakie?

Not being able to nicely plot GeoDataFrames directly with GeoMakie has been a small pain point of mine.

Below is a tentative working example implementation.
It was written quickly for a specific purpose but could be generalised.

import ArchGDAL as AG
import Dataframes, GeoDataFrames
using GeoMakie

function plot_map(gdf::DataFrame; geom_col=:geometry)
    f = Figure(; size=(600, 900))
    ga = GeoAxis(
        f[1,1];
        dest="+proj=latlong +datum=WGS84",
        xlabel="Longitude",
        ylabel="Latitude",
        xticklabelpad=15,
        yticklabelpad=40,
        xticklabelsize=10,
        yticklabelsize=10,
        aspect=AxisAspect(0.75)
    )

    plottable = GeoMakie.geo2basic(AG.forceto.(gdf[!, geom_col], AG.wkbPolygon))
    poly!(ga, plottable)

    # Need to auto-set limits explicitly, otherwise tick labels don't appear properly (?)
    autolimits!(ga)
    xlims!(ga)
    ylims!(ga)

    display(f)

    return f
end