Aller au contenu

Objets gérés#

Les collectivités gèrent de nombreuses données liées au réseau routier : travaux, réfection d'enrobés, signalisation, taille des haies, etc.

Chaque objet, point ou ligne (multiple), est défini par ses références calculées à partir du réseau routier (voir Concepts). Ces objets sont stockés dans vos propres tables PostgreSQL, appelées objets gérés. Quand le graphe routier est modifié, ces objets doivent être mis à jour.

Illustration du référencement linéaire

La couche des objets gérés#

La couche managed_objects liste toutes les tables PostgreSQL impactées par une modification du graphe, avec la règle de mise à jour à appliquer à chacune :

id schema_name table_name geometry_type update_policy_on_graph_change add_trigger_on_geom_change
1 managed demo_trees POINT references True
2 managed demo_safety_barriers MULTILINESTRING geometry False
  • schema_name et table_name : la table métier,
  • geometry_type : le type de géométrie de la table, par exemple POINT ou MULTILINESTRING,
  • update_policy_on_graph_change : la règle choisie par l'administrateur :
    • references : la géométrie est conservée et les références sont mises à jour,
    • geometry : les références sont conservées et la géométrie est mise à jour.
  • add_trigger_on_geom_change : si True, le trigger qui calcule les références, et, pour les tables de lignes, le trigger qui met à jour les lignes raccordées, sont créés sur cette table par la fonction road_graph.add_managed_objects_triggers() (voir plus bas). Valeur par défaut : False.

Chaque table doit avoir les colonnes de références correspondant à son type de géométrie. Elles peuvent être ajoutées automatiquement avec la fonction road_graph.add_managed_object_reference_fields, pour une table ou pour toutes les tables de cette couche (voir Ajouter les champs de références).

Ajouter une table métier#

Pour gérer une nouvelle table métier avec le graphe routier :

  1. préparez la table, avec ses colonnes de références,
  2. enregistrez-la dans la couche managed_objects,
  3. ajoutez les colonnes de références si besoin,
  4. calculez les références de ses entités,
  5. éventuellement, activez le calcul automatique des références des entités créées ou déplacées par la suite.

Préparer la table#

La table doit avoir :

  • une clé primaire,
  • une colonne de géométrie geom, dans le même système de coordonnées que le graphe routier, de type Point pour les objets ponctuels, ou LineString / MultiLineString pour les objets linéaires,
  • une colonne texte road_code,
  • les colonnes de références, qui sont calculées à partir du graphe routier :
Type de géométrie Colonnes obligatoires Colonnes facultatives
Point marker_code (entier), abscissa (réel) cumulative (réel), offset (réel), side (texte)
(Multi)LineString start_marker_code (entier), start_abscissa (réel), end_marker_code (entier), end_abscissa (réel) start_cumulative, end_cumulative (réel), offset (réel), side (texte)

Par exemple, pour une table d'arbres :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
CREATE TABLE managed.demo_trees (
    id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
    species text NOT NULL,
    road_code text,
    marker_code integer,
    abscissa real,
    side text,
    "offset" real,
    cumulative real,
    geom geometry(POINT, 2154)
);

Les colonnes de références peuvent aussi être ajoutées automatiquement, une fois la table créée, avec la fonction road_graph.add_managed_object_reference_fields (voir Ajouter les champs de références).

