-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
querying features that enclose a point #199
Comments
Thanks @barryrowlingson, that is a really good idea that i hadn't thought of, the good news for which is, yes, that would be really easy to incorporate within osm_nearby(x, y) %>%
osmdata_sf/sp/sc() but also, in line with your example, accept additional defining features, osm_nearby(x, y) %>%
add_osm_feature(tag = "natural", value = "water") %>%
osmdata_sf/sp/sc() That function could then also immediately accept an additional osm_nearby(osm_id = <long long int>) %>%
osmdata_sf/sp/sc() The only real potential incongruity there would be that |
BTW @barryrowlingson i don't have enough rep points to comment on |
I don't think "nearby" is the right word for this, since that implies a location just outside a polygon would also return the polygon. The query as written finds things that enclose the point, and hence I think it can't return point features or line features (nodes/ways). Its more like You could probably also do a separate
which returns things within 15 metres of that location. Wow this is nice... |
@barryrowlingson am now finally getting on to this. The above commits implement the example given in the new library (osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
lat <- 54.33601
lon <- -3.07677
key <- "natural"
value <- "water"
q <- opq_enclosing (lon, lat, key, value) %>%
opq_string ()
q
#> [1] "[out:xml][timeout:25];\n(\nis_in(54.33601,-3.07677)->.a;relation(pivot.a) [\"natural\"=\"water\"];);\n(._;>;);\nout;"
x <- osmdata_sf (q)
x
#> Object of class 'osmdata' with:
#> $bbox :
#> $overpass_call : The call submitted to the overpass API
#> $meta : metadata including timestamp and version numbers
#> $osm_points : 'sf' Simple Features Collection with 1241 points
#> $osm_lines : NULL
#> $osm_polygons : 'sf' Simple Features Collection with 2 polygons
#> $osm_multilines : NULL
#> $osm_multipolygons : 'sf' Simple Features Collection with 1 multipolygons Created on 2020-06-08 by the reprex package (v0.3.0)
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
lat <- 54.04827
lon <- -2.82288
key <- value <- NULL
q <- opq_enclosing (lon, lat, key, value, enclosing = "way") %>%
opq_string ()
q
#> [1] "[out:xml][timeout:25];\n(\nis_in(54.04827,-2.82288)->.a;way(pivot.a););\n(._;>;);\nout;"
x <- osmdata_sf (q)
x
#> Object of class 'osmdata' with:
#> $bbox :
#> $overpass_call : The call submitted to the overpass API
#> $meta : metadata including timestamp and version numbers
#> $osm_points : 'sf' Simple Features Collection with 51 points
#> $osm_lines : NULL
#> $osm_polygons : 'sf' Simple Features Collection with 1 polygons
#> $osm_multilines : NULL
#> $osm_multipolygons : NULL Created on 2020-06-08 by the reprex package (v0.3.0) As expected, the default
TODO
|
The OpenStreetMap web page has two query outputs - features near the query point and features enclosing the query point. The "enclosing" features list means you can click somewhere and get what's under that point. This can return multiple features, like a lake, the county the lake is in, the country the county is in and soon.
I reverse-engineered what the web page was querying to come up with the following function:
which I used to answer a GIS StackExchange question here: https://gis.stackexchange.com/questions/345994/get-waterbody-info-from-base-map-in-leaflet
I don't pretend to really understand the OverpassAPI syntax thoroughly but here it is in plain text:
where lat,long is the point coordinate and
tag=value
is something likenatural=water
if the user wants to search for lakes, for example. I'm not sure if the multipleout
lines are necessary. I don't know if theway
lines needs a tag filter. I don't understand the magic behind thepivot.a
thing. All I understand (see the GIS SE question) is that this R function returns the lakes under a point.Currently my code returns the raw JSON, so its a bit useless in R without some post-processing, but there must be code in
osmdata
to do all that. Could this query of finding features enclosing a point be included inosmdata
?The text was updated successfully, but these errors were encountered: