Reverse Geocode from geoshape

1254
3
Jump to solution
07-09-2020 06:43 PM
ChrisRoberts2
Occasional Contributor III

I am hoping that someone has a bright idea here, because I am out of them.

I have a Collector/Explorer app with a link on the pop up for the Parcel Layer, that parses the boundary coordinates to a geoshape question in Survey123 .. that bit works great.

What I want to do is in Survey123 is perform a reverse geocode on the Geoshape to get the street address.  It would appear, obviously, that the pulldata("@geoshape",${location},"reverseGeocode.address.Street","https://xxxxxxxx/server/rest/services/Locators/xxxxxxx/GeocodeServer") calculation doesn't work for a geoshape question.

So I came up with a solution to add a geopoint question inside a repeat (because you cant have a geoshape and geopoint in the same form unless one is in a repeat) and use that to reverse geocode on. Now that works in the form itself, so tick!.

Then I thought I could calculate XY centroid of the poly in Collector using Arcade, tick, then parse that to the geopoint question.  HOWEVER, I have since found out that parsing information from Collector to Survey123 to questions inside a repeat isn't supported. 

Anyone have any solutions?  Any help would be greatly appreciated!

0 Kudos
1 Solution

Accepted Solutions
ChrisRoberts2
Occasional Contributor III

I think I cracked it!

For those that are interested:

I added two lat and long  hidden null fields outside the Repeat in the survey. 

Then in the geopoint question added a concat calculation 'concat(${latitude}," ", ${longitude})' using  those two fields.

I then just use 

pulldata("@geopoint",${location},"reverseGeocode.address.Street","https://xxxxxxxx/server/rest/services/Locators/xxxxxxx/GeocodeServer to grab the street address

In the launch url I parse the poly centroid xy to the hidden lat and long fields in the Survey form and a geopoint is created at the centre of the polygon and the address is populated.

Happy Days! 

View solution in original post

3 Replies
ChrisRoberts2
Occasional Contributor III

I think I cracked it!

For those that are interested:

I added two lat and long  hidden null fields outside the Repeat in the survey. 

Then in the geopoint question added a concat calculation 'concat(${latitude}," ", ${longitude})' using  those two fields.

I then just use 

pulldata("@geopoint",${location},"reverseGeocode.address.Street","https://xxxxxxxx/server/rest/services/Locators/xxxxxxx/GeocodeServer to grab the street address

In the launch url I parse the poly centroid xy to the hidden lat and long fields in the Survey form and a geopoint is created at the centre of the polygon and the address is populated.

Happy Days! 

CherylWheeler11
New Contributor III

Hi Chris, I wonder if you could elaborate on "In the launch url I parse the poly centroid xy to the hidden lat and long fields". I am attempting to extract the geoshape centroid and not sure how to do this.

Thanks very much for your help

0 Kudos
ChrisRoberts2
Occasional Contributor III

Hi Cheryl

I extract the lats and longs for the centroid of the Parcel Polygon in Field Maps/Explorer using Arcade (I found on the forums and slightly tweaked):

function MetersToLatLon(mx, my) {
// Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
// Fuente: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (mx / originShift) * 180.0;
var lat = (my / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];
}


var poly = Geometry($feature);

var result = "";
if (!IsEmpty(poly)) {
var pnt_centr = Centroid(poly);

var latlon = MetersToLatLon(pnt_centr.x, pnt_centr.y);

result = latlon[0] ; //returns latitude replace with [1] to get longitude
} else {
result = "";
}

return result;

and in the launch url I parse those expressions to the lats and long fields in the Survey123 form.

eg

https://survey123.arcgis.com/share/xxxxx?portalUrl=https://xxxxx/portal&open=menu&field:longitud...

hope that helps