Skip to content

ST_Contains(POLYGON_2D, POINT_2D) false positives when point latitude equals polygon vertex latitude #806

@khdlr

Description

@khdlr

ST_Contains(POLYGON_2D, POINT_2D) false positive outside polygon bbox

ST_Contains returns true for a point that is clearly outside the polygon bbox when using the typed POLYGON_2D / POINT_2D overload. (Possibly related issue: #434)

Repro

LOAD spatial;

WITH poly AS (
  SELECT ST_GeomFromText(
    'POLYGON ((
      11.6742158 48.156714,
      11.6781624 48.144285,
      11.6837275 48.1447925,
      11.6742158 48.156714
    ))'
  ) AS geom
),
pts AS (
  SELECT * FROM (VALUES
    (-123.1061120::DOUBLE, 48.144285::DOUBLE)
  ) AS t(lon, lat)
)
SELECT
  ST_XMin(geom) AS xmin,
  ST_XMax(geom) AS xmax,
  ST_Contains(geom::POLYGON_2D, ST_MakePoint(lon, lat)::POINT_2D) AS typed_contains,
  ST_Contains(geom, ST_MakePoint(lon, lat)::GEOMETRY) AS generic_contains
FROM poly, pts;

Result

The polygon x-range is about 11.674–11.684, but the test point has lon = -123.106112.

Expected:

typed_contains = false
generic_contains = false

Actual:

typed_contains = true
generic_contains = false

This seems to happen when the point latitude equals a local-minimum vertex latitude of the polygon.

Environment

OS: Linux 6.19.14
DuckDB version: v1.5.2
Spatial Extension version:

┌───────────────────┬──────────────┬────────────────┐
│ extension_version │ install_mode │ installed_from │
│      varchar      │   varchar    │    varchar     │
├───────────────────┼──────────────┼────────────────┤
│ dc1996b           │ REPOSITORY   │ core           │
└───────────────────┴──────────────┴────────────────┘

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions