Skip to content

The new --de9im reports duplicate or even contradictory relations for identical geometries with ≥ 500 points #23

Description

@hannahbast

For two byte-identical geometries with at least DUPLICATE_REMOVAL_MIN_SIZE = 500 points, the --de9im output contains every relation twice. With fewer points, or with the classic relations (equals etc.), the same input is reported once. For polygons the two reports are identical. For linestrings they can disagree: the same directed pair is reported once with matrix M and once with M transposed (e.g. 10FF0FFF2 and 1FF00FFF2), and for byte-identical geometries the true matrix must be transpose-symmetric, so at least one of the two is wrong.

Here is a minimal example, two identical 1000-vertex ellipses (generator below):

$ ./spatialjoin --de9im < ellipse.txt
a	2FFF1FFF2	b
a	2FFF1FFF2	b
b	2FFF1FFF2	a
b	2FFF1FFF2	a

With 400 instead of 1000 vertices, each line appears once. The probable cause and a suggested (verified) fix are in the first comment below.

NOTE: I found this via the DE-9IM spatial join in QLever (ad-freiburg/qlever#3183). Joining the 162 Luxembourg OSM admin boundaries with themselves returns 180 instead of 162 pairs. The 18 extra rows are exactly the boundaries with ≥ 500 points.

python3 -c "
import math
n = 1000  # with 400, the output is correct
pts = ','.join(f'{5+3*math.cos(2*math.pi*i/n):.7f} {50+2*math.sin(2*math.pi*i/n):.7f}' for i in range(n+1))
print(f'a\tPOLYGON(({pts}))\nb\tPOLYGON(({pts}))')" > ellipse.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions