Skip to content

Commit

Permalink
Merge pull request #298 from getodk/features/xpath/variadic-distance-…
Browse files Browse the repository at this point in the history
…params

Variadic `distance`, minor related XPath geo functionality improvements
  • Loading branch information
eyelidlessness authored Feb 10, 2025
2 parents 81a57c3 + a17a2c6 commit 64f259e
Show file tree
Hide file tree
Showing 17 changed files with 834 additions and 394 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-items-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@getodk/xpath": minor
---

The `xf:distance` function signature is now variadic, consistent with the revised signature specified by ODK XForms.
5 changes: 5 additions & 0 deletions .changeset/funny-items-know2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@getodk/xforms-engine": minor
---

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.
10 changes: 10 additions & 0 deletions .changeset/wise-dancers-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@getodk/xpath": patch
---

Improved consistency with Collect/JavaRosa:


- `area` and `distance` handle a trailing semicolon in serialized semicolon-separated `geopoint` lists
- `distance` produces an error for invalid input
- `area` returns `0` for invalid input
71 changes: 71 additions & 0 deletions packages/common/src/fixtures/xpath-fns/variadic-distance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms"
xmlns:odk="http://www.opendatakit.org/xforms">
<h:head>
<h:title>Examples using the distance() and area() function</h:title>
<model odk:xforms-version="1.0.0">
<instance>
<data id="distance_examples" version="20241025195211">
<location1>-6.8137120026589315 39.29392995851879 400 10</location1>
<location2>-6.815178491608137 39.29533915133268</location2>
<location3>-6.81189589956027 39.2973513889647 600</location3>
<location4>-6.81223343508222 39.29735351357036</location4>
<geoshape_12341 />
<distance_1234 />
<area_1234 />
<distance_mixed />
<distance_via_geoshape />
<meta>
<instanceID />
</meta>
</data>
</instance>
<bind nodeset="/data/location1" readonly="true()" type="string" />
<bind nodeset="/data/location2" readonly="true()" type="string" />
<bind nodeset="/data/location3" readonly="true()" type="string" />
<bind nodeset="/data/location4" readonly="true()" type="string" />
<bind nodeset="/data/geoshape_12341" readonly="true()" type="string"
calculate="join(&quot;; &quot;, /data/location1 , /data/location2 , /data/location3 , /data/location4 , /data/location1 )" />
<bind nodeset="/data/distance_1234" readonly="true()" type="string"
calculate="distance( /data/location1 , /data/location2 , /data/location3 , /data/location4 )" />
<bind nodeset="/data/area_1234" readonly="true()" type="string"
calculate="area( /data/geoshape_12341 )" />
<bind nodeset="/data/distance_mixed" readonly="true()" type="string"
calculate="distance( /data/location1 , /data/location2 , /data/location3 , /data/location4 , '-6.8137120026589315 39.29392995851879 400 10')" />
<bind nodeset="/data/distance_via_geoshape" readonly="true()" type="string"
calculate="distance( /data/geoshape_12341 )" />
<bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid" />
</model>
</h:head>
<h:body>
<input ref="/data/location1">
<label>where 1</label>
</input>
<input ref="/data/location2">
<label>where 2</label>
</input>
<input ref="/data/location3">
<label>where 3</label>
</input>
<input ref="/data/location4">
<label>where 4</label>
</input>
<input ref="/data/geoshape_12341">
<label>geoshape 12341</label>
</input>
<input ref="/data/distance_1234">
<label>distance 1234</label>
</input>
<input ref="/data/area_1234">
<label>area 1234</label>
</input>
<input ref="/data/distance_mixed">
<label>distance 12341 mixed-type arguments</label>
</input>
<input ref="/data/distance_via_geoshape">
<label>distance 12341 via geoshape</label>
</input>
</h:body>
</h:html>
Loading

0 comments on commit 64f259e

Please sign in to comment.