Distance between geopoint from csv and newly collected geo point

Hi @Xiphware,
I am trying to find the distance between a geo point (lat, long) stored in a csv file and a new geo point submitted through the form using the distance() function. However, I get the error

The function 'distance' received a value that does not represent GPS coordinates

whenever I try to deploy the form. Is there a way to use coordinates from a file with the distance function? I have attached the form and coordinates samples.

nurseryKPI_v2.xlsx (22.9 KB)
preload_polygon.csv (6.8 KB)

Thanks

I managed to figure it out. Everything read from a csv file is treated as a string, so I was basically passing the distance function a string and it didn't know what to do with that, hence the error. So enclosing my pulldata() in the number() solved it :slight_smile: . 24 hours plus just trying to figure this little issue out.

Thank you for sharing what you discovered!

Well done! Can you perhaps post your updated corrected form, for the benefit of future generations... :slightly_smiling_face:

Sure thing. Below is the updated form with the correction.
nurseryKPI_v2.xlsx (19.6 KB)

1 Like

Thanks. I took a closer look at your calculations, I spotted a couple potential gotches...

First, when you programmatically construct a geopoint from your 'pulled' latitude and longitude you omit the altitude and elevation, which are strictly required by the specification for a geopoint.

nurserygeopoint = concat(${nurserylatitude},' ',${nurserylongitude})

whereas a geopoint actually consist of 4 fields; from https://docs.getodk.org/form-question-types/#location-widgets

For example, if a Collect user captured a point while at the coordinates 12°22'17.0"N 1°31'10.9"W, with a reported accuracy radius of 17.4 meters, and at 305 meters above sea level, the geopoint representation would be:

12.371400 -1.519700 305 17.4

but your calculation is missing altitude and accuracy values.

Although the distance() function doesn't need either the altitude or accuracy for its calculations - and appears to ignore the fact they are missing, fortunately! - you should be very careful when manually constructing value types that have a prescribed format. Other geo functions and calculations may well rely upon these fields and would therefore probably barf if fed your particular geopoint.

I might therefore suggest the following change:

nurserygeopoint = concat(${nurserylatitude},' ',${nurserylongitude},' 0 0')

Similarly, when you combine the two geopoints into a geotrace with

distancegeopoint = concat(${nurserygeopoint},' ; ',${gps})

I notice that your delimiter has leading and trailing spaces (!). Again, you should tread somewhat carefully with these formats, and although the distance() function is ignoring this whitespace, I'd probably recommend sticking with a single ';' delimiter just to be safe.

distancegeopoint = concat(${nurserygeopoint},';',${gps})

1 Like