Skip to content

ST_Envelope and ST_Envelope_Aggr have inconsistent edge case handling with PostGIS #1979

@paleolimbot

Description

@paleolimbot

In Sedona, we get an empty point back for a scalar envelope and an arbitrary polygon back for empty aggregate envelope:

from sedona.spark import *

config = SedonaContext.builder().getOrCreate()
sedona = SedonaContext.create(config)

sedona.sql("SELECT ST_Envelope(ST_GeomFromWKT('LINESTRING EMPTY'))").show()
#> +------------------------------------------------+
#> |st_envelope(st_geomfromwkt(LINESTRING EMPTY, 0))|
#> +------------------------------------------------+
#> |                                     POINT EMPTY|
#> +------------------------------------------------+

sedona.sql("SELECT ST_Envelope_Aggr(ST_GeomFromWKT('LINESTRING EMPTY'))").show()
#> +-----------------------------------------------------+
#> |st_envelope_aggr(st_geomfromwkt(LINESTRING EMPTY, 0))|
#> +-----------------------------------------------------+
#> |                                 POLYGON ((-1 -1, ...|
#> +-----------------------------------------------------+

In PostGIS, we get an EMPTY of the same type back for a scalar ST_Envelope and a NULL back for empty input of an aggregate (there is no aggregate envelope in PostGIS that I'm aware of).

# docker run --rm postgis/postgis:latest
postgres=# SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LINESTRING EMPTY')));
    st_astext     
------------------
 LINESTRING EMPTY
(1 row)

postgres=# SELECT ST_AsText(ST_Extent(ST_GeomFromText('LINESTRING EMPTY')));
 st_astext 
-----------
 
(1 row)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions