Calculate distance between geopoints

Hi all,

I am using ODK Collect (1.21.2) and XLS form, and I am designing a form to record locations for field collected insect samples. I'd like each new sampling location (in the same form) to be over a minimum distance from the one before it. Is it possible in the form to 1.Calculate the linear distance between sample geopoints, and 2. Have a constraint based on this minimum distance for new geopoints?

Any advice/assistance would be greatly appreciated...

If you put your two geopoints in a geotrace, you can measure the distance of the trace - ie the distance between the two locations - using the ODK distance() function.

After which you can use this value in a constraint no different than a regular constraint calculation; eg ${distance} < 100

1 Like

@Xiphware I had considered this, but the sample points need to selected independently, and there are several questions in the form related to sample collection information following the first geopoint selection, and before the selection (and geopoint) of the next sample collection location. Does that make sense?

You do not need to capture an actual geotrace per se - you can in fact construct a geotrace by simply concat'ing two (independently acquired) geopoints together, separated by a ';', eg

concat(${location1}, ';', ${location2})

Try this:

geopointdistance.xls (5.5 KB)



Works perfectly. Thanks @Xiphware!

Hello, i try to download the example but appear a message that the site do not exist.

Please is the output in metres?

per distance() :

distance(nodeset | geoshape | geotrace)

Returns the distance, in meters, of either:

  • a nodeset of geopoints
  • the perimeter of a geoshape
  • the length of a geotrace value

Hi @Xiphware thank you this is good. But is there a way I can make the location 1 a constant in all the forms. ie. the enumerator will be coming from the same location(their house) each day to carry out activities, then location 2 is taken at the point of activity.
This is so that they do not have to keep taking the coordinates of their homes each time before they leave.