ropensci / osmplotr

Data visualisation using OpenStreetMap objects
https://docs.ropensci.org/osmplotr
132 stars 21 forks source link

How to download relational tags in bounding box #4

Closed Robinlovelace closed 7 years ago

Robinlovelace commented 8 years ago

First I'd like to say great package - many thanks for developing this!

As the below code shows it works to download parts of Hackney's road network, which is very useful!

The issue is that many of the paths I'm interested in are referenced only as relations, such as "London Cycle Route Network 9" and I cannot find a way to download these from in your methods. I read with interest your vignette which suggests that you will be fixing an issue related to relations soon (with an example of rivers) and I just wondered if that will solve my issue of not being able to download the cycle path relations. Hopefully the screenshot (see relation description bottom left) and code below should clarify what I'm trying to do.

cycleway

# devtools::install_github("mpadge/osmplotr")
library(osmplotr)
library(tmap)

b = bb("Hackney, London")
b = as.vector(b)
class(b)

h = extract_osm_objects(key = "highway", bbox =  b)
summary(h)

# download the cycleways/cyclable routes
hc = extract_osm_objects(key = "highway", value = "cycleway", bbox = b)
hlcn = extract_osm_objects(key = "highway", bbox =  b, extra_pairs = c("lcn", "yes"))
hlcn9 = extract_osm_objects(key = "highway", bbox =  b, extra_pairs = c("lcn_ref", "9"))
hlcna = extract_osm_objects(key = "highway", bbox =  b, extra_pairs = c("Cycle Route", "London Cycle Network Route 9"))

plot(h)
plot(hc, add = T, col = "red", lwd = 2)
plot(hlcn, add = T, col = "green", lwd = 3)
plot(hlcn9, add = T, col = "green", lwd = 3)

Many thanks, it's really useful in any case!

mpadge commented 8 years ago

Hi Robin,

Thanks for the appreciation and the interest! The code is bound to break on queries that I have simply not been able to anticipate, but ... I'm not sure that your falls into that category. It seems that things work as they should, but that the query itself simply returns very patchy data.

The lines themselves can be compared with the direct overpass results by pasting this query into overpass-turbo:

(node
  ["highway"]
  ["lcn_ref"~"9"]
  (51.523240,-0.069362,51.563240,-0.029362);
way
  ["highway"]
  ["lcn_ref"~"9"]
  (51.523240,-0.069362,51.563240,-0.029362);
rel
  ["highway"]
  ["lcn_ref"~"9"]
  (51.523240,-0.069362,51.563240,-0.029362););
(._;>;);
out;

You can then inspect the data, showing that the 11 ways that are returned exactly match those from extract_osm_objects. What you see with add_osm_object is simply all there is. There are no data at all for "London Cycle Network Route 9" (and the overpass API requires black spaces to be filled with periods: "London.Cycle.Network.Route.9")

Let me know if I've misunderstood your problem, and I'll be happy to look into it further. Thanks again for the interest!

mpadge commented 7 years ago

@Robinlovelace I've made a few tweaks to osmplotr which also fix your previous problem:

> key <- 'route'
> value <- 'bicycle'
> extra_pairs <- c ('name', 'London.Cycle.Network.Route.9')
> bbox <- get_bbox (c (-0.3,51.4,0.2,51.7))
> dat1 <- extract_osm_objects (bbox=bbox, key=key, value=value,
+                              extra_pairs=extra_pairs)

The bbox in that case encompasses the entire route. But note that even with a smaller bbox:

> bb <- tmap::bb ('Hackney, London')
> dat2 <- extract_osm_objects (bbox=bb, key=key, value=value,
 +                             extra_pairs=extra_pairs, return_type='lines')
> identical (dat1, dat2)
TRUE

The full data set is still returned.

> map <- osm_basemap (bbox=bbox)
> map <- add_osm_objects (map, dat1, col="yellow", size=1)
> print_osm_map (map)

map

I've also got osmdatar to the stage where it mostly works except for extraction of multipolygons. I'm keen to CRAN it pretty soon, and so would like to get the R side of things polished sometime soon. Are you still interested in contributing?

Robinlovelace commented 7 years ago

Hi @mpadge many thanks for this, this is fantastic progress. I'm sorry I've been so slow to get moving on this, snowed under preparing for the release of this next week: http://pct.bike/

No doubt these methods you're developing will make it easier to create applications for sustainable transport planning, like the Propensity to Cycle Tool.