D 2018-04-16T13:30:23.355 L VirtualRouting P 2d771f3e54e2be5d42b6dc5e6fb8a21f06d156fa U sandro W 130021 back
Technical noteThe internal encoding adopted by the Binary Data Table is unchanged and is the same for both VirtualNetwok and VirtualRouting.You can safely base a VirtualRouting Table on any existing Binary Data Table created by the spatialite-network CLI tool, exactly as you can base a VirtualNetwork Table on any Binary Data Table created by the CreateRouting() SQL function. WarningIn the case of Spatial Networks based on any geographic Reference System (using longitudes and latitudes) there is an important difference between Binary Data Tables created by the spatialite_network GUI tool and Binary Data Tables created by the CreateRouting() SQL function when costs are implicitly based on the geometric length of the Link's Linestring:
|
Highlight: where you areYou've just created two VirtualRouting Tables based on different settings; both them are perfectly valid and reasonable, but they are intended for different purposes:
Conclusion: a single VirtualRouting Table can't be able to adequately support support the specific requirements and expectations of different users. Defining more Routing Tables with different settings for the same Network usually is a good design choice leading to more realistic results. |
Handling dynamic NetworksSometimes it happens that a Network could be subject to rather frequent changes: some new Links require to be added, obsolete Links require to be removed, other Links may assume a different Cost, one-ways could be reversed, the discipline of pedestrian areas could be modified and so on.A VirtualRouting Table is always based on a companion Binary Data Table, that is intrinsically static, and consequently you are required to re-create both them from time to time in order to support all recent changes affecting the underlaying Network. The optimal frequency for cyclically refreshing the Routing Tables strictly depends on specific requirements, but the two overall approaches are commonly adopted:
|
Warning: how to correctly drop Network TablesWhen dropping a VirtualRouting Table and its companion Binary Data Table following the correct sequence of SQL commands is paramount.Failing to strictly respect the expected sequence will surely cause you several troubles and severe headaches, and will possibly lead to an irremediably corrupted database.
|
Algorithm | Request | Options | Delimiter | RouteId | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | PointFrom | PointTo | Tolerance | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Dijkstra | Shortest Path | Full | , [dec=44, hex=2c] | 0 | 0 | Route | NULL | 178731 | 183286 | NULL | NULL | NULL | 300.912208 | BLOB sz=272 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 0 | 1 | Link | 224014 | 178731 | 182885 | NULL | NULL | NULL | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | NULL | NULL | 0 | 2 | Link | 224446 | 182885 | 178880 | NULL | NULL | NULL | 69.727726 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | 0 | 3 | Link | 224414 | 178880 | 183286 | NULL | NULL | NULL | 136.372057 | NULL | VIA MARGARITONE |
RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|
0 | Route | NULL | 183286 | 178731 | 300.912208 | BLOB sz=272 GEOMETRY | NULL |
1 | Link | 224414 | 183286 | 178880 | 136.372057 | NULL | VIA MARGARITONE | 2 | Link | 224446 | 178880 | 182885 | 69.727726 | NULL | VIA MARGARITONE |
3 | Link | 224014 | 182885 | 178731 | 94.812424 | NULL | VIA PIETRO ARETINO |
RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|
0 | Route | NULL | 178731 | 183286 | 101.815552 | BLOB sz=2032 GEOMETRY | NULL |
1 | Link | 224014 | 178731 | 182885 | 13.127874 | NULL | VIA PIETRO ARETINO |
2 | Link | 224446 | 182885 | 178880 | 9.654608 | NULL | VIA MARGARITONE |
3 | Link | 219171 | 178880 | 178732 | 7.809952 | NULL | VIA FRANCESCO CRISPI |
4 | Link | 219058 | 178732 | 178754 | 12.445626 | NULL | VIA FRANCESCO CRISPI |
5 | Link | 225888 | 178754 | 183461 | 1.599865 | NULL | VIA FRANCESCO CRISPI |
6 | Link | 225887 | 183461 | 182800 | 3.300590 | NULL | VIA FRANCESCO CRISPI |
7 | Link | 223935 | 182800 | 182799 | 6.688786 | NULL | VIALE LUCA SIGNORELLI |
8 | Link | 226038 | 182799 | 183456 | 1.294017 | NULL | VIALE LUCA SIGNORELLI |
9 | Link | 225832 | 183456 | 183444 | 2.385486 | NULL | VIALE LUCA SIGNORELLI |
10 | Link | 225831 | 183444 | 183554 | 3.160662 | NULL | VIALE LUCA SIGNORELLI |
11 | Link | 225765 | 183554 | 183954 | 7.469917 | NULL | VIALE LUCA SIGNORELLI |
12 | Link | 225766 | 183954 | 183905 | 3.236389 | NULL | VIALE LUCA SIGNORELLI |
13 | Link | 225979 | 183905 | 183626 | 13.983629 | NULL | STRADA SENZA NOME |
14 | Link | 224905 | 183626 | 183128 | 5.627358 | NULL | STRADA SENZA NOME |
15 | Link | 224897 | 183128 | 183286 | 10.030792 | NULL | VIA MARGARITONE |
RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|
0 | Route | NULL | 183286 | 178731 | 103.305259 | BLOB sz=944 GEOMETRY | NULL |
1 | Link | 224414 | 183286 | 178880 | 18.882285 | NULL | VIA MARGARITONE |
2 | Link | 219171 | 178880 | 178732 | 7.809952 | NULL | VIA FRANCESCO CRISPI |
3 | Link | 219058 | 178732 | 178754 | 12.445626 | NULL | VIA FRANCESCO CRISPI |
4 | Link | 224538 | 178754 | 181972 | 7.047784 | NULL | VIA ANTONIO GUADAGNOLI |
5 | Link | 222575 | 181972 | 181971 | 1.852283 | NULL | VIA ANTONIO GUADAGNOLI | 6 | Link | 224967 | 181971 | 182891 | 14.273185 | NULL | VIA ANTONIO GUADAGNOLI |
7 | Link | 224168 | 182891 | 183057 | 6.643309 | NULL | VIA MACALLE' |
8 | Link | 224167 | 183057 | 183056 | 3.151272 | NULL | VIA MACALLE' |
9 | Link | 224174 | 183056 | 182941 | 7.966870 | NULL | VIA RODI |
10 | Link | 224059 | 182941 | 182001 | 6.393747 | NULL | VIA RODI |
11 | Link | 222637 | 182001 | 182000 | 2.475538 | NULL | VIA PIETRO ARETINO |
12 | Link | 222636 | 182000 | 178731 | 14.363408 | NULL | VIA PIETRO ARETINO |
Linestrings returned by VirtualRoutingAll LINESTRING Geometries created by any VirtualRouting will always contain M values:
In other words, all Linestrings returned by VirtualRouting can effectively support LR (Linear Referencing) SQL functions, as in the following examples: (assuming the same path returned by the latest bycar query). |
![]() |
Algorithm | Options | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|
A* | Full | 0 | Route | NULL | 178731 | 183286 | 300.912208 | BLOB sz=272 GEOMETRY | NULL |
NULL | NULL | 1 | Link | 224014 | 178731 | 182885 | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | 2 | Link | 224446 | 182885 | 178880 | 69.727726 | NULL | VIA MARGARITONE |
NULL | NULL | 3 | Link | 224414 | 178880 | 183286 | 136.372057 | NULL | VIA MARGARITONE |
Algorithm | Options | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|
A* | No Links | 0 | Route | NULL | 178731 | 183286 | 300.912208 | BLOB sz=272 GEOMETRY | NULL |
Algorithm | Options | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|
A* | No Geometries | 0 | Route | NULL | 178731 | 183286 | 300.912208 | NULL | NULL |
NULL | NULL | 1 | Link | 224014 | 178731 | 182885 | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | 2 | Link | 224446 | 182885 | 178880 | 69.727726 | NULL | VIA MARGARITONE |
NULL | NULL | 3 | Link | 224414 | 178880 | 183286 | 136.372057 | NULL | VIA MARGARITONE |
Algorithm | Options | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|
A* | Simple | 0 | Route | NULL | 178731 | 183286 | 300.912208 | NULL | NULL |
Algorithm | Request | Options | Delimiter | RouteId | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Dijkstra | Shortest Path | Full | , [dec=44, hex=2c] | 0 | 0 | Route | NULL | 178731 | 183882 | 154.750839 | BLOB sz=240 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 0 | 1 | Link | 222636 | 178731 | 182000 | 103.735722 | NULL | VIA PIETRO ARETINO |
NULL | NULL | NULL | NULL | 0 | 2 | Link | 225527 | 182000 | 183882 | 51.015117 | NULL | VIA LICIO NENCETTI |
NULL | NULL | NULL | NULL | 1 | 0 | Route | NULL | 178731 | 184030 | 176.364755 | BLOB sz=304 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 1 | 1 | Link | 224014 | 178731 | 182885 | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | NULL | NULL | 1 | 2 | Link | 224862 | 182885 | 182043 | 37.095287 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | 1 | 3 | Link | 226070 | 182043 | 184030 | 44.457044 | NULL | PIAZZA SANT'AGOSTINO |
NULL | NULL | NULL | NULL | 2 | 0 | Route | NULL | 178731 | 178754 | 224.677095 | BLOB sz=240 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 2 | 1 | Link | 219045 | 178731 | 178732 | 76.021007 | NULL | VIA ASSAB |
NULL | NULL | NULL | NULL | 2 | 2 | Link | 219058 | 178732 | 178754 | 148.656089 | NULL | VIA FRANCESCO CRISPI |
NULL | NULL | NULL | NULL | 3 | 0 | Route | NULL | 178731 | 181999 | 260.132354 | BLOB sz=240 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 3 | 1 | Link | 224014 | 178731 | 182885 | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | NULL | NULL | 3 | 2 | Link | 224446 | 182885 | 178880 | 69.727726 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | 3 | 3 | Link | 225800 | 178880 | 181999 | 95.592204 | NULL | VIA FRANCESCO CRISPI |
NULL | NULL | NULL | NULL | 4 | 0 | Route | NULL | 178731 | 183286 | 300.912208 | BLOB sz=272 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 4 | 1 | Link | 224014 | 178731 | 182885 | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | NULL | NULL | 4 | 2 | Link | 224446 | 182885 | 178880 | 69.727726 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | 4 | 3 | Link | 224414 | 178880 | 183286 | 136.372057 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | NULL | NULL | Unreachable NodeTo | NULL | 178731 | 290458 | NULL | NULL | NULL |
NULL | NULL | NULL | NULL | NULL | NULL | Unreachable NodeTo | NULL | 178731 | 124622 | NULL | NULL | NULL |
Algorithm | Request | Options | Delimiter | RouteId | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Dijkstra | Shortest Path | Full | , [dec=44, hex=2c] | 0 | 0 | Route | NULL | 178731 | 183882 | 154.750839 | NULL | NULL |
NULL | NULL | NULL | NULL | 1 | 0 | Route | NULL | 178731 | 184030 | 176.364755 | NULL | NULL |
NULL | NULL | NULL | NULL | 2 | 0 | Route | NULL | 178731 | 178754 | 224.677095 | NULL | NULL |
NULL | NULL | NULL | NULL | 3 | 0 | Route | NULL | 178731 | 181999 | 260.132354 | NULL | NULL |
NULL | NULL | NULL | NULL | 4 | 0 | Route | NULL | 178731 | 183286 | 300.912208 | NULL | NULL |
NULL | NULL | NULL | NULL | NULL | NULL | Unreachable NodeTo | NULL | 178731 | 290458 | NULL | NULL | NULL |
NULL | NULL | NULL | NULL | NULL | NULL | Unreachable NodeTo | NULL | 178731 | 124622 | NULL | NULL | NULL |
Dangerous pitfalls related to multiple destination listsSQL syntax directly allows to specify lists of multiple values, so may be you are now wondering about writing the multiple destinations query tested in the previous examples this way:SQLite will process a request written this way by repeatedly calling VirtualRouting passing each time a single Destination; and consequently VirtualRouting will never receive the critical information that a single monolithic request was intended to be executed in a single shot. So the request context will be easily misinterpreted, and any expected speed benefit will be completely frustrated. BewareNever ever attempt to define a list of multiple destinations using the standard SQL syntax WHERE NodeTo IN (......), because this will certainly cause many unexpected troubles.Badly formatted resultsets will be then returned, may be containing wrong results. You are warned. |
How to correctly format multiple destinations listsVirtualRouting always expects to receive a multi-destinations list as a TEXT string containing tightly packed values separated by a conventional delimiter (usually represented by a comma).Examples of well formatted multi-destinations lists: This will have no adverse consequences in the case of integer values, but can easily have catastrophic effects on alphanumeric values. Defining a custom delimiterSometimes it could be useful setting up a delimiter different from comma. |
Algorithm | Request | Role | NodeFrom | NodeTo | Cost | Geometry |
---|---|---|---|---|---|---|
Dijkstra | Isochrone | Solution | 181999 | 178717 | 572.455143 | BLOB sz=60 GEOMETRY |
NULL | NULL | Solution | 181999 | 178718 | 587.303779 | BLOB sz=60 GEOMETRY |
............. | ||||||
NULL | NULL | Solution | 181999 | 184035 | 579.786724 | BLOB sz=60 GEOMETRY |
NULL | NULL | Solution | 181999 | 184036 | 642.691597 | BLOB sz=60 GEOMETRY |
The Traveling Salesman ProblemGiven a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city ? |
Algorithm | Request | Options | Delimiter | RouteId | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Dijkstra | TSP NN | Full | , [dec=44, hex=2c] | 0 | 0 | TSP Solution | NULL | 178731 | 178731 | 1254.433933 | BLOB sz=2000 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 1 | 0 | Route | NULL | 178731 | 184030 | 176.364755 | BLOB sz=304 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 2 | 1 | Link | 224014 | 178731 | 182885 | 94.812424 | NULL | VIA PIETRO ARETINO |
NULL | NULL | NULL | NULL | 2 | 2 | Link | 224862 | 182885 | 182043 | 37.095287 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | 2 | 3 | Link | 226070 | 182043 | 184030 | 44.457044 | NULL | PIAZZA SANT'AGOSTINO |
NULL | NULL | NULL | NULL | 2 | 0 | Route | NULL | 184030 | 181999 | 139.114938 | BLOB sz=496 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 3 | 1 | Link | 226071 | 184030 | 182629 | 55.689009 | NULL | VIA GIUSEPPE GARIBALDI |
NULL | NULL | NULL | NULL | 3 | 2 | Link | 225512 | 182629 | 182933 | 34.184194 | NULL | CORSO ITALIA |
NULL | NULL | NULL | NULL | 3 | 3 | Link | 225511 | 182933 | 181999 | 49.241735 | NULL | CORSO ITALIA |
NULL | NULL | NULL | NULL | 3 | 0 | Route | NULL | 181999 | 183286 | 217.672885 | BLOB sz=688 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 4 | 1 | Link | 222635 | 181999 | 181998 | 101.629750 | NULL | CORSO ITALIA |
NULL | NULL | NULL | NULL | 4 | 2 | Link | 224780 | 181998 | 183560 | 73.733572 | NULL | VIA DELL'ANFITEATRO |
NULL | NULL | NULL | NULL | 4 | 3 | Link | 225827 | 183560 | 183286 | 42.309564 | NULL | VIA DELL'ANFITEATRO |
NULL | NULL | NULL | NULL | 4 | 0 | Route | NULL | 183286 | 178754 | 378.313684 | BLOB sz=272 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 5 | 1 | Link | 224414 | 183286 | 178880 | 136.372057 | NULL | VIA MARGARITONE |
NULL | NULL | NULL | NULL | 5 | 2 | Link | 219171 | 178880 | 178732 | 93.285538 | NULL | VIA FRANCESCO CRISPI |
NULL | NULL | NULL | NULL | 5 | 3 | Link | 219058 | 178732 | 178754 | 148.656089 | NULL | VIA FRANCESCO CRISPI |
NULL | NULL | NULL | NULL | 5 | 0 | Route | NULL | 178754 | 183882 | 188.216831 | BLOB sz=400 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 6 | 1 | Link | 224538 | 178754 | 181972 | 50.900663 | NULL | VIA ANTONIO GUADAGNOLI |
NULL | NULL | NULL | NULL | 6 | 2 | Link | 224537 | 181972 | 182000 | 86.301051 | NULL | VIA DEL NINFEO |
NULL | NULL | NULL | NULL | 6 | 3 | Link | 225527 | 182000 | 183882 | 51.015117 | NULL | VIA LICIO NENCETTI |
NULL | NULL | NULL | NULL | 6 | 0 | Route | NULL | 183882 | 178731 | 154.750839 | BLOB sz=240 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 7 | 1 | Link | 225527 | 183882 | 182000 | 51.015117 | NULL | VIA LICIO NENCETTI |
NULL | NULL | NULL | NULL | 7 | 2 | Link | 222636 | 182000 | 178731 | 103.735722 | NULL | VIA PIETRO ARETINO |
Algorithm | Request | Options | Delimiter | RouteId | RouteRow | Role | LinkRowid | NodeFrom | NodeTo | Cost | Geometry | Name |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Dijkstra | TSP NN | No Links | , [dec=44, hex=2c] | 0 | 0 | TSP Solution | NULL | 178731 | 178731 | 1254.433933 | BLOB sz=2000 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 1 | 0 | Route | NULL | 178731 | 184030 | 176.364755 | BLOB sz=304 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 2 | 0 | Route | NULL | 184030 | 181999 | 139.114938 | BLOB sz=496 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 3 | 0 | Route | NULL | 181999 | 183286 | 217.672885 | BLOB sz=688 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 4 | 0 | Route | NULL | 183286 | 178754 | 378.313684 | BLOB sz=272 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 5 | 0 | Route | NULL | 178754 | 183882 | 188.216831 | BLOB sz=400 GEOMETRY | NULL |
NULL | NULL | NULL | NULL | 6 | 0 | Route | NULL | 183882 | 178731 | 154.750839 | BLOB sz=240 GEOMETRY | NULL |
Warning: how to correctly handling TSP resultsets with spatialite_guiYou should never forget or overlook that both TSP NN and TSP GA are heuristic algorithms heavily relying on random choices.This could easily have the practical consequence that resolving twice (or even more times) the same identical TSP query could eventually return different resultsets. There is nothing intrinsically wrong in this, it simply is a direct consequence of using randomness; we are simply bargaining exactness and reproducibility for quickness. spatialite_gui on its own adopts a paged strategy when showing huge resultsets; this requires repeating again the initial SQL query each time that a new page of 500 rows has to be shown on the current window panel. The two things don't go together well; so don't be surprised when eventually discovering that spatialite_gui will behave bizarrely while presenting some resultset returned by a TSP query.
|
More about Linear Referencing and VirtualRouting LinestringsYou have already seen in a previous example that all LINESTRINGs created by VirtualRouting support the M (measure) coordinate intended as a progressive cost for each vertex. And you already know the they can support linear referencing (LR) SQL functions.Let's now go in further depth. Trajectory objectsA Trajectory is any Linestring supporting M coordinates with a continuously increasing trend.In simpler words, the M-value of each vertex (except the last one) must be lesser than the M-Value of the next vertex. The side map graphically shows the estimated positions every 100m assuming the same path returned by the latest TSP query. |
![]() |