Skip to content

Commit

Permalink
Demonstrate issue with #554
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Mar 14, 2024
1 parent d593b9f commit 3371d91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 8 additions & 4 deletions reprexes/test-rnet_merge_rsgeo_issue_552.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
# l <- sf::read_sf("test_line.geojson")
# n_segments <- jsonlite::read_json("n_segments.json", simplifyVector = TRUE)


l <- sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.1.2/test_line.geojson")
n_segments <- jsonlite::read_json("https://github.com/ropensci/stplanr/releases/download/v1.1.2/n_segments.json")
n_segments <- jsonlite::read_json("https://github.com/ropensci/stplanr/releases/download/v1.1.2/n_segments.json", simplifyVector = TRUE)


res_rsgeo <- rsgeo::line_segmentize(l$geometry, n_segments)
length(res_rsgeo)
# extract geometry and convert to rsgeo
geo <- rsgeo::as_rsgeo(sf::st_geometry(l))

# segmentize the line strings
res_rsgeo <- rsgeo::line_segmentize(geo, n_segments)

# make them into sfc_LINESTRING
res <- sf::st_cast(sf::st_as_sfc(res_rsgeo), "LINESTRING")

length(res)
sum(n_segments)
16 changes: 16 additions & 0 deletions vignettes/merging-route-networks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ We pre-processed the input simple geometry to make it even simpler as shown belo
# summary(sf::st_length(rnet_x))
plot(sf::st_geometry(rnet_x))
rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20)
names(rnet_x)
# Keep only the id column for x:
rnet_x = rnet_x %>% select(identifier)
# nrow(rnet_x)
# plot(sf::st_geometry(rnet_x))
rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20, min_length = 5)
Expand Down Expand Up @@ -141,6 +144,19 @@ sum(rnet_merged$value * sf::st_length(rnet_merged), na.rm = TRUE)
sum(rnet_y$value * sf::st_length(rnet_y), na.rm = TRUE)
```

Let's try joining with a character column:

```{r}
rnet_y$road_type = sample(c("A", "B", "C"), nrow(rnet_y), replace = TRUE)
funs = list(value = sum, road_type = function(x) { table(x)[[1]] })
rnet_merged = rnet_merge(sum_flows = FALSE,
rnet_x,
rnet_y,
dist = 20, segment_length = 10, funs = funs, max_angle_diff = 20)
```

# 3 km dataset

Now let's testing on 3km dataset

```{r}
Expand Down

0 comments on commit 3371d91

Please sign in to comment.