Skip to content

Commit

Permalink
add date+diff metadata for #179
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Mar 6, 2020
1 parent fa1ae12 commit 4426561
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: osmdata
Version: 0.1.3.002
Version: 0.1.3.003
Authors@R: c(
person("Mark", "Padgham", email="[email protected]", role=c("aut", "cre")),
person("Bob", "Rudis", role="aut"),
Expand Down
55 changes: 49 additions & 6 deletions R/get-osmdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ fill_overpass_data <- function (obj, doc, quiet = TRUE, encoding = "UTF-8")
encoding = encoding)

docx <- xml2::read_xml (doc)
obj$meta <- list (timestamp = get_timestamp (docx),
OSM_version = get_osm_version (docx),
overpass_version = get_overpass_version (docx))
obj <- get_metadata (obj, docx)
} else
{
if (is.character (doc))
Expand All @@ -181,14 +179,59 @@ fill_overpass_data <- function (obj, doc, quiet = TRUE, encoding = "UTF-8")
stop ("file ", doc, " does not exist")
doc <- xml2::read_xml (doc)
}
obj$meta <- list (timestamp = get_timestamp (doc),
OSM_version = get_osm_version (doc),
overpass_version = get_overpass_version (doc))
obj <- get_metadata (obj, doc)
doc <- as.character (doc)
}
list (obj = obj, doc = doc)
}

get_metadata <- function (obj, doc)
{
meta <- list (timestamp = get_timestamp (doc),
OSM_version = get_osm_version (doc),
overpass_version = get_overpass_version (doc))
q <- obj$overpass_call

# q is mostly passed as result of opq_string_intern, so date and diff query
# metadata must be extracted from string
if (is.character (q))
{
x <- strsplit (q, "\"") [[1]]
if (grepl ("date", x [1]))
{
if (length (x) < 2)
stop ("unrecongised query format")
meta$datetime_to <- x [2]
meta$query_type <- "date"
} else if (grepl ("diff", x [1]))
{
if (length (x) < 4)
stop ("unrecongised query format")
meta$datetime_from <- x [2]
meta$datetime_to <- x [4]
meta$query_type <- "diff"
}
} else
{
if (!is.null (attr (q, "datetime2")))
{
meta$datetime_to <- attr (q, "datetime2")
meta$datetime_from <- attr (q, "datetime")
meta$query_type <- "diff"
} else if (!is.null (attr (q, "datetime")))
{
meta$datetime_to <- attr (q, "datetime")
meta$query_type <- "date"
}
}
obj$meta <- meta
attr (q, "datetime") <- attr (q, "datetime2") <- NULL

obj$overpass_call <- q

return (obj)
}

#' Make an 'sf' object from an 'sfc' list and associated data matrix returned
#' from 'rcpp_osmdata_sf'
#'
Expand Down
13 changes: 8 additions & 5 deletions R/opq.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,21 @@ opq <- function (bbox = NULL, datetime = NULL, datetime2 = NULL,
if (!is.null (datetime2))
{
datetime2 <- check_datetime (datetime2)
prefix <- paste0 ('[diff:\"', datetime,'\",\"', datetime2, '\"]',
prefix <- paste0 ('[diff:\"', datetime, '\",\"', datetime2, '\"]',
prefix)
} else
{
prefix <- paste0 ('[date:\"', datetime,'\"]', prefix)
prefix <- paste0 ('[date:\"', datetime, '\"]', prefix)
}
}

res <- list (bbox = bbox_to_string (bbox),
prefix = paste0 (prefix, ";\n(\n"),
suffix = suffix, features = NULL)
class (res) <- c (class (res), "overpass_query")
attr (res, "datetime") <- datetime
attr (res, "datetime2") <- datetime

return (res)
}

Expand All @@ -85,9 +88,9 @@ check_datetime <- function (x)
substring (x, 17, 17) != ":" &
substring (x, 20, 20) != "Z")
stop ("x is not is ISO8601 format ('YYYY-MM-DDThh:mm:ssZ')")
YY <- substring (x, 1, 4)
MM <- substring (x, 6, 7)
DD <- substring (x, 9, 10)
YY <- substring (x, 1, 4) # nolint
MM <- substring (x, 6, 7) # nolint
DD <- substring (x, 9, 10) # nolint
hh <- substring (x, 12, 13)
mm <- substring (x, 15, 16)
ss <- substring (x, 18, 19)
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"codeRepository": "https://github.com/ropensci/osmdata",
"issueTracker": "https://github.com/ropensci/osmdata/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.3.2",
"version": "0.1.3.3",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 4426561

Please sign in to comment.