README.md

SfSpHelpers

R-CMD-check

Basic R package to perform routine spatial operations

Installation

You can install the development version of SfSpHelpers from GitHub with:

# install.packages("devtools")
devtools::install_github("cgauvi/sfSpHelpers")

Example

For instance, create a 2D kernel density heatmap from a sf object with POINT geometry to show the density of points. Can then easily be mapped using mapview or ggplot2

library(SfSpHelpers)
library(sf)
library(ggplot2)

#Trees
shp_trees <-  st_read('https://www.donneesquebec.ca/recherche/dataset/bc5afddf-9439-4e96-84fb-f91847b722be/resource/bbdca0dd-82df-42f9-845b-32348debf8ab/download/vdq-arbrepotentielremarquable.geojson')

#Neighborhoods - read with the get_zipped_remote_shapefile util from the open data portal 
shp_neigh <-  get_zipped_remote_shapefile("https://www.donneesquebec.ca/recherche/dataset/5b1ae6f2-6719-46df-bd2f-e57a7034c917/resource/508594dc-b090-407c-9489-73a1b46a8477/download/vdq-quartier.zip")


shp_tree_bbox_poly <- bbox_polygon(shp_trees)
shp_neigh <- st_intersection(shp_neigh, shp_tree_bbox_poly)

#get_polygon_heatmap Works with polygons also (takes centroid implicitely)
shp_polyons <- get_polygon_heatmap(shp_trees , bw=.001, gsize=500 )

#Can use the colors produced automatically, but this is a red to yellow gradient 
ggplot(shp_polyons)+
  geom_sf( aes(fill=colors) ,lwd=0) +
  geom_sf(data=shp_neigh, aes(col=NOM),alpha=0) + 
  scale_fill_viridis_d()+
  coord_sf(datum = NA) + 
  ggplot2::theme_minimal(base_family="Roboto Condensed", base_size=11.5) +
  guides( color = 'none', fill = 'none') +
  ggtitle("Quebec city remakable tree density") + 
  labs(subtitle = "2D kernel density estimate",
         caption ='Source: https://www.donneesquebec.ca - vdq-arbrepotentielremarquable.geojson')

See the vignettes for more details.



cgauvi/sfSpHelpers documentation built on June 30, 2023, 10:48 p.m.