Skip to content

Instantly share code, notes, and snippets.

@greimel
Created August 17, 2020 09:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greimel/13567aef4557852669a1077025cd4fc0 to your computer and use it in GitHub Desktop.
Save greimel/13567aef4557852669a1077025cd4fc0 to your computer and use it in GitHub Desktop.
using Pkg
pkg"activate polygons"
pkg"add Shapefile#sd/geometrybasics"
pkg"add AbstractPlotting#sd/geom_merge"
pkg"add GeometryBasics#sd/polygons"
pkg"add GLMakie CairoMakie"
using Shapefile
using AbstractPlotting, GLMakie
#using CairoMakie
# CairoMakie.activate!()
# GLMakie.activate!()
dir = "shp-dir"
if !isdir(dir)
url_gadm = "https://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36_DEU_shp.zip"
zip_archive = download(url_gadm) # 29 MB
mkdir(dir)
#dir = mktempdir()
run(`unzip $zip_archive -d $dir`)
end
tbl_states = Shapefile.Table(joinpath(dir, "gadm36_DEU_1.shp"))
tbl_municip = Shapefile.Table(joinpath(dir, "gadm36_DEU_3.shp"))
shp_states = tbl_states.Geometry
shp_municip = tbl_municip.Geometry
@time display(poly(shp_states, color = 1:length(shp_states), scale_plot = false))
# GLMakie: 0.34s
# CairoMakie 1.8s
@time display(poly(shp_municip, color = 1:length(shp_municip), scale_plot = false))
# GLMakie: 1.8s
# CairoMakie 8s
## Comparison to R - CAUTION - the packages are a bit of a pain to install
pkg"add RCall"
using RCall
#run(`brew install gdal`)
R"""
#install.packages("sp")
#install.packages("rgdal", repos="http://R-Forge.R-project.org")
#install.packages("ggplot2")
library(rgdal)
library(ggplot2)
shp_states <- readOGR(dsn = file.path($(dir), "gadm36_DEU_1.shp"), stringsAsFactors = F)
shp_municip <- readOGR(dsn = file.path($(dir), "gadm36_DEU_3.shp"), stringsAsFactors = F)
"""
@time begin
R"""
map <- ggplot() + geom_polygon(data = shp_states, aes(x = long, y = lat, fill = group), colour = "white") + theme(legend.position="none")
show(map)
"""
end
# 6.5s
# (with fill=NA: 1s)
@time begin
R"""
map <- ggplot() + geom_polygon(data = shp_municip, aes(x = long, y = lat, fill = group), colour = "white") + theme(legend.position="none")
show(map)
"""
end
# 17s
# (with fill=NA: 10.2s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment