Select to view content in your preferred language

Format for passing values via Attribute Expressions from Collector to Survey123

3652
10
Jump to solution
04-27-2018 09:29 AM
JosephDrahos
New Contributor II

I have seen some great questions, answers and discussions posted at a few other locations here on GeoNet, but I still have a lingering issue that I am trying to resolve. As a bit of background, I am utilizing the Collector app with prepositioned locations, then using the Collector pop-up to pass values of a particular point into a related Survey123 record. I am currently using two fields stop_lat and stop_lon that have the coordinates (in decimal degrees) and passing these onto the Survey123 app. These fields were populated using the 'Calculate Geometry' tool prior to being published as a Hosted Feature Layer in AGOL. Survey123 accepts these values just fine and automatically places its geopoint on top of the Collector point.

The potential issue I need to address, is situations in which the field collectors will need to move the Collector point because it may not be located in the correct spot. If it continues to pass those stop_lat and stop_lon values, Survey123 will place its geopoint at the original coordinates rather than the updated ones.

To address this, I used information from a combination of these two resources (understanding-survey123s-custom-url-scheme) and (how-can-i-get-xy-in-dec-degrees-from-a-poly-feat-serv-using-arcade). It gets me to a 90% solution though. I am able to extract the lat/longs from the Collector point geometry and convert to decimal degrees using slightly modified versions of Xander's code. When I look at the hyperlink in my Collector pop-up, it appears to be passing on those values as intended. However, for some reason Survey123 does not appear to recognize them, and places its geopoint at the location that my device's GPS says I'm at.

So my thoughts are, that maybe I am using an incorrect format for passing those values calculated in the attribute expressions to Survey123. This is what I am currently using in my Collector pop-up:

arcgis-survey123://?ItemID=2b630de13e764c889f6e010246701471&field:globalid={GlobalID}&field:stop_id={stop_id}&field:stop_name={stop_name}&field:agency_id={agency_id}&field:agency_name={agency_name}&field:row={row}&field:city={CITY}&field:district={district}&center={expression/expr1},{expression/expr0}

I have looked at the number of decimal places for expr1 and expr0 and they are both set to 8 decimal places; so that isn't the issue. I have tried using the nice titles of the expressions, in my case GeometryY and GeometryX, but those are not recognized at all. Is {expression/expr1} and {expression/expr0} the correct format for centering the Survey123 geopoint?

Can anyone spot what my flaw may be?

I'm wondering if maybe I've been looking at it too long and can't see what I am missing.

Thank you in advance for the guidance or direction that anyone can provide.

10 Replies
JoshConrad1
New Contributor III

All:

I have been experiencing the same issues described in this thread: trying to create an attribute expression that calculates lat/long coordinates from a hosted feature layer, then integrate Field Maps with Survey123 to open a form and have the geopoint plot the submitted survey on top of the feature using the result of the attribute expression using a custom URL via the custom URL popup (&center=).

I have been using the "Expression/expr2 - Code to calculate geometry" formula called out in this post (and a multitude of others on the community page) and it was correctly calculating the coordinates in ArcGIS Online Web Viewer Classic, but then when we tested this functionality in the field, the point was not mapping.

I found that the original formula in the "Expression/expr2 - Code to calculate geometry" results in an Array data type, with associated brackets. These brackets do not show up in ArcGIS Online, but when you view the popup in Field Maps, you can see the brackets. So because of this, i tested further and in the original function, i removed the brackets in the result line, which worked but was not perfect. It was not perfect because the coordinate results ended up being truncated to 2 decimals, and even though the submitted form was executing, the point was being plotted hundred of feet away.

After 10 hours of testing and researching these threads (which by the way, all of the contributions are EXPONENTIALLY HELPFUL AND I AM SO GRATEFUL OF YOUR KNOWLEDGE) i was able to find the CORRECT SOLUTION:

1.) Create an attribute expression for latitude:

var lat;
var originShift = 2.0 * PI * 6378137.0 / 2.0;

lat = number(Geometry($feature).y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return lat;

2.) Create an attribute expression for longitude:

var lon;
var originShift = 2.0 * PI * 6378137.0 / 2.0;

lon = number(Geometry($feature).x / originShift) * 180.0;
return lon;

3.) Because of the "number" identifier, In ArcGIS Online Web Map Viewer Classic go to Configure Popups, make sure your pop up display is custom, then the important step is to click Configure Attributes. Navigate to the newly created expressions and expand the decimal places to a minimum of 5.

4.) Lastly, in the custom URL make the "&center={expression/expr3},{expression/expr4} where expr 3 is Lat and expr 4 is Long.

I have been testing since i discovered this and it has been running smoothly. Happy Mapping!

0 Kudos