ODK XForms spec proposal: add `intersects` XPath function to detect geotrace/shape intersections

In support of Blocking invalid (self-intersecting) polygons in Collect, we propose adding the following function to the spec:

The intersects function takes in a geotrace or geoshape and returns true if the geometry self-intersects (any line between two vertices in the shape crosses another one), false otherwise. If the parameter type is not geotrace, geoshape, or a string with that formatting, an error is thrown.

An example constraint for a geoshape question that must not have self-intersections would be:

not(intersects(.))

This leaves open the possibility of eventually extending the function to take in multiple trace/shape parameters and computing whether there are intersections between any of them.

The only related prior art we found was the EXPath geo package which defined a very similar intersects function. This function fits in well with other geo functions in the ODK XPath spec: area, distance, geofence.

Please let us know if you have any questions or comments!

2 Likes

Just to be mischievous… :nerd_face:

Polygons can arguably also self-intersect across a point, or even at a point (!). eg A

The order of the vertices can further complicate matters - eg does B ‘self-intersect’?

[FWIW similar degenerate cases - with point intersections - came up with geofence… :man_facepalming: ]

1 Like

There are so many fun and annoying cases, thanks for sharing yours!

A we consider a self-intersection because either 2 and 5 are exactly the same point or the segments 1,3 and 4,6 intersect very close to 2 and 5.

B we consider an intersection if and only if 2 and 5 are identical or 5 is "above" 2 (further up on the y axis). If 2 and 5 look really close but 2 is ever so slightly further "above" 5, it would not be an intersection even if it visually appears like one.

More details and a beta to try at Understanding invalid polygon (Self-Intersecting) issues in Collect - #15 by LN