Routing¶
Django-Geostore integrate a way to use your LineString layer as a routing one. It uses pgRouting as backend.
Prerequisites¶
- pgRouting>=2.5
- Enable geostore.routing in your project settings
INSTALLED_APPS = (
...
"geostore",
"geostore.routing",
...
)
Settings up¶
pgRouting needs to update a table that contains all linestring to create topological connection. You need to execute a command to create topology at first. Once, after every feature update topology will be automatically updated.
Commands¶
./manage.py update_topology -pk <layer_pk> --tolerance <tolerance>
You must provide the pk of the layer you want to use. Tolerance for extremity snapping is 0.00001 by default (unity should match to your INTERNAL_GEOMETRY_SRID, by default for 4326 see https://www.usna.edu/Users/oceano/pguth/md_help/html/approx_equivalents.htm )
Usage¶
The layer viewset provide an endpoint to get a routing result between two or more points.
^layer/<pk>/route
Arguments¶
First attribute needed, and mandatory, is geom
, it must contains a LineString from start to endpoint, passing through all
the way points. Geostore will create a path passing on the intersection the closest of those point, in the order you provided it.
It can also be provided a callbackid
, that is used to identify the request. It can be useful in async environment. The callbackid
is provided «as is» in the response.
Query content can provided in a POST or a GET request.
An example of response:
{
'request': {
'callbackid': 'my_callback',
'geom': {
"type": 'LineString',
"coordinates": [
[
10.8984375,
52.1874047455997
],
[
1.58203125,
46.042735653846506
]
]
}
},
'geom': {
'type': 'LineString',
'coordinates': [
[
1.6259765625,
45.767522962149876
],
[
5.2294921875,
46.558860303117164
],
[
10.986328125,
52.10650519075632
]
]
},
'route': {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
'type': 'LineString',
'coordinates': [
[
1.6259765625,
45.767522962149876
],
[
5.2294921875,
46.558860303117164
]
]
},
"properties": {
"id": 1
},
},
{
"type": "Feature",
"geometry": {
'type': 'LineString',
'coordinates': [
[
5.2294921875,
46.558860303117164
],
[
10.986328125,
52.10650519075632
]
]
},
"properties": {
"id": 2
},
}
]
}
}