diff --git a/NAMESPACE b/NAMESPACE index a10b560..ab051df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -35,7 +35,7 @@ export(osm_diff_upload_changeset) export(osm_download_changeset) export(osm_feed_notes) export(osm_get_data_gpx) -export(osm_get_metadata_gpx) +export(osm_get_gpx_metadata) export(osm_get_objects) export(osm_get_points_gps) export(osm_get_preferences_user) diff --git a/R/osm_get_gpx_metadata.R b/R/osm_get_gpx_metadata.R new file mode 100644 index 0000000..5257b99 --- /dev/null +++ b/R/osm_get_gpx_metadata.R @@ -0,0 +1,56 @@ +# Vectorized version of osm_get_metadata_gpx() + +#' Download GPS Track Metadata +#' +#' Use this to access the metadata about GPX files. Available without authentication if the file is marked public. +#' Otherwise only usable by the owner account and requires authentication. +#' +#' @param gpx_id A vector of track ids represented by a numeric or a character value. +#' @param format Format of the output. Can be `R` (default) or `xml`. +#' +#' @return +#' If `format = "R"`, returns a data frame with one trace per row. If `format = "xml"`, returns a +#' [xml2::xml_document-class] with the following format: +#' ```xml +#' +#' +#' +#' PHP upload test +#' test +#' php +#' +#' +#' ... +#' +#' +#' ``` +#' @family get GPS' functions +#' @export +#' +#' @examples +#' \dontrun{ +#' trk_meta <- osm_get_gpx_metadata(gpx_id = 3498170) +#' trk_meta +#' } +osm_get_gpx_metadata <- function(gpx_id, format = c("R", "xml")) { + format <- match.arg(format) + + if (length(gpx_id) == 1) { + out <- osm_get_metadata_gpx(gpx_id = gpx_id, format = format) + } else { + outL <- lapply(gpx_id, function(id) { + osm_get_metadata_gpx(gpx_id = id, format = format) + }) + + if (format == "R") { + out <- do.call(rbind, outL) + } else if (format == "xml") { + out <- xml2::xml_new_root(outL[[1]]) + for (i in seq_len(length(outL) - 1)) { + xml2::xml_add_child(out, xml2::xml_child(outL[[i + 1]])) + } + } + } + + return(out) +} diff --git a/R/osmapi_gps_traces.R b/R/osmapi_gps_traces.R index 5622d16..484f4a0 100644 --- a/R/osmapi_gps_traces.R +++ b/R/osmapi_gps_traces.R @@ -300,8 +300,8 @@ osm_delete_gpx <- function(gpx_id) { #' #' #' ``` -#' @family get GPS' functions -#' @export +# @family get GPS' functions +#' @noRd #' #' @examples #' \dontrun{ @@ -436,8 +436,7 @@ osm_get_data_gpx <- function(gpx_id, format) { #' #' @return #' If `format = "R"`, returns a data frame with one trace per row. If `format = "xml"`, returns a -#' [xml2::xml_document-class] similar to the one of [osm_get_metadata_gpx()], except with multiple possible `` -#' elements. Example: +#' [xml2::xml_document-class] similar to [osm_get_gpx_metadata()]. Example: #' ``` xml #' #' diff --git a/README.Rmd b/README.Rmd index 5c4783c..6593d82 100644 --- a/README.Rmd +++ b/README.Rmd @@ -78,7 +78,7 @@ Get GPX data: ``` r ## Requires authentication usr_traces <- osm_list_gpxs() -osm_get_metadata_gpx(gpx_id = 3790367) +osm_get_gpx_metadata(gpx_id = 3790367) osm_get_data_gpx(gpx_id = 3790367, format = "R") ``` ```{r gpx} diff --git a/README.md b/README.md index b07e434..c5313a3 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ Get GPX data: ``` r ## Requires authentication usr_traces <- osm_list_gpxs() -osm_get_metadata_gpx(gpx_id = 3790367) +osm_get_gpx_metadata(gpx_id = 3790367) osm_get_data_gpx(gpx_id = 3790367, format = "R") ``` diff --git a/inst/WORDLIST b/inst/WORDLIST index a2b7560..d5da991 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -217,6 +217,7 @@ OsmChange OsmChange's osmdata osmexctract +outL packageStartupMessage packageVersion pageNumber @@ -318,6 +319,7 @@ uvAy vals vapply VAZUTwcmHJLwDEX +Vectorized Visca VORx vt diff --git a/man/osm_get_data_gpx.Rd b/man/osm_get_data_gpx.Rd index fe14066..c807dca 100644 --- a/man/osm_get_data_gpx.Rd +++ b/man/osm_get_data_gpx.Rd @@ -35,7 +35,7 @@ trk_data } \seealso{ Other get GPS' functions: -\code{\link{osm_get_metadata_gpx}()}, +\code{\link{osm_get_gpx_metadata}()}, \code{\link{osm_get_points_gps}()}, \code{\link{osm_list_gpxs}()} } diff --git a/man/osm_get_metadata_gpx.Rd b/man/osm_get_gpx_metadata.Rd similarity index 71% rename from man/osm_get_metadata_gpx.Rd rename to man/osm_get_gpx_metadata.Rd index d6cd8e6..7f81d4c 100644 --- a/man/osm_get_metadata_gpx.Rd +++ b/man/osm_get_gpx_metadata.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/osmapi_gps_traces.R -\name{osm_get_metadata_gpx} -\alias{osm_get_metadata_gpx} +% Please edit documentation in R/osm_get_gpx_metadata.R +\name{osm_get_gpx_metadata} +\alias{osm_get_gpx_metadata} \title{Download GPS Track Metadata} \usage{ -osm_get_metadata_gpx(gpx_id, format = c("R", "xml")) +osm_get_gpx_metadata(gpx_id, format = c("R", "xml")) } \arguments{ -\item{gpx_id}{The track id represented by a numeric or a character value.} +\item{gpx_id}{A vector of track ids represented by a numeric or a character value.} \item{format}{Format of the output. Can be \code{R} (default) or \code{xml}.} } @@ -22,16 +22,19 @@ If \code{format = "R"}, returns a data frame with one trace per row. If \code{fo test php + + ... + }\if{html}{\out{}} } \description{ -Use this to access the metadata about a GPX file. Available without authentication if the file is marked public. +Use this to access the metadata about GPX files. Available without authentication if the file is marked public. Otherwise only usable by the owner account and requires authentication. } \examples{ \dontrun{ -trk_meta <- osm_get_metadata_gpx(gpx_id = 3498170) +trk_meta <- osm_get_gpx_metadata(gpx_id = 3498170) trk_meta } } diff --git a/man/osm_get_points_gps.Rd b/man/osm_get_points_gps.Rd index c9ead72..c7bebdd 100644 --- a/man/osm_get_points_gps.Rd +++ b/man/osm_get_points_gps.Rd @@ -66,7 +66,7 @@ pts_gps \seealso{ Other get GPS' functions: \code{\link{osm_get_data_gpx}()}, -\code{\link{osm_get_metadata_gpx}()}, +\code{\link{osm_get_gpx_metadata}()}, \code{\link{osm_list_gpxs}()} } \concept{get GPS' functions} diff --git a/man/osm_list_gpxs.Rd b/man/osm_list_gpxs.Rd index 1d374a3..6d3cada 100644 --- a/man/osm_list_gpxs.Rd +++ b/man/osm_list_gpxs.Rd @@ -11,8 +11,7 @@ osm_list_gpxs(format = c("R", "xml")) } \value{ If \code{format = "R"}, returns a data frame with one trace per row. If \code{format = "xml"}, returns a -\link[xml2:oldclass]{xml2::xml_document} similar to the one of \code{\link[=osm_get_metadata_gpx]{osm_get_metadata_gpx()}}, except with multiple possible \verb{} -elements. Example: +\link[xml2:oldclass]{xml2::xml_document} similar to \code{\link[=osm_get_gpx_metadata]{osm_get_gpx_metadata()}}. Example: \if{html}{\out{
}}\preformatted{ @@ -41,7 +40,7 @@ traces \seealso{ Other get GPS' functions: \code{\link{osm_get_data_gpx}()}, -\code{\link{osm_get_metadata_gpx}()}, +\code{\link{osm_get_gpx_metadata}()}, \code{\link{osm_get_points_gps}()} } \concept{get GPS' functions} diff --git a/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3458743/details.xml b/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3458743/details.xml new file mode 100644 index 0000000..0018e44 --- /dev/null +++ b/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3458743/details.xml @@ -0,0 +1,8 @@ + + + + Puiggiró + explorant + Cingles de Bertí + + diff --git a/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3790367/details.xml b/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3790367/details.xml index 6b91fbe..a71aa4b 100644 --- a/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3790367/details.xml +++ b/tests/testthat/mock_get_metadata_gpx/osm.org/api/0.6/gpx/3790367/details.xml @@ -1,6 +1,6 @@ - + Airoto Marimanha Oriental camp a diff --git a/tests/testthat/mock_list_gpxs/osm.org/api/0.6/user/gpx_files.xml b/tests/testthat/mock_list_gpxs/osm.org/api/0.6/user/gpx_files.xml index 421659f..df74c66 100644 --- a/tests/testthat/mock_list_gpxs/osm.org/api/0.6/user/gpx_files.xml +++ b/tests/testthat/mock_list_gpxs/osm.org/api/0.6/user/gpx_files.xml @@ -1,55 +1,58 @@ - + StJuliàDeRibelles_HostalDeLaMuga_Talaixà_Sadernes - + St. Aniol - Passant del Gamarús - cova dels Trabucaires - Passant d'en Llebre - + camins de Cerdanyola trailrun - + Corriols per les rodalies del Bruc - + Roca de la Pena circular - + Roca de la Pena des de Llobera - + Airoto Marimanha Oriental camp a través - + Castell - Canigó - refugi d'Aragó - + + Turó de les 11 hores + + Volta circular amb corriols per traçar - + Camins pendents d'agegir entre Perles i Fígols pel Collet de la Canal d'en Joan - + Gósol - Vulturó per Josa del Cadí - + Vulturó i fins més avall del refugi de St. Jordi - + Tornada a Gòsol - + Imlil - Tamsoult - + Toubkal - Imlil - + Tamsoult - Refuge Toubkal diff --git a/tests/testthat/test-gps_traces.R b/tests/testthat/test-gps_traces.R index 68ee186..d657c5c 100644 --- a/tests/testthat/test-gps_traces.R +++ b/tests/testthat/test-gps_traces.R @@ -1,11 +1,11 @@ -column_meta_gpx <- c("id", "name", "user", "visibility", "pending", "timestamp", "lat", "lon", "description", "tags") +column_meta_gpx <- c("id", "name", "uid", "user", "visibility", "pending", "timestamp", "lat", "lon", "description", "tags") column_gpx <- c("lat", "lon", "ele", "time") column_pts_gps <- c("lat", "lon", "time") class_columns <- list( - id = "character", name = "character", user = "character", visibility = "character", pending = "logical", - timestamp = "POSIXct", lat = "character", lon = "character", description = "character", tags = "list", - ele = "character", time = "POSIXct" + id = "character", name = "character", uid = "character", user = "character", visibility = "character", + pending = "logical", timestamp = "POSIXct", lat = "character", lon = "character", description = "character", + tags = "list", ele = "character", time = "POSIXct" ) @@ -87,17 +87,21 @@ test_that("edit gpx works", { ## Download Metadata: `GET /api/0.6/gpx/#id/details` ---- test_that("osm_get_metadata_gpx works", { + trk_meta <- list() with_mock_dir("mock_get_metadata_gpx", { - trk_meta <- osm_get_metadata_gpx(gpx_id = 3790367) + trk_meta$track <- osm_get_gpx_metadata(gpx_id = 3790367) + trk_meta$tracks <- osm_get_gpx_metadata(gpx_id = c(3790367, 3458743)) }) - expect_s3_class(trk_meta, "data.frame") - expect_named(trk_meta, column_meta_gpx) + lapply(trk_meta, function(x) expect_s3_class(x, "data.frame")) + lapply(trk_meta, function(x) expect_named(x, column_meta_gpx)) - mapply(function(x, cl) expect_true(inherits(x, cl)), x = trk_meta, cl = class_columns[names(trk_meta)]) + lapply(trk_meta, function(trk) { + mapply(function(x, cl) expect_true(inherits(x, cl)), x = trk, cl = class_columns[names(trk)]) + }) # Check that time is extracted, otherwise it's 00:00:00 in local time - expect_false(strftime(as.POSIXct(trk_meta$timestamp), format = "%M:%S") == "00:00") + lapply(trk_meta, function(x) expect_false(unique(strftime(as.POSIXct(x$timestamp), format = "%M:%S") == "00:00"))) })