Opened 6 months ago

Closed 4 months ago

Last modified 4 months ago

#4926 closed defect (fixed)

Aggregate ST_Union yields SRID 0 for empty geometries

Reported by: ewie Owned by: pramsey
Priority: medium Milestone: PostGIS 3.0.4
Component: postgis Version: 3.0.x
Keywords: Cc:

Description

Aggregating empty geometries with ST_Union produces an empty geometry with SRID 0 regardless of the SRID of the original geometries (see the query below). Interestingly, ST_MemUnion maintains the original SRID.

Is the behaviour of ST_Union intentional? The documentation doesn't say anything about that.

I had a look into the source code and found that the SRID is determined from the first non-empty geometry and defaults to SRID_UNKNOWN if there are no geometries or only empty geometries. https://trac.osgeo.org/postgis/browser/trunk/postgis/lwgeom_geos.c?rev=17951#L544

with
t(geom) as (
  values
--    (ST_GeomFromText('point (0 0)', 25832)),
    (ST_GeomFromText('point empty', 25832))
),
u(geom) as (
  select ST_Union(geom) from t
),
m(geom) as (
  select ST_MemUnion(geom) from t
)
select 'geom' kind, geom, ST_SRID(geom) from t
union all
select 'ST_Union', geom, ST_SRID(geom) from u
union all
select 'ST_MemUnion', geom, ST_SRID(geom) from m
PostgreSQL 12.3, compiled by Visual C++ build 1914, 64-bit

POSTGIS="3.0.1 3.0.1" [EXTENSION] PGSQL="120" GEOS="3.8.0-CAPI-1.13.1 " SFCGAL="1.3.2" PROJ="Rel. 5.2.0, September 15th, 2018" GDAL="GDAL 2.4.4, released 2020/01/08" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.4.3 (Internal)" TOPOLOGY RASTER

Change History (4)

comment:1 Changed 6 months ago by robe

Milestone: PostGIS 3.0.4

comment:2 Changed 4 months ago by Paul Ramsey <pramsey@…>

Resolution: fixed
Status: newclosed

In 43b1ea0b/git:

Preserve SRID on all-empty unions of geometry, closes #4926

comment:3 Changed 4 months ago by Paul Ramsey <pramsey@…>

In 78df938/git:

Preserve SRID on all-empty unions of geometry, closes #4926

comment:4 Changed 4 months ago by Paul Ramsey <pramsey@…>

In 7838435/git:

Preserve SRID on all-empty unions of geometry, closes #4926

Note: See TracTickets for help on using tickets.