Lizmap Web Client tools#
The road network can be published with Lizmap Web Client (LWC). The Lizmap module lizmap-roadnetwork-module adds tools to the web map so that users can work with linear references (road, marker, abscissa, offset and side) directly in the browser.
These tools rely on Lizmap actions:
each tool calls a named action, which runs the PostgreSQL function lizmap_get_data(json).
This function calls the road_graph functions of the plugin
and returns the result as GeoJSON.
Note
The user interface is displayed in the language of Lizmap: English or French, see Translations. This page gives the labels of the French interface, with the English text.
Features#
The module adds four tools:
| Tool | Where | Lizmap actions used |
|---|---|---|
| Road network panel | Mini-dock Graphe routier | get_references_from_point, get_road_point_from_reference |
| Create a geometry from references | Editing form | get_references_from_point, get_road_point_from_reference, get_road_substring_from_references, get_edge_start_or_end_tip_from_references |
| Split a line | Feature popup | split_line_by_point |
| Merge two lines | Feature popup | merge_selected_lines |
Road network panel#
The module adds a mini-dock named Graphe routier (Road network). It opens when the map loads.

The panel contains a form with these fields:
| Label | Meaning |
|---|---|
| Route | Road code, for example D1. The list of values comes from the roads layer. |
| PR | Marker code (in French: point de repère) |
| Abscisse | Abscissa: distance in meters from the marker |
| Cumul | Cumulative distance in meters from the start of the road (read-only) |
| Décalage | Offset: distance in meters from the road axis |
| Côté | Side of the road: Gauche (left) or Droite (right) |
Get the references of a point#
When the panel is open, click on the map. The module runs the action
get_references_from_point with the clicked point. The returned references
fill the form, and the point is displayed on the map.
Show the references when hovering the map#
Check Activer le calcul au survol (Enable calculation on hover).
When the mouse moves over the map, a tooltip displays the references
of the point under the cursor, for example D1 - PR 3 + 250m (2m G).
The values in the form are updated too.
To limit the number of requests to the server:
- the module sends at most one request every 200 ms,
- no request is sent while the user drags the map.
This option is not available while the editing form is open.
Center the map on references#
Type a road, a marker, an abscissa, an offset and a side in the form,
then click Centrer (Center). The module runs the action
get_road_point_from_reference and zooms on the returned point, at the scale of the map
closest to 1:2,500 (project variable road_network_zoom_scale).
Tip
Click and hover only work at scale 1:50,000 or larger (project variable road_network_min_scale).
At a smaller scale, a message asks the user to zoom in.
Create a geometry from references#
When the user opens the Lizmap editing form for a point or line layer, the module adds a collapsible section above the form: Create the geometry from references.

