[postgis-tickets] [PostGIS] #4926: Aggregate ST_Union yields SRID 0 for empty geometries

PostGIS trac at osgeo.org
Tue Jun 8 03:38:03 PDT 2021


#4926: Aggregate ST_Union yields SRID 0 for empty geometries
---------------------+---------------------
 Reporter:  ewie     |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  medium   |  Milestone:
Component:  postgis  |    Version:  3.0.x
 Keywords:           |
---------------------+---------------------
 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
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4926>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list