sedona icon indicating copy to clipboard operation
sedona copied to clipboard

Bug: ST_Withins returns False when comparing identical polygons

Open petern48 opened this issue 6 months ago • 3 comments

spark.sql("""
SELECT
    ST_Within(
        ST_GeomFromText('POINT (1 1)'),
        ST_GeomFromText('POINT (1 1)')
    ),  -- True
    ST_Within(
        ST_GeomFromText('POLYGON ((0 0, 1 0, 2 1, 3 1, 0 0))'),
        ST_GeomFromText('POLYGON ((0 0, 1 0, 2 1, 3 1, 0 0))')
    ),  -- False
    ST_Within(
        ST_GeomFromText('MULTIPOLYGON (((0 0, 1 1, 0 1, 0 0)))'),
        ST_GeomFromText('MULTIPOLYGON (((0 0, 1 1, 0 1, 0 0)))')
    )  -- True
""").show()

Above is a query testing ST_Within on identical objects for Points, Polygons, and Multipolygons. The second case for Polygons returns False.

In the PostGIS implementation of ST_Within, "The within relation is reflexive: every geometry is within itself" so I'm guessing the second case is what's wrong.

petern48 avatar Jul 04 '25 02:07 petern48