2

I am querying the Overpass API using osmdata in R, searching for all ways where bicycle = yes and would like to exclude ferry routes.

Below is my code so far and a picture of the map result. As you can see there in the map there is a protruding line representing the ferry route.

I've tried a few variations of add_osm_feature("route", != "ferry") but can't seem to get it working.

Is it possible to exclude ferry routes at all?

query_1 <- getbb("Copenhagen Municipality, Denmark") %>%
  opq() %>%
  add_osm_feature("bicycle", "yes")

query_1_sf <- osmdata_sf(query_1)

###mapping
map <- get_map(getbb("Copenhagen"), maptype = "toner-background")

ggmap(map)+
  geom_sf(data = query_1_sf$osm_lines,
          inherit.aes = FALSE,
          colour = "#238443",
          size = .5)+
  labs(x = "", y = "")

![ enter image description here

1 Answer 1

4

The = in the function call to add_feature is not a comparison, but rather passing the value of an argument, as opposed to == or >= which are used in queries, and some functions that accept comparisons.

In the man page for the function, the last example is this: q <- opq ("portsmouth uk") %>% add_osm_feature(key = "highway", value = "!primary")

Which is illustrative of the syntax osmdata uses; you may pass it like: add_osm_feature(key = "route", value = "!ferry") for your use case, or set it manually to slot query_1$features with:

query_1$features = " [\"bicycle\"=\"yes\"] [\"route\"!=\"ferry\"]"

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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