Skip to content

Commit

Permalink
Fix missing object in osm_get_objects(..., full_object = TRUE, format…
Browse files Browse the repository at this point in the history
… = "R")

FIX #35
  • Loading branch information
jmaspons committed Jul 1, 2024
1 parent 08fb4b1 commit 01618f5
Show file tree
Hide file tree
Showing 12 changed files with 1,649 additions and 1,123 deletions.
13 changes: 6 additions & 7 deletions R/osm_get_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ osm_get_objects <- function(osm_type, osm_id, version, full_objects = FALSE,
full_obj <- do.call(rbind, full_objL)
} else if (format == "xml") {
full_obj <- xml2::xml_new_root(full_objL[[1]])
for (i in seq_len(length(full_objL) - 1)) {
for (j in seq_len(xml2::xml_length(full_objL[[i + 1]]))) {
xml2::xml_add_child(full_obj, xml2::xml_child(full_objL[[i + 1]], search = j))
}
for (i in seq_along(full_objL[-1]) + 1) {
lapply(xml2::xml_children(full_objL[[i]]), function(node) {
xml2::xml_add_child(full_obj, node)
})
}
} else if (format == "json") {
full_obj <- full_objL[[1]]
Expand Down Expand Up @@ -144,9 +144,8 @@ osm_get_objects <- function(osm_type, osm_id, version, full_objects = FALSE,
# Order by types (node, way, relation)

if (format == "R") {
out <- do.call(rbind, out[intersect(c("node", "way", "relation"), names(out))])
out <- rbind(out[out$type == "node", ], out[out$type == "way", ])
out <- rbind(out, out[out$type == "relation", ])
out <- do.call(rbind, out)
out <- rbind(out[out$type == "node", ], out[out$type == "way", ], out[out$type == "relation", ])
rownames(out) <- NULL

if (tags_in_columns) {
Expand Down
1,040 changes: 787 additions & 253 deletions tests/testthat/_snaps/elements.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.8.10 (012345 ******.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<osm version="0.6" generator="CGImap 0.9.3 (012345 ******.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node id="35308286" visible="true" version="17" changeset="140341361" timestamp="2023-08-24T20:19:22Z" user="jmaspons" uid="11725140" lat="42.5189047" lon="2.4565596">
<tag k="ele" v="2784.66"/>
<tag k="name" v="Pic du Canigou"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0.6",
"generator": "CGImap 0.8.10 (012345 ******.openstreetmap.org)",
"generator": "CGImap 0.9.3 (012345 ******.openstreetmap.org)",
"copyright": "OpenStreetMap and contributors",
"attribution": "http://www.openstreetmap.org/copyright",
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0.6",
"generator": "CGImap 0.8.10 (012345 ******.openstreetmap.org)",
"generator": "CGImap 0.9.3 (012345 ******.openstreetmap.org)",
"copyright": "OpenStreetMap and contributors",
"attribution": "http://www.openstreetmap.org/copyright",
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
Expand Down Expand Up @@ -778,11 +778,11 @@
{
"type": "relation",
"id": 6002785,
"timestamp": "2021-12-23T15:52:41Z",
"version": 6,
"changeset": 115301929,
"user": "jmaspons",
"uid": 11725140,
"timestamp": "2024-06-14T12:56:49Z",
"version": 7,
"changeset": 152677228,
"user": "Jean-Louis Stanus",
"uid": 116840,
"members": [
{
"type": "way",
Expand All @@ -806,6 +806,7 @@
"religion": "christian",
"tourism": "attraction",
"type": "multipolygon",
"wheelchair": "no",
"wikidata": "Q798606",
"wikipedia": "ca:Sant Pere de Rodes"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.8.8 (012345 ******.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<osm version="0.6" generator="CGImap 0.9.3 (012345 ******.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node id="1987589881" visible="true" version="1" changeset="13666675" timestamp="2012-10-28T20:10:51Z" user="EliziR" uid="605366" lat="42.3229954" lon="3.1666430"/>
<node id="1987589883" visible="true" version="1" changeset="13666675" timestamp="2012-10-28T20:10:51Z" user="EliziR" uid="605366" lat="42.3230133" lon="3.1667173"/>
<node id="1987589884" visible="true" version="1" changeset="13666675" timestamp="2012-10-28T20:10:51Z" user="EliziR" uid="605366" lat="42.3230151" lon="3.1665900"/>
Expand Down Expand Up @@ -137,7 +137,7 @@
<tag k="name" v="Claustre"/>
<tag k="name:ca" v="Claustre"/>
</way>
<relation id="6002785" visible="true" version="6" changeset="115301929" timestamp="2021-12-23T15:52:41Z" user="jmaspons" uid="11725140">
<relation id="6002785" visible="true" version="7" changeset="152677228" timestamp="2024-06-14T12:56:49Z" user="Jean-Louis Stanus" uid="116840">
<member type="way" ref="188131984" role="outer"/>
<member type="way" ref="399588560" role="inner"/>
<tag k="amenity" v="place_of_worship"/>
Expand All @@ -150,6 +150,7 @@
<tag k="religion" v="christian"/>
<tag k="tourism" v="attraction"/>
<tag k="type" v="multipolygon"/>
<tag k="wheelchair" v="no"/>
<tag k="wikidata" v="Q798606"/>
<tag k="wikipedia" v="ca:Sant Pere de Rodes"/>
</relation>
Expand Down
Loading

0 comments on commit 01618f5

Please sign in to comment.