Importez ensuite vos données dans cette table, par exemple avec les outils de QGIS (glisser-déposer dans le panneau Explorateur, ou l'algorithme de traitement Exporter vers PostgreSQL), ou en SQL.

Enregistrer la table#

Ajoutez la table dans la couche managed_objects (table road_graph.managed_objects), avec son nom de schéma, son nom de table, son type de géométrie et sa règle de mise à jour :

1
2
3
4
INSERT INTO road_graph.managed_objects (
    schema_name, table_name, geometry_type, update_policy_on_graph_change
)
VALUES ('managed', 'demo_trees', 'POINT', 'references');

Ajouter les champs de références#

La fonction road_graph.add_managed_object_reference_fields ajoute à une table les colonnes de références listées plus haut, selon son type de géométrie. Le type de géométrie est lu dans la couche managed_objects si la table y est enregistrée, ou sinon à partir de sa colonne de géométrie geom.

Par exemple, pour une table de panneaux de signalisation qui n'a pas encore les colonnes de références :

1
2
3
4
5
6
7
8
CREATE TABLE managed.road_signs (
    id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
    label text,
    geom geometry(POINT, 2154)
);

-- Add the reference fields
SELECT * FROM road_graph.add_managed_object_reference_fields('managed', 'road_signs');

La fonction renvoie une ligne par colonne, avec son statut :

field_name field_type field_status
road_code text added
marker_code integer added
abscissa real added
cumulative real added
offset real added
side text added
  • Les colonnes existantes ne sont pas modifiées : leur statut est already exists, ou already exists with the type ... si leur type n'est pas celui attendu. La fonction peut donc être lancée plusieurs fois.
  • Les colonnes facultatives (cumulative, start_cumulative, end_cumulative, offset et side) ne sont pas ajoutées si le troisième paramètre vaut False : road_graph.add_managed_object_reference_fields('managed', 'road_signs', False).
  • Si les colonnes ne peuvent pas être ajoutées, la fonction renvoie une ligne avec le statut table not found, geom column not found or geometry type not supported: ....

Pour ajouter les colonnes de références à toutes les tables listées dans la couche managed_objects :

1
2
3
4
SELECT o.schema_name, o.table_name, f.field_name, f.field_type, f.field_status
FROM road_graph.managed_objects AS o
CROSS JOIN LATERAL road_graph.add_managed_object_reference_fields(o.schema_name, o.table_name) AS f
ORDER BY o.id;

Tip

La colonne road_code est ajoutée vide. Si elle est toujours vide au moment du calcul des références, les références sont calculées sur la route la plus proche, et la colonne road_code est remplie. Remplissez-la au préalable pour imposer la route d'une entité, par exemple à un carrefour.

Calculer les références#

Une fois les entités importées, calculez leurs références à partir de leurs géométries avec la fonction de la base de données road_graph.update_table_references_from_geometries :

1
2
3
4
5
-- Calculate the references of all the features of the table
SELECT road_graph.update_table_references_from_geometries('managed', 'demo_trees', NULL);

-- Calculate the references of the features of some roads only
SELECT road_graph.update_table_references_from_geometries('managed', 'demo_trees', ARRAY['D138', 'D152']);

Les paramètres de la fonction sont le nom du schéma, le nom de la table, et une liste facultative de codes de routes. Pour chaque entité :

  • si la colonne road_code est remplie, les références sont calculées sur cette route,
  • si elle est vide, la route la plus proche est utilisée, et la colonne road_code est remplie.

Elle renvoie le nombre d'entités mises à jour et leurs identifiants, par exemple :

1
{"nb": 7, "last_updated_objects_ids": [1, 2, 3, 4, 5, 6, 7]}

Si vos données contiennent les références mais pas de géométrie, utilisez plutôt la fonction road_graph.update_table_geometries_from_references, avec les mêmes paramètres, pour calculer les géométries à partir des références.

Calcul automatique des références#

La fonction trigger road_graph.calculate_managed_object_references calcule les références d'une entité d'objet géré à chaque fois qu'elle est insérée ou que sa géométrie est modifiée. La table doit être listée dans road_graph.managed_objects, et avoir une colonne road_code et une colonne geom.

The road of the references is chosen as follows:

  • if the column road_code is filled, the references are calculated on this road,
  • if it is empty, the closest road to the point, or to the middle of the line, is used, and the column road_code is filled. The start of a line is often on an intersection, unlike its middle,
  • if the geometry is updated but not the column road_code, for example when this column is read-only in the form, the road is replaced by the closest one when the feature has moved away from its road: its point, or the middle of the line, is closer to another road, and more than 50 m away from its road, or farther from it than before by more than 10 m. A road code changed with the geometry is always kept.

The offset and the side of a line are calculated at its middle. The tolerance of 10 m can be changed for the current session, for example to 20 m:

1
SET road.graph.road.code.drift.tolerance TO '20';

The function road_graph.add_managed_objects_triggers() creates this trigger, named trg_calculate_managed_object_references, on every table listed in road_graph.managed_objects with the column add_trigger_on_geom_change set to True. For the linestring and multilinestring tables, it also creates the trigger trg_update_managed_object_linked_geometries (see Automatic update of the connected lines). Run it after adding new tables in the managed objects layer, or after checking this column:

1
SELECT * FROM road_graph.add_managed_objects_triggers();

It can be run several times: each trigger is only created when it does not already exist. Unchecking add_trigger_on_geom_change does not remove an existing trigger. The function returns one line per trigger, with its status, or one line without trigger name when no trigger can be created for the table:

schema_name table_name trigger_name trigger_status
public demo_painting trg_calculate_managed_object_references created
public demo_painting trg_update_managed_object_linked_geometries created
public demo_trees trg_calculate_managed_object_references already exists
public demo_nogeom geom column not found
public missing_table table not found
public demo_signs not requested

For each table, the created trigger is equivalent to:

1
2
3
4
CREATE TRIGGER trg_calculate_managed_object_references
BEFORE INSERT OR UPDATE OF geom
ON public.demo_painting
FOR EACH ROW EXECUTE PROCEDURE road_graph.calculate_managed_object_references();

Automatic update of the connected lines#

The trigger function road_graph.update_managed_object_linked_geometries keeps the lines connected when the geometry of a line is updated: the other lines of the same table and the same road whose start or end point touched (5 cm tolerance) the start or end point of the line before its modification are shortened or extended to stay connected to it:

  • an upstream line gets the new start references of the line as end references,
  • a downstream line gets the new end references of the line as start references.

Their geometry is calculated again from their references with the function road_graph.get_road_substring_from_references, keeping their offset and side. The cumulative distances are also updated if the table has the fields start_cumulative and end_cumulative. A connected line is not modified if the updated line now covers it entirely.

The table must be listed in road_graph.managed_objects with a line geometry type, and have the fields road_code, start_marker_code, start_abscissa, end_marker_code and end_abscissa. The function road_graph.add_managed_objects_triggers() creates this trigger on the line tables with the column add_trigger_on_geom_change set to True. It is fired after the update of the geometry, so that the references of the updated line have already been calculated, for example by the trigger trg_calculate_managed_object_references. It is equivalent to:

1
2
3
4
CREATE TRIGGER trg_update_managed_object_linked_geometries
AFTER UPDATE OF geom
ON public.demo_painting
FOR EACH ROW EXECUTE PROCEDURE road_graph.update_managed_object_linked_geometries();

The connected lines are not modified when a line is split or merged with the Lizmap actions, when the managed objects are updated from the road graph, or when the editing session is merged.

Update rules#

When the user merges the data from the editing session, every impacted object is automatically updated based on the rule chosen by the administrator:

  • Point objects are often not moved, but their references must be updated, e.g. a road sign.
  • (Multi)linestring objects must often follow the changes: the start and end points are kept and only the nodes in between are edited, e.g. a painting roadwork.

To keep the merge fast on long roads, only the objects which may be impacted by the modifications are updated (see Impacts of the modifications on the references):

  • the objects located less than 50 m from the modified edges,
  • if the geometry of the road has changed, the objects located downstream of the first modified edge: up to the end of the road if the table has a cumulative field, or else up to the last marker of the modified edges,
  • the objects located between a modified marker and the previous marker.

An edge only split by a node, for example at a new crossroad, or whose attributes only have changed, does not change the geometry of the road. The other objects keep their references and geometries.

If the geometry of an object cannot be calculated from its references, for example when its end references are before its start references, the object is not updated and a warning is displayed, but the merge is not cancelled.

The algorithm Update managed objects from the road graph can also be run manually on a given layer, with the following parameters:

  • Update policy: Update geometries or Update references,
  • Update geometries - Preserve start & end points when updating line geometries: No or Yes.

Example: impacts of a graph modification#

The road D613 has two business objects:

  • a tree, in the table demo_trees with the update policy references, located at PR 43 + 450.53 m,
  • a safety barrier, in the table demo_safety_barriers with the update policy geometry, from PR 43 + 120 m to PR 45 + 18 m.

The road is realigned between the marker 43 and the tree: in an editing session, a vertex of the edge is moved 40 m away from the road axis. The edge, and therefore the road, becomes 46.71 m longer (from 563.30 m to 610.01 m).

When the editing session is merged, the two objects are updated according to their policy:

Object Update policy Before the merge After the merge
Tree references PR 43 + 450.53 m PR 43 + 497.24 m: the tree has not moved, but it is now 46.71 m further from the marker 43
Safety barrier geometry PR 43 + 120 m to PR 45 + 18 m, 1,843.31 m long Same references. The geometry is calculated again and follows the new shape of the road: 1,889.57 m long
  • For the tree, a real object on the ground, the geometry is right and the references are updated.
  • For the safety barrier, the references are kept: its start and end points stay at the same places, since the markers have not moved, and the geometry between them follows the realigned road.

The updated objects are listed in the column last_updated_objects_ids of the managed_objects layer, and are displayed by the layer vm_managed_objects (see below).

Last updated objects#

The layer vm_managed_objects shows, for each managed table, the objects updated by the last merge of an editing session, as a 10m buffer around them. It is useful to have a quick look at the impacted objects.

This layer is a materialized view based on the view road_graph.v_managed_objects, which can be slow to compute. It is refreshed automatically at the end of the merge of an editing session. To refresh it manually, for example after running the algorithm Update managed objects from the road graph, use:

1
REFRESH MATERIALIZED VIEW CONCURRENTLY road_graph.vm_managed_objects;