Hi Cesar,
This is certainly possible using an Arcade expression. Here are some detailed instructions on setting this up (the example is using a polygon but the steps are the same). This hasn't quite made it into a blog yet..
Brett
Pre-populate a Survey123 form with Existing Feature Layer Line/Polygon geometry via Custom URL
With Survey123 version 3.6+, line and polygon geometry capture is available via the `geotrace` and `geoshape` question types. You may be familiar with calculating geopoint questions which requires a set of text in the format `<LAT> <LON>`. Geotrace and Geoshape questions both extend this format to support a sequence of points; the format is `<LAT1> <LON1>;<LAT2> <LON2>;<LAT3> <LON3>;...`. A polygon will automatically close (create a segment from the last point to the first point). We can create an Arcade expression to calculate this sequence from the geometry of a line/polygon feature:
Line
var geom = Geometry($feature);
var outparts = [];
var counter = 0;
for (var p in geom.paths){
var thispath = geom.paths
;
for (var pt in thispath){
var ptstr = Concatenate(thispath[pt].y, " ", thispath[pt].x);
outparts[counter]= ptstr;
counter = counter + 1;
}
}
Return Concatenate(outparts, ";")
Polygon
var geom = Geometry($feature);
var firstpart = geom.rings[0];
var outparts = [];
var counter = 0;
for (var pt in firstpart){
var ptstr = Concatenate(firstpart[pt].y, " ", firstpart[pt].x);
outparts[counter]= ptstr;
counter = counter + 1;
}
return Concatenate(outparts, ";")
This allows us to pass the geometry into Survey123 to pre-populate the geotrace/geoshape question via a custom URL.
Steps
1) Open your web map to configure the pop-up for your polygon layer. *Note that for Survey123 to read the coordinates properly, the map must be in WGS84 (SRID 4326) projection.
2) Add a new Attribute Expression.
3) Copy/paste the Arcade expression (blue text above) into the Expression dialog and click OK (I'm using the polygon expression in this example):
4) You should now see your attribute expression in the list (I renamed mine to ‘Shape as Text’):
5) Construct your custom URL (to add as a link in the pop-up) using the 'field:<question_name>={field_name}' syntax to set the value of the geoshape question.
See the Understanding Survey123's custom URL Scheme blog post for more details on where to find your itemID etc.
Here is an example URL that passes values for 5 attribute fields plus the geometry field (also the geoshape question name highlighted in yellow):
arcgis-survey123://?itemID=7bf73e2a957a4d1c8ce899771af0db3e&field:PARCEL_PFI={PARCEL_PFI}&field:PARCEL_SPI={PARCEL_SPI}&field:PC_PLANNO={PC_PLANNO}&field:PC_LOTNO={PC_LOTNO}&field:extra_comments={extra_comments}&field:Parcel_polygon={expression/expr0}
6) Change your ‘Pop-up Contents’ to display a custom attribute, then click ‘Configure’:
7) Add some text (eg ‘Launch Survey’) to use as your link and copy / paste in your custom URL:
😎 Click OK to close the ‘Configure Pop-up’ and save your webmap.
You should now be able to click on a polygon to see the pop-up and then follow the link to launch the survey. The survey form will pre-populate with the geometry and attribute values you included in your URL:
Limitations
1) Note that for Survey123 to read the coordinates properly, the map must be in WGS84 (SRID 4326) projection. Esri offers a number of basemaps in this projection.
2) The line script assembles multiple parts into a single-part geometry.
3) The polygon arcade expression only uses the first part of the shape; this will not include 'donut holes' in polygons, multipart etc.