Created
August 10, 2020 13:38
-
-
Save greimel/394912444266ca750786332bac80e10a to your computer and use it in GitHub Desktop.
Plotting maps of Germany with Plots.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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