OSMtidy - Vignette 1, Getting started

Dr Annie Visser-Quinn, a.visser-quinn@hw.ac.uk

2020-07-10

1. Prerequisites

2. Data

The input to OSMtidy is a shapefile, or polygon, outline of a given location. This vignette provides an example of how to obtain such data. Here, the data is extracted for free from the Ordnance Survey. The data is available at: https://www.ordnancesurvey.co.uk/business-government/products/boundaryline. The product used is OS OpenData - Unitary Authorities (filename district_borough_unitary_ward_region.shp). Please remember to reference source data accordingly.

3. Tidy data

The first step is to select a single ward area to focus on. Here we look at a ward in the City of Edinburgh (Scotland) called Leith Walk.

shp <- st_read("district_borough_unitary_ward_region.shp", quiet = TRUE)
shp
#> Simple feature collection with 7125 features and 15 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: 5512.998 ymin: 5333.603 xmax: 655989 ymax: 1220302
#> proj4string:    +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs 
#> First 10 features:
#>                                        NAME AREA_CODE    DESCRIPTIO
#> 1                        Chiltern Rise Ward       DIW District Ward
#> 2  Lacey Green, Speen and the Hampdens Ward       DIW District Ward
#> 3                   Booker and Cressex Ward       DIW District Ward
#> 4                                Abbey Ward       DIW District Ward
#> 5                                Sands Ward       DIW District Ward
#> 6                             Disraeli Ward       DIW District Ward
#> 7           Terriers and Amersham Hill Ward       DIW District Ward
#> 8                    Greater Hughenden Ward       DIW District Ward
#> 9           Tylers Green and Loudwater Ward       DIW District Ward
#> 10                     The Risboroughs Ward       DIW District Ward
#>                 FILE_NAME NUMBER NUMBER0 POLYGON_ID UNIT_ID      CODE HECTARES
#> 1  BUCKINGHAMSHIRE_COUNTY      1       1      51815   11853 E05002679 2245.296
#> 2  BUCKINGHAMSHIRE_COUNTY      2       2      51826   11864 E05002689 2322.664
#> 3  BUCKINGHAMSHIRE_COUNTY      3       3      51819   11858 E05002676  262.429
#> 4  BUCKINGHAMSHIRE_COUNTY      4       4     125171   11788 E05002674  455.674
#> 5  BUCKINGHAMSHIRE_COUNTY      5       5      51822   11861 E05002695  337.526
#> 6  BUCKINGHAMSHIRE_COUNTY      6       6      51918   11784 E05002680  213.448
#> 7  BUCKINGHAMSHIRE_COUNTY      7       7     125173   11810 E05002697  276.751
#> 8  BUCKINGHAMSHIRE_COUNTY      8       8     126851   42959 E05002683 1879.171
#> 9  BUCKINGHAMSHIRE_COUNTY      9       9     117730   11750 E05002701  719.226
#> 10 BUCKINGHAMSHIRE_COUNTY     10      10     128834   11865 E05002699 1065.502
#>    AREA TYPE_CODE         DESCRIPT0 TYPE_COD0 DESCRIPT1
#> 1     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 2     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 3     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 4     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 5     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 6     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 7     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 8     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 9     0        VA CIVIL VOTING AREA      <NA>      <NA>
#> 10    0        VA CIVIL VOTING AREA      <NA>      <NA>
#>                          geometry
#> 1  MULTIPOLYGON (((477425.3 19...
#> 2  MULTIPOLYGON (((481498.6 19...
#> 3  MULTIPOLYGON (((483096.8 19...
#> 4  MULTIPOLYGON (((485369 1910...
#> 5  MULTIPOLYGON (((481944.2 19...
#> 6  MULTIPOLYGON (((486440 1933...
#> 7  MULTIPOLYGON (((488140.6 19...
#> 8  MULTIPOLYGON (((483481.9 19...
#> 9  MULTIPOLYGON (((491787 1907...
#> 10 MULTIPOLYGON (((482000.6 20...

In the next code chunk, we reduce the data down to the location of interest.

shp <- 
  shp %>%
  filter(str_detect(FILE_NAME, "CITY_OF_EDINBURGH")) %>% 
  filter(str_detect(NAME, "Leith Walk")) %>%
  select(geometry)
shp
#> Simple feature collection with 1 feature and 0 fields
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: 325186.8 ymin: 674419.7 xmax: 327500.8 ymax: 676416
#> proj4string:    +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs 
#>                         geometry
#> 1 MULTIPOLYGON (((327500.8 67...

shp %>% ggplot() + geom_sf()

Now we can simplify the jagged outlines of the ward and trasnform the projection to epsg 4326.

shp <- shp %>% st_simplify(dTolerance = 25) %>% st_transform(4326)
shp 
#> Simple feature collection with 1 feature and 0 fields
#> geometry type:  POLYGON
#> dimension:      XY
#> bbox:           xmin: -3.199973 ymin: 55.95726 xmax: -3.162921 ymax: 55.97507
#> CRS:            EPSG:4326
#>                         geometry
#> 1 POLYGON ((-3.162921 55.9633...

shp %>% ggplot() + geom_sf()

The final step is to export the shapefile using the sf function st_write(). When using OSMtidy, all the associated shapefile files need to be placed in the shapefile folder in the OSMtidy directory.

shp %>% st_write("exampleEdinburgh.shp", delete_dsn = TRUE, delete_layer = TRUE, quiet = TRUE)
#> Warning in CPL_write_ogr(obj, dsn, layer, driver,
#> as.character(dataset_options), : GDAL Error 1: exampleEdinburgh.shp does not
#> appear to be a file or directory.

Now you’re ready to run OSMtidy! See Vignette 2 for a walkthrough.