Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 25, 2024
2 parents 473f8d9 + c4bd595 commit 513a5ed
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 40 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: osmdata
Title: Import 'OpenStreetMap' Data as Simple Features or Spatial Objects
Version: 0.2.5.022
Version: 0.2.5.023
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre")),
person("Bob", "Rudis", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
along with geometries (#338 thanks to @RegularnaMatrica)
- Mention key-only feature requests in README (#342 thanks to @joostschouppe)
- Merge any columns in `osmdata_sf()` with mixed-case duplicated names (#348)
- Set encoding to UTF-8 for tags and user names (#347)


0.2.5
Expand Down
20 changes: 13 additions & 7 deletions R/get-osmdata-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ osmdata_data_frame <- function (q,
colClasses = "character", # osm_id doesn't fit in integer
check.names = FALSE,
comment.char = "",
stringsAsFactors = stringsAsFactors
stringsAsFactors = stringsAsFactors,
encoding = "UTF-8"
)
} else if (isTRUE (obj$meta$query_type == "adiff")) {
datetime_from <- obj$meta$datetime_from
Expand Down Expand Up @@ -122,13 +123,15 @@ xml_to_df <- function (doc, stringsAsFactors = FALSE) {

tags <- mapply (function (i, k) {
i <- i [, k, drop = FALSE] # remove osm_id column if exists
out <- matrix (
NA_character_,
nrow = nrow (i), ncol = length (keys),
dimnames = list (NULL, keys)
)
out <- enc2utf8 (out)
out <- data.frame (
matrix (
nrow = nrow (i), ncol = length (keys),
dimnames = list (NULL, keys)
),
stringsAsFactors = stringsAsFactors,
check.names = FALSE
out,
stringsAsFactors = stringsAsFactors, check.names = FALSE
)
out [, names (i)] <- i
return (out)
Expand Down Expand Up @@ -214,6 +217,7 @@ xml_adiff_to_df <- function (doc,
tags_u <- xml2::xml_find_all (osm_actions, xpath = ".//tag")
col_names <- sort (unique (xml2::xml_attr (tags_u, attr = "k")))
m <- matrix (
NA_character_,
nrow = length (osm_obj), ncol = length (col_names),
dimnames = list (NULL, col_names)
)
Expand All @@ -225,6 +229,7 @@ xml_adiff_to_df <- function (doc,
tagV <- vapply (tag, function (x) x, FUN.VALUE = character (2))
m [i, tagV [1, ]] <- tagV [2, ]
}
m <- enc2utf8 (m)

osm_type <- xml2::xml_name (osm_obj)
osm_id <- xml2::xml_attr (osm_obj, "id")
Expand Down Expand Up @@ -325,6 +330,7 @@ get_meta_from_xml <- function (osm_obj) {
osm_uid = xml2::xml_attr (osm_obj, attr = "uid"),
osm_user = xml2::xml_attr (osm_obj, attr = "user")
)
out$osm_user <- enc2utf8 (out$osm_user)

} else {
out <- matrix (nrow = length (osm_obj), ncol = 0)
Expand Down
6 changes: 6 additions & 0 deletions R/get-osmdata-sc.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ osmdata_sc <- function (q, doc, quiet = TRUE) {
overpass_version = temp$obj$meta$overpass_version
)

has_tags <- c ("nodes", "relation_properties", "object")
obj [has_tags] <- lapply(obj [has_tags], function (x) {
x [, c ("key", "value")] <- setenc_utf8 (x [, c ("key", "value")])
x
})

if (!missing (q)) {
if (!is.character (q)) {
obj$meta$bbox <- q$bbox
Expand Down
3 changes: 2 additions & 1 deletion R/get-osmdata-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ osmdata_sf <- function (q, doc, quiet = TRUE, stringsAsFactors = FALSE) { # noli
if (!"osm_id" %in% names (res$polygons_kv) [1]) {
res <- fill_kv (res, "polygons_kv", "polygons", stringsAsFactors)
}
kv_df <- grep ("_kv$", names (res))
kv_df <- grep ("_kv$", names (res)) # objects with tags
res [kv_df] <- fix_columns_list (res [kv_df])
res [kv_df] <- lapply (res [kv_df], setenc_utf8)

if (missing (q)) {
obj$bbox <- paste (res$bbox, collapse = " ")
Expand Down
6 changes: 5 additions & 1 deletion R/get-osmdata-sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ osmdata_sp <- function (q, doc, quiet = TRUE) {
obj$osm_multipolygons <- res$multipolygons

osm_items <- grep ("^osm_", names (obj))
obj[osm_items] <- fix_columns_list (obj[osm_items])
obj [osm_items] <- fix_columns_list (obj [osm_items])
obj [osm_items] <- lapply (obj [osm_items], function (x) {
x@data <- setenc_utf8 (x@data)
x
})
class (obj) <- c (class (obj), "osmdata_sp")

return (obj)
Expand Down
16 changes: 16 additions & 0 deletions R/get-osmdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,19 @@ get_center_from_cpp_output <- function (res, what = "points") {

return (as.data.frame (this))
}


#' Set encoding to UTF-8
#'
#' @param x a data.frame or a list.
#'
#' @return `x` with all the columns or items of type character with UTF-8 encoding set.
#' @noRd
setenc_utf8 <- function (x) {
char_cols <- which (vapply (x, is.character, FUN.VALUE = logical (1)))
x [char_cols] <- lapply (x [char_cols], function (y) {
enc2utf8 (y)
})

return (x)
}
2 changes: 2 additions & 0 deletions R/getbb.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ getbb <- function (place_name,
)

if (format_out == "data.frame") {
utf8cols <- c ("licence", "name", "display_name")
obj [, utf8cols] <- setenc_utf8 (obj [, utf8cols])
return (obj)
}

Expand Down
38 changes: 8 additions & 30 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
"identifier": "osmdata",
"description": "Download and import of 'OpenStreetMap' ('OSM') data as 'sf' or 'sp' objects. 'OSM' data are extracted from the 'Overpass' web server (<https://overpass-api.de/>) and processed with very fast 'C++' routines for return to 'R'.",
"name": "osmdata: Import 'OpenStreetMap' Data as Simple Features or Spatial Objects",
"relatedLink": [
"https://docs.ropensci.org/osmdata/",
"https://CRAN.R-project.org/package=osmdata"
],
"relatedLink": ["https://docs.ropensci.org/osmdata/", "https://CRAN.R-project.org/package=osmdata"],
"codeRepository": "https://github.com/ropensci/osmdata/",
"issueTracker": "https://github.com/ropensci/osmdata/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.2.5.022",
"version": "0.2.5.23",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.3.1 (2023-06-16)",
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -348,25 +345,12 @@
},
"sameAs": "https://CRAN.R-project.org/package=xml2"
},
"SystemRequirements": {}
"SystemRequirements": null
},
"applicationCategory": "DataAccess",
"isPartOf": "https://ropensci.org",
"keywords": [
"open0street0map",
"openstreetmap",
"overpass0API",
"OSM",
"overpass-api",
"r",
"cpp",
"rstats",
"osm",
"osm-data",
"r-package",
"peer-reviewed"
],
"fileSize": "2467.715KB",
"keywords": ["open0street0map", "openstreetmap", "overpass0API", "OSM", "overpass-api", "r", "cpp", "rstats", "osm", "osm-data", "r-package", "peer-reviewed"],
"fileSize": "17525.157KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down Expand Up @@ -400,10 +384,7 @@
"issueNumber": "14",
"datePublished": "2017",
"isPartOf": {
"@type": [
"PublicationVolume",
"Periodical"
],
"@type": ["PublicationVolume", "Periodical"],
"volumeNumber": "2",
"name": "Journal of Open Source Software"
}
Expand All @@ -412,10 +393,7 @@
],
"releaseNotes": "https://github.com/ropensci/osmdata/blob/master/NEWS.md",
"readme": "https://github.com/ropensci/osmdata/blob/main/README.md",
"contIntegration": [
"https://github.com/ropensci/osmdata/actions?query=workflow%3AR-CMD-check",
"https://app.codecov.io/gh/ropensci/osmdata"
],
"contIntegration": ["https://github.com/ropensci/osmdata/actions?query=workflow%3AR-CMD-check", "https://app.codecov.io/gh/ropensci/osmdata"],
"developmentStatus": "https://www.repostatus.org/#active",
"review": {
"@type": "Review",
Expand Down

0 comments on commit 513a5ed

Please sign in to comment.