A sensible default for the directed argument #50
Replies: 6 comments
-
My 10 cents: thinking about users, the one that is most useful depends on what they will need/expect. We haven't seen many use cases outside transport but can think of both directed (river network) and undirected (electricity grid) examples. As long as the My thinking, which may be biased by personal preference, would be that 2 ( I think 2 with prominent examples of object creation with |
Beta Was this translation helpful? Give feedback.
-
As a 5 cent addendum to your 10 cents @Robinlovelace, and in complete contradiction of that feller who previously insisted:
an additional option to your list @luukvdmeer would be,
This is what What this means in practice is that all representations should explicitly flag the directedness of each edge, and in the library (osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
x <- opq ("roxel germany") %>%
add_osm_feature (key = "highway") %>%
osmdata_sf () %>%
osm_poly2line ()
table (x$osm_lines$oneway)
#>
#> no yes
#> 21 143
length (which (x$osm_lines$oneway == "yes")) / nrow (x$osm_lines)
#> [1] 0.05506353 Created on 2020-06-08 by the reprex package (v0.3.0) And 5% of ways in Roxel are actually one way. This just indicates that this information is essential to any accurate representation of way networks, and that:
This is in fact what both |
Beta Was this translation helpful? Give feedback.
-
Good idea to add the |
Beta Was this translation helpful? Give feedback.
-
It's non-trivial, because the front-end code calls the "edges" "from" and "to", but these are
|
Beta Was this translation helpful? Give feedback.
-
The Regarding the naming of |
Beta Was this translation helpful? Give feedback.
-
Belated answer to @luukvdmeer's question
I think the |
Beta Was this translation helpful? Give feedback.
-
Following a discussion that emerged in #46, we should decide on a sensible default for the
directed
argument when creating networks.The
sfnetwork
construction function takes a data frame (sf
,data.frame
,tbl_df
, ..) that specifies the location and possible attributes of the nodes, and a data frame (sf
,data.frame
,tbl_df
, ..) that specifies the edges, at least with ato
andfrom
column referring to node indices, and optionally also with a linestring geometry. By default, construction assumes thatdirected = TRUE
. This is the same assumption thattidgyraph
andigraph
make. I think for this case that 1) preserving the default of the "parent packages" prevents confusion and 2) having adirected = TRUE
is most intuitive here, because you are already forced to provide your edges explicitly with afrom
andto
column.However,
sfnetworks
also offers the possibility to create a network directly from ansf
object with linestring geometries, by usingas_sfnetwork.sf
. Here, thefrom
andto
columns are internally derived from the linestrings that you provide. The first point of the linestring is thefrom
node, and the last point of the linestring is theto
node. Here I completely agree with @agila5 and @mpadge that it is more intuitive to have a default ofdirected = FALSE
, especially because, as @mpadge pointed out, simple feature geometries are not intended to have a direction (despite that, there is actually a possibility insf
to reverse the direction of linestring, by usingst_reverse
, so as a user you do have some influence on the direction of your input).In summary, I see 3 options, which all have their pro's and con's:
directed = TRUE
default in all construction functions. This preserves the defaults ofigraph
andtidygraph
, and will probably be most intuitive for users constructing their network by providing an already established network structure in the form of a list of data frames for nodes and edges (with the latter containingto
andfrom
columns).directed = FALSE
default in all construction functions. This is probably most intuitive for users that letsfnetworks
derive the network structure from a singlesf
object with linestring geometries.directed = TRUE
for the generalsfnetwork()
construction function, but using a default ofdirected = FALSE
for theas_sfnetwork.sf()
method. This uses the most intuitive default for both cases, but on the other hand might cause more confusion because the default is not the same throughout the whole package.Comments relating to this discussion in #46:
#46 (comment)
#46 (comment)
#46 (comment)
#46 (comment)
#46 (comment)
Beta Was this translation helpful? Give feedback.
All reactions