Advanced QGIS forms into the web with Lizmap

Nicolas BOISTEAULT - 3LIZ

FOSS4G 2022

Organize form's fields

  • Use QGIS "Drag and Drop Designer"

FOSS4G 2022

Toggle tabs or group boxes visibility on condition

FOSS4G 2022

FOSS4G 2022

center

FOSS4G 2022

Upload photos

  • Use "Attachment" widget and "Filter" to define allowed extensions

FOSS4G 2022

FOSS4G 2022
  • Edit pictures directly in Lizmap

FOSS4G 2022

Save login and groups

  • Expression variables: @lizmap_user for users, @lizmap_user_groups for groups

center

FOSS4G 2022

Value relation

FOSS4G 2022

center

FOSS4G 2022

Use case: suggestion based on previous record

SELECT * FROM (
  (
    SELECT DISTINCT ON (login)
      1 AS id,
      obs.id_animal,
      amph.scientific_name,
      login
    FROM foss4g.observations obs
    LEFT JOIN foss4g.amphibians_reptiles amph 
    ON obs.id_animal = amph.id_animal
    ORDER BY login, date_obs DESC
  )
  UNION ALL 
  (
  SELECT row_number() over (ORDER BY scientific_name) + 1 AS id,
    id_animal,
    scientific_name,
    NULL AS login 
  FROM foss4g.amphibians_reptiles
  )
) sub_query ORDER BY id
FOSS4G 2022

center

FOSS4G 2022

FOSS4G 2022

Result 🎉

center

FOSS4G 2022

Thank you for your attention

FOSS4G 2022

(15s) Hi, I'm going to show you some tips to make advanced forms in QGIS which will be easy for users to be filled. I also will show you those forms in the web thanks to Lizmap with no more configuration most of the time. This way you'll get more participation and less mistake in your data.

(20s) First with the QGIS "Drag and Drop Designer" we can: - Decide which fields needs to be filled - Change the field's order - Create tabs and group boxes

(35s) Let's say we create a form for a crowdsourcing campaign but also for logged in users in Lizmap (like people in our organization). This form have many fields but many of them are not mandatory so we don't want to show them all because when forms seem too long to fill, some users might give up and close it. To avoid that here we create a boolean field called `has_details`, with `Add details` as an Alias to have a more understandable title and define it as a `Checkbox`...

(15s) ...we also create a `Details` tab configured with a `Control Visibility by Expression` to only display it when the `has_details` checkbox is checked.

(10s) Here is the result. As you can see `Details` tab is only visible when `Add details?` is checked

(10s) Now we want people to upload photos. We create fields defined with the `Attachment` widget type and with a Filter to only display JPEG and PNG files

(10s) You can see in Lizmap, only files with defined extensions are displayed when selecting them

(10s) After file selection, you can also rotate or crop images. It is more convenient than to have to install a software for that.

(15s) When contributors are logged in Lizmap, we can use their user login or user groups in form's expressions thanks to expression variables. Here we create an invisible `login` field which get filled with the user login when form is saved.

(5s) The Value Relation widget is very convenient to display a list of value from another layer.

(10s) But sometimes the list can be very long. In this example, we display scientific names for amphibians and reptiles in France. To ease selection we could, for example, suggest the last previous record on top of the list for logged in users

(10s) For that, we create a layer from a view with this SQL query. It is a UNION ALL with the last previous record for logged in users and the whole list of animals

(20s) In red, the attribute table shows us the last record for alice, bob and demo users. The rest is the whole list of animals.

(15s) To only get the previous record for the logged in user in Lizmap we use this `Filter expression` which uses again the `@lizmap_user` expression variable

(15s) As you can see now when a logged in user saves a form he then has on top of the scientific name's list the last specie suggested.

(5s)