Why does OD matrix in sfnetwork returns one NA in dimension names?

51 views Asked by At

I have a rooted tree with spatially explicit edges representing a river network (new_net). I want to compute an origin-destination (OD) matrix to get the distances between multiple points representing small catchment outlets (1754 points) located on this river network.

I start by creating a network using my network dataset hyriv_line:

net <- as_sfnetwork(hyriv_line, directed = T)

Then I blend the outlet points (dir_outlets) to the network:

  # Update river network with outlets
  new_net <- net %>% # Original river network
    activate("nodes") %>%
    st_network_blend(dir_outlets) %>% # Blend in catchment outlets
    activate("edges") %>%
    mutate(weight = edge_length()) # Compute lenght of each river reach

Then I compute the OD matrix between all my outlet points:

  cost_matrix_out <- st_network_cost(new_net, 
                                 from = dir_outlets, to = dir_outlets, # from-to point sf
                                 mode = "out", # outbound (column-wise results)
                                 Inf_as_NaN = T)

It runs smoothly, but then, when looking at the resulting matrix, dimension names in rows appear with a leading X, meaning that something is wrong. One record —always the same, #823— looks like its name cannot be read properly, thereby adding NA instead in the OD matrix, hence the leading X. Column #823 in the matrix also has no name (see below). Snapshot of my OD matrix with NA is row name and empty column name

I can't make sense of it. I checked the point layer many times and its structure is sound. Any insight as to what I can further check?

Data for dir_outlet (where the name comes from):

dput(head(st_drop_geometry(dir_outlets[820:825,])), control = "showAttributes")
structure(list(c(7120213140, 7120933070, 7120213260, 7120933120, 
7120933150, 7120213350), c(7120933250, 7120213890, 7120213070, 
7120933570, 7120933230, 7120933250), c("7120213140", "7120933070", 
"7120213260", "7120933120", "7120933150", "7120213350")), .Names = c("from", 
"to", "name"), row.names = 820:825, class = "data.frame")
0

There are 0 answers