Skip to content

Commit 64f259e

Browse files
Merge pull request #298 from getodk/features/xpath/variadic-distance-params
Variadic `distance`, minor related XPath geo functionality improvements
2 parents 81a57c3 + a17a2c6 commit 64f259e

File tree

17 files changed

+834
-394
lines changed

17 files changed

+834
-394
lines changed

.changeset/funny-items-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@getodk/xpath": minor
3+
---
4+
5+
The `xf:distance` function signature is now variadic, consistent with the revised signature specified by ODK XForms.

.changeset/funny-items-know2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@getodk/xforms-engine": minor
3+
---
4+
5+
The `xf:distance` XPath function now accepts multiple arguments. This makes it easier to compute the distance between multiple points within a form's primary instance. Previously, to achieve this, you'd have to introduce a `calculate` which concatenates those points together, then call the distance function with a reference to that `calculate` as the argument.

.changeset/wise-dancers-itch.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@getodk/xpath": patch
3+
---
4+
5+
Improved consistency with Collect/JavaRosa:
6+
7+
8+
- `area` and `distance` handle a trailing semicolon in serialized semicolon-separated `geopoint` lists
9+
- `distance` produces an error for invalid input
10+
- `area` returns `0` for invalid input
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0"?>
2+
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml"
3+
xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4+
xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms"
5+
xmlns:odk="http://www.opendatakit.org/xforms">
6+
<h:head>
7+
<h:title>Examples using the distance() and area() function</h:title>
8+
<model odk:xforms-version="1.0.0">
9+
<instance>
10+
<data id="distance_examples" version="20241025195211">
11+
<location1>-6.8137120026589315 39.29392995851879 400 10</location1>
12+
<location2>-6.815178491608137 39.29533915133268</location2>
13+
<location3>-6.81189589956027 39.2973513889647 600</location3>
14+
<location4>-6.81223343508222 39.29735351357036</location4>
15+
<geoshape_12341 />
16+
<distance_1234 />
17+
<area_1234 />
18+
<distance_mixed />
19+
<distance_via_geoshape />
20+
<meta>
21+
<instanceID />
22+
</meta>
23+
</data>
24+
</instance>
25+
<bind nodeset="/data/location1" readonly="true()" type="string" />
26+
<bind nodeset="/data/location2" readonly="true()" type="string" />
27+
<bind nodeset="/data/location3" readonly="true()" type="string" />
28+
<bind nodeset="/data/location4" readonly="true()" type="string" />
29+
<bind nodeset="/data/geoshape_12341" readonly="true()" type="string"
30+
calculate="join(&quot;; &quot;, /data/location1 , /data/location2 , /data/location3 , /data/location4 , /data/location1 )" />
31+
<bind nodeset="/data/distance_1234" readonly="true()" type="string"
32+
calculate="distance( /data/location1 , /data/location2 , /data/location3 , /data/location4 )" />
33+
<bind nodeset="/data/area_1234" readonly="true()" type="string"
34+
calculate="area( /data/geoshape_12341 )" />
35+
<bind nodeset="/data/distance_mixed" readonly="true()" type="string"
36+
calculate="distance( /data/location1 , /data/location2 , /data/location3 , /data/location4 , '-6.8137120026589315 39.29392995851879 400 10')" />
37+
<bind nodeset="/data/distance_via_geoshape" readonly="true()" type="string"
38+
calculate="distance( /data/geoshape_12341 )" />
39+
<bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid" />
40+
</model>
41+
</h:head>
42+
<h:body>
43+
<input ref="/data/location1">
44+
<label>where 1</label>
45+
</input>
46+
<input ref="/data/location2">
47+
<label>where 2</label>
48+
</input>
49+
<input ref="/data/location3">
50+
<label>where 3</label>
51+
</input>
52+
<input ref="/data/location4">
53+
<label>where 4</label>
54+
</input>
55+
<input ref="/data/geoshape_12341">
56+
<label>geoshape 12341</label>
57+
</input>
58+
<input ref="/data/distance_1234">
59+
<label>distance 1234</label>
60+
</input>
61+
<input ref="/data/area_1234">
62+
<label>area 1234</label>
63+
</input>
64+
<input ref="/data/distance_mixed">
65+
<label>distance 12341 mixed-type arguments</label>
66+
</input>
67+
<input ref="/data/distance_via_geoshape">
68+
<label>distance 12341 via geoshape</label>
69+
</input>
70+
</h:body>
71+
</h:html>

0 commit comments

Comments
 (0)