Skip to content

Instantly share code, notes, and snippets.

@greimel
Created August 10, 2020 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greimel/394912444266ca750786332bac80e10a to your computer and use it in GitHub Desktop.
Save greimel/394912444266ca750786332bac80e10a to your computer and use it in GitHub Desktop.
Plotting maps of Germany with Plots.jl
using Shapefile
using DataFrames, Missings
using Underscores
import Plots
url_gadm = "https://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36_DEU_shp.zip"
zip_archive = download(url_gadm) # 29 MB
dir = mktempdir()
run(`unzip $zip_archive -d $dir`)
tbl_states = Shapefile.Table(joinpath(dir, "gadm36_DEU_1.shp"))
tbl_municip = Shapefile.Table(joinpath(dir, "gadm36_DEU_3.shp"))
shp_states = Shapefile.shapes(tbl_states) |> disallowmissing
shp_municip = Shapefile.shapes(tbl_municip) |> disallowmissing
# Plot the full map with Plots.jl as a reference (note Berlin and Bremen)
@time display(Plots.plot(shp_states, lw = 0.2)) # takes 0.47s
@time display(Plots.plot(shp_municip, lw = 0.2)) # takes 49.1s
# Plot two municipalities with complex shapes
df = tbl_municip |> DataFrame
df[!,:shape] = shp_municip
Plots.plot( df[620, :shape]) # many parts
Plots.plot!(df[628, :shape]) # two parts and holes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment