Capturing vector coordinates

Demonstrates how to capture the coordinates of line and polygon features.

The examples below demonstrate how to use the CURRENTLOCATION function in conjunction with SETINTERVAL and CLEARINTERVAL to capture the coordinates of simple line or polygon features. This could be used for “digitizing” pipe lengths, pavement features, wetland boundaries, etc. While Fulcrum only currently supports point geometries in the map view, this workflow allows you to capture simple vector geometries for use outside of Fulcrum in various GIS applications.

Capturing A Line Feature

In the example below, our form is setup with the following fields:

var lineCoords = [],
  digitizeLine;

ON('click', 'start_digitizing', function(event) {
  lineCoords = [];
  digitizeLine = SETINTERVAL(function() {
    if (CURRENTLOCATION()) {
      lineCoords.push(CURRENTLOCATION().longitude + ' ' + CURRENTLOCATION().latitude);
    }
    SETVALUE('line', 'LINESTRING (' + lineCoords + ')');
  }, 1000);
});

ON('click', 'stop_digitizing', function(event) {
  CLEARINTERVAL(digitizeLine);
});

Capturing A Polygon Feature

In the example below, our form is setup with the following fields:

var polygonCoords = [],
  digitizePolygon;

ON('click', 'start_digitizing', function(event) {
  polygonCoords = [];
  digitizePolygon = SETINTERVAL(function() {
    if (CURRENTLOCATION()) {
      polygonCoords.push(CURRENTLOCATION().longitude + ' ' + CURRENTLOCATION().latitude);
    }
    SETVALUE('polygon', 'POLYGON (' + polygonCoords + ',' + polygonCoords[0] + ')');
  }, 1000);
});

ON('click', 'stop_digitizing', function(event) {
  CLEARINTERVAL(digitizePolygon);
});

In the above examples, the GPS capture interval is 1 second (1,000 milliseconds). This could be modified to emphasize greater precision (more coordinate pairs) for smaller features- or a longer interval for a more general representation of larger features.

To view the polygon vector geometries in CARTO, you could use the following SQL query, where polygon is the name of the geometry field and repeatable_vector_geometries is the name of the table:

SELECT cartodb_id, ST_Transform (ST_GeomFromText(polygon, 4326), 3857) AS the_geom_webmercator FROM repeatable_vector_geometries

Note also that this workflow should be considered highly experimental and is not officially supported. Capturing lots of coordinates at a fast interval while Fulcrum is running in the background could cause memory and performance issues.