Closed StephanLo closed 7 months ago
Hi @StephanLo and thank you very much for raising this issue!
The correct syntax for what you need is something like the following (i.e. you also need to specify the SELECT ...
and FROM ...
parts of the query):
library(osmextract)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
#> Check the package website, https://docs.ropensci.org/osmextract/, for more details.
test_query <- oe_get(
place = "ITS Leeds",
query = "SELECT * FROM multipolygons WHERE landuse IN ('landfill')"
)
#> The input place was matched with: ITS Leeds
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading query `SELECT * FROM multipolygons WHERE landuse IN ('landfill')'
#> from data source `C:\Users\user\AppData\Roaming\R\data\R\osmextract\test_its-example.gpkg'
#> using driver `GPKG'
#> Simple feature collection with 0 features and 25 fields
#> Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
#> Geodetic CRS: WGS 84
Created on 2024-04-25 with reprex v2.0.2
Anyway, I agree that the error message is not that informative and that the logic behind oe_read
could be improved, so I will adjust it as soon as possible. Meanwhile, let me know if that fixes your error.
Thank you for the quick reply @agila5 .
It works! Thanks, I just added the following first:
extra_tags = "landuse"
An additional question is I noticed that including the query or not doesn't change the download file size. So, I guess it downloads the entire OSM dataset for the 'place', and then reads in the features that match the query? From the documentation it also seems that "query" and "wkt_filter" are applied to the already downloaded .pbf file.
I'm wondering: Is it possible to "filter / query on the server side, and then only download the matching dataset?
If preferred, I can open another issue for the question*
Thank you for the quick reply @agila5 . It works!
Great!
So, I guess it downloads the entire OSM dataset for the 'place', and then reads in the features that match the query?
Yes, exactly. The query
and wkt_filter
parameters are directly passed to st_read()
and they do not interact with the download process.
I'm wondering: Is it possible to "filter / query on the server side, and then only download the matching dataset?
I'd be happy to be proven wrong but, AFAICT, that's not possible. Moreover, I would also say that the core of osmexctract
lies in the definition of several functions to interact with fixed and complete OSM data extracts (obtained from Geofabrik or several other providers). You need to download the data only once, and then you can extract all the information you want. On the other hand, if you need to "filter" the OSM data before the download step, then I would suggest using osmdata
. I hope that answers your question :)
Dear @agila5
Understood! Thank you for your kind reply.
I guess the way it functions has got to do with the way those providers are set up, so I suppose there is not much scope for controlling the queries from osmextract's side? (I'm wondering if its worth making a feature request, or it anyways not feasible?)
In my case the scope is global, but just for one feature type. But, I don't want to download the whole OSM dataset, So, I will use osmdata, generate a grid, and do it tile for tile, to avoid query time out. Thanks for the kind assistance, and the package!
Stephan
Sounds like the problem is solved :tada: Just to add though, it should be possible (not sure now or in future) to put together a query from {osmextract} that requests and downloads a .pbf file with the info you need and then reads it in. As far as I recall the Overpass API does NOT return .pbf files of the type imported by {osmextract} so we'd have to use something different.
A recent development in this space is Overture Maps, which allows you to download all instances of anything with a single query, as outlined here: https://docs.overturemaps.org/getting-data/more-queries/
I guess the way it functions has got to do with the way those providers are set up, so I suppose there is not much scope for controlling the queries from osmextract's side? (I'm wondering if its worth making a feature request, or it anyways not feasible?)
Please create a new feature request, and we'll work on it when/whether it will be possible (see also @Robinlovelace comment).
btw: I slightly modified the message for the type of error that you reported, adding a more informative explanation. Please double-check that it's clear.
Thank you very much! I will make a feature request.
This feels more like a user error than bug, but the error code asked me to make an issue. I'm sorry if this was not the correct place to post! I can ask in discussion forum instead if necessary.
Describe issue I want to download only specific features (specifically, features with tag 'landuse' equal to 'landfill') in osmdata we specify the tag and value. Based on the osmextract vignette, it seems as if this should be possible with type of query I specified below. But, it returns an error as shown. I think this is because I'm doing something wrong, but the error suggested an issue. Any advice on this? Thank you!
Additional context