2

We are using QField for field data collection (forest survey). Our data is stored in a PostGIS/PostgreSQL database and we use QFieldSync to export and import data. This works fine as long, as we use data, that is stored in a single table. During normalization of our database, we had to split up the original survey table into tree tables, one main table containing the static data of the site (including the geometry) and two detail tables (survey and planned actions) that are linked by an 1:many relation to the main table. In QGIS we can use the Data-driven Input Mask-plugin to work with the 3 tables. This seems to work quite well (after our first tests). But we don't know how to archive this in QField?

On way would be to go back to our original flat all-in-one table just for field survey and import the new data later to the 3 tables in the database. Another way would be to create a huge view from the 3 tables and work with the view in the field. The view could then be imported to update the underlying tables (would need to create Trigger in order to make the view updatable).

But may be there is another more elegant and reliable path to follow, since it should be a common problem.

2
  • is the data collection/editing done offline/disconnected? Commented Aug 9, 2020 at 22:51
  • Yes the data collection is done offline. The old and new data is stored in a data.gpkg generated by QfiedSync.
    – geom
    Commented Aug 10, 2020 at 20:19

2 Answers 2

0

I only use file based data, not PostGIS, but for file based data, you can set-up 1 to many relations. For instance I capture photos for trees, and the photos are in the child table of a 1:n relationship. Working the other way I think you can use the Relation reference to view data of the parent record when editing or viewing a child record. My set-up for child photos is as follows: Parent Table [trees] has field [id] Child Table [Photos] has field [ID] and [treeID], the latter being the foreign key. Set up the one to many relationship in Project Properties, with [tree].[ID] referencing [photos].[treeID]. In the trees form, drag the relation widget into the form and set cardinality to one to many.

0
0

@Oisin Hi, I was really curios if that could work with offline date from an PostGIS layer (but it should). I set up the 1:n relations (as association) in my project and they showed up in the attribute form of the parent layer in QGIS. When I tried to add child-datasets in QGIS, PostGIS refuses to save them. In QField I got the same behavior. I can save the parent dataset, but I cannot add a child datasets. I get an error that 'Parent primary keys are not available'.

1
  • Ok, Matthias Kuhn from Opengis.ch answered to my problem on github.com/opengisch/QField/issues/1210. The solution is to use uuid instead of serial fields for the primary keys and the foreign keys. They are generated directly in QField and do not cause any problems with already existing keys in the PostgreSQL-database.
    – geom
    Commented Aug 19, 2020 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.