Skip to content

Commit

Permalink
add 'extract_network_data' fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Jun 7, 2024
1 parent 9f34729 commit 7e8c49b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: naturoute
Title: Routing through natural spaces
Version: 0.0.0.003
Version: 0.0.0.004
Authors@R:
person(given = "Mark",
family = "Padgham",
Expand Down
26 changes: 25 additions & 1 deletion R/prepare-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
#' @return A character vector of two elements containing full file paths to data
#' on the OSM network and natural spaces.
#' @export
nr_prepare_data <- function (city, osm_file, osm_boundary_id, results_dir) {
nr_prepare_data <- function (city, osm_file, osm_boundary_id, results_dir = ".") {

results_dir <- normalizePath (results_dir)

fbdry <- get_bounary_polygon (osm_boundary_id)
f <- extract_data_in_bdry (city, results_dir, fbdry)
f_network <- extract_network_data (city, results_dir)
}


Expand All @@ -34,3 +37,24 @@ extract_data_in_bdry <- function (city, results_dir, fbdry) {
}
return (f)
}

extract_network_data <- function (city, results_dir) {
fin <- file.path (results_dir, paste0 (city, ".osm.pbf"))
if (!file.exists (fin)) {
stop ("Input file [", fin, "] not found", call. = FALSE)
}
fout <- file.path (results_dir, paste0 (city, "-network.osm"))

if (!file.exists (fout)) {
tags <- c (
"highway", "restriction", "access", "foot", "motorcar",
"motor_vehicle", "vehicle", "toll", "bicycle",
"cycleway", "cycleway:left", "cycleway:right"
)
tags <- paste0 (paste0 ("wr/", tags), collapse = " ")
cmd <- paste ("osmium tags-filter", fin, tags, "-o", fout)
system (cmd)
}

return (fout)
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/UrbanAnalyst/naturoute",
"issueTracker": "https://github.com/UrbanAnalyst/naturoute/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.0.0.003",
"version": "0.0.0.004",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 7e8c49b

Please sign in to comment.