Calculating distances between locations (geopoints) in Survey123 with the Haversine Formula

Consider the scenario where a person is applying for a liquor licence and the law stipulates: New liquor premises must be located at least five hundred meters (500m) away from schools, places of worship; recreation facilities, rehabilitation or retreat centers, residential areas and public institutions.

For this requirement Survey123 can be a valuable tool and in this blog post I will show you how you can enable this functionality in a Survey123 form:

Step 1: Create a new survey with Survey123 Connect

Step 2: Create a geopoint field in the main survey which will be used to capture the location of the new licence premises

Step 3: Create a repeated section to capture the occurrences of nearby schools, places of worship etc. Each with a premise type and a geopoint

Your survey design should look similar to this:

type name label
geopoint new_licence_location New Licence Location
begin repeat nearby_places Nearby Permises
select_one category place_type Type of Premises
geopoint nearby_location Nearby Location
end repeat

Step 4: Now, split both the coordinates sets into their x,y pairs and convert them to radians:

calculate gps_lat gps lat pulldata(‘@geopoint’, ${new_licence_location}, ‘y’) * pi() div 180
calculate gps_long gps long pulldata(“@geopoint”, ${new_licence_location}, “x”) * pi() div 180

Do the same for the nearby_location geopoint field.
Step 5: Use the X, Y pairs to perform the distance calculation (in meters) with the Haversine formula:

acos(sin(${gps_lat_end})*sin(${gps_lat}) + cos(${gps_lat_end})*cos(${gps_lat})*cos(${gps_long}-${gps_long_end}) ) * 6371000

After having made some cosmetic enhancements and adding the 500m stipulation your survey should look like this:

DistanceCalcScreen

Feel free to use and adapt as you require. Here is a link to the Survey123 Excel design file: Licence Application

Mathematically Verifying South African ID Numbers with Survey123

This blog post describes how South African ID numbers can be verified mathematically in Survey123. South African ID numbers have the following format:

{YYMMDD}{G}{SSS}{C}{A}{Z}

YYMMDD : Date of birth.
G  : Gender. 0-4 Female; 5-9 Male.
SSS  : Sequence No. for DOB/G combination.
C  : Citizenship. 0 SA; 1 Other.
A  : Usually 8, or 9
Z  : Control digit

The most challenging part of verifying the ID number is the control digit which is calculated by using the Luhn algorithm – this will be the focus of this blog post.

The best way to tackle complex mathematical functions in Survey123 is to break it up into separate mathematical calculations and using calculated fields:

The check digit is the last digit of the SA ID number so it can be retrieved with the following function: substr(${idnr}, string-length(${idnr}) – 1, string-length(${idnr})) where ${idnr} refers to the captured ID number.

Once you have an understanding of the substr() function the rest of the calculations used to verify the ID number is pretty much straight forward.

The survey’s XLSForm file can be found here (and can be freely used): SA Id number

  1. Copy the file to your downloads folder
  2. Open Survey123 Connect
  3. Create a New Survey and base it on an existing file
  4. Choose the Excel file that you have downloaded
  5. Your survey will be generated

Notes:

  1. The SA ID Number does not indicate if a user was born in 19yy or 20yy so both options are catered for – with a logic test to see if the birth date is in the future (age not greater than zero)
  2. Race is no longer indicated in the SA ID Number

Three Steps to Asset Management with ArcGIS Online and Collector

Three quick steps to do Asset Management with Collector and ArcGIS Online:

Step 1 (ArcMap) – Authoring your feature classes and tables:

What you need: ArcMap and an ArcGIS Online Organizational Account

  • Create a database in ArcMap
  • Create a (point) Feature Class to store your Assets
  • Create a Table to store your Assets’ Condition Assessments
  • Create a Table to store Maintenance Tasks associated with your Assets
  • Link them all together with Relationship Classes to create a 1:M link between Assets and Assessments and Assets and Maintenance Tasks

ArcMap Asset Management FCs

  • Add the Asset Feature Class and the two related tables to a map document and publish it as a service to your ArcGIS Online account

Step 2 (ArcGIS Online) – Authoring your Web Map for use in Collector:

What you need: An ArcGIS Online Organizational Account

  • Create a new Map in AGOL and add your newly created Asset Management service to it
  • Add a basemap of your choice to your Map
  • Save your Map

Step 3 (Collector) – Deploying your Asset Management application:

What you need: An iPhone or Android phone with the Collector for ArcGIS Application installed

  • Start Collector and log in with your AGOL credentials
  • Open the Map created in Step 2
  • Start performing your Asset Management tasks!

Collector 1

For some additional images relating to this post – please see here: Asset Management Images

Homework for the avid reader:

  • Add a Tracking Layer for Field Workers to the AGOL Web Map
  • Install ArcGIS Operations Dashboard
  • Create a Dashboard that monitors real-time field activities such as Field Worker positions, Assets that require maintenance etc

OPS Dashboard