TransWikia.com

Getting UK local authority boundaries in OpenStreetMap through R

Geographic Information Systems Asked on April 28, 2021

I’m trying to plot some infrastructure data that comes from the OpenStreetMap using R. I’m using the osmdata package with ggplot2. I’m trying to pull the local authority boundaries of a few local authorities in Scotland, mainly islands in the west and north. I can’t locate the local authority boundaries at an administrative level ("admin_level"). According to the OSM wiki, there appears to be a bespoke tag for local authorities. My question is: how can I use R to identify local authority boundaries for the UK?

My code, which returns zero features is:

### cycling through the admin levels 1:n doesn't provide the correct boundary 


outer_heb_1 <- 
      getbb("Outer Hebrides") %>% ## bounding box for Outer Hebrides
       opq()   %>% # build the Overpass query
    add_osm_feature(key = "admin_level", # Admin, level 4
                    value = "4") %>% 
  osmdata_sf() # return a simple features


### trying boundary/local authority in add_osm_feature
outer_heb_1 <- 
      getbb("Outer Hebrides") %>% ## bounding box for Outer Hebrides
       opq()   %>% # build the Overpass query
    add_osm_feature(key = 'boundary', # Admin, level 4
                    value = "local_authority") %>% 
  osmdata_sf() # return a simple features

One Answer

If you need to download the polygonal boundaries from OSM using osmdata, I think you should check the argument format_out in getbb(). For example:

# First of all, load packages
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(mapview)

# Download boundaries
outer_hebrides <- getbb("Outer Hebrides, Scotland", format_out = "sf_polygon")$multipolygon
outer_hebrides
#> Simple feature collection with 1 feature and 0 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -13.68751 ymin: 56.77795 xmax: -5.810481 ymax: 59.13431
#> geographic CRS: WGS 84
#>                         geometry
#> 1 MULTIPOLYGON (((-13.68751 5...

# Plot
mapview(outer_hebrides)

Created on 2021-03-10 by the reprex package (v1.0.0)

Correct answer by agila on April 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP