Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add timestamp in osmdata_sf() results? #269

Open
vanhry opened this issue Mar 20, 2022 · 4 comments
Open

How can I add timestamp in osmdata_sf() results? #269

vanhry opened this issue Mar 20, 2022 · 4 comments

Comments

@vanhry
Copy link

vanhry commented Mar 20, 2022

When I query osm data, I want to receive the timestamp, when some object was added or changed, is it possible to include this data?
There is my query:

q <- opq("London",timeout = 20000) %>%
  add_osm_feature(key = "landuse", value="grass",value_exact = F) %>%
  osmdata_sf()

Then I use q$osm_polygons data.

in general, I want to convert this script to R:

[out:json][timeout:200];
{{geocodeArea:London}}->.searchArea;
way["landuse"~"grass"](area.searchArea);
(._;>;);
out meta;
@mpadge
Copy link
Member

mpadge commented Mar 21, 2022

Thanks @vanhry, that's an interesting question. timestamps of individual objects are not by default delivered by the overpass server, but can be extracted as "metadata" as in your query above. Getting a local copy of the raw + metadata can be done by modifying your example like this:

q <- opq("London",timeout = 20000) %>%
  add_osm_feature(key = "landuse", value="grass",value_exact = F) %>%
  opq_string()
q <- gsub("out body", "out body meta", q)
filename <- "mydata.osm"
x <- osmdata_xml(q, filename = filename)

You'll then see the timestamps (and other metadata) appear alongside each object. The file can still be read directly with osmdata_sf(), but those metadata can not be converted into equivalent data columns in the sf objects, because there is no direct translation between OSM and sf objects. It might be tempting to think that the meta statement shown above might translate nicely to some kind of meta = FALSE parameter which could be switched on to get these data, but:

  1. I would be opposed to doing that becuase the amount of additional data downloaded from the overpass server is considerable - queries generally deliver 2-3 times as much data with metadata included; and
  2. There is no direct way to append these metadata to sf objects.

A more workable alternative might be to utilise the ::timestamp data accessible via the csv output mode, as is currently under discussion in #252. I suggest leaving this issue open for the moment, and I'll return to it as part of addressing that broader issue. Once some kind of osmdata_csv() function has been developed, that will then allow simple queries taking OSM ID values as inputs and returning timestamps as outputs. In the context of your example, you'll get the standard output from your searchArea query above as delivered with the last line of out body, and then be able to use the resultant ID values to get any desired bits of out meta. Happy to discuss any other ideas you might have until then.

@vanhry
Copy link
Author

vanhry commented Mar 21, 2022

Thanks @mpadge, You helped me a lot!

@jmaspons
Copy link
Collaborator

jmaspons commented Dec 1, 2022

If #285 is accepted, I can work on implementing different out modes such as meta, tags and others. Can be useful to select objects based on tags and metadata and then download the spatial data based on OSM type and ID now that #283 is working.

@jmaspons
Copy link
Collaborator

jmaspons commented Dec 2, 2022

Almost ready for a PR at jmaspons@83148a9 . Waiting for #285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants