In Fulcrum, there are two methods to capture polyline and polygon vertices: (1) through repeatable sections with coordinates or (2) through the
CURRENTLOCATION() data event function (see http://developer.fulcrumapp.com/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: http://developer.fulcrumapp.com/expressions/examples/repeatable-vector-geometries/.
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.
Save your changes and proceed with collecting some 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.
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.
The queries below demonstrate the power of spatial SQL functions that can be used to generate new geometries based off of existing features.
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;
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;
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.