0

I'd like to download data for California (i.e., parking lots > 8100 m2). But I can't get osmdata::getbb() to produce the correct boundary.

library(tidyverse)
library(osmdata)
library(sf)
library(mapview)

osm_data<- getbb ("california",
                    display_name_contains="United States",
                    format_out = "polygon") %>%
  opq() %>%
  add_osm_feature("amenity","parking")%>%
  osmdata_sf()


PL<-osm_data$osm_polygons%>%mutate(area=st_area(.))%>%filter(as.numeric(area)>8100)

mapview(PL)

It returns polygons for the Oakland area only. Does someone know how to get the correct bbox for California?

1

1 Answer 1

2

That getbb query returns polygons for six things that match "california". Four of them clearly have coordinates far from the state, which has a longitude around -122:

> cabb = getbb("California", display_name_contains="United States", format="polygon")
> str(cabb)
List of 6
 $ : num [1:1307, 1:2] -122 -122 -122 -122 -122 ...
 $ : num [1:212, 1:2] -92.6 -92.6 -92.6 -92.6 -92.6 ...
 $ : num [1:8, 1:2] -92.6 -92.6 -92.6 -92.6 -92.6 ...
 $ : num [1:10, 1:2] -84.3 -84.3 -84.3 -84.3 -84.3 ...
 $ : num [1:453, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ...
 $ :List of 8
  ..$ : num [1:7901, 1:2] -124 -124 -124 -124 -124 ...
  ..$ : num [1:100, 1:2] -123 -123 -123 -123 -123 ...
  ..$ : num [1:394, 1:2] -121 -121 -121 -121 -121 ...
  ..$ : num [1:48, 1:2] -120 -120 -120 -120 -120 ...
  ..$ : num [1:121, 1:2] -120 -120 -120 -120 -120 ...
  ..$ : num [1:74, 1:2] -119 -119 -119 -119 -119 ...
  ..$ : num [1:191, 1:2] -119 -119 -119 -119 -119 ...
  ..$ : num [1:140, 1:2] -119 -119 -119 -119 -119 ...

The sixth element here is a multipolygon which looks most like the state, so you can get the mainland boundary which is the first element of that.

> bb = cabb[[6]][[1]]

However I now think you will hit timeout and size problems because California has a lot of parking amenties...

> osm_data = bb %>% opq() %>% add_osm_feature("amenity","parking") %>% osmdata_sf()
Error in check_for_error(doc) : General overpass server error; returned:
The data included in this document is from www.openstreetmap.org. The data is made available under ODbL. runtime error: Query timed out in "query" at line 4 after 26 seconds. 
> 

I'd suggest you get the latest extract from GeoFabrik (https://download.geofabrik.de/north-america/us/california.html) and work on that instead if you hit limits of the OSM search.

1
  • Correct on all accounts -- thank you! I appreciate the link for the shp file download of N and S CA too. I thought I could only download the osm.pbf for CA and was having trouble extracting the data.
    – Kevin
    Aug 24 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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