Created
April 25, 2019 14:31
-
-
Save SimonCoulombe/c5fcab52dd6bcbcfd85d013319ab53a1 to your computer and use it in GitHub Desktop.
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
#idée : https://pudding.cool/2018/12/3d-cities-story/index.html | |
# how to https://docs.google.com/document/d/1Us_1QBHShdMe8-laKhGh_mjkXxOw-74-9mxJAx_DvKE/edit | |
# GHS population grid 2015 aux 250m téléchargé ici | |
#https://ghslsys.jrc.ec.europa.eu/datasets.php#2016public | |
# alternative à 100m vs 100 m ,world pop , mais pas canada :A http://www.worldpop.org.uk/data/get_data/ | |
# comment importer un raster- https://geocompr.robinlovelace.net/read-write.html | |
# raster rstudio leaflet https://rstudio.github.io/leaflet/raster.html | |
library(raster) | |
library(sf) | |
library(leaflet) | |
library(dplyr) | |
raster_filepath = system.file(here::here("Rapport/201808/data/raw/GHS_POP_GPW42015_GLOBE_R2015A_54009_250_v1_0", "GHS_POP_GPW42015_GLOBE_R2015A_54009_25_v1_0.tif")) | |
r = raster(here::here("Rapport/201808/data/raw/GHS_POP_GPW42015_GLOBE_R2015A_54009_250_v1_0", "GHS_POP_GPW42015_GLOBE_R2015A_54009_250_v1_0.tif")) | |
crs(r) | |
e <- as(extent(1000000,10000100,0,100), 'SpatialPolygons') | |
crs(e) <- crs(r) | |
r2 <- crop(r, e) | |
pal <- colorNumeric(c("red", "blue"), values(r2), | |
na.color = "transparent") | |
leaflet()%>% | |
addRasterImage(r2, colors = pal) %>% | |
addLegend(pal = pal, values = values(r2)) | |
r2 | |
leaflet()%>% | |
addRasterImage(r2, colors = pal, opacity = 0.8) %>% | |
addLegend(pal = pal, values = values(r2), | |
title = "dentity") %>% | |
addTiles() | |
#https://stackoverflow.com/questions/33227182/how-to-set-use-ggplot2-to-map-a-raster | |
library(rgdal) | |
library(rasterVis) | |
library(RColorBrewer) | |
colr <- colorRampPalette(brewer.pal(11, 'RdYlBu')) | |
levelplot(r, | |
margin=FALSE, # suppress marginal graphics | |
colorkey=list( | |
space='bottom', # plot legend at bottom | |
labels=list(at=-5:5, font=4) # legend ticks and labels | |
), | |
par.settings=list( | |
axis.line=list(col='transparent') # suppress axes and legend outline | |
), | |
scales=list(draw=FALSE), # suppress axis labels | |
col.regions=colr, # colour ramp | |
at=seq(-5, 5, len=101)) | |
levelplot(r2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment