luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
345 stars 20 forks source link

New st_precision method #209

Closed agila5 closed 2 years ago

agila5 commented 2 years ago

Is your feature request related to a problem? Please describe. Define an st_precision() method for sfnetwork objects following the same ideas as in st_crs() and st_agr():

library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(sfnetworks)

sfn <- as_sfnetwork(roxel)
st_crs(sfn)
#> Coordinate Reference System:
#>   User input: EPSG:4326 
#>   wkt:
#> GEOGCRS["WGS 84",
#>     DATUM["World Geodetic System 1984",
#>         ELLIPSOID["WGS 84",6378137,298.257223563,
#>             LENGTHUNIT["metre",1]]],
#>     PRIMEM["Greenwich",0,
#>         ANGLEUNIT["degree",0.0174532925199433]],
#>     CS[ellipsoidal,2],
#>         AXIS["geodetic latitude (Lat)",north,
#>             ORDER[1],
#>             ANGLEUNIT["degree",0.0174532925199433]],
#>         AXIS["geodetic longitude (Lon)",east,
#>             ORDER[2],
#>             ANGLEUNIT["degree",0.0174532925199433]],
#>     USAGE[
#>         SCOPE["Horizontal component of 3D system."],
#>         AREA["World."],
#>         BBOX[-90,-180,90,180]],
#>     ID["EPSG",4326]]
st_agr(sfn)
#> factor(0)
#> Levels: constant aggregate identity
st_precision(sfn)
#> Error in UseMethod("st_precision"): no applicable method for 'st_precision' applied to an object of class "c('sfnetwork', 'tbl_graph', 'igraph')"

Created on 2022-06-08 by the reprex package (v2.0.1)

Describe the solution you'd like No error.

Describe alternatives you've considered Not sure 😅

Robinlovelace commented 2 years ago

Could this also help in networks where the geometries are imperfect but you want segment vertices that are close to 'snap' making a more routable network?

agila5 commented 2 years ago

I think you can already snap close segments using to_spatial_contracted(), but I think the new method may help quickly checking if the input object already has a default precision.

luukvdmeer commented 2 years ago

Added methods for st_precision and st_set_precision in v0.6.0. Cannot create a method for st_precision<- since this is not a generic (TODO: open issue in sf about this?)

Btw, just like CRS, precision is always set simultaneously for both network elements, no matter which one is active.