The fields depend on the geometry type of the layer:
- Point layer: road, marker, abscissa, offset and side.
- Line layer: road, start marker and abscissa (PR début, Abscisse début), end marker and abscissa (PR fin, Abscisse fin), offset and side.
If the editing form has a field named road_code, its value is copied
into the Route field. If it has the fields offset and side, for example when an existing feature
is edited, their values are copied into the offset and side fields: the geometry keeps the offset of the data.
Buttons#
| Button | Action |
|---|---|
| Create | Computes the geometry from the references and replaces the geometry of the edited feature. For a point layer, the module runs get_road_point_from_reference. For a line layer, it runs get_road_substring_from_references. If the start references are after the end references, the module swaps them. |
| Reset | Deletes the drawn geometry and resets the reference fields. |
| Edge, start row | Sets the start references to the start of the edge located at the start references. |
| Road, start row | Sets the start references to the start of the road. |
| Edge, end row | Sets the end references to the end of the edge located at the end references. |
| Road, end row | Sets the end references to the end of the road. |
The Tronçon and Route buttons are only available for line layers.
They run the action get_edge_start_or_end_tip_from_references.
After that, the line geometry is computed again.
Snap a drawn geometry to the road#
When the user draws or modifies the geometry with the Lizmap drawing tools, the module:
- runs
get_references_from_pointfor the point, or for the first and last vertices of the line, - fills the reference fields with the returned values,
- replaces the drawn geometry with the geometry computed from these references.
As a result, the geometry always follows the road. If the road field has a value, only this road is used to find the references.
If no reference is found after 2 seconds, a message tells the user that the geometry could not be created. The most common cause is a point more than 50 m away from the road.
When the feature is saved, the Graphe routier panel opens again.
Split a line at a point#
This tool adds a button to the popup of the features of a line layer. It splits a line in two features at a point.
The button is only displayed if the user can modify the geometry and
create features in this layer, in the Lizmap editing configuration.
These rights can be changed with the project variable road_network_split_rights
(see Configure the module).
- Open the Graphe routier panel and click on the line where it must be split. A red point is displayed on the map.
- In the popup of the line, click the button. Its label is the
titleof thesplit_line_by_pointaction. - Confirm the operation.
The module sends the red point to the action split_line_by_point.
The database function road_graph.split_table_linestring_feature_by_point
splits the line, and the layer is refreshed.
The two lines follow the direction of the road, even if the line was drawn in the opposite direction: the original feature keeps the first part, and the new feature gets the second part. Their start and end references are calculated in the direction of the road.
The default popup button of this action is hidden, because it does not send the clicked point.
Merge two lines#
This tool adds a button to the popup of the features of a line layer. It merges two features of the same layer into one feature.
The button is only displayed if the user can modify the geometry and
create features in this layer, in the Lizmap editing configuration.
The right to delete features is not required by default, even if the second feature is deleted.
These rights can be changed with the project variable road_network_merge_rights
(see Configure the module).
- In the popup of the first line, click Choose this feature to merge. The button label becomes Feature chosen to merge. To cancel, click this button again.
- Click on the second line on the map. In its popup, click Merge with the chosen feature.
- Confirm the operation.
The module runs the action merge_selected_lines with the IDs of the two features.
The database function road_graph.merge_table_linestring_features merges them
and the layer is refreshed. The popup then shows only the merged feature.
The merged feature is the feature chosen first: it keeps its field values, and the second feature is deleted. Its references are calculated from the merged line, in the direction of the road.
Once a first feature is chosen, the merge button is only displayed for features of the same layer.
Installation#
1. Install the module#
Install the module lizmap-roadnetwork-module in Lizmap Web Client 3.9 or 3.10, as explained in its README. The installation creates the group of users Road network Lizmap, with the right Use the road network tools in the map. In the Lizmap administration, add the users to this group, or give this right to other groups: the tools are only loaded for the users with this right.
2. Publish the layers#
In the QGIS project:
- add the
road_graph.edgeslayer. The actions about references use this layer. - add the
road_graph.roadslayer and publish it as WFS (Project properties > QGIS Server > WFS capabilities). The module uses it to fill the list of roads. The layer must have the fieldsid,road_codeand a field to sort the roads,road_orderby default. - for the split and merge tools, add the line layers that the users can edit.
3. Create the database functions and the actions file#
Create the functions public.lizmap_get_data(json) and public.query_to_geojson(text)
in the database. The file lizmap_get_data_example.sql
creates both of them, with all the actions.
The function uses the projection EPSG:2154. Change it if your data uses
another projection.
Create a file named after the QGIS project, with the extension .action.
For example, for road_network.qgs, create road_network.qgs.action
in the same folder.
The file lizmap_action_file_example.json gives a complete example. Update it:
- replace
edges_7df8a321_25e8_4a67_9bf8_796e4782e147with the ID of youredgeslayer, - replace
LINE_LAYER_IDwith the IDs of the line layers for the split and merge tools, inlayersand incallbacks. Without such a layer, remove the actionssplit_line_by_pointandmerge_selected_lines: they are optional.
The action names must not change, because the module uses them.
The four actions of the edges layer are required: without them, or without the database functions,
the module does not load the tools, and writes the reason in the Lizmap admin log.
| Action | Scope | Options | Returned feature |
|---|---|---|---|
get_references_from_point |
layer |
road_code, vertex_number |
Point with road_code, marker_code, abscissa, cumulative, offset, side, vertex_number |
get_road_point_from_reference |
layer |
road_code, marker_code, abscissa, offset, side |
Point with the references |
get_road_substring_from_references |
layer |
road_code, start_marker_code, start_abscissa, end_marker_code, end_abscissa, offset, side |
Multilinestring with the start and end references |
get_edge_start_or_end_tip_from_references |
layer |
road_code, marker_code, abscissa, start_or_end (start or end), tip_type (edge or road) |
Point with marker_code, abscissa, start_or_end |
split_line_by_point |
feature |
none (the clicked point is sent as WKT) | The clicked point, message and message_detail |
merge_selected_lines |
layer |
feature_id_a, feature_id_b |
message and message_detail, no geometry |
vertex_number tells the module where to put the result:
-1 for the panel, 0 for the start point and 1 for the end point
of the edited geometry.
4. Configure the module#
The module is configured with variables of the QGIS project (Project properties > Variables).
It is used only for the projects with the variable road_network_edges_layer_id.
The algorithm Configure the project for Lizmap
sets all these variables in the current project, and publishes the roads layer in WFS.
The administration project created by the plugin already has the variable road_network_edges_layer_id.
| Variable | Default value | Description |
|---|---|---|
road_network_edges_layer_id |
Required. QGIS ID of the edges layer |
|
road_network_roads_layer_name |
roads |
Name of the roads layer, published in WFS |
road_network_roads_order_field |
road_order |
Field used to sort the list of roads |
road_network_min_scale |
50000 |
Smallest scale denominator for the click and hover tools |
road_network_zoom_scale |
2500 |
Scale denominator used to zoom on the point found from the references: the closest scale of the map is used |
road_network_split_rights |
createFeature,modifyGeometry |
Editing rights needed on a line layer to display the split button |
road_network_merge_rights |
createFeature,modifyGeometry |
Editing rights needed on a line layer to display the merge button. Add deleteFeature to also require the right to delete features |
The editing rights are the capabilities of the layer in the Lizmap editing configuration,
separated by commas: createFeature (create features), modifyAttribute (modify the attributes),
modifyGeometry (modify the geometry) and deleteFeature (delete features).
An invalid value is replaced by the default value, with a warning in the Lizmap admin log.
Migration from the JavaScript script#
Before the module, the tools were given by a JavaScript script, copied with its CSS and CSV files
in the media/js/ folder of the Lizmap repository. To use the module instead:
- install the module and give the right to the users,
- create the project variables from the constants of the
CONFIGURATIONsection of the script:ROAD_EDGES_LAYER_IDbecomesroad_network_edges_layer_id,ROAD_MIN_SCALEbecomesroad_network_min_scale, etc. The editing rights are separated by commas, for examplecreateFeature,modifyGeometry, - create the function
query_to_geojson, if it is not in the database yet, - delete the files
road_network.js,road_network.cssandroad_network.csvfrom themedia/js/folder: otherwise, the tools may be started twice.
Translations#
The texts of the tools are in the module, in English and in French, and they are displayed in the language of the user interface of Lizmap.
The module also translates, from their English text:
- the
titleandconfirmproperties of the actions, in the.qgs.actionfile, - the messages returned by the
lizmap_get_datafunction, in themessagefield. Lizmap displays them at the top of the map, and the module replaces them by their translation.
A message can contain a variable part, for example the detail of an error
returned by the database. In this case, the lizmap_get_data function must also return
this variable part in a message_detail field, and the message must end with it:
| Field | Value |
|---|---|
message |
An error occurred while splitting the line: The point is not close enough to the feature (distance 12 > 5m) |
message_detail |
The point is not close enough to the feature (distance 12 > 5m) |
The message is translated with the variable part replaced by the {detail} placeholder,
for example An error occurred while splitting the line: {detail}. The variable part itself is not translated.
If you change a text in the .qgs.action file or in the lizmap_get_data function,
it is displayed without translation.
Limitations#
- The module supports Lizmap Web Client 3.9 and 3.10.
- The tools only support point and line layers.
- The start and end references of a line must be on the same road.
- The split and merge tools are not available for the
edgeslayer.