Git Product home page Git Product logo

ignf / route-graph-generator Goto Github PK

View Code? Open in Web Editor NEW
7.0 6.0 3.0 777 KB

Script collection used to generate routing data for Road2 (https://github.com/IGNF/road2)

Home Page: https://ignf.github.io/route-graph-generator/

License: GNU General Public License v3.0

Dockerfile 3.14% Shell 0.88% Python 69.05% PLpgSQL 17.47% Lua 9.46%
road2 routing generation-algorithms pgrouting osrm valhalla isochrone

route-graph-generator's Introduction

Route Graph Generator

Présentation

Route Graph Generator (r2gg) est un script Python qui permet la génération de graphes pour des moteurs de calcul d'itinéraire. Il a été développé pour générer les données directement utilisable par Road2.

Actuellement, il y a trois formats de sortie : OSRM, pgRouting et Valhalla.

La conversion se fait via les fonctions de la bibliothèque r2gg développée dans ce but. Une documentation plus détaillée de r2gg est consultable ici.

Prérequis

Les prérequis au fonctionnement des scripts de génération sont décrits dans le readme de l'image docker.

Les extensions SQL postgres_fdw et PostGIS doivent être installées sur la base de données pivot :

pivot=# CREATE EXTENSION postgres_fdw;
pivot=# CREATE EXTENSION PostGIS;

Dans le cas d'une convertion vers une base de données pgRouting, les extensions SQL postgres_fdw, PostGIS et pgRouting doivent être installées sur la base de données de destination, pgrouting par exemple :

pgrouting=# CREATE EXTENSION postgres_fdw;
pgrouting=# CREATE EXTENSION PostGIS;
pgrouting=# CREATE EXTENSION pgRouting;

Les procédures du projet pgrouting-procedures doivent également être installées sur la base de données de destination, sur le bon schema

Installation

Pour installer les commandes de génération de données, lancer la commande suivante à la racine du projet :

pip3 install --user -e .

Utilisation

Fichier de configuration

Pour pouvoir lancer les scripts de génération, il faut définir une configuration (au format JSON) par ressource à générer. Ce fichier de configuration fait références à d'autres fichiers de configuration : pour la gestion des logs, la gestion des connexions aux bases de données, et pour le calcul des coûts. Des exemples de tous ces fichiers sont présents dans le dépôt dans le dossier io. La documentation de ces fichiers de configuration est consultable ici.

Un exemple de ces fichiers est disponible dans la partie docker.

Exécution

Les scripts de génération sont divisés en trois processus distincts : l'extraction des données d'une base de données vers une base de données dite "pivot", et, en fonction de la ressource, la conversion depuis la base "pivot" vers une base pgRouting, ou vers des fichiers .osrm, ou encore vers des fichiers valhalla.

Ces trois processus se lancent à l'aide de commandes différentes, prenant toutes le même fichier de configuration.

Pour extraire les données vers la base pivot

r2gg-sql2pivot config.json

Pour convertir les données au fromat pgRouting (le type de ressource dans config.json doit être pgr)

r2gg-pivot2pgrouting config.json

Pour convertir les données au format osrm (le type de ressource dans config.json doit être osrm)

r2gg-pivot2osm config.json
r2gg-osm2osrm config.json

Pour convertir les données au format valhalla (le type de ressource dans config.json doit être valhalla)

r2gg-pivot2osm config.json
r2gg-osm2valhalla config.json

Enfin, si on souhaite générer la configuration pour Road2, il y a une dernière commande

r2gg-road2config config.json

Version

Elle est indiquée dans le __about__.py.

Licence

Route-graph-generator est diffusé sous la licence GPL v3.

Participer aux développements

Les participations à ce projet sont encouragées (votre notre charte à ce sujet). Nous avons mis en place un guide des contributions pour vous accompagner dans cette démarche.

route-graph-generator's People

Contributors

azarz avatar benoitblanc avatar frozar avatar gwenandres avatar ign-ngauthe avatar jmkerloch avatar lgrd avatar pjjmunier avatar xavdmz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

yhilem frozar xavdmz

route-graph-generator's Issues

safety check returns some vulnerability

Python package safety returns some vulnerability:

+==============================================================================+

                                   /$$$$$$            /$$
                                  /$$__  $$          | $$
               /$$$$$$$  /$$$$$$ | $$  \__//$$$$$$  /$$$$$$   /$$   /$$
              /$$_____/ |____  $$| $$$$   /$$__  $$|_  $$_/  | $$  | $$
             |  $$$$$$   /$$$$$$$| $$_/  | $$$$$$$$  | $$    | $$  | $$
              \____  $$ /$$__  $$| $$    | $$_____/  | $$ /$$| $$  | $$
              /$$$$$$$/|  $$$$$$$| $$    |  $$$$$$$  |  $$$$/|  $$$$$$$
             |_______/  \_______/|__/     \_______/   \___/   \____  $$
                                                              /$$  | $$
                                                             |  $$$$$$/
      by pyup.io                                              \______/

+==============================================================================+

 REPORT 

  Safety is using PyUp's free open-source vulnerability database. This
data is 30 days old and limited. 
  For real-time enhanced vulnerability data, fix recommendations, severity
reporting, cybersecurity support, team and project policy management and more
sign up at https://pyup.io or email [email protected]

  Safety v2.3.5 is scanning for Vulnerabilities...
  Scanning dependencies in your environment:

  -> /home/jmkerloch/dev/route-graph-generator/.venv/lib/python3.10/site-packages
  -> /home/jmkerloch/dev/route-graph-generator

  Using non-commercial database
  Found and scanned 76 packages
  Timestamp 2023-06-29 08:06:39
  8 vulnerabilities found
  0 vulnerabilities ignored

+==============================================================================+
 VULNERABILITIES FOUND
+==============================================================================+

-> Vulnerability found in sqlparse version 0.4.2
   Vulnerability ID: 55054
   Affected spec: >=0.1.15,<0.4.4
   ADVISORY: Sqlparse 0.4.4 includes a fix for CVE-2023-30608: Parser
   contains a regular expression that is vulnerable to ReDOS (Regular...
   CVE-2023-30608
   For more information, please visit https://pyup.io/v/55054/f17


-> Vulnerability found in setuptools version 45.2.0
   Vulnerability ID: 52495
   Affected spec: <65.5.1
   ADVISORY: Python Packaging Authority (PyPA) setuptools before 65.5.1
   allows remote attackers to cause a denial of service via HTML in a crafted...
   CVE-2022-40897
   For more information, please visit https://pyup.io/v/52495/f17


-> Vulnerability found in requests version 2.28.2
   Vulnerability ID: 58755
   Affected spec: >=2.3.0,<2.31.0
   ADVISORY: Requests is a HTTP library. Since Requests 2.3.0, Requests
   has been leaking Proxy-Authorization headers to destination servers when...
   CVE-2023-32681
   For more information, please visit https://pyup.io/v/58755/f17


-> Vulnerability found in markdown-it-py version 2.1.0
   Vulnerability ID: 54650
   Affected spec: >=0,<2.2.0
   ADVISORY: Denial of service could be caused to markdown-it-py, before
   v2.2.0, if an attacker was allowed to force null assertions with specially...
   CVE-2023-26303
   For more information, please visit https://pyup.io/v/54650/f17


-> Vulnerability found in markdown-it-py version 2.1.0
   Vulnerability ID: 54651
   Affected spec: >=0,<2.2.0
   ADVISORY: Denial of service could be caused to the command line
   interface of markdown-it-py, before v2.2.0, if an attacker was allowed to...
   CVE-2023-26302
   For more information, please visit https://pyup.io/v/54651/f17


-> Vulnerability found in lxml version 4.6.4
   Vulnerability ID: 43366
   Affected spec: <4.6.5
   ADVISORY: Lxml 4.6.5 includes a fix for CVE-2021-43818: Prior to
   version 4.6.5, the HTML Cleaner in lxml.html lets certain crafted script...
   CVE-2021-43818
   For more information, please visit https://pyup.io/v/43366/f17


-> Vulnerability found in lxml version 4.6.4
   Vulnerability ID: 50748
   Affected spec: <4.9.1
   ADVISORY: Lxml 4.9.1 includes a fix for CVE-2022-2309: NULL Pointer
   Dereference allows attackers to cause a denial of service (or application...
   CVE-2022-2309
   For more information, please visit https://pyup.io/v/50748/f17


-> Vulnerability found in cryptography version 39.0.0
   Vulnerability ID: 53048
   Affected spec: >=1.8,<39.0.1
   ADVISORY: Cryptography 39.0.1 includes a fix for CVE-2023-23931: In
   affected versions 'Cipher.update_into' would accept Python objects which...
   CVE-2023-23931
   For more information, please visit https://pyup.io/v/53048/f17

 Scan was completed. 8 vulnerabilities were found. 

+==============================================================================+
   REMEDIATIONS

  8 vulnerabilities were found in 6 packages. For detailed remediation & fix 
  recommendations, upgrade to a commercial license. 

+==============================================================================+

  Safety is using PyUp's free open-source vulnerability database. This
data is 30 days old and limited. 
  For real-time enhanced vulnerability data, fix recommendations, severity
reporting, cybersecurity support, team and project policy management and more
sign up at https://pyup.io or email [email protected]

+==============================================================================+

We should try to update some requirements.

Refactor entrypoint definition

In current version, r2gg external package are imported in r2gg/_init__.py

This must be changed so we can import __about__.py while building documentation.

  • refactor r2gg/__init__.py to remove import of base package => move method to a cli.py file
  • update 'setup.py' for new entry point

[ci] add GitHub action workflow for package publication

Create a new .github/workflows/package-publish.yml to add package publication to CI.

  • define pypi user that will be used for the publication
  • add secrets in GitHub settings to store pypi user and password
  • define github action used for pypi publication

[doc] deploy documentation on GitHub pages

Documentation should be available on GitHub pages:

  • add GitHub action workflow to generate documentation
  • step1 : generate documentation with sphinx (waiting #7)
  • step2 : deploy generated documentation on GitHub pages

Update from psycopg2 to psycopg3

          Ici psycopg 2 est utilisé alors que dans le reste de l'outillage de la GPF on utilise la v3 ? 

AMHA cela représente une source de confusion et de petites erreurs difficiles à identifier dans le futur.

Originally posted by @Guts in #38 (comment)

Remove of prefix _ for python file

@azarz @lgrd All python files are prefixed with _.

Is there any reason for that ?

I'm afraid this kind of naming could be misinterpreted by some parser. It may be better to remove all prefix.

[feat] Partial updates from OSM data

Feature

Be able to do partial updates from OSM data

Is your feature request related to a problem? Please describe.

When I want to update my graph, I have to make a delete and replace.

Describe the solution you'd like

I would like to be able to do partial updates from OSM data.

Describe alternatives you've considered

No alternatives considered.

Additional context

None

Add conversion script for BD Topo

Currently the only sql conversion script is for the BD Uni, however many users will want to start the conversion from a local instance of the BD Topo.

A sql script for the conversion from BD Topo should be added.

[test] add end to end tests

There are no test in the repository.

We need to add some end to end tests for all entry point:

  • r2gg:sql2pivot
  • r2gg:pivot2pgrouting
  • r2gg:pivot2osm
  • r2gg:osm2osrm
  • r2gg:osm2valhalla
  • r2gg:road2config

TO BE DEFINED :

  • test framework (suggestion pytest)
  • how to have input data ?
  • how to check results ?

Use schema for pivot to osm and pivot to pgr

          Hi ! I've just seen that schemas are not used for the pivot in _pivot_to_osm.py and _pivot_to_pgr.py. They are used only for the final pgr base. So, if we don't change that, your modification will not be used in the next step of the generation. :/

Do you want to make the changes ? For information, I can help, but only in one or two weeks. Now, I have to make continue my work on the admin API.

Originally posted by @lgrd in #33 (comment)

[doc] Add documentation generation with sphinx

Add documentation with sphynx:

  • create a root directory documentation
  • add conf.py to define sphynx option
  • TO BE DISCUSSED : move all .md documentation files to the `documentation directory
  • create landing page documentation/index.md

Refactor Dockerfile to remove r2gg_pipeline.sh call

Docker image should not contains commands (only bash).

Need to update :

  • docker/Dockerfile : remove r2gg_pipeline.sh call
  • docker/Dockerfile: use requirements/base.txt to install dependancies and sync their installation across the project

⚠️ road2 must also be updated to adapt docker-compose.yml : r2gg_pipeline.sh call must be added (issue to be created)

Generating graph data from BD TOPO to use for a Chinese Postman problem

(Version française en fin de ticket!)


I am trying to create a route that passes through the lanes contained within a polygon (IRIS), to create a map that will support a field survey (a pedestrian team survey route).

  • The route must pass through each route at least once;
  • The route should be as short as possible.
  • The route can eventually leave the polygon and use the adjacent lanes to return to the polygon by another route if this allows optimisation.

This corresponds to the problem of the Chinese postman: https://fr.wikipedia.org/wiki/Probl%C3%A8me_du_postier_chinois

pgRouting seems to be able to calculate these routes: https://docs.pgrouting.org/latest/en/chinesePostmanProblem-family.html.
The data I want to work with is the troncon_de_route layer of the BD TOPO. If I'm not mistaken, I'll have to use route-graph-generator to generate the graphs.

I followed the r2gg README and already made progress. Here is what I've done so far:

  • The troncon_de_route layer has been imported into a PostGIS database, on which the postgres_fdw and pgRouting extensions have also been installed;
  • The procedures https://github.com/IGNF/pgrouting-procedures are also installed;
  • I have adapted the general config file config.json to fit my project. My version is available here: https://mapper.space/tests/r2gg/config.json
  • The other config files have also been customized (for log management, database connection management, and cost calculation);
  • I finally tried to customize bduni_convert.sql but without much success and this is where I get stuck. Running r2gg-pivot2pgrouting config.json gets me numerous SQL errors. Completely modifying the SQL conversion script without errors seems to be beyond my skills at the moment.

I have several questions:

  • Am I on the right track?
  • Do you have any guidance on what to include in the SQL script? I don't need to get the attribute data from road_section, geometry and georeferencing info would be enough.
  • Do you know of any other solution, if possible simpler, to achieve what I am trying to do? (I have already tried the Chinese Postman plugin from QGIS but the plugin has outdated dependencies. I filed a ticket a week ago, with no news yet, and I haven't tried to modify the plugin to fix the dependency issues. It could be a a solution but for the moment I'm focused on r2gg).

Thanks in advance for your feedback :)


Je cherche à créer un itinéraire qui passe par les voies contenues au sein d'un polygone (IRIS), pour créer une carte qui servira d'appui à une enquête de terrain (itinéraire d'enquête d'une équipe piétonne).

  • L'itinéraire doit passer par chaque voie au moins une fois;
  • L'itinéraire doit être le plus court possible.
  • L'itinéraire peut éventuellement sortir du polygone et emprunter les voies adjacentes pour revenir dans le polygone par un autre chemin si ça permet d'optimiser.

Ça correspond au problème du postier chinois: https://fr.wikipedia.org/wiki/Probl%C3%A8me_du_postier_chinois

pgRouting semble être en mesure de calculer ces itinéraires: https://docs.pgrouting.org/latest/en/chinesePostmanProblem-family.html.
Les données à partir desquelles je souhaite travailler correspondent à la couche troncon_de_route de la BD TOPO. Si je ne fais pas erreur, il faut donc que je passe par route-graph-generator pour générer les graphes à partir de la BD TOPO.

J'ai suivi le README et déjà avancé. Voilà où j'en suis:

  • Les données troncon_de_route sont importées dans une base PostGIS, sur laquelle les extensions postgres_fdw et pgRouting ont été également installées;
  • Les procédures https://github.com/IGNF/pgrouting-procedures sont installées elles aussi;
  • J'ai adapté le fichier de config générale config.json pour correspondre à mon projet. Ma version est consultable ici: https://mapper.space/tests/r2gg/config.json
  • Les autres fichiers de config ont également été personnalisés (pour la gestion des logs, la gestion des connexions aux bases de données, et pour le calcul des coûts);
  • J'ai enfin tenté de personnaliser bduni_convert.sql mais en tatonnant, et c'est ici que ça bloque. Lorsque je lance r2gg-pivot2pgrouting config.json, j'ai de nombreuses erreurs lors de l'éxécution du SQL. La modification complète et sans erreur du script de conversion SQL semble être au-delà de mes compétences pour l'instant.

Je me pose donc plusieurs questions:

  • Est-ce que je suis sur la bonne voie?
  • Auriez-vous des indications sur ce qu'il faut indiquer dans le script SQL? Je n'ai pas besoin de récupérer les données attributaires de troncon_de_route, la géométrie et le géoréférencement suffiraient.
  • Auriez-vous connaissance d'une autre solution, si possible plus simple, pour réaliser ce que j'essaye de faire?
    (J'ai déjà essayé le plugin Chinese Postman de QGIS mais le plugin a des problèmes de dépendances obsolètes. J'ai déposé un ticket il y a une semaine, sans nouvelles pour l'instant, et je n'ai pas essayé de modifier le plugin pour en corriger les problèmes de dépendances. C'est une solution mais pour le moment je me suis concentré sur r2gg.)

Merci d'avance pour vos retours :)

Update dockerfile to use requirements.txt

Dockerfile docker/debian/Dockerfile should be updated to use requirements.txt

Hello ! I think we will have to use this file inside the dockerfile because the dependancies are outdated now and not sync with those requirements. ^^'

Originally posted by @lgrd in #22 (comment)

[feat] Convert from OSM data (files or links)

Need

r2gg can create a .osm from the pivot. And r2gg can read them to create osrm or valhalla data. But it can't convert an osm data to pivot.

Functionalities

  • Download an osm file
  • Convert an osm file to the pivot format
  • Be able to make an entire generation from osm to pgr, osrm and valhalla

Tasks

  • Update the generation file format
  • Be sure of the CLI and its IO
  • Code it
  • Update and run tests
  • Update docs (changelog and documentation directory) of this project
  • Update contributing.md of this project
  • Update contributing.md of Road2
  • Update readme.md and docs of Road2

Code

// TODO

La fonction public.clean_graph() n'existe pas

J'ai pu remplir la base de donnée pivot et je travaille sur la création de la base de données pour pgRouting avec la commande r2gg-pivot2pgrouting. Lorsque je lance cette commande, l'ensemble du script s'exécute correctement jusqu'au moment où la fonction public.clean_graph() est utilisée :

for profile_name in profile_names:
logger.info("Cleaning isolated edges for profile {}...".format(profile_name))
clean_graph_query = "SELECT {0}.clean_graph('{1}')".format(schema, profile_name)
logger.info("SQL: {}".format(clean_graph_query))
cursor_isolated.execute(clean_graph_query)

A ce moment, j'ai le message d'erreur suivant :

Traceback (most recent call last):
  File "/home/frozar/.local/bin/r2gg-pivot2pgrouting", line 33, in <module>
    sys.exit(load_entry_point('r2gg', 'console_scripts', 'r2gg-pivot2pgrouting')())
  File "/home/frozar/wk/flaxib/wk/route-graph-generator/r2gg/__init__.py", line 12, in pivot2pgrouting
    pgr_convert(config, resource, db_configs, connection, logger)
  File "/home/frozar/wk/flaxib/wk/route-graph-generator/r2gg/_main.py", line 132, in pgr_convert
    pivot_to_pgr(resource, cost_calculation_file_path, connection, connection_out, logger)
  File "/home/frozar/wk/flaxib/wk/route-graph-generator/r2gg/_pivot_to_pgr.py", line 384, in pivot_to_pgr
    cursor_isolated.execute(clean_graph_query)
psycopg2.errors.UndefinedFunction: function public.clean_graph(unknown) does not exist
LINE 1: SELECT public.clean_graph('pedestrian')

En cherchant dans le projet pour savoir où est défini la fonction public.clean_graph(), je ne trouve rien.

Je pense donc que la définition de cette fonction n'est pas dans ce projet.

Si tel est le cas, pouvez-vous rajouter la définition de cette fonction dans le fichier _pivot_to_pgr.py svp ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.