sedona
sedona copied to clipboard
ST_Envelope and ST_Envelope_Aggr have inconsistent edge case handling with PostGIS
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)
I had like to fix issue #1979 to align ST_Envelope and ST_Envelope_Aggr behavior with PostGIS. I will make scalar empty inputs return the same empty geometry and have aggregates return NULL on empty inputs.