is it possible to improve the speed of the last subset operation in this code? This code fetches a small portion of Open Streetmap data, searches for all the roads that have names and creates a new osm o bject that only contains the roads. Im interrested in optimizing the last bit of the code:
highway_subset <- subset(muc, ids = highway_subset_ids)
class(muc)
[1] "osmar" "list"
muc is a list of lists end each element of the list has an id that is used to create a subset.
Here is the complete example:
library("osmar")
src <- osmsource_api(url = "https://api.openstreetmap.org/api/0.6/")
muc_bbox <- center_bbox(11.575278, 48.137222, 1000, 1000)
muc <- get_osm(muc_bbox, src)
highway_subset_ids <- subset(muc, way_ids = find(muc, way(tags(k == "highway"))))
highway_subset_ids <- find(highway_subset_ids, way(tags(k == "name")))
highway_subset_ids <- find_down(muc, way(highway_subset_ids))
highway_subset <- subset(muc, ids = highway_subset_ids)
Thank you very much in advance.
UPDATE
If you have trouble with ssl, try to copy paste the following code example. It is as minimum as i could make it.
The line i would like to optimize is this one:
final_subset <- subset(highway_subset, ids = highway_subset_ids)
library("osmar")
highway_subset <-
structure(list(nodes = structure(list(
attrs = structure(
list(
id = numeric(0),
visible = character(0),
timestamp = structure(
list(
sec = numeric(0),
min = integer(0),
hour = integer(0),
mday = integer(0),
mon = integer(0),
year = integer(0),
wday = integer(0),
yday = integer(0),
isdst = integer(0),
zone = character(0),
gmtoff = integer(0)
),
class = c("POSIXlt", "POSIXt")
),
version = numeric(0),
changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(
integer(0),
.Label = c("2455020", "2590140", "367380"),
class = "factor"
),
lat = numeric(0),
lon = numeric(0)
),
row.names = integer(0),
class = "data.frame"
),
tags = structure(
list(
id = numeric(0),
k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")
),
row.names = integer(0),
class = "data.frame"
)
),
class = c("nodes", "osmar_element", "list")
),
ways = structure(
list(
attrs = structure(
list(
id = c(105071009, 366457476),
visible = c("true", "true"),
timestamp = structure(
list(
sec = c(10, 48),
min = c(54L, 15L),
hour = c(13L, 20L),
mday = c(4L, 15L),
mon = c(2L, 4L),
year = 117:116,
wday = c(6L, 0L),
yday = c(62L, 135L),
isdst = 0:1,
zone = c("CET", "CEST"),
gmtoff = c(NA_integer_, NA_integer_)
),
class = c("POSIXlt", "POSIXt")
),
version = c(15, 5),
changeset = c(46573027, 39338422),
user = structure(
2:1,
.Label = c("bjoern262", "saerdnaer"),
class = "factor"
),
uid = structure(
4:3,
.Label = c("367380",
"64536", "651621", "6998"),
class = "factor"
)
),
row.names = c(2L,
4L),
class = "data.frame"
),
tags = structure(
list(
id = c(
105071009,
105071009,
105071009,
105071009,
105071009,
105071009,
105071009,
105071009,
105071009,
105071009,
105071009,
366457476,
366457476,
366457476,
366457476,
366457476
),
k = structure(
c(1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 3L, 5L, 6L, 7L, 11L),
.Label = c(
"conveying",
"description",
"highway",
"incline",
"indoor",
"layer",
"level",
"oneway",
"operator",
"ref",
"tunnel"
),
class = "factor"
),
v = structure(
c(6L,
9L, 10L, 4L, 11L, 3L, 2L, 11L, 8L, 7L, 11L, 5L, 11L, 1L, 1L,
11L),
.Label = c(
"-3",
"-3;-4",
"-4",
"down",
"footway",
"forward",
"MP19",
"MVG",
"Rolltreppe MP19",
"steps",
"yes"
),
class = "factor"
)
),
row.names = 4:19,
class = "data.frame"
),
refs = structure(
list(
id = c(105071009, 105071009, 366457476,
366457476, 366457476),
ref = c(3270556979, 1211172719, 3270556979,
3704371485, 3704371444)
),
row.names = c(20L, 21L, 68L, 69L,
70L),
class = "data.frame"
)
),
class = c("ways", "osmar_element",
"list")
),
relations = structure(
list(
attrs = structure(
list(
id = numeric(0),
visible = character(0),
timestamp = structure(
list(
sec = numeric(0),
min = integer(0),
hour = integer(0),
mday = integer(0),
mon = integer(0),
year = integer(0),
wday = integer(0),
yday = integer(0),
isdst = integer(0),
zone = character(0),
gmtoff = integer(0)
),
class = c("POSIXlt", "POSIXt")
),
version = numeric(0),
changeset = numeric(0),
user = structure(integer(0), .Label = character(0), class = "factor"),
uid = structure(
integer(0),
.Label = c(
"137242",
"161619",
"2455020",
"2590140",
"531886",
"72235",
"8748",
"9451067"
),
class = "factor"
)
),
row.names = integer(0),
class = "data.frame"
),
tags = structure(
list(
id = numeric(0),
k = structure(integer(0), .Label = character(0), class = "factor"),
v = structure(integer(0), .Label = character(0), class = "factor")
),
row.names = integer(0),
class = "data.frame"
),
refs = structure(
list(
id = numeric(0),
type = structure(integer(0), .Label = character(0), class = "factor"),
ref = numeric(0),
role = structure(integer(0), .Label = character(0), class = "factor")
),
row.names = integer(0),
class = "data.frame"
)
),
class = c("relations",
"osmar_element", "list")
)
),
class = c("osmar", "list")
)
highway_subset_ids <- find_down(highway_subset, way(highway_subset$ways$attrs$id))
final_subset <- subset(highway_subset, ids = highway_subset_ids)
Thank you!