Exploitation commands¶
Delete attachment from disk¶
When an attachment (eg. pictures) is removed, its file is not automatically removed from disk.
sudo geotrek clean_attachments # remove old files
sudo geotrek thumbnail_cleanup # remove old thumbnails
docker compose run --rm web ./manage.py clean_attachments # remove old files
docker compose run --rm web ./manage.py thumbnail_cleanup # remove old thumbnails
Remove duplicate paths¶
Duplicate paths can appear while adding paths with commands or directly in the application. Duplicate paths can cause some problems of routing for topologies, it can generate corrupted topologies (that become MultiLineStrings instead of LineStrings).
sudo geotrek remove_duplicate_paths
docker compose run --rm web ./manage.py remove_duplicate_paths
During the process of the command, every topology on a duplicate path will be set on the original path, and the duplicate path will be deleted.
Merge segmented paths¶
A path network is most optimized when there is only one path between intersections. If the path database includes many fragmented paths, they could be merged to improve performances.
sudo geotrek merge_segmented_paths
docker compose run --rm web ./manage.py merge_segmented_paths
Important
This command can take several hours to run. During the process, every topology on a path will be set on the path it is merged with, but it would still be more efficient (and safer) to run it before creating topologies.
Before :
p1 p2 p3 p5 p6 p7 p8 p9 p14
+-------+------+-------+------+-------+------+-------+------+------+
| |
| p4 | p13
| |
+ +-------
| | |
| p10 | p16 |
p11 | | |
+------+------+ p15 --------
|
| p12
|
After :
p1 p6 p14
+--------------+-----------------------------+---------------------+
| |
| | p13
| |
| p10 +-------
| | |
| | p16 |
p11 | | |
+------+------+ p15 --------
|
| p12
|
(Re)generate pgRouting’s network topology¶
Builds the paths graph (pgRouting’s network topology) based on paths geometries. This graph is used to route on the paths network when creating linear objects.
This command is useful after importing a large number of paths, and required after modifying pgRouting’s tolerance.
The --flush option resets the graph before regenerating it. Without it, only missing parts of the graph are generated.
sudo geotrek generate_pgr_network_topology --flush
docker compose run --rm web ./manage.py generate_pgr_network_topology --flush
Note
For more information, consult pgRouting’s documentation: https://docs.pgrouting.org/latest/en/index.html
Unset structure on categories¶
Use this command if you wish to undo linking categories to structures for some models :
sudo geotrek unset_structure
docker compose run --rm web ./manage.py unset_structure
usage: manage.py unset_structure [-h] [--all] [--list] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
[--skip-checks]
[model [model ...]]
Unset structure in lists of choices and group choices with the same name.
positional arguments:
model List of choices to manage
optional arguments:
-h, --help show this help message and exit
--all Manage all models
--list Show available models to manage
--version show program's version number and exit
-v {0,1,2,3}, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
Note
You can’t chose for each choice which set of category you want to unset structures, it will happen for all categories.
Firstly, if a categroy is linked to a structure, it creates the same category but with no structure associated. Secondly, every element with this old category gets assigned to this new category. Finally all old categories are removed.
Reorder topologies¶
All topologies store information about which paths they go through and in which order. When a path is split in two by another path, a new path is added to the database. Linear topologies crossing that area then need to be updated to include this new path. This is badly managed at the moment, especially for path order.
This command attempts to find a valid path order that produces a single continuous LineString from start to end, staying as close as possible to the corrupted order. It uses the same algorithm that handles path ordering during topology display. Running it removes redundant data, which can speed up topology editing afterward.
sudo geotrek reorder_topologies
docker compose run --rm web ./manage.py reorder_topologies
To process only specific topologies, pass their IDs with the -i / --ids option:
sudo geotrek reorder_topologies --ids 12 45 78
docker compose run --rm web ./manage.py reorder_topologies --ids 12 45 78
By default, the command processes all non-deleted topologies. When using --ids, it processes exactly the topologies whose IDs are provided, regardless of their deletion status.
Note
In some cases the algorithm cannot find a valid solution and will produce a MultiLineString instead. Affected topologies will not be updated and will be listed at the end of the command output.
Automatic commands¶
You can set up automatic commands by creating a cron file under /etc/cron.d/geotrek_command that contains:
0 3 * * * root /usr/sbin/geotrek <command> <options>
0 3 * * * root /usr/bin/docker compose run --rm web ./manage.py <command> <options>
This example will automatically reorder topologies at 4 am every day.
0 4 * * * root /usr/sbin/geotrek reorder_topologies
This example will automatically reorder topologies at 4 am every day.
0 4 * * * root /usr/bin/docker compose run --rm web ./manage.py reorder_topologies
Indication
To help you find cron schedule expression you can use crontab guru.