UrbanAnalyst / dodgr

Distances on Directed Graphs in R
https://urbananalyst.github.io/dodgr/
127 stars 16 forks source link

weight_streetnet error with silicate data #147

Closed Hussein-Mahfouz closed 3 years ago

Hussein-Mahfouz commented 3 years ago

I'm trying to weigh an osm street network using the weight_streetnet function. Passing an sf object (from dodgr_streetnet) works but passing a silicate object (from dodgr_streetnet_sc) raises an error. I think this may be a bug, but i'm not sure. Reprex below:

library(dodgr)
packageVersion("dodgr")
#> [1] '0.2.7'
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

#sf format 
hampi <- dodgr_streetnet("hampi india")
hampi_weighted<- weight_streetnet(hampi, wt_profile = "bicycle") 
# check...all good
head(hampi_weighted) 
#>   geom_num edge_id    from_id from_lon from_lat      to_id   to_lon   to_lat
#> 1        1       1  339318500 76.47491 15.34167  339318502 76.47612 15.34173
#> 2        1       2  339318502 76.47612 15.34173  339318500 76.47491 15.34167
#> 3        1       3  339318502 76.47612 15.34173 2398958028 76.47621 15.34174
#> 4        1       4 2398958028 76.47621 15.34174  339318502 76.47612 15.34173
#> 5        1       5 2398958028 76.47621 15.34174 1427116077 76.47628 15.34179
#> 6        1       6 1427116077 76.47628 15.34179 2398958028 76.47621 15.34174
#>            d d_weighted highway   way_id component      time time_weighted
#> 1 129.972181  144.41353    path 28565950         1 38.991654     43.324060
#> 2 129.972181  144.41353    path 28565950         1 38.991654     43.324060
#> 3   8.888670    9.87630    path 28565950         1  2.666601      2.962890
#> 4   8.888670    9.87630    path 28565950         1  2.666601      2.962890
#> 5   9.326536   10.36282    path 28565950         1  2.797961      3.108845
#> 6   9.326536   10.36282    path 28565950         1  2.797961      3.108845

#sc format 
hampi_sc <- dodgr_streetnet_sc("hampi india")
# This is where the error occurs
hampi_sc_weighted <- weight_streetnet(hampi_sc, wt_profile = "bicycle") 
#> Loading required namespace: geodist
#> Error in cbind(as.numeric(obj[, xy_cols[1]]), as.numeric(obj[, xy_cols[2]])): 'list' object cannot be coerced to type 'double'

Created on 2020-11-03 by the reprex package (v0.3.0)

Hussein-Mahfouz commented 3 years ago

Sorry I just saw that this issue was raised in #145 . I am still getting the error though

mpadge commented 3 years ago

Thanks @Hussein-Mahfouz, that is indeed a repeat of #145. As noted there, you should just need to:

remotes::install_github("hypertidy/geodist") # v0.0.6.2 or later
remotes::install_github("atfutures/dodgr") # v0.2.7.24 or later

Please close this issue once you confirm that it works for you.

Hussein-Mahfouz commented 3 years ago

Thanks for the tip, the code works now.

Some additional info: I managed to install geodist using remotes::install_github("hypertidy/geodist"), but trying to install dodgr using remotes::install_github("atfutures/dodgr") raises the following error:

ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [dodgr.so] Error 1
ERROR: compilation failed for package ‘dodgr’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/dodgr’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/dodgr’
Error: Failed to install 'dodgr' from GitHub:
  (converted from warning) installation of package ‘/var/folders/rx/8r9pc6jd3dx0vrxnd6lfp0nw0000gn/T//RtmpqpDNwk/file9bab4556fcef/dodgr_0.2.7.024.tar.gz’ had non-zero exit status

I'm not sure what is causing it. However, the code does work now. Perhaps updating geodist was enough.

mpadge commented 3 years ago

Good to hear that it all works now. The error you see is caused by the remotes installation by default installing all dependencies. In this case, some dependencies use fortran and need the gfortran compiler which you evidently do not have installed. Just install that and you should be good.

Hussein-Mahfouz commented 3 years ago

Oh I see. Thanks for explaining!