100 random locations on Vesterbro to RÃ¥dhusplads. So sample polygon and use r5r to get traveltimes.
library(tmap)
## Warning: package 'tmap' was built under R version 4.0.5
library(sf)
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
wd <- "C://Users//np83zg//OneDrive - Aalborg Universitet//Skrivebord//cars-master//rspace_osm//cppRouting//"
file_name <- "LTMzone_niveau2_m_udland.shp"
setwd(wd)
shp_ntm <- st_read(file_name)
## Reading layer `LTMzone_niveau2_m_udland' from data source `C:\Users\np83zg\OneDrive - Aalborg Universitet\Skrivebord\cars-master\rspace_osm\cppRouting\LTMzone_niveau2_m_udland.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1278 features and 15 fields (with 7 geometries empty)
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -5086456 ymin: -7164669 xmax: 6029458 ymax: 9490738
## Projected CRS: ETRS89 / UTM zone 32N
plot(shp_ntm[,c("zoneid","geometry")])
# We only need Denmark
selector <- shp_ntm$CNTR_CODE=="DK"
colnames <- c("zoneid","geometry")
plot(shp_ntm[selector,colnames])
colnames <- c("GruppeID","geometry")
plot(shp_ntm[selector,colnames])
# Limit the ntm-zones to Denmark ... we ignore transport
# in and out of the country ...
ntm <- shp_ntm[selector,]
ntm <- ntm[!is.na(ntm$komnr),]
length(unique(ntm$komnr))
## [1] 98
length(unique(ntm$zoneid))
## [1] 907
colnames <- c("zoneid","zonenavn","komnr","Shape_Area","geometry")
ntm <- ntm[,colnames]
tm_shape(ntm[,c("komnr","geometry")]) +
tm_polygons("komnr")
# minor data transformations (crs,area)
ntm <- st_transform(ntm,crs=4326)
# Test the data column Shape_Area
ss <- st_area(ntm)
plot(ss,ntm$Shape_Area)
# Recode to km^2 and lower precision
ntm$area <- round(st_area(ntm),0)
ntm$Shape_Area <- NULL
# Check centroid plot ... where are there most zones
centroids <- st_centroid(ntm$geometry)
## Warning in st_centroid.sfc(ntm$geometry): st_centroid does not give correct
## centroids for longitude/latitude data
centroids <- st_as_sf(centroids)
centroids$id <- ntm$zoneid
plot(centroids)
#st_write(ntm,dsn="ntm.shp",append=TRUE)
# Make a coordinate matrix ...
xy <- matrix(unlist(unclass(st_centroid(ntm$geometry))),ncol=2,byrow=2)
## Warning in st_centroid.sfc(ntm$geometry): st_centroid does not give correct
## centroids for longitude/latitude data
id <- ntm$zoneid
# Create the coordinate dataset ...
coord_df <- data.frame(ID=id,X=xy[,1],Y=xy[,2])
coord_df
## ID X Y
## 1 530030 8.871359 55.75216
## 2 480050 10.146158 55.46160
## 3 810120 10.268959 57.18203
## 4 563000 8.411613 55.40972
## 5 813130 10.326862 57.32651
## 6 510020 9.406825 55.30736
## 7 657220 8.944937 56.29289
## 8 860120 10.262853 57.48261
## 9 479250 10.596682 54.99552
## 10 561120 8.500821 55.48454
## 11 766050 9.701972 55.76091
## 12 766010 10.001091 55.80396
## 13 621250 9.337882 55.50978
## 14 482010 10.868764 55.03598
## 15 665020 8.388776 56.49694
## 16 825000 11.019810 57.27361
## 17 846130 9.911194 56.73223
## 18 773030 8.687401 56.75273
## 19 707060 10.765538 56.46499
## 20 849220 9.373810 57.06340
## 21 840040 9.726481 56.87394
## 22 740270 9.341706 56.28654
## 23 779210 8.910908 56.59143
## 24 575010 9.176948 55.53722
## 25 153020 12.399966 55.64595
## 26 155010 12.645998 55.59264
## 27 550030 8.988779 55.04865
## 28 820060 9.282866 56.89556
## 29 791330 9.669624 56.48331
## 30 860320 9.815786 57.38353
## 31 851410 10.181520 56.92016
## 32 851520 10.197877 57.07338
## 33 561340 8.760347 55.40819
## 34 561360 8.600332 55.50572
## 35 561310 8.782114 55.27618
## 36 740160 9.525393 56.09859
## 37 540240 9.669036 54.95880
## 38 573210 8.341550 55.73775
## 39 751110 10.211748 56.14704
## 40 751720 10.005741 56.14471
## 41 573120 8.606518 55.71976
## 42 615240 9.744738 55.94118
## 43 849130 9.659166 57.20580
## 44 813320 10.401792 57.62779
## 45 621230 9.431291 55.36093
## 46 210050 12.428980 55.92125
## 47 190040 12.384472 55.78659
## 48 615250 9.605890 55.98578
## 49 615210 9.949584 55.93497
## 50 740220 9.734835 56.20338
## 51 846300 10.006689 56.63579
## 52 846110 10.259664 56.77743
## 53 706260 10.482496 56.16998
## 54 706250 10.554949 56.23673
## 55 706240 10.686179 56.20228
## 56 706230 10.704505 56.17923
## 57 706210 10.735553 56.28334
## 58 791250 9.351620 56.44825
## 59 791240 9.397207 56.41978
## 60 791220 9.395458 56.47806
## 61 791230 9.398308 56.44658
## 62 165020 12.357438 55.66314
## 63 730320 10.033075 56.46303
## 64 730330 10.037180 56.48409
## 65 730220 9.856265 56.48993
## 66 165010 12.354529 55.68677
## 67 169030 12.267121 55.68302
## 68 223010 12.525771 55.87857
## 69 175010 12.463392 55.66847
## 70 175020 12.447439 55.67566
## 71 175030 12.449520 55.68601
## 72 163030 12.419033 55.74584
## 73 163020 12.430591 55.73113
## 74 175040 12.453191 55.69822
## 75 175050 12.438445 55.70382
## 76 190020 12.364249 55.83163
## 77 190010 12.403058 55.81451
## 78 190030 12.356390 55.81249
## 79 190060 12.335879 55.77454
## 80 190050 12.400881 55.76382
## 81 250040 12.086226 55.86383
## 82 250030 12.078520 55.83066
## 83 250020 12.102134 55.80236
## 84 102770 12.487041 55.67000
## 85 102760 12.487435 55.65882
## 86 102750 12.505925 55.64686
## 87 102810 12.553252 55.66811
## 88 102820 12.544023 55.66769
## 89 102650 12.473906 55.69998
## 90 102130 12.572096 55.67580
## 91 102830 12.552438 55.65938
## 92 102840 12.532940 55.65857
## 93 102850 12.545402 55.65191
## 94 751310 10.218153 56.04079
## 95 751120 10.207024 56.16455
## 96 751450 10.108479 56.19286
## 97 751420 10.163270 56.15237
## 98 751430 10.096037 56.15406
## 99 751710 10.039882 56.20154
## 100 751440 10.147936 56.18063
## 101 751410 10.169514 56.16659
## 102 751350 10.077686 56.10715
## 103 751340 10.118802 56.08695
## 104 751330 10.103734 56.03165
## 105 751320 10.188693 56.07574
## 106 820010 9.456396 56.69795
## 107 751540 10.186269 56.19669
## 108 751530 10.200054 56.17691
## 109 751520 10.226498 56.20705
## 110 751510 10.242933 56.19344
## 111 820040 9.509200 56.79991
## 112 846210 9.802007 56.63749
## 113 846230 9.795316 56.58655
## 114 846220 9.688601 56.65432
## 115 791210 9.447578 56.45447
## 116 820070 9.304281 56.97643
## 117 820050 9.434145 56.86245
## 118 621220 9.556091 55.38633
## 119 621210 9.595463 55.45855
## 120 621240 9.331509 55.42007
## 121 740240 9.551406 56.29024
## 122 740260 9.429084 56.25757
## 123 740250 9.466740 56.21951
## 124 740210 9.681362 56.14840
## 125 740230 9.673873 56.25754
## 126 740140 9.494361 56.18662
## 127 740170 9.454051 56.04296
## 128 740120 9.558853 56.17950
## 129 740110 9.601764 56.19436
## 130 621120 9.471906 55.52057
## 131 621130 9.481521 55.50522
## 132 621170 9.441595 55.48021
## 133 621180 9.441090 55.50217
## 134 621140 9.478512 55.49132
## 135 607010 9.774976 55.60769
## 136 561220 8.417836 55.53356
## 137 573150 8.474482 55.62936
## 138 661260 8.422697 56.36791
## 139 657310 8.865377 56.04602
## 140 756230 9.066558 55.91478
## 141 756220 9.241434 56.00162
## 142 661210 8.626220 56.34530
## 143 787240 8.322162 56.81321
## 144 440030 10.558656 55.45926
## 145 440010 10.660435 55.52590
## 146 440020 10.662151 55.44289
## 147 479210 10.685249 55.04282
## 148 410070 9.706033 55.49808
## 149 410060 9.766749 55.49029
## 150 410050 9.815055 55.52288
## 151 173050 12.513737 55.77616
## 152 173040 12.521064 55.78557
## 153 410010 9.971608 55.47484
## 154 410040 9.844302 55.46100
## 155 530020 9.069821 55.73702
## 156 530010 9.029779 55.66068
## 157 530040 8.937649 55.83448
## 158 450040 10.716383 55.37537
## 159 420080 9.866582 55.28616
## 160 420070 9.963192 55.28679
## 161 420060 10.042873 55.37378
## 162 420050 10.133918 55.39303
## 163 420040 10.185800 55.35029
## 164 440050 10.577839 55.40717
## 165 440040 10.589907 55.35722
## 166 665050 8.230881 56.57390
## 167 665010 8.261851 56.40977
## 168 480020 10.363396 55.56007
## 169 480030 10.221570 55.50826
## 170 846120 10.145489 56.74124
## 171 480040 10.138621 55.55701
## 172 482030 10.714357 54.81776
## 173 482020 10.742612 54.91925
## 174 707090 10.316326 56.52613
## 175 540320 9.773168 55.03295
## 176 561130 8.436849 55.48387
## 177 561210 8.483360 55.54155
## 178 479220 10.646032 55.06792
## 179 450030 10.788340 55.33790
## 180 450020 10.802832 55.31074
## 181 450010 10.763479 55.30951
## 182 450070 10.684551 55.24005
## 183 706130 10.473929 56.34887
## 184 706120 10.585606 56.31124
## 185 706110 10.548113 56.39891
## 186 851620 9.963050 57.18002
## 187 561140 8.447194 55.46943
## 188 657120 8.948458 56.16793
## 189 671120 8.584323 56.48887
## 190 671110 8.557232 56.43828
## 191 671130 8.550719 56.52602
## 192 615140 9.765083 55.85424
## 193 615110 10.294479 55.75984
## 194 615170 9.874848 55.86726
## 195 615160 9.825397 55.87435
## 196 615150 9.828700 55.85893
## 197 746040 9.697410 56.08123
## 198 746020 9.865133 56.10301
## 199 746010 9.921992 56.17814
## 200 746090 9.906697 56.00809
## 201 813310 10.571551 57.72893
## 202 813330 10.427957 57.51139
## 203 671200 8.533818 56.64293
## 204 851120 9.674601 56.96082
## 205 851810 9.955345 57.08464
## 206 860350 9.944438 57.53285
## 207 860360 9.966895 57.57897
## 208 320050 11.945955 55.30941
## 209 350030 11.880925 55.59094
## 210 306140 11.447174 55.76364
## 211 265230 12.095575 55.63370
## 212 265220 12.101343 55.65593
## 213 330240 11.370430 55.32370
## 214 265110 12.156180 55.69881
## 215 336040 12.211917 55.36590
## 216 269030 12.160629 55.53865
## 217 860340 9.870714 57.47298
## 218 860330 9.720586 57.37225
## 219 860310 9.960222 57.37524
## 220 860130 10.227012 57.56491
## 221 860140 10.064738 57.54285
## 222 860110 10.149594 57.39133
## 223 810210 10.074490 57.27297
## 224 810130 10.133080 57.19826
## 225 810110 10.374249 57.15370
## 226 813120 10.495560 57.33996
## 227 813110 10.465003 57.25210
## 228 849120 9.696895 57.11927
## 229 849140 9.588633 57.23267
## 230 849210 9.532617 57.12476
## 231 849230 9.304522 57.11887
## 232 580160 9.362873 54.83445
## 233 580220 9.319764 55.06361
## 234 580110 9.422542 55.10691
## 235 480010 10.403906 55.49914
## 236 665070 8.194110 56.66772
## 237 665060 8.176022 56.60439
## 238 410020 9.881664 55.39708
## 239 779150 9.007459 56.57638
## 240 727030 10.111575 55.98177
## 241 727010 10.237449 55.96587
## 242 851610 10.070003 57.11416
## 243 540140 9.815235 54.93102
## 244 540310 9.904547 54.98548
## 245 550080 8.521870 55.13599
## 246 540230 9.604132 54.91191
## 247 540220 9.693425 54.87561
## 248 173030 12.513350 55.79320
## 249 173020 12.536293 55.78502
## 250 173010 12.568065 55.78997
## 251 173090 12.442104 55.79375
## 252 540210 9.742109 54.91681
## 253 580130 9.385596 55.03016
## 254 580120 9.397530 55.06143
## 255 849110 9.799218 57.17648
## 256 580140 9.502175 54.99360
## 257 580150 9.376880 54.89186
## 258 580260 9.141743 54.91863
## 259 550050 8.861791 54.93925
## 260 550060 8.747161 55.00518
## 261 550070 8.786708 55.17134
## 262 550020 9.019164 55.18871
## 263 550040 8.923534 54.95960
## 264 550010 9.107683 55.12797
## 265 510010 9.643058 55.23580
## 266 510050 9.485332 55.18777
## 267 510080 9.050857 55.27191
## 268 316270 11.502367 55.72025
## 269 316210 11.730478 55.56762
## 270 316250 11.487083 55.63773
## 271 340010 11.603814 55.42125
## 272 340020 11.533824 55.46265
## 273 330160 11.240841 55.43160
## 274 330120 11.325076 55.42114
## 275 330320 11.113965 55.34953
## 276 330230 11.282856 55.25500
## 277 330310 11.231525 55.35301
## 278 390240 12.040997 54.92742
## 279 390230 12.203652 54.93357
## 280 390220 12.275591 54.98408
## 281 390210 12.402729 54.99615
## 282 360120 11.517764 54.77573
## 283 326210 11.136119 55.66907
## 284 400330 14.700035 55.10134
## 285 400130 15.040123 55.03724
## 286 400110 15.115223 55.10883
## 287 400140 14.900999 55.07661
## 288 330220 11.379277 55.22939
## 289 316150 11.664540 55.70896
## 290 390140 11.878918 55.04368
## 291 390150 11.975302 54.99988
## 292 390160 11.901934 55.00511
## 293 340040 11.475359 55.54042
## 294 340050 11.374549 55.53820
## 295 329010 11.862636 55.40064
## 296 329020 11.877795 55.45798
## 297 329030 11.762935 55.43224
## 298 329040 11.791010 55.47077
## 299 329050 11.787816 55.50271
## 300 265310 12.114734 55.61171
## 301 265330 12.013580 55.55455
## 302 265320 12.098256 55.55920
## 303 173070 12.459250 55.78204
## 304 173060 12.500120 55.76743
## 305 740130 9.570676 56.16131
## 306 740150 9.449466 56.15427
## 307 849150 9.705267 57.27688
## 308 849160 9.704313 57.32119
## 309 102740 12.502237 55.66127
## 310 102730 12.502185 55.66673
## 311 147250 12.498235 55.67781
## 312 147220 12.515036 55.68635
## 313 159030 12.510216 55.73702
## 314 210020 12.503827 55.93637
## 315 147140 12.522670 55.67191
## 316 400150 14.972303 55.16322
## 317 400210 14.774369 55.23691
## 318 400120 15.123621 55.06440
## 319 849240 9.140835 57.09045
## 320 410030 9.939371 55.43497
## 321 492010 10.485307 54.86609
## 322 657160 8.978957 56.11227
## 323 657150 8.911677 56.13615
## 324 510030 9.512601 55.26144
## 325 510060 9.284573 55.18966
## 326 510070 9.268575 55.24018
## 327 561320 8.765832 55.31677
## 328 561330 8.783605 55.34861
## 329 561350 8.708588 55.47362
## 330 573240 8.189548 55.55623
## 331 573230 8.231419 55.64251
## 332 573220 8.219082 55.76157
## 333 665030 8.321869 56.55513
## 334 851510 10.287025 57.02711
## 335 540330 9.715678 55.05854
## 336 540160 9.792106 54.91909
## 337 561240 8.406392 55.50333
## 338 561230 8.443119 55.50693
## 339 540120 9.917954 54.92066
## 340 540130 9.866241 54.95357
## 341 575030 9.157866 55.37980
## 342 575020 9.137735 55.47376
## 343 240060 12.148021 55.79582
## 344 253020 12.308499 55.60012
## 345 217010 12.600719 56.03818
## 346 751610 10.327308 56.27143
## 347 751620 10.287510 56.22681
## 348 751630 10.233349 56.28287
## 349 751640 10.235447 56.23814
## 350 751650 10.184716 56.22837
## 351 751660 10.154051 56.26435
## 352 756140 9.207192 56.09736
## 353 217020 12.577213 56.01522
## 354 217030 12.569035 56.03598
## 355 217040 12.542026 55.99453
## 356 217050 12.503348 55.99986
## 357 217060 12.467039 56.03824
## 358 217070 12.522100 56.07100
## 359 217080 12.440803 56.08295
## 360 157140 12.574041 55.73738
## 361 157130 12.566057 55.75670
## 362 157120 12.582511 55.76178
## 363 187010 12.386877 55.62056
## 364 187020 12.365556 55.63962
## 365 183020 12.287193 55.62589
## 366 183010 12.359657 55.61038
## 367 161030 12.391453 55.66622
## 368 161020 12.411800 55.67710
## 369 151070 12.367934 55.74564
## 370 151060 12.359371 55.72940
## 371 151050 12.334902 55.72550
## 372 151040 12.355207 55.71479
## 373 151030 12.378627 55.71586
## 374 151020 12.392403 55.73574
## 375 151010 12.405211 55.71679
## 376 151080 12.328048 55.75160
## 377 102640 12.477476 55.69086
## 378 102630 12.485665 55.68324
## 379 185200 12.661421 55.61505
## 380 185120 12.750449 55.63819
## 381 185130 12.628313 55.63590
## 382 185140 12.606237 55.63107
## 383 185150 12.620729 55.61851
## 384 185160 12.561244 55.59498
## 385 167060 12.471370 55.60957
## 386 167050 12.457826 55.62435
## 387 167040 12.484692 55.62694
## 388 167030 12.496265 55.63777
## 389 167020 12.457504 55.64113
## 390 102860 12.528568 55.64361
## 391 219020 12.248695 55.96906
## 392 219010 12.335575 55.97934
## 393 253040 12.260834 55.56839
## 394 259020 12.015663 55.43481
## 395 259060 12.112615 55.50183
## 396 259070 12.060775 55.50140
## 397 259030 12.125677 55.45841
## 398 259050 12.170687 55.49386
## 399 259040 12.179231 55.46335
## 400 201040 12.282747 55.84293
## 401 219050 12.276780 55.93012
## 402 219040 12.311352 55.93153
## 403 103290 12.557953 55.62630
## 404 103280 12.584050 55.63730
## 405 103270 12.571549 55.64604
## 406 103180 12.576348 55.65875
## 407 201030 12.336345 55.86036
## 408 201020 12.347763 55.87936
## 409 210010 12.493300 55.91531
## 410 210060 12.397606 55.97279
## 411 219060 12.190111 55.90488
## 412 306240 11.609654 55.93850
## 413 316280 11.663209 55.75394
## 414 316260 11.414342 55.65484
## 415 510040 9.513287 55.23502
## 416 851630 9.951814 57.12745
## 417 851640 9.842594 57.11592
## 418 820030 9.294700 56.78073
## 419 820020 9.251767 56.70853
## 420 746080 9.913807 56.03098
## 421 746070 9.954298 56.04417
## 422 746060 9.992129 56.05813
## 423 746050 10.047097 56.07694
## 424 746030 9.777059 56.08792
## 425 561250 8.355946 55.55773
## 426 707040 10.883850 56.39244
## 427 707030 10.885065 56.43125
## 428 707080 10.343315 56.43469
## 429 707070 10.541513 56.47853
## 430 707050 10.794437 56.35762
## 431 657110 9.046837 56.15659
## 432 657130 8.987778 56.14496
## 433 580250 9.258375 54.93219
## 434 706160 10.274002 56.34086
## 435 706140 10.446122 56.30165
## 436 706150 10.371563 56.35622
## 437 751250 10.090164 56.13214
## 438 751240 10.141191 56.12105
## 439 851350 9.944535 57.02385
## 440 851340 9.929848 57.00262
## 441 851330 9.990664 57.01147
## 442 851240 9.832486 56.97014
## 443 851230 9.826659 57.00698
## 444 851220 9.880491 56.99732
## 445 461390 10.424394 55.37340
## 446 461330 10.431065 55.33145
## 447 461320 10.471644 55.36846
## 448 461310 10.510614 55.34098
## 449 461270 10.375599 55.39578
## 450 461260 10.360823 55.38224
## 451 461250 10.392587 55.37636
## 452 461240 10.392346 55.38723
## 453 461230 10.404083 55.39945
## 454 461220 10.413355 55.39104
## 455 461210 10.440934 55.39037
## 456 461150 10.379227 55.45130
## 457 461140 10.389261 55.40741
## 458 461130 10.415303 55.40875
## 459 461120 10.432014 55.42100
## 460 155020 12.590373 55.56879
## 461 657140 8.953251 56.14125
## 462 851840 9.872487 57.08276
## 463 173080 12.478046 55.79545
## 464 630330 9.426438 55.70351
## 465 630360 9.191691 55.85654
## 466 630350 9.316043 55.89480
## 467 766060 9.625837 55.82034
## 468 766030 9.814079 55.71908
## 469 766040 9.752765 55.79143
## 470 766020 9.990148 55.72838
## 471 766070 9.607026 55.88990
## 472 630210 9.628381 55.73145
## 473 756130 9.138594 56.17032
## 474 756120 9.225397 56.18822
## 475 756110 9.350855 56.14087
## 476 615230 9.868201 55.90208
## 477 730530 10.087222 56.53925
## 478 730310 10.072988 56.47662
## 479 730510 10.220661 56.62907
## 480 760220 8.392103 56.01635
## 481 630320 9.419481 55.62505
## 482 630310 9.314247 55.61478
## 483 161010 12.409250 55.69676
## 484 607020 9.637165 55.58232
## 485 607050 9.715517 55.56903
## 486 607030 9.759130 55.57884
## 487 607040 9.758909 55.56413
## 488 773020 8.838885 56.79721
## 489 479240 10.544266 55.05968
## 490 430210 10.250778 55.22614
## 491 450060 10.698216 55.30279
## 492 420030 10.199589 55.30700
## 493 420020 10.080118 55.28236
## 494 420010 10.092160 55.19712
## 495 741010 10.572317 55.95177
## 496 741020 10.593679 55.82895
## 497 787110 8.921401 57.06825
## 498 787210 8.544272 56.88418
## 499 787130 8.670012 57.02039
## 500 787220 8.460851 56.95354
## 501 787120 8.653344 57.09358
## 502 773010 8.784381 56.87310
## 503 851420 10.072608 56.99367
## 504 840030 9.838209 56.88024
## 505 840020 9.946165 56.84747
## 506 840050 9.667653 56.73932
## 507 840010 10.104247 56.82162
## 508 657320 9.041916 56.04747
## 509 657230 8.636940 56.24866
## 510 265130 12.108819 55.75470
## 511 265250 12.046611 55.64592
## 512 265260 12.016785 55.63641
## 513 265210 12.135795 55.65670
## 514 265240 12.082634 55.64308
## 515 326170 11.162884 55.87309
## 516 370320 11.828724 55.17439
## 517 370140 11.766488 55.23041
## 518 370110 11.762972 55.26622
## 519 376190 11.913731 54.71690
## 520 540250 9.531832 54.92088
## 521 370150 11.736805 55.23369
## 522 479230 10.603866 55.06479
## 523 479110 10.732675 55.13185
## 524 540150 9.810658 54.90536
## 525 540110 9.985520 54.89884
## 526 851310 10.010527 57.05765
## 527 851750 9.909867 57.04496
## 528 851740 9.863466 57.03545
## 529 851730 9.894270 57.02330
## 530 851720 9.921873 57.03256
## 531 851710 9.922934 57.04598
## 532 851770 9.855084 57.06052
## 533 851760 9.901805 57.05379
## 534 657240 8.750424 56.16579
## 535 657210 9.065600 56.22593
## 536 707020 10.903630 56.41451
## 537 707010 11.571535 56.71187
## 538 851830 9.905417 57.08324
## 539 851820 9.930567 57.06093
## 540 730350 9.979649 56.45965
## 541 730340 10.002926 56.48038
## 542 461110 10.477872 55.41894
## 543 461450 10.319474 55.39262
## 544 461460 10.247091 55.38550
## 545 340030 11.589069 55.53296
## 546 306250 11.611782 55.89772
## 547 376230 11.656316 54.80877
## 548 376170 12.020668 54.87556
## 549 461420 10.277727 55.42331
## 550 461440 10.342049 55.41060
## 551 461430 10.354112 55.42214
## 552 461410 10.302596 55.45038
## 553 580240 9.277498 54.98798
## 554 580230 9.197575 55.05461
## 555 779140 9.034818 56.58737
## 556 779130 9.031759 56.54070
## 557 779120 9.136822 56.54185
## 558 779110 9.187348 56.59250
## 559 779270 9.014240 56.82699
## 560 779260 8.934076 56.74585
## 561 779250 9.080427 56.73371
## 562 779230 9.004529 56.67182
## 563 779220 8.773829 56.61847
## 564 791310 9.649725 56.35937
## 565 791320 9.516349 56.38172
## 566 791350 9.418536 56.61003
## 567 791340 9.536755 56.54993
## 568 573160 8.409248 55.65225
## 569 573140 8.457755 55.59476
## 570 573130 8.708229 55.61482
## 571 573110 8.629893 55.80240
## 572 561110 8.492178 55.46323
## 573 621150 9.503094 55.47518
## 574 621160 9.468126 55.48035
## 575 630230 9.519701 55.73229
## 576 630240 9.542692 55.70848
## 577 851320 10.002651 57.03256
## 578 630340 9.402252 55.78578
## 579 630380 9.239919 55.68546
## 580 630370 9.175537 55.79242
## 581 575080 8.927162 55.57267
## 582 223020 12.460852 55.88615
## 583 153030 12.420731 55.62160
## 584 153010 12.436129 55.65808
## 585 250070 11.993921 55.78586
## 586 250050 11.959240 55.90096
## 587 810230 9.841125 57.27688
## 588 810220 9.943458 57.26482
## 589 492020 10.392970 54.86074
## 590 492030 10.283595 54.91697
## 591 430240 10.156395 55.09744
## 592 430220 10.290634 55.14550
## 593 450050 10.656668 55.36054
## 594 430160 10.405047 55.22243
## 595 430150 10.473695 55.24239
## 596 430120 10.581375 55.21742
## 597 430110 10.550196 55.17917
## 598 813250 10.391108 57.43720
## 599 813240 10.458062 57.40528
## 600 813220 10.520841 57.45971
## 601 813210 10.542441 57.44534
## 602 813230 10.497479 57.44662
## 603 787150 8.664921 56.95519
## 604 615130 9.808197 55.83362
## 605 787140 8.713625 56.96253
## 606 760250 8.117017 56.05476
## 607 760240 8.176650 56.17601
## 608 760230 8.263676 56.09577
## 609 760210 8.357178 56.16768
## 610 760260 8.161531 55.90459
## 611 657330 8.873999 55.94158
## 612 479140 10.457303 55.08623
## 613 479130 10.537215 55.13383
## 614 479120 10.641194 55.14401
## 615 430140 10.476688 55.29717
## 616 430130 10.553417 55.29811
## 617 326160 11.324311 55.70679
## 618 320020 12.085071 55.32189
## 619 326150 11.256442 55.69929
## 620 260010 12.059876 55.90878
## 621 260030 12.058226 55.96310
## 622 260040 12.024010 55.96757
## 623 260050 12.020492 55.98686
## 624 260060 12.001267 56.01203
## 625 265120 12.166981 55.73817
## 626 370240 11.532196 55.29260
## 627 370230 11.652847 55.18235
## 628 370210 11.723186 55.33885
## 629 370220 11.636593 55.23922
## 630 370330 11.859942 55.26267
## 631 336030 12.287297 55.39156
## 632 336010 12.359533 55.27046
## 633 320060 11.974618 55.36681
## 634 320030 12.122523 55.23684
## 635 320040 12.042488 55.22720
## 636 269020 12.204110 55.51842
## 637 851110 9.750160 57.01283
## 638 851130 9.512690 56.95575
## 639 787230 8.421071 56.74622
## 640 730130 10.023377 56.40463
## 641 730120 10.030682 56.44567
## 642 730110 10.182784 56.43192
## 643 730150 9.860250 56.40103
## 644 730140 9.905594 56.43163
## 645 630220 9.562177 55.73638
## 646 621260 9.464015 55.56145
## 647 621110 9.545226 55.52731
## 648 760120 8.576162 56.02551
## 649 575070 8.910812 55.47616
## 650 710010 10.098018 56.25243
## 651 710070 9.774917 56.36040
## 652 710060 9.847846 56.24243
## 653 710050 9.961334 56.30941
## 654 710040 10.050236 56.32554
## 655 710030 10.137994 56.34302
## 656 710020 10.069274 56.27842
## 657 751230 10.172692 56.10727
## 658 751220 10.186598 56.13199
## 659 751210 10.212809 56.10851
## 660 791150 9.095902 56.45169
## 661 791140 9.199969 56.32831
## 662 791130 9.374159 56.37965
## 663 791120 9.254426 56.47220
## 664 791110 9.352875 56.51194
## 665 756210 9.424699 55.96252
## 666 760130 8.524593 56.13277
## 667 665040 8.192313 56.50611
## 668 760110 8.715555 56.08344
## 669 760170 8.395738 55.84957
## 670 760150 8.493150 55.94731
## 671 250080 11.918194 55.76110
## 672 630150 9.514609 55.68375
## 673 630140 9.573597 55.68168
## 674 630130 9.528438 55.62965
## 675 630120 9.607893 55.63782
## 676 760160 8.519696 55.91191
## 677 760140 8.683542 55.90468
## 678 630110 9.679112 55.65181
## 679 607070 9.623087 55.53316
## 680 607060 9.700165 55.53734
## 681 661140 8.674087 56.31582
## 682 661130 8.708984 56.35886
## 683 661120 8.774252 56.40819
## 684 661110 8.872963 56.46699
## 685 661270 8.284350 56.28431
## 686 661250 8.486308 56.32825
## 687 661240 8.586562 56.37548
## 688 661230 8.615796 56.39542
## 689 661220 8.622307 56.36352
## 690 851210 10.002771 56.95084
## 691 851360 9.952987 57.04201
## 692 461380 10.294334 55.34420
## 693 461370 10.335241 55.37207
## 694 615220 9.936382 55.87820
## 695 250060 11.986297 55.84596
## 696 250010 12.162105 55.84680
## 697 230040 12.521750 55.83623
## 698 230030 12.519984 55.81229
## 699 230020 12.561569 55.81923
## 700 230010 12.559225 55.84767
## 701 230090 12.417329 55.83860
## 702 230080 12.436115 55.82226
## 703 253030 12.290109 55.58532
## 704 253060 12.182029 55.59456
## 705 169050 12.194265 55.64827
## 706 461360 10.367821 55.36513
## 707 461350 10.338978 55.32168
## 708 461340 10.400351 55.35941
## 709 169010 12.310984 55.64413
## 710 169040 12.259781 55.64928
## 711 169020 12.302038 55.65880
## 712 210030 12.529938 55.96429
## 713 376150 11.897132 54.75758
## 714 376140 11.869633 54.77661
## 715 376110 11.923743 54.62668
## 716 376120 11.952304 54.67688
## 717 376180 11.819272 54.90495
## 718 376160 11.882162 54.81850
## 719 376130 12.007013 54.79220
## 720 376220 11.708394 54.70131
## 721 376210 11.805634 54.76633
## 722 360110 11.420222 54.82505
## 723 360140 11.393748 54.66583
## 724 360240 11.136829 54.83550
## 725 320010 12.196744 55.28049
## 726 360250 11.137781 54.76627
## 727 360210 11.261949 54.81878
## 728 390120 12.065603 55.03081
## 729 330150 11.308602 55.38972
## 730 330130 11.395483 55.39786
## 731 326140 11.326029 55.61019
## 732 316220 11.751747 55.61914
## 733 390110 12.036935 55.11234
## 734 390130 11.852256 55.09406
## 735 326230 11.053689 55.72579
## 736 326220 11.091765 55.68530
## 737 326110 11.320976 55.51003
## 738 326120 11.197448 55.52160
## 739 430250 10.215850 55.03697
## 740 430230 10.321785 55.08775
## 741 479260 10.436502 54.98035
## 742 575060 9.002346 55.48962
## 743 575050 9.077119 55.46488
## 744 575040 8.999414 55.37067
## 745 201010 12.389648 55.86786
## 746 103230 12.620933 55.64605
## 747 219030 12.344551 55.91407
## 748 253010 12.336029 55.59569
## 749 103170 12.603619 55.66357
## 750 253050 12.240872 55.59279
## 751 240050 12.174754 55.78338
## 752 240040 12.194029 55.76882
## 753 240030 12.265414 55.79966
## 754 240020 12.243464 55.76391
## 755 240010 12.283188 55.72362
## 756 167010 12.467171 55.65800
## 757 163010 12.440069 55.71921
## 758 159060 12.492448 55.74814
## 759 159050 12.472064 55.73618
## 760 159020 12.467216 55.72436
## 761 159010 12.500016 55.72642
## 762 159090 12.431615 55.76340
## 763 159080 12.461248 55.76492
## 764 159070 12.470146 55.75136
## 765 147130 12.537155 55.67347
## 766 147120 12.540083 55.68185
## 767 147110 12.550307 55.67922
## 768 147210 12.527092 55.69265
## 769 102710 12.518134 55.65696
## 770 102720 12.522568 55.66517
## 771 151090 12.285805 55.75452
## 772 103160 12.612777 55.66607
## 773 102670 12.483390 55.71693
## 774 102660 12.466171 55.70950
## 775 102620 12.501237 55.69343
## 776 102610 12.495415 55.70478
## 777 102350 12.585697 55.69884
## 778 102340 12.578761 55.70529
## 779 102330 12.603012 55.71241
## 780 102320 12.577862 55.71440
## 781 102310 12.569652 55.72409
## 782 102410 12.562294 55.71121
## 783 102420 12.566841 55.69889
## 784 102430 12.550098 55.70453
## 785 102440 12.555877 55.69033
## 786 102450 12.542329 55.69588
## 787 103220 12.616234 55.65541
## 788 103210 12.636201 55.65446
## 789 102160 12.561229 55.67719
## 790 102170 12.572402 55.67206
## 791 102110 12.581054 55.67502
## 792 102140 12.572416 55.68064
## 793 102120 12.580127 55.67924
## 794 102230 12.573956 55.68683
## 795 102220 12.599795 55.68571
## 796 102210 12.585891 55.69110
## 797 103250 12.603092 55.64229
## 798 103240 12.601575 55.65246
## 799 103260 12.586828 55.65373
## 800 102510 12.552817 55.71833
## 801 102520 12.529368 55.72323
## 802 102530 12.534475 55.71277
## 803 102550 12.515326 55.69655
## 804 102540 12.529033 55.70177
## 805 102560 12.510514 55.71230
## 806 103150 12.621201 55.67076
## 807 103140 12.593867 55.67251
## 808 103130 12.606406 55.68032
## 809 103120 12.633631 55.67787
## 810 103110 12.618919 55.68951
## 811 259010 12.134171 55.40850
## 812 259080 11.975513 55.49570
## 813 230070 12.460506 55.81336
## 814 230060 12.452580 55.84608
## 815 230050 12.491272 55.85881
## 816 157110 12.587776 55.77253
## 817 157260 12.511636 55.75296
## 818 157250 12.525455 55.74125
## 819 157240 12.535842 55.73083
## 820 157230 12.547357 55.73664
## 821 157220 12.528098 55.75948
## 822 157210 12.546507 55.76012
## 823 157150 12.558340 55.74423
## 824 860220 9.993022 57.48567
## 825 330110 11.422083 55.44934
## 826 360130 11.443212 54.71438
## 827 306280 11.384679 55.96573
## 828 860230 9.979307 57.46287
## 829 860210 9.989325 57.44192
## 830 306260 11.544381 55.89162
## 831 306270 11.532640 55.93838
## 832 316240 11.602638 55.63944
## 833 269010 12.224215 55.54061
## 834 336020 12.342447 55.33084
## 835 330210 11.175610 55.19495
## 836 370120 11.806007 55.22167
## 837 370130 11.768439 55.20103
## 838 370310 11.963187 55.18887
## 839 400230 14.831588 55.15450
## 840 400220 14.743978 55.15744
## 841 306150 11.418775 55.80939
## 842 306120 11.560183 55.85043
## 843 306110 11.644910 55.82791
## 844 306130 11.520980 55.80925
## 845 350010 11.935921 55.55242
## 846 350020 11.987425 55.60015
## 847 400320 14.720657 55.12183
## 848 400310 14.745266 55.09723
## 849 316110 11.815275 55.77534
## 850 270230 12.215132 56.01994
## 851 306220 11.719640 55.92687
## 852 260070 11.944903 55.97970
## 853 260080 11.871550 55.97191
## 854 270220 12.124270 56.05696
## 855 270240 12.122744 56.01609
## 856 270210 12.134336 56.08009
## 857 270150 12.190015 56.09028
## 858 270140 12.241119 56.11168
## 859 270130 12.305709 56.11716
## 860 270120 12.376298 56.10008
## 861 270110 12.306683 56.05642
## 862 350050 11.853424 55.65175
## 863 350040 11.961047 55.66111
## 864 350060 11.914747 55.71467
## 865 306210 11.758145 55.95649
## 866 306230 11.667793 55.91911
## 867 326130 11.209384 55.59976
## 868 766090 9.485812 55.86600
## 869 330140 11.346318 55.40191
## 870 316230 11.715823 55.65689
## 871 316120 11.766559 55.69643
## 872 316130 11.717138 55.69115
## 873 316140 11.708810 55.71160
## 874 360230 11.183915 54.90539
## 875 360220 11.451175 54.96273
## 876 210040 12.473815 55.97249
## 877 147240 12.503753 55.67087
## 878 147160 12.532297 55.68642
## 879 147150 12.526771 55.67936
## 880 147230 12.511089 55.67889
## 881 102150 12.565548 55.68304
## 882 159040 12.498569 55.73908
## 883 103190 12.584401 55.66591
## 884 102180 12.562461 55.66928
## 885 540170 9.790359 54.96379
## 886 561370 8.554540 55.52451
## 887 530050 9.158904 55.74051
## 888 730520 10.164164 56.50733
## 889 706170 10.614329 56.30449
## 890 730210 9.960899 56.54196
## 891 510090 9.419589 55.25164
## 892 615120 9.881356 55.82307
## 893 621270 9.469425 55.44508
## 894 860150 10.093398 57.47711
## 895 165030 12.343952 55.65243
## 896 165040 12.331719 55.66445
## 897 330330 11.156177 55.32319
## 898 561380 8.784849 55.49660
## 899 766080 9.911713 55.77213
## 900 102870 12.542352 55.64378
## 901 260020 12.083648 55.91825
## 902 185170 12.589399 55.61333
## 903 390170 11.889902 55.01742
## 904 461160 10.395508 55.42014
## 905 479270 10.603457 55.08509
## 906 727020 10.122313 55.90546
## 907 851250 9.900322 56.93386
head(coord_df)
## ID X Y
## 1 530030 8.871359 55.75216
## 2 480050 10.146158 55.46160
## 3 810120 10.268959 57.18203
## 4 563000 8.411613 55.40972
## 5 813130 10.326862 57.32651
## 6 510020 9.406825 55.30736
# Draw random points in polygons ..
library(sp)
## Warning: package 'sp' was built under R version 4.0.5
out <- spsample(as_Spatial(ntm[1,]),3,type="random")
## Warning in proj4string(obj): CRS object has comment, which is lost in output
st_as_sf(out)
## Simple feature collection with 3 features and 0 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 8.808126 ymin: 55.6804 xmax: 8.890199 ymax: 55.79864
## Geodetic CRS: WGS 84 (with axis order normalized for visualization)
## geometry
## 1 POINT (8.810561 55.6804)
## 2 POINT (8.890199 55.68546)
## 3 POINT (8.808126 55.79864)
st_sample(ntm[1:2,],10)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## Geometry set for 10 features
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 8.838631 ymin: 55.4735 xmax: 10.0957 ymax: 55.80943
## Geodetic CRS: WGS 84
## First 5 geometries:
## POINT (8.878177 55.80344)
## POINT (10.0496 55.4735)
## POINT (8.942653 55.78745)
## POINT (10.0957 55.50255)
## POINT (8.864981 55.74528)
# Sample 100 points in a zone and calculate transport time to a fixed zone
from_zone <- 102830
to_zone <- 102130 # RÃ¥dhuspladsen
z_sample <- st_sample(ntm[ntm$zoneid==from_zone,],100)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
origin <- st_coordinates(z_sample)
destination <- st_coordinates(centroids[centroids$id==102130,])
# Given origin-destination data how can I compute travel time?
library(r5r)
## Warning: package 'r5r' was built under R version 4.0.5
## Loading required namespace: rJava
## Please make sure you have already allocated some memory to Java by running:
## options(java.parameters = '-Xmx2G').
## Currently, Java memory is set to -Xmx512m
wd <- getwd()
data_path <- paste(wd,"//cph//",sep="")
r5r_core <- setup_r5(data_path = data_path, verbose = FALSE)
## Using cached version from C:/Users/np83zg/OneDrive - Aalborg Universitet/Dokumenter/R/win-library/4.0/r5r/jar/r5-v6.2-all_20210408.jar
##
## Using cached network.dat from C:/Users/np83zg/OneDrive - Aalborg Universitet/Skrivebord/cars-master/rspace_osm/cppRouting//cph///network.dat
setwd(wd)
max_walk_dist <- 5000
max_trip_duration <- 120
departure_datetime <- as.POSIXct("13-05-2019 12:00:00",
format = "%d-%m-%Y %H:%M:%S")
origin_df <- data.frame(id=paste(102830,1:100,sep="_"),lat=origin[,2],lon=origin[,1])
destination_df <- data.frame(id=102130,lat=destination[,2],lon=destination[,1])
# calculate a travel time matrix
# calculate a travel time matrix
dit <- detailed_itineraries(r5r_core = r5r_core,
origins = origin_df,
destinations = destination_df,
mode = "CAR",
departure_datetime = departure_datetime,
max_walk_dist = max_walk_dist,
shortest_path = FALSE,
verbose = FALSE)
## Warning in assert_points_input(destinations, "destinations"): 'destinations$id'
## forcefully cast to character.
## Destinations dataframe expanded to match the number of origins.
# extract OSM network
street_net <- street_network_to_sf(r5r_core)
# plot
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
ggplot() +
geom_sf(data = street_net$edges, color='gray85') +
geom_sf(data = dit, aes(color=mode))