Takes a line (represented in sf or sp classes) and returns a numeric value representing distance in meters.

geo_length(shp)

Arguments

shp

A spatial line object

Examples

lib_versions <- sf::sf_extSoftVersion()
lib_versions
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>        "3.8.0"        "3.0.4"        "6.3.1"         "true"         "true" 
#>           PROJ 
#>        "6.3.1" 
if (lib_versions[3] >= "6.3.1") {
  geo_length(routes_fast)
  geo_length(routes_fast_sf)
}
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
#>  [1]    0.0000 1538.8810 2990.7783 2297.5929 1870.2117 2239.1301 3352.8345
#>  [8] 1538.8810    0.0000 1580.7084 1506.1390 2483.2391 3156.1339 3877.7765
#> [15] 2992.2337 1708.4876    0.0000 2121.8359 3098.9361 3768.5096 3711.6150
#> [22] 2366.0647 1506.1390 2078.5604    0.0000  977.1004 1646.6739 2371.6377
#> [29] 1875.7200 2483.2391 3055.6605  977.1004    0.0000  872.9039 1727.9827
#> [36] 2239.4037 3085.7290 3725.2340 1646.6739  872.9039    0.0000 1303.2590
#> [43] 3285.0306 3829.5751 3868.1338 2323.4363 1727.9827 1303.2590    0.0000