Skip to content

Snap to roads

Use the snap to roads operation to snap GPS truck points to the nearest road.

What is snap to roads?

The snap to roads operation allows you to align GPS track points with the nearest routable road segments in a transportation network. The operation is designed to work with GPS data which can be imprecise. By snapping the GPS points to the nearest road segments, the operation improves accuracy of GPS data and provides a more reliable representation of the actual route taken.

In addition to returning snapped points and line (road) segments, the operation can also return attributes for the features such as posted speed limits and segment lengths. These attributes can be used to perform analyses such as route adherence, which compares actual travel paths to planned or expected routes.

You use snap to roads to:

  • Improve the accuracy of GPS track points by removing inaccuracies.
  • Reconstruct accurate routes and route length for tax reimbursement.
  • Monitor driver behavior by comparing actual driving speed against posted speed limits and comparing the snapped route with the planned route.

How to use snap to roads

Snap to roads works by using a combination of GPS data (as input) and existing road network data to determine the most likely road that a vehicle or person traveled on. This is done by analyzing the GPS data and comparing it to the road network data to find the closest routable match.

The typical workflow for performing a snap to roads operation is as follows:

  1. Prepare the input data: The data is typically a set of GPS track points that represents a vehicle's path.
  2. Call the snap to roads operation: Snap the GPS track points to the underlying road network data.
  3. Process the output data: The output data will be a series of snapped GPS track points along with lines representing the routes for analyzing GPS data.

URL requests

You can perform the snap to roads operation by making an HTTPS request to the SnapToRoadsSync operation. The operation is available as a synchronous operation that will return the results immediately after processing the input data. The operation can be called using a REST API or through a web application.

Use dark colors for code blocksCopy
1
https://route-api.arcgis.com/arcgis/rest/services/World/SnapToRoadsSync/GPServer/SnapToRoads/execute

Required parameters

NameDescriptionExamples
pointsThe input data containing the GPS track points.points=Featureset object
fThe format of the data returned.f=json f=pjson
tokenAn API key or OAuth 2.0 access token.token=<ACCESS_TOKEN>

Optional parameters

NameDescriptionExamples
travel_modeThe mode of travel.travel_mode=Travel mode object
return_linesReturn the road segments that the GPS points were snapped to.return_lines=true
road_properties_on_snapped_pointsReturn road attributes such as speed limits and segment lengths.road_properties_on_snapped_points=["posted_speed_limit_mph"]
road_properties_on_linesReturn road attributes on the snapped road segments.road_properties_on_lines=["length_miles"]
contextA JSON object that contains additional parameters for the operation, for example, the spatial reference of the output features.context={"key":"value"}

Example request

Below is a request that shows how to use the snap to roads operation. The input data must be formatted as a Featureset which should include the geometry, attributes, and spatial reference of the features.

REST API

cURLcURLHTTPArcGIS API for PythonArcGIS REST JS
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
curl --location 'https://route-api.arcgis.com/arcgis/rest/services/World/SnapToRoadsSync/GPServer/SnapToRoads/execute' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'f=json' \
--data-urlencode 'token={YOUR_ACCESS_TOKEN}' \
--data-urlencode 'points={
  "features": [
    {
      "attributes": {
        "OBJECTID": 1,
        "location_timestamp": 1704522159000
      },
      "geometry": {
        "x": -122.43410099956145,
        "y": 37.800155000053394
      }

Code examples

Snap points and get route attributes

This example uses the snap to roads operation to snap GPS points to roads and return a route with road attributes. The speed limit and length attributes are provided for each segment. Hover over each segment to view the attributes.

Use the snap to roads operation to display posted speed limits.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
          const queryParams = new URLSearchParams({
            f: "json",
            token: appConfig.ACCESS_TOKEN,
            points: JSON.stringify({ features: agsPoints }),
            return_location_fields: true,
            return_lines: true,
            road_properties_on_lines: JSON.stringify([
              "posted_speed_limit_mph",
              "length_miles",
            ]),
          })
          const service = appConfig.SNAP_TO_ROADS_URL
          const response = await fetch(service, {
            method: "POST",
            headers: headerParams,
            body: queryParams,
          })
          const agsJSONResponse = await response.json()
Expand

Planned versus snapped route adherence analysis

This example uses the snap to roads operation to visualize and analyze a planned versus snapped route. The operation returns snapped points, a route, and road attributes such as posted speed limits and segment lengths. It displays the planned route provided by an operator, the actual route driven by a truck, and the snapped route generated by the operation. It also shows how route analysis can be performed for route statistics, identify speeding locations, and highlights route deviations.

Visualizing route adherence analysis for actual versus planned route.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
          // Create parameters for the Snap to Roads service
          const params = {
            points: inputFeatures,
            token: accessToken,
            travel_mode: travelMode,
            return_lines: true,
            return_location_fields: true,
            road_properties_on_snapped_points: [
              "posted_speed_limit_mph",
              "length_miles",
            ],
            road_properties_on_lines: [
              "posted_speed_limit_mph",
              "length_miles",
            ],
          }
          const results = await EsriGeoprocessor.execute(
            serviceURLs.snapToRoads,
            params
          )
Expand

Upload GPX file and snap tracks points

This example uploads a GPX file, parses the GPS track points, and uses the snap to roads operation to return snapped points and a route. The snapped points, route, and GPS track points are displayed on the map. The example also allows you to download a sample GPX file to test the operation.

Upload a GPX file and snap the GPS track points to the nearest road segments.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
        // Query the raw points layer for features
        const features = await rawPointsLayer.queryFeatures()

        // Create a feature set
        const params = {
          points: features,
          token: apiKey,
          travel_mode: travelMode,
          return_lines: true,
          return_location_fields: true,
          road_properties_on_snapped_points: [
            "posted_speed_limit_mph",
            "length_miles",
          ],
          road_properties_on_lines: ["posted_speed_limit_mph", "length_miles"],
        }

        try {
          // Execute the geoprocessing service
          const result = await EsriGeoprocessor.execute(
            serviceURLs.snapToRoads,
            params
          )
Expand

Snap points based on walking travel mode

This example uses the snap to roads operation to snap GPS points based on the Walking Distance travel mode. The snap to roads algorithms use the travel mode settings when determining the most likely roads that were traveled. The snapped points and route returned from the operation are displayed on the map, and the attributes of the snapped points are shown in a popup.

Use the snap to roads operation with a travel mode.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
        const inputParams = {
          points: pts,
          travel_mode: currentTravelMode,
          return_location_fields: true,
          road_properties_on_lines: ["length_miles"],
          token: accessToken,
          return_lines: true,
        }

        const results = await EsriGeoprocessor.execute(serviceURL, inputParams)
Expand

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.