Select to view content in your preferred language

Trouble with passing XY coordinates Collector via Arcade Expression

1698
7
09-01-2020 08:12 AM
AdamBourque
Regular Contributor

Hello all, I was very excited to see this update that Collector supports Arcade expressions. I am trying to pass the existing feature service coordinates to the survey feature service layer using this article How To: Launch and populate a Survey123 for ArcGIS survey from Collector for ArcGIS using XY coordin... 

I still pass the Facility ID value through the popup which works 

arcgis-survey123://?itemID=82f592fb0cf2454f93a757705b3d50dc&field:FacilityID={FACILITYID}{expression/expr0}

but the location won't pass to my survey with this arcade expression implemented on AGOL feature layer: (it works during the "test" button but does not pass the values.

function MetersToLatLon(x, y) {
// Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
// Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];
}
function CreateURLSurvey(lat, lon) {
var url = "&center=" + lat + "," + lon;// This is the line that defines the location
Console(url);
return url;
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;

 

Furthermore, do I need a geopoint field in the survey? (I've tried both and still no success, unless there's something specific in calculcation or something I am missing). 

Thank you all! 

0 Kudos
7 Replies
XanderBakker
Esri Esteemed Contributor

Hi Adam Bourque ,

I would probably suggest a couple of things to see where things fail. Is there a url created or does it just fail.Is there a way to see what the complete url is at this moment?

The expression currently is returning the part of the url including "&center". What happens when you take that part out and hardcode that on the URL after {FACILITYID}? What if you simple return the coordinates (before transforming them from Web Mercator into WGS1984), like this:

return Geometry($feature).Y + "," + Geometry($feature).X

Does it generate a URL at all?

What if you return some dummy WGS1984 coordinates. Does that work? The idea is to validate where this is going wrong.

Another option would be to explore ArcGIS Field Maps, which is currently in beta but is supposed to have better support for Arcade.

0 Kudos
AdamBourque
Regular Contributor

Hi Xander, I tried your suggestion and hit "test" end up giving the wrong coordinates, or not in WGS1984 anyways which I would like to keep. 

Anyways, the arcade expression generates the correct coordinates (assuming &center= is valid) ; however, it does not automatically generate those coordinates for the Survey submission, instead it uses my current location. 

The survey successfully works via URL incorporated in the pop-up rather than using Arcade expression, but the Arcade expression fails to pass the latitude/longitude even though the "Test" works. I have tried on both COLLECTOR and AGOL 

Appreciate the attempted help Xander Bakker

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Adam Bourque ,

So, if I understand this correctly, the initial expression does create the correct URL including the correct coordinates, but Survey123 rejects those and uses the GPS location. Is that the case?

0 Kudos
KerryKang
Frequent Contributor

@XanderBakker 

Hi, 

I have the same issue. I could create a correct url but Survey123 picks up GPS location. I hope to utilize this during offline mode especially using Field Maps' offline area rather than preparing tile map packages.

 

Kerry

 

0 Kudos
BHeist
by
Occasional Contributor

Has there been any updates to this? A possible solution to get it work and pass along the XY to the Survey using Arcade? 

I was able to get it to work by using a Custom Attribute Display but not with an Arcade Expression. 

0 Kudos
DavidBuehler
Frequent Contributor

@XanderBakker

I used expression mentioned at the top of this post (https://support.esri.com/en/technical-article/000020624).  I am using at 3.12+ Survey, and a webmap in AGOL, it pushes over the the geometry, but it does not push over any other field.  It leaves that as the the {} example &field:FacilityID={FacilityID}  leaves the field filled with {FacilityID}.

 

Thoughts?

0 Kudos
JoshConrad1
Regular Contributor

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