shiftScale_geo | R Documentation |
The steps are:
1. Create a sf ojbect with shifted geospatial coordinates and/or scaled-up/down
2. Create a sf ojbect that encirle 1, totally unnecessary but aesthically pleasing.
3. Create a sf ojbect that encircle the original region that was shifted & scaled-up
4. Create a sf ojbect that connects both circles to convey it a zoomed inlet map
encircle_coord
finds the centre and radius to completely encompass the provided geospatial object
encircle_geo
takes a named list with centre and radius and return a simple feature object of the circle
shiftScale_geo(geo, shiftM = c(-9000, 150000), scaleF = 3)
encircle_coord(geo)
encircle_geo(centreRadius)
cone_geo(centreRadius_ori, centreRadius_inlet)
geo |
a simple feature data.frame |
shiftM |
a numeric of length 2, the distances in meters to shift in longitude and latitude respectively |
scaleF |
a numeric of length 1, the scaling factor |
centreRadius , centreRadius_ori , centreRadius_inlet |
a named list with centre (a sfc_POINT) and radius |
shiftScale_geo
a simple feature data.frame
encircle_coord
a named list with a simple feature point (centre) and the radius in meters
encircle_geo
a simple feature object
cone_geo
a simple feature object
## Not run:
require(sf)
require(tidyverse)
shp_ch_paths_2018 <- shp_path(2018)
# loop and load the geo data in a named list
shp_ch_geodata <- shp_ch_paths_2018 %>% map(function(x) {
layerName <- st_layers(x)
st_read(x, layer = layerName$name) %>%
select(ends_with("NR"), ends_with("NAME"))
})
# shift and scale up canton Geneva for the inlet map
geo_subset <- shp_ch_geodata$municipalities %>% filter(KTNR == 25)
inlet_geo <- shiftScale_geo(geo = geo_subset, scaleF = 4.4)
# Create circles sf to encompass the inlet map and its original location
geo_subset_coord <- encircle_coord(geo_subset)
inlet_coord <- encircle_coord(inlet_geo)
cone_sfc <- cone_geo(geo_subset_coord, inlet_coord)
circle_zoom_sfc <- encircle_geo(geo_subset_coord)
circle_inlet_sfc <- encircle_geo(inlet_coord)
# plot
gp <- ggplot() +
geom_sf(data = cone_sfc, fill = "lightgrey", lwd = 0, alpha = 0.2) +
geom_sf(data = circle_zoom_sfc, fill = "lightgrey", lwd = 0, alpha = 0.5) +
geom_sf(data = circle_inlet_sfc, fill = "lightgrey", lwd = 0, alpha = 0.5) +
geom_sf(data = shp_ch_geodata$municipalities, aes(fill = GMDNR),
lwd = 0.05, colour = "#0d0d0d") +
geom_sf(data = inlet_geo, aes(fill = GMDNR), lwd = 0.1, colour = "#0d0d0d") +
geom_sf(data = shp_ch_geodata$cantons, lwd = 0.15, colour = "#333333", fill = NA) +
geom_sf(data = shp_ch_geodata$country, lwd = 0.25, colour = "#000d1a", fill = NA) +
geom_sf(data = shp_ch_geodata$lakes, lwd = 0, fill = "#0066cc")
gp +
theme_map() +
scale_fill_viridis_c() +
coord_sf(datum = NA, expand = F)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.