ropensci / osmdata

R package for downloading OpenStreetMap data
https://docs.ropensci.org/osmdata
317 stars 45 forks source link

Possibility to set timeout for overpass api queries #114

Closed beingalink closed 6 years ago

beingalink commented 6 years ago

It looks like I'm unable to retrieve data for this query:

osm_bicycle_designated <- getbb("Bayern", display_name_contains = "Deutschland", featuretype = "state") %>%
  opq() %>% 
  add_osm_feature(key = "bicycle", value = "designated") %>%
  osmdata_sf()

It would be nice if I could set the query timeout myself. Also throwing a warning message in these cases would help as I didn't realize at first where the problem was.

Thanks for this great software and please keep this going!

mpadge commented 6 years ago

You can set timeout directly in opq - see ?opq, which also has a memsize argument useful for large queries. Nevertheless, you still might not get results because overpass itself will pre-estimate the rough size of the query and prioritize accordingly. In this case, all cycle paths in Bayern may simply be too many. Try with a smaller getbb first and see how you go

beingalink commented 6 years ago

Hi,

thanks for your answer. Unfortunately I seem to misunderstand you. opq(timeout = 40) doesn't work for me. Could you perhaps demonstrate the usage according to my example? Thanks in advance!

edit: Sorry, I just saw that there is a new version 0.0.5.99 which isn't on CRAN yet. This version seems to have the features you mentioned. Guess I need to wait until it's on CRAN.

mpadge commented 6 years ago

All works for me. Your query above times out, but simply replacing second line with

    opq (timeout = 100) %>%

gives results. As warned, it's a huge amount of data, so is probably better saved in intermediate form first:

osm_bicycle_designated <- getbb("Bayern", display_name_contains = "Deutschland", featuretype = "state") %>%
  opq(timeout = 100) %>% 
  add_osm_feature(key = "bicycle", value = "designated") %>%
  osmdata_xml(filename="dat.xml", quiet = FALSE)

That generates around 60MB of data. Converting that to sf may or may not work, depending on your system. Just try

dat <- osmdata_sf (q, doc = "dat.osm")

and see how you go

beingalink commented 6 years ago

Sorrry, the problem is that I'm not on the latest version which only has this feature. The version I need isn't on CRAN yet, so I need to wait. Will try then and report back if it works for me. Thanks for your patience.

mpadge commented 6 years ago

No worries @beingalink! You can use devools:

devtools::install_github("ropensci/osmdata")

That will install the latest development version without having to wait for CRAN