Arcade expression for string of LatLon coordinates from Polygon in ArcGIS Online

601
6
02-01-2021 10:13 AM
Labels (1)
TaylorSchyrbiak
New Contributor II

I have an arcade expression as follows in the add-ons of a polygon hosted feature layer on arcgis online:

 

var geom = Geometry($feature);

 

var firstpart = geom.rings[0];

 

var outparts = [];

 

var counter = 0;

 

function metersToLatLon(mx, my) {

 

   var originShift = 2.0 * PI * 6378137.0 / 2.0;

 

   var lon = (firstpart[pt].x / originShift) * 180.0;

 

   var lat = (firstpart[pt].y / originShift) * 180.0;

 

   lat = 180.0 / PI * (2.0 * Atan(Exp(lat * PI / 180.0)) - PI / 2.0);

return Concatenate(lat, " ", lon);

 

}

 

for (var pt in firstpart){

 

    var ptstr = metersToLatLon(firstpart[pt].x, firstpart[pt].y);

 

    outparts[counter]= ptstr;

 

    counter = counter + 1;  

 

}

 

return Concatenate(outparts, ";")

 

 

The expression works as intended when tested, however, when I try to view in the popup or attributes table, nothing appears. It also has not successfully saved in the layer. Ideas??

The goal of this workflow is to have a polygon shape passed through URL to a survey123 form geoshape question, hence the metersToLatLon function. 

0 Kudos
6 Replies
XanderBakker
Esri Esteemed Contributor

Hi @TaylorSchyrbiak ,

Have you manually tried to pass the geoshape to the URL to see if it works? How are you consuming the URL with the geoshape? In a browser or using the Survey123 app? What version do you have? If I looked correctly I see that the geoshape was first introduced at version 3.6.137:

https://doc.arcgis.com/en/survey123/faq/pdf/whatsnewarchive.pdf 

However, I am not sure if there is support for geoshapes in the URL when a Survey is edited in the browser...

 

Since you already have the geometry would using the inbox be a solution for you? https://doc.arcgis.com/en/survey123/desktop/create-surveys/prepareforediting.htm 

Tags (1)
0 Kudos
TaylorSchyrbiak
New Contributor II

I went a step further and set up the URL with my survey... and using my arcade expression above, I successfully passed a polygon shape from collector for arcgis to my geoshape question in the survey123 field app. Not sure why it won't show in the pop up or attribute table though. And indeed, the web app does not appear to have this capability for geoshapes. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @TaylorSchyrbiak ,

There can be several reasons. Maybe the different text sections are not structured in a way to pass a valid URL. In Arcade you have the UrlEncode function that will replace spaces by %20 and other characters by something that is the valid representation in a URL.

It is also necessary to explain how you create the URL that is presented in the pop up. 

It would be good if you could post an example of the URL that is formed at this moment to see what is going wrong. 

0 Kudos
TaylorSchyrbiak
New Contributor II

This is the URL I currently have set up (other than I've just listed the surveyID as 123):

arcgis-survey123://?itemID=123&field:spray_status={spray_status}&field:vineyard_={vineyard_}&field:block_={block_}&field:polygon_={expression/expr0}

This is the URL is currently produces:

arcgis-survey123://?itemID=123&field:spray_status=requested&field:vineyard_=Bullpine&field:block_=BullpineD&field:polygon_=

And this is an example of what I am trying to pass to the polygon_ question from the arcade expression first mentioned in this post:

49.076299867222936 -119.49206557279504;49.07729539411242 -119.49157106101092;49.07748055058896 -119.49015584073926;49.076918323830725 -119.48940482221228;49.07629733102711 -119.48848015844256;49.07563048532977 -119.48942211118825;49.07576573916958 -119.49133601232523;49.07553254850802 -119.49236478454819;49.076299867222936 -119.49206557279504

 

Also, even though it doesn't show in the url, it does transfer to the survey123 field app properly. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @TaylorSchyrbiak ,

When you construct a URL there can be multiple interpretations of the URL. For a URL to be valid I suppose you would have to apply the UrlEncode function (see: https://developers.arcgis.com/arcade/function-reference/text_functions/#urlencode ) to the geoshape in order to replace the spaces by %20 and the semicolons by %3B. 

I have also had some problems in the past using arcgis-survey123:// to create a valid link to Survey123 and have used "https://survey123.arcgis.app?itemID=yourID&... with better results in the past.

 

In order to validate, I would have to create a survey and a web map with polygons to test this out and I am not sure when I will have time to do this. 

0 Kudos
TaylorSchyrbiak
New Contributor II

I tried applying the UrlEncode function to the arcade expression, and while it again showed successfully in the test,

(e.g. 49.076299867222936%20-119.49206557279504%3B49.07729539411242%20-119.49157106101092%3B49.07748055058896%20-119.49015584073926%3B49.076918323830725%20-119.48940482221228%3B49.07629733102711%20-119.48848015844256%3B49.07563048532977%20-119.48942211118825%3B49.07576573916958%20-119.49133601232523%3B49.07553254850802%20-119.49236478454819%3B49.076299867222936%20-119.49206557279504)

it still didn't show in the pop-up nor the URL that was formed. 

Thanks for your input. The fact that it still passes to the survey123 field app means that I can get by for now. 

0 Kudos