+62
-3
lines changedFilter options
+62
-3
lines changed Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ src/*.o
8
8
src/*.so
9
9
src/*.dll
10
10
*.html
11
+
iow.*
Original file line number Diff line number Diff line change
@@ -411,7 +411,7 @@ line2points.Spatial <- function(l, ids = rep(1:nrow(l), each = 2)) {
411
411
out
412
412
}
413
413
#' @export
414
-
line2points.sf <- function(l, ids = rep(1:nrow(l))) {
414
+
line2points.sf <- function(l, ids = rep(1:nrow(l), each = 2)) {
415
415
y_coords <- x_coords <- double(length = length(ids)) # initiate coords
416
416
d_indices <- 1:nrow(l) * 2
417
417
o_indices <- d_indices - 1
@@ -421,7 +421,7 @@ line2points.sf <- function(l, ids = rep(1:nrow(l))) {
421
421
y_coords[d_indices] <- sapply(l$geometry, tail, n = 1) # last (y) element of each line
422
422
p_multi <- sf::st_multipoint(cbind(x_coords, y_coords))
423
423
p <- sf::st_cast(sf::st_sfc(p_multi), "POINT")
424
-
sf::st_sf(data.frame(id = ids), p)
424
+
sf::st_sf(data.frame(id = ids), geometry = p, crs = sf::st_crs(l))
425
425
}
426
426
427
427
#' @rdname line_to_points
Original file line number Diff line number Diff line change
@@ -18,4 +18,62 @@ knitr::opts_chunk$set(
18
18
library(stplanr)
19
19
```
20
20
21
-
## This vignette is work in progress - watch this space!
21
+
## This vignette is work in progress - watch this space!
22
+
23
+
24
+
```{r, echo=FALSE, eval=FALSE}
25
+
# upload roads data
26
+
if(!file.exists("roads_iow.Rds")) {
27
+
download.file("https://github.com/ropensci/stplanr/releases/download/0.3.1/roads_iow.Rds", "roads_iow.Rds")
28
+
}
29
+
roads_iow = readRDS("roads_iow.Rds")
30
+
sf::write_sf(roads_iow, "roads_iow.geojson")
31
+
piggyback::pb_upload("roads_iow.geojson")
32
+
```
33
+
34
+
```{r}
35
+
roads_iow = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/0.3.1/roads_iow.geojson")
36
+
```
37
+
38
+
# osrm
39
+
40
+
```{r, echo=FALSE}
41
+
if(!file.exists("iow.pbf"))
42
+
download.file("http://download.geofabrik.de/europe/great-britain/england/isle-of-wight-latest.osm.pbf", "iow.pbf")
43
+
options(osrm.server = "http://0.0.0.0:5000/", osrm.profile = "driving")
44
+
```
45
+
46
+
Then in bash run the following commands to make the [OSRM docker image](https://hub.docker.com/r/osrm/osrm-backend/) work for you.
47
+
48
+
```{r, engine='bash', eval=FALSE}
49
+
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/iow.pbf
50
+
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/iow.osrm
51
+
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/iow.osrm
52
+
docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/iow.osrm
53
+
curl "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true"
54
+
```
55
+
56
+
Now we can do routing in R!
57
+
58
+
```{r, eval=FALSE}
59
+
l = pct::wight_lines_30
60
+
p = line2points(l)
61
+
r = osrm::osrmRoute(src = p[1, ], dst = p[2, ], returnclass = "sf")
62
+
plot(r)
63
+
```
64
+
65
+
```{r, eval=FALSE}
66
+
route_osrm2 = function(l) {
67
+
p = line2points(l)
68
+
s = (1:nrow(l)) * 2 - 1
69
+
list_out = lapply(s, function(i) osrm::osrmRoute(p[i, ], dst = p[i + 1, ], returnclass = "sf"))
70
+
do.call(rbind, list_out)
71
+
}
72
+
routes_osrm = route_osrm2(l)
73
+
plot(routes_osrm)
74
+
```
75
+
76
+
77
+
78
+
79
+
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4