[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.3-16-gb7d9df3
git at osgeo.org
git at osgeo.org
Fri Mar 5 03:47:18 PST 2021
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, stable-3.0 has been updated
via b7d9df342268c9614e40978f54b229f52cb7012c (commit)
from 0091177ea6801e75ce0ac0f7b1487e8ee711f95e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit b7d9df342268c9614e40978f54b229f52cb7012c
Author: Sandro Santilli <strk at kbt.io>
Date: Fri Mar 5 12:04:39 2021 +0100
Fix SRID in Geometry(TopoGeometry) for empty TopoGeometry objects
Includes testcase and NEWS item
References #4871 in 3.0 branch (3.0.4dev)
diff --git a/NEWS b/NEWS
index f6dce68..934f625 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
-PostGIS 3.04
+PostGIS 3.0.4dev
2021/xx/xx
+ - #4871, TopoGeometry::geometry cast returns NULL for empty
+ TopoGeometry objects (Sandro Santilli)
- #4817, Handle complex compound coordinate systems (Paul Ramsey)
- Support newer proj versions that have deprecated pj_get_release (Paul Ramsey)
- #4835, Adjust geodetic tolerance for calculations (Paul Ramsey)
diff --git a/topology/test/Makefile.in b/topology/test/Makefile.in
index 4ec466e..b4c1c06 100644
--- a/topology/test/Makefile.in
+++ b/topology/test/Makefile.in
@@ -74,6 +74,7 @@ TESTS = regress/legacy_validate.sql regress/legacy_predicate.sql \
regress/createtopogeom.sql \
regress/createtopology.sql \
regress/gml.sql \
+ regress/geometry_cast.sql \
regress/getnodebypoint.sql \
regress/getedgebypoint.sql \
regress/getfacebypoint.sql \
diff --git a/topology/test/regress/geometry_cast.sql b/topology/test/regress/geometry_cast.sql
new file mode 100644
index 0000000..5e65870
--- /dev/null
+++ b/topology/test/regress/geometry_cast.sql
@@ -0,0 +1,51 @@
+\set VERBOSITY terse
+set client_min_messages to WARNING;
+
+select NULL FROM createtopology('tt', 4326);
+
+-- layer 1 is PUNTUAL
+CREATE TABLE tt.f_point(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_point', 'g', 'POINT');
+
+-- layer 2 is LINEAL
+CREATE TABLE tt.f_line(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_line', 'g', 'LINE');
+
+-- layer 3 is AREAL
+CREATE TABLE tt.f_area(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_area', 'g', 'POLYGON');
+
+-- layer 4 is MIXED
+CREATE TABLE tt.f_coll(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_coll', 'g', 'COLLECTION');
+
+-- layer 5 is HIERARCHICAL PUNTUAL
+CREATE TABLE tt.f_hier_point(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_hier_point', 'g', 'POINT', 1);
+
+-- layer 6 is HIERARCHICAL LINEAL
+CREATE TABLE tt.f_hier_line(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_hier_line', 'g', 'LINE', 2);
+
+-- layer 7 is HIERARCHICAL AREAL
+CREATE TABLE tt.f_hier_area(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_hier_area', 'g', 'POLYGON', 3);
+
+-- layer 8 is HIERARCHICAL MIXED
+CREATE TABLE tt.f_hier_coll(id serial);
+SELECT NULL FROM AddTopoGeometryColumn('tt', 'tt', 'f_hier_coll', 'g', 'COLLECTION', 4);
+
+
+-- Cast empties
+SELECT 'empty', 'puntal', ST_AsEWKT(CreateTopoGeom('tt', 1, 1)::geometry);
+SELECT 'empty', 'lineal', ST_AsEWKT(CreateTopoGeom('tt', 2, 2)::geometry);
+SELECT 'empty', 'areal', ST_AsEWKT(CreateTopoGeom('tt', 3, 3)::geometry);
+SELECT 'empty', 'mixed', ST_AsEWKT(CreateTopoGeom('tt', 4, 4)::geometry);
+
+SELECT 'empty', 'hier', 'puntal', ST_AsEWKT(CreateTopoGeom('tt', 1, 5)::geometry);
+SELECT 'empty', 'hier', 'lineal', ST_AsEWKT(CreateTopoGeom('tt', 2, 6)::geometry);
+SELECT 'empty', 'hier', 'areal', ST_AsEWKT(CreateTopoGeom('tt', 3, 7)::geometry);
+SELECT 'empty', 'hier', 'mixed', ST_AsEWKT(CreateTopoGeom('tt', 4, 8)::geometry);
+
+-- Cleanup
+SELECT NULL FROM DropTopology('tt');
diff --git a/topology/test/regress/geometry_cast_expected b/topology/test/regress/geometry_cast_expected
new file mode 100644
index 0000000..b692443
--- /dev/null
+++ b/topology/test/regress/geometry_cast_expected
@@ -0,0 +1,8 @@
+empty|puntal|SRID=4326;MULTIPOINT EMPTY
+empty|lineal|SRID=4326;MULTILINESTRING EMPTY
+empty|areal|SRID=4326;MULTIPOLYGON EMPTY
+empty|mixed|SRID=4326;GEOMETRYCOLLECTION EMPTY
+empty|hier|puntal|SRID=4326;MULTIPOINT EMPTY
+empty|hier|lineal|SRID=4326;MULTILINESTRING EMPTY
+empty|hier|areal|SRID=4326;MULTIPOLYGON EMPTY
+empty|hier|mixed|SRID=4326;GEOMETRYCOLLECTION EMPTY
diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index d0903d9..b822ee7 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -1230,10 +1230,12 @@ LANGUAGE 'plpgsql' STABLE STRICT;
-- }{
CREATE OR REPLACE FUNCTION topology.Geometry(topogeom topology.TopoGeometry)
RETURNS Geometry
-AS $$
+AS $BODY$
DECLARE
toponame varchar;
+ toposrid INT;
geom geometry;
+ elements_count INT;
rec RECORD;
plyr RECORD;
clyr RECORD;
@@ -1241,9 +1243,9 @@ DECLARE
BEGIN
-- Get topology name
- SELECT name FROM topology.topology
+ SELECT name, srid FROM topology.topology
WHERE id = topogeom.topology_id
- INTO toponame;
+ INTO toponame, toposrid;
IF toponame IS NULL THEN
RAISE EXCEPTION 'Invalid TopoGeometry (unexistent topology id %)', topogeom.topology_id;
END IF;
@@ -1293,15 +1295,41 @@ BEGIN
ELSIF topogeom.type = 3 THEN -- [multi]polygon -- }{
- sql := 'SELECT st_multi(st_union('
- 'topology.ST_GetFaceGeometry('
- || quote_literal(toponame) || ','
- || 'element_id))) as g FROM '
- || quote_ident(toponame)
- || '.relation WHERE topogeo_id = '
- || topogeom.id || ' AND layer_id = '
- || topogeom.layer_id || ' AND element_type = 3 ';
- EXECUTE sql INTO geom;
+ sql := format(
+ $$
+SELECT
+ count(element_id),
+ ST_Multi(
+ ST_Union(
+ topology.ST_GetFaceGeometry(
+ %1$L,
+ element_id
+ )
+ )
+ ) as g
+FROM %1$I.relation
+WHERE topogeo_id = %2$L
+AND layer_id = %3$L
+AND element_type = 3
+ $$,
+ toponame,
+ topogeom.id,
+ topogeom.layer_id
+ );
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+ RAISE DEBUG 'Query: %', sql;
+#endif
+ EXECUTE sql INTO elements_count, geom;
+
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+ RAISE DEBUG 'TopoGeometry of type 3 (areal)'
+ ' in topo with srid % defined by % face elements'
+ ' casted to geometry with srid %',
+ toposrid,
+ elements_count,
+ ST_Srid(geom)
+ ;
+#endif
ELSIF topogeom.type = 2 THEN -- [multi]line -- }{
@@ -1372,11 +1400,12 @@ BEGIN
ELSE
geom := 'GEOMETRYCOLLECTION EMPTY';
END IF;
+ geom := ST_SetSRID(geom, toposrid);
END IF;
RETURN geom;
END
-$$
+$BODY$
LANGUAGE 'plpgsql' VOLATILE STRICT;
--} Geometry(TopoGeometry)
-----------------------------------------------------------------------
Summary of changes:
NEWS | 4 +-
topology/test/Makefile.in | 1 +
topology/test/regress/geometry_cast.sql | 51 ++++++++++++++++++++++++++
topology/test/regress/geometry_cast_expected | 8 ++++
topology/topology.sql.in | 55 +++++++++++++++++++++-------
5 files changed, 105 insertions(+), 14 deletions(-)
create mode 100644 topology/test/regress/geometry_cast.sql
create mode 100644 topology/test/regress/geometry_cast_expected
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list