Tutorial: Field surveys using Mergin Maps

2. Project preparation

2.4. Adding a survey layer

Vector layers can be added as survey layer for the Input app.

In this section we'll create a survey layer for collecting ground truth for crop cover classification with remote sensing.

The following steps will be covered:

  • Create a point vector layer with the necessary attributes
  • Styling of the points
  • Make an attributes form using widgets
  • Settings for the Input preview panel
We continue with the same project from the previous section.

Create a point vector layer with the necessary attributes

1. In the Main Menu go to Layer | Create Layer | New GeoPackage Layer....

Create new geopackage layer

2. Click the Browse button Browse button to go to your project folder and choose the GeoPackage from the previous section, e.g. survey.gpkg.

3. For Table name type Groundtruth. For Geometry type choose Point. Make sure the projection is set to EPSG:32632.

4. Now we're going to add the attributes. A unique feature ID is automatically generated in a GeoPackage, so we don't have to add the observation ID attribute. Add the attributes like in the screenshot below. Add them by using the Add to list button.

Create Geopackage survey layer

5. Click OK when done.

6. A popup will ask you if you want to overwrite or add a new layer. Choose Add New Layer so it will be added to the GeoPackage.

Add new layer

Styling of the survey points

The Input app will use the same styling as defined in QGIS. Let's create a point symbology.
7. Click Open Layer Styling Panel buttonto open the Layer Styling panel.
8. Use the Single symbol renderer and click Add symbol layerto add a symbol layer.
9. For the first symbol layer make the Fill color transparent and the Stroke color black. Increase the Size to 4 mm and Stroke width to 1 mm For the second symbol layer choose a cross as marker symbol and choose Stroke color black. Increase the Size to 8 mm and Stroke width to 1 mm.
survey point marker

Make an attribute form using widgets

The next step is to design the attribute form using widgets.
10. Click right on the Groundtruth layer and choose Properties...
11. In the Properties window go to the Attributes Form tab.

Here we can design the form. We'll use the default Autogenerate option. Under fields we see all attributes in the Groundtruth layer.

12. Click on fid. On the right side of the window we can configure the widget. The value of fid is assigned automatically by QGIS and does not need to be edited by user. Set the Widget type to hidden to make it invisible in the form.
No widget for fid

13. Click on Observation number.  Choose the Text Edit widget and check the Not null box under Constraints. This means that it is a mandatory field. Keep the other fields as default.
Observation number widget
14. Click on Observer. At Alias type Observer name. Choose the Text Edit widget and check the Not null box under Constraints. Keep the other fields as default.
15. Click on Date and Time. We don't need an alias. Widget Type is automatically set to Date/Time. Change Widget Display to Custom and make it dd-MM-yyyy HH:mm:ss. Don't check the box before Calendar popup. Under Defaults type as default value $now to have the current date/time automatically filled in.

Date time widget

16. Click Picture. For Widget Type choose Attachment. Check the box for Relative paths. Under Integrated document viewer choose Image. At Constraints check the box before Not null.
17. Click Land Cover. For Alias type Land Cover Class. For Widget Type choose Value Map. With value maps we can create drop down menus in the Input app. Fill in the table as follows:


Value Description
1 Crop land
2 Tree cover
3 Shrubland
4 Grassland
5 Wetland
6 Artificial
7 Bare soil
8 Fallow land
9 Seasonal water
10 Permanent water

18. Set Constraints to Not null. And put the default value on 1, because for the purpose of crop mapping this will be chosen mostly.
19. Click Crop type.
20. For Widget Type choose Value Map. Use the following table:


Value Description
1 Wheat
2 Maize
3 Rice
4 Barley
5 Soybeens
6 Pulses
7 Cotton
8 Potatoes
9 Alfalfa
10 Sorghum

21. At Constraints write the following Expression"Land Cover"  = 1. This means that this can only be filled in when the Land Cover equals 1. By checking the box Enforce expression constraint you can prevent users to override the restriction.
22. For the field Water Source the Widget Type is Value Map. Fill in the dialogue as the screenshot below.
Water source widget
23. For Irrigation method fill in the dialogue as the screenshot below:
Irrigation method widget

24. For Coverage use the following screenshot:
coverage widget
25. For Size use the screenshot below:
Field size widget
26. For the Notes use this:
Notes widget

27. Click OK.
28. Open the attribute table of the Groundtruth layer and switch to Form View using Form View button to check the widgets.

Settings for the Input preview panel

Similar to Google maps, when a feature is identified on the map a preview panel will appear. To enable a layer being identified, the option should be enabled in QGIS desktop, under Project properties.

29. For setting the preview panel, you need to click right on the Groundtruth layer and choose Properties. Then select the Display tab.

  • title - this will use "Display Name" which can be a field name or an expression.

  • content - there are three options for what to show in content area: 1. field values, 2. image, 3. HTML. This will use "HTML Map Tip". QGIS always interprets the content of map tip as being HTML, however Input extends the syntax to allow two more modes. If the map tip is not specified, Input will try to use the first three fields and show their attribute values.

Field values

Sample map tip content that will show "description" and "time" field values:

# fields
fid
date and time

If the map tip content has # fields marker on the first line, the following lines will be understood as field names that should be listed in the preview. At most three fields will be shown. Expressions are not allowed.

Image

Sample map tip content that will cause an image to be show specified by file path in field "image_1" (containing path relative to the project directory):

# image
file:///[%@project_folder%]/[% "Picture" %]

If the map tip has # image marker on the first line, the following line is understood as the URL for the image. It can be a regular file on the file system, but it could be even a remote image from network. Expressions embedded in the image URL will be evaluated (enclosed in [% 1+1 %]).

HTML

Sample map tip content that will show render as HTML page:

<p><strong>Notes:</strong>[% "notes" %]</p>

If the map tip does not contain any special marker, it is assumed that the map tip is HTML content. Only a limited subset of HTML is supported - see https://doc.qt.io/qt-5/richtext-html-subset.html