Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line_segmentize() returning incorrect result #42

Open
Robinlovelace opened this issue Apr 23, 2024 · 4 comments
Open

line_segmentize() returning incorrect result #42

Robinlovelace opened this issue Apr 23, 2024 · 4 comments

Comments

@Robinlovelace
Copy link

Robinlovelace commented Apr 23, 2024

line_segmentize() should always return n linestrings if it's going to work as expected in other functions. In this case n = 6 but the object returned has a length of 5:

sfc_integer = sf::st_linestring(
    cbind(
        c(418938.4, 418949.7, 418961),
        c(434303.2, 434280.1, 434257)
    )
) |>
  sf::st_sfc()
sfc_no_integer = sf::st_linestring(
    cbind(
        c(418938.4, 418949.7, 418961.1),
        c(434303.2, 434280.1, 434257)
    )
) |>
  sf::st_sfc()

rsgeo::line_segmentize(rsgeo::as_rsgeo(sfc_integer), n = 6) |>
  sf::st_as_sfc() |>
  sf::st_cast("LINESTRING") |>
  length()
#> [1] 5

rsgeo::line_segmentize(rsgeo::as_rsgeo(sfc_no_integer), n = 6) |>
  sf::st_as_sfc() |>
  sf::st_cast("LINESTRING") |>
  length()
#> [1] 6

Created on 2024-04-23 with reprex v2.1.0

@Robinlovelace
Copy link
Author

Essentially the same as #34, but this is projected data and with a decent distance between them. Could it be because one of the values in the coords is an integer I wonder...

robinlovelace-ate added a commit to acteng/network-join-demos that referenced this issue Apr 23, 2024
Robinlovelace added a commit to ropensci/stplanr that referenced this issue Apr 23, 2024
@JosiahParry
Copy link
Owner

Repro:

    #[test]
    fn robin_test() {
        let linestring: LineString = vec![
            [418938.4, 434303.2],
            [418949.7, 434280.1],
            [418961.0, 434257.0],
        ]
        .into();
        let segments = linestring.line_segmentize(6).unwrap();
        assert_eq!(6, segments.0.len());
    }

@Robinlovelace
Copy link
Author

Where does the underlying Rust code live? Must be some Rustaceans who will have good ideas on a fix.

@Robinlovelace
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants