duckdb / duckdb/duckdb-spatial
Unpredictable/incorrect results for ST_Contains with Polygon_2D and Point_2D geometries
- Dominant language
- C
- Stars
- 708
- Forks
- 96
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 5
Description
DuckDB Version: v1.1.2 f680b7d08f
MacOS 14.4.1 (M2)
Installed via Homebrew
I have uploaded a sample database here which is needed to reproduce the problem: https://www.dropbox.com/s/up7uvgdz15924dr/test.tar.xz?dl=0
*This issue is only reproducible with a persistent database, not an in-memory database*
Steps to reproduce issue:
```
LOAD spatial;
# Import sample database
IMPORT DATABASE 'test';
# Import doesn't work with Point_2D columns (I have filed a separate issue about that), so we create it now:
ALTER TABLE test ADD COLUMN location Point_2D;
UPDATE test SET location = ST_Point2D(lon, lat);
# The following query should return no results, but it returns 98 rows
SELECT id
FROM test
WHERE list_contains(area_layer_ids, 2)
AND ST_Contains('POLYGON ((145.16503 -37.92571, 145.24262 -37.86881, 145.30991 -37.91, 145.31163 -37.92869, 145.16503 -37.92571))'::Geometry::Polygon_2D, location);
# If I change 'location' to ST_Point2D(lon,lat), the query works as expected (returns zero rows):
SELECT id
FROM test
WHERE list_contains(area_layer_ids, 2)
AND ST_Contains('POLYGON ((145.16503 -37.92571, 145.24262 -37.86881, 145.30991 -37.91, 145.31163 -37.92869, 145.16503 -37.92571))'::Geometry::Polygon_2D, ST_Point2D(lon,lat));
```
I tried to come up with a smaller reproducible example, e.g. removing `list_contains` from the query, or using a smaller dataset, but this seemed to prevent the bug from being triggered.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.