I’ve been getting more questions lately on QGIS from all over the place. A pandemic will apparently: cause you to experiment with software, do some weird things with existing software, or call me up and ask “How do you work from home this sucks”. So one question started out with “I need to edit some data for the team and I need to keep up with what I edited and no it’s not in a database”.
In my perfect world you edit against postgresql/postgis and I set up some triggers to at the very least record who and when and possibly X and Y (or Y and X). If you’re stuck with a shapefile, spatialite database, or Geopackage what can you do? So you have these things called widgets in QGIS……
So we’re going to play with a geopackage because that gives me some talking points for the next blog post. The ruggedly handsome client (me) has shoved some data into a geopackage. Geopackage has no login so I’m going to add my data to QGIS and do the following things:
- Add two fields called ‘edituser’ and ‘editdate’
- Set up two widgets in your QGIS Session.
If you right click on a data layer and go to properties you can set up a widget for your fields (under Attribute Forms). A widget can be a drop down list (something like a domain on a subtype for you over in ESRI Land).
So for the edituser field I will pick a simple text edit widget with a default value of ‘rjhale’ (At the Bottom of the menu).
The editdate field gets slightly more complicated. For that one I reach into the myriad of QGIS functions and pull out the $now. So I apply it as a default (and check that I want it to update if I move the line):
So moving forward I can at least keep up with “who” edited and “when”.
That’s possible the simplest use case of a widget you can have. What if you wanted to update the length of a line automatically? The QGIS Function is $length and you could apply that as a default to a widget on a field and have it calculate the length.
The big take away on this is you can do some very simple things to help your editing life. Two widgets with default values and you can keep up with what you’ve done (or maybe a co-worker) in an attempt to combine the data back together at a later time. A giant shoutout to Spatial Thoughts as I start to dive into more widget magic over the next bit.