Calculations on Geopoints

41383
60
06-08-2016 03:32 PM
IsmaelChivite
Esri Notable Contributor
7 60 41.4K

[Updated February 22, 2019]

NOTE: This content is now obsolete. Please refer to this blog post for more up to date content.

The calculation column in XLSForms allows you write expressions that, when evaluated, set the response for a particular question. Calculations are supported in most of the questions types such as integers, text, date etc  For example, the Calculation expression below will sum the number of girls and boys in a class, so the field user does not need to enter the total number.

 

CalculationSurvey123.png

Calculations are pretty straight-forward once you understand the operators you can use. This help topic has a nice table with all the operators supported. I also really like Hanna's Blog Post

 

It may not be obvious how to use Calculations against geopoint questions, but it is possible!  Calculating a geopoint will literally move the map to the computed location. For example, say you have a list of wells and you want the user to select one of them, to set the X/Y coordinates of the well in a geopoint question.Geo_Smaller.gif

 

To Calculate a geopoint, the most important aspect is understanding how geopoints are internally represented in Survey123 for ArcGIS. The format is simple: a space-separated list of valid latitude (decimal degrees) and longitude (decimal degrees). For example, this is how a geopoint question, under the covers, is managed within the Survey123 app:

 

 43.221 -117.342

 

A geopoint object requires at least the latitude and longitude, but additional values can be added for its elevation (in meters), horizontal accuracy (in meters) etc

 

 43.221 -117.342 34 2

 

Of course, that is not what the field user sees, because they see a map... but you need to know how a geopoint object is stored if you want to work with Calculations and Geopoints. If your calculation generates a string like that, the map in your geopoint question will center itself there. You can also set the value of a geopoint question using the default column.

 

Ok, so lets look at this step by step through an example. Pretend we want to build a survey where the user selects a city from a list and have  the map automatically center at that city.

 

The location of every city is encoded in the cities choice list. Note that the coordinates of their location are in the name column. I separated coordinates with an underscore because spaces are not allowed in the name column.

 

 

The calculation expression parses this value to extract and format the data to be passed to the geopoint question. For that, the substr function is used. I had to put care into ensuring that the different values encoded started and ended at fixed positions in the string. That is, I reserved the first 10 characters for the latitude, then I added the separator, and then I left the rest of characters for the longitude etc If needed, I would add extra zeros at the end to make sure the coordinates had exactly the expected number of characters. There are some functions like split, that would theoretically help us parse strings with more flexibility, but at the moment they are not yet supported in Survey123. To properly build the string representing the geopoint object, I used the concat() function.

 

type name label calculation choice_filter

select_one continentcontinentContinent  
select_one citiescitiesCity continent=${continent}
geopointlocationMapconcat(substr(${cities}, 0,10)," ",substr(${cities}, -10)) 

 

Encoding the coordinates in a choice list will  work well for small numbers of points. Storing the coordinates in a CSV file and using pulldata() to get them is recommended if you plan to work with large lists.

 

Survey123 Connect for ArcGIS includes two sample XLSForms that will help you play with the  concept of calculating geopoints. To open the Samples follow these steps:

  1. Open Survey123 Connect or ArcGIS
  2. Click on New Survey
  3. Select the Samples category from the dialog and look for the Calculate Location from Choice List, or Calculate Location from CSV

 

 

 If you would like to block field users from overwriting the location set by your calculation, you can set your geopoint question to read-only.

       

So far, we have learned how a calculation can set the value of a geopoint, but you can also do the reverse. That is, you can use a calculation to extract data from a geopoint question, such as the X,Y and Z values and use them in your own expressions.  This technique uses the pulldata() function and it is described in more detail in thehttps://community.esri.com/groups/survey123/blog/2016/11/03/extracting-information-from-geopoint-que... blog post.

60 Comments
JamesTedrick
Esri Esteemed Contributor

You could make the camera question relevant based on a previous answer, but it still may not do quite what you want.  Just to note, calculating a point based on information like an existing facility location is a different collection methodology from requesting the user's location - normally these shouldn't be mixed (for example, you'll end up with a 'cloud' of points around the facility due to GPS error; if you have the existing location, you should use it to nail down the location).

by Anonymous User
Not applicable

Yes but if the road conditions can either be entered from in situ measurements or based on observations from a camera then I need the ability to enter by both location. 

RobertGeitner
Occasional Contributor

Hello,

I have an existing gdb with thousands of UTM NAD 83 coordinates and I was wondering if I could create a survey and use the pulldata() function in order to create a geopoint based on UTM coordinates. I know you can use the ${locationcalculation} to create a geopoint based on lat longs, but since our surveyors would like to populate this survey with UTM, am I able to create geopoints from those?  

JamesTedrick
Esri Esteemed Contributor

Hi Robert,

There isn't a direct UTM to WGS function in Survey123, though what you are asking for could be done with custom JavaScript function (note this is beta functionality) - utm/index.es.js at master · TimothyGu/utm · GitHub  is one example of the functions needed.

RobertGeitner
Occasional Contributor

James,

So is there any way to create a survey that feeds into an existing feature layer? 

Thanks,

Rob

Nicole_Ueberschär
Esri Regular Contributor

Hi Robert, 

You can use an existing feature layer by adding the url into the submission-url field in the settings. 

The easiest way is to create a new survey using the option "Feature Service" and then select the feature service from your portal. 

You can look up the details here: Use Survey123 with existing feature services—Survey123 for ArcGIS | Documentation 

FanYang
Emerging Contributor

Hi Ismael,

Is it possible to calculate the GeoPoint from user input address geocode? 

Like user input the street number, street name, city and postal code. Can we use these field values to calculate the Geopoint with geocoding instead of lat/long? Thanks!

Fan

Andrew_Winchell
Occasional Contributor

Has this been addressed in any of the newer releases or a possibility using a custom javascript function?

Our workflow requires the assets to be scanned in and information filled out during assembly and then another person will open the survey through the inbox and update the location to where it actually gets placed in the ground. Right now I have a question “Update location?: yes/no”, that if it is no the geopoint is irrelevant but if yes I would like to default to the devices current location.

FredMitchell
Regular Contributor

@JamesTedrick @IsmaelChivite are there any updates on when the bug for allowing the webform geopoint map to move/zoom to a concat/pulldata xy location that is being brought over from the address in another field upon data entry? Also, would love for this not to overwrite the default map extent and initial centering until an address has been entered. For reference on how I'm using this in a current form see the following post (https://community.esri.com/t5/arcgis-survey123-questions/automate-map-zoom-based-on-data-entered-in-...)

FredMitchell
Regular Contributor

Hi @FanYang,

See my post here (https://community.esri.com/t5/arcgis-survey123-questions/automate-map-zoom-based-on-data-entered-in-...) and the reply by @BarbaraWebster1  for how to calculate a geopoint based on an address entered in a previous field. It's still a little buggy and if you're using web form vs the survey123 app it doesn't automatically pan/zoom to the location. It also overrides the default map extent and location. Hoping these bugs will be addressed soon.

Fred