Skip to content
New issue

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

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

Already on GitHub? # to your account

SpatialLinesNetwork not working with sf objects #240

Closed
Robinlovelace opened this issue Dec 20, 2017 · 2 comments
Closed

SpatialLinesNetwork not working with sf objects #240

Robinlovelace opened this issue Dec 20, 2017 · 2 comments
Labels

Comments

@Robinlovelace
Copy link
Member

Just testing this on OSM data and found a bug that also affects our test data:

library(stplanr)
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2

# rnet example
class(route_network)
#> [1] "SpatialLinesDataFrame"
#> attr(,"package")
#> [1] "sp"
SLN = SpatialLinesNetwork(route_network)
class(SLN)
#> [1] "SpatialLinesNetwork"
#> attr(,"package")
#> [1] "stplanr"
weightfield(SLN)  # field used to determine shortest path
#> [1] "length"
plot(SLN)
from_id = 1
to_id = 50
points(sln2points(SLN)[from_id, ], cex = 5)
points(sln2points(SLN)[to_id, ], cex = 5)
shortpath <- sum_network_routes(SLN, from_id, to_id, sumvars = "length")
plot(shortpath, col = "red", lwd = 4, add = TRUE)

SLN_sf = SpatialLinesNetwork(st_as_sf(route_network))
#> Error in mutate_impl(.data, dots): Evaluation error: This function should not be called directly.

# Another example from OSM
r = opq(bbox = c(0, 53, 0.5, 53.5)) %>% add_osm_feature("highway", "primary") %>% 
  osmdata_sf()
ways = r$osm_lines
summary(st_geometry_type(ways))
#>           GEOMETRY              POINT         LINESTRING 
#>                  0                  0                 94 
#>            POLYGON         MULTIPOINT    MULTILINESTRING 
#>                  0                  0                  0 
#>       MULTIPOLYGON GEOMETRYCOLLECTION     CIRCULARSTRING 
#>                  0                  0                  0 
#>      COMPOUNDCURVE       CURVEPOLYGON         MULTICURVE 
#>                  0                  0                  0 
#>       MULTISURFACE              CURVE            SURFACE 
#>                  0                  0                  0 
#>  POLYHEDRALSURFACE                TIN           TRIANGLE 
#>                  0                  0                  0
plot(ways)
#> Warning: plotting the first 9 out of 21 attributes; use max.plot = 21 to
#> plot all

ways_sln = SpatialLinesNetwork(ways)
#> Error in mutate_impl(.data, dots): Evaluation error: This function should not be called directly.
richardellison added a commit that referenced this issue Dec 24, 2017
Make SpatialLinesNetwork generic, close #240
@richardellison
Copy link
Collaborator

Still getting errors, so re-opening. I think I have fixed it and will put in a PR shortly.

richardellison added a commit to richardellison/stplanr that referenced this issue Dec 24, 2017
Robinlovelace added a commit that referenced this issue Dec 26, 2017
@richardellison
Copy link
Collaborator

Should be fixed in #243.

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

No branches or pull requests

2 participants