From feb8e021f7ffe4430eeb439d627fe2da909428ec Mon Sep 17 00:00:00 2001 From: Thomas Rushby <t.w.rushby@soton.ac.uk> Date: Fri, 20 May 2022 16:54:29 +0100 Subject: [PATCH] Add writing out of simple features (sf) data. --- ONS-open-geography.Rmd | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ONS-open-geography.Rmd b/ONS-open-geography.Rmd index d05cd9e..c906936 100644 --- a/ONS-open-geography.Rmd +++ b/ONS-open-geography.Rmd @@ -25,6 +25,8 @@ always_allow_html: yes --- ```{r setup, include=FALSE} +# Set to save downloaded geom to shp file +writeFile <- TRUE # you might need to install these first library(sf) @@ -35,6 +37,11 @@ library(dplyr) library(knitr) ``` +```{r} +source("env.R") +``` + + # Introduction This script provides an example of downloading and importing administrative boundaries from the Office for National Statistics Open Geography portal into RStudio and plotting on a map. It is based upon a useful example by [Trafford Data Lab](https://medium.com/@traffordDataLab/pushing-the-boundaries-with-the-open-geography-portal-api-4d70637bddc3). @@ -145,3 +152,14 @@ leaflet(sf_data) %>% bringToFront = TRUE)) ``` +# Write out shape file + +```{r} +# Set output directory +outDir <- paste0(dPath, "_R_output/") +# Write simple features to file see https://r-spatial.github.io/sf/articles/sf2.html#using-st_write +if(writeFile) { + st_write(sf_data, paste0(outDir,"LA_solent_2020.shp")) +} +``` + -- GitLab