The following article was written before the release of our Lines and Polygons feature. This article should be consider deprecated unless you are interested in learning more about app design, exporting Fulcrum data, and QGIS.
In Fulcrum, there are two methods to capture polyline and polygon vertices:
Through repeatable sections with coordinates
Through the
CURRENTLOCATION()
data event function (see https://docs.fulcrumapp.com/docs/data-events-examples#capturing-vector-coordinates).
This guide will walk you through the first option– capturing simple vector features using repeatable fields. The idea is to have a parent form that stores your attribute information, and child records that act as vector vertices or nodes. As long as you enable location on your child records, you can use a little spatial SQL to ‘connect the dots’ and generate the lines and polygons. Fulcrum’s ability to export directly to SpatiaLite makes this exercise fairly straightforward and easily repeatable.
Note: You can also use calculation fields to generate WKT line geometries from repeatable vertices. Check out this example for more information: https://docs.fulcrumapp.com/docs/calculations-examples#vector-geometries-from-repeatables.
The Case For Vectors
Let’s walk through an example where this functionality might come in handy. We will start by cloning the Archaeological Sites App from the Fulcrum App Gallery. This app was designed for collecting basic information on sites that may be historically significant. We will be modifying the app to allow us to collect additional GPS locations, where we will be placing boundary flags to denote the footprint of the site. Ultimately we want to end up with a polygon layer that can be brought into our GIS for mapping and analysis.
Designing The App
Add the Archaeological Sites App to your Fulcrum account.
Open the app in the Form builder screen and add a new repeatable field for Boundary Flags. Be sure to check the Location Enabled box!
Inside Boundary Flags, add a text field for recording the flag’s tag label.
Save your changes and proceed with collecting some data.
Collecting Data
You can add a new record anywhere at the site to enter your attribute information. As you walk the perimeter of the site and place boundary flags, be sure to add a Boundary Flag record at each flag location. It may help to switch to the map view on the Boundary Flags screen so you can see your location and flag markers as you proceed. The tag label fields are optional but may be helpful if you’d like to examine the individual flag points. Ultimately these points will be converted to a polygon with the attributes of the parent form.
You can collect as many Site features as you’d like with associated Flag markers, but be sure to capture your points in logical order, without overlapping the resulting polygon.
Data Export and Processing
After syncing with the server, proceed with the standard export process, making sure to choose SpatiaLite as the export format.
We will use the open source QGIS software to view our data and generate the new geometries.
Open QGIS and add your Fulcrum data points to the canvas.Layer -> Add SpatiaLite LayerClick the ‘New’ button to create a new connection to your SpatiaLite database.Click the ‘Connect’ button to connect and view the tables.Select both the archaeological_sites and archaeological_sites_boundary_flags tables and click ‘Add’.
Use the QGIS Data Manager to run your spatial queries.Database -> DB Manager -> DB ManagerExpand SpatiaLite and double click on archaeological_sites.sqlite.Click the ‘SQL Window’ button to launch the SQL editor window.
SpatiaLite Queries
The queries below demonstrate the power of spatial SQL functions that can be used to generate new geometries based off of existing features.
Points to Lines
The SpatiaLite MakeLine
function is the same as the PostGIS ST_MakeLine
function, which is documented here. In our case, we would use the following query to build lines of child records (flags) with the attributes of the parent records (sites).
SELECT sites.fulcrum_id, sites.site_name, sites.site_number, sites.nearest_town, MakeLine(flags.geometry) AS geometry
FROM archaeological_sites_boundary_flags flags
LEFT JOIN archaeological_sites sites ON flags.fulcrum_record_id = sites.fulcrum_id
GROUP BY fulcrum_record_id;
SpatiaLite SQL Window
Flag Lines in QGIS
Points to Polygons
For polygons, we simply plug our MakeLine
function into a BuildArea
function. The SpatiaLite BuildArea
function is the same as the PostGIS ST_BuildArea
function, which is documented here. The BuildArea
function requires closed polylines, so we need to close our line with the AddPoint
function. This just duplicates the first point as the last point, making it a properly closed line.
SELECT sites.fulcrum_id, sites.site_name, sites.site_number, sites.nearest_town, BuildArea(AddPoint(MakeLine(flags.geometry), PointN(MakeLine(flags.geometry), 1))) AS geometry
FROM archaeological_sites_boundary_flags flags
LEFT JOIN archaeological_sites sites ON flags.fulcrum_record_id = sites.fulcrum_id
GROUP BY fulcrum_record_id;
Flag Polygons in QGIS
Conclusion
Hopefully this guide has demonstrated that converting Fulcrum child nodes into line and polygon geometries opens up a lot of interesting opportunities for mapping your data. While we work to make vector geometries first class citizens in Fulcrum, we hope documenting this alternative approach may prove helpful for certain scenarios.