2

I am trying to map the Lower-layer Super Output Area (LSOA)of London. I could only find the shapefiles in this address:

https://data.gov.uk/dataset/6cdebf5d-c69b-4480-8c9c-53ab8a816b9d/statistical-gis-boundary-files-for-london

in the following zip file:

"statistical-gis-boundaries-london.zip"

Below is the code I'm using to map the shapfiles using R.

library(rgdal)
library(tidyverse)
library(leaflet)

lsao <- readOGR(dsn = "ESRI", layer = "LSOA_2011_London_gen_MHW") #Read the shapefiles from the ESRI folder

lsao %>% 
leaflet() %>%
  setView(-0.1000, 51.5,zoom = 10) %>% 
  addTiles() %>%
  addPolygons()

The above code just opens a Leaflet map with no polygons on the map. I have never had a problem mapping shapefiles using the above code and that's why I think there might be something wrong with the shapefiles on the UK government website. I was wondering if anyone has more information on this issue?

4
  • I can't see any shapefiles on that page - only CSV and XLS and ZIPs of those.
    – Spacedman
    Jan 29, 2022 at 10:18
  • @Spacedman just updated the post.
    – Amin Shn
    Jan 29, 2022 at 10:28
  • You don't say what you expect to happen from your code and what actually happens. Jan 29, 2022 at 11:07
  • @bugmenot123 sorry, just updated the post.
    – Amin Shn
    Jan 29, 2022 at 11:13

2 Answers 2

2

you can use below code:

lsao_london <- readOGR(dsn="folder name", layer="data name")
lsao_london <- spTransform(, CRS("+proj=longlat +datum=WGS84")) 
2

The data needs to be transformed to lat-long coordinates (EPSG:4326) to work with leaflet. For sp classes, use spTransform, but it is recommended you use sf package functions for spatial data, so read in with st_read and use st_transform to reproject.

2
  • Thank you, I am fairly new to these stuff, would you please share the correct code for reading the file and transforming it? I have no idea how to use st_read & st_transform.
    – Amin Shn
    Jan 29, 2022 at 11:13
  • 1
    You're probably better off finding a tutorial for spatial data in R than for me to feed you code here. bookdown.org/robinlovelace/geocompr and go through a few chapters.
    – Spacedman
    Jan 29, 2022 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.