[postgis-tickets] r14884 - #3470, ST_Polygonize doesn't accept NULL geometries
Daniel Baston
dbaston at gmail.com
Wed May 4 15:02:48 PDT 2016
Author: dbaston
Date: 2016-05-04 15:02:48 -0700 (Wed, 04 May 2016)
New Revision: 14884
Modified:
branches/2.2/postgis/lwgeom_accum.c
branches/2.2/postgis/lwgeom_geos.c
branches/2.2/regress/tickets.sql
branches/2.2/regress/tickets_expected
Log:
#3470, ST_Polygonize doesn't accept NULL geometries
Modified: branches/2.2/postgis/lwgeom_accum.c
===================================================================
--- branches/2.2/postgis/lwgeom_accum.c 2016-05-04 21:48:46 UTC (rev 14883)
+++ branches/2.2/postgis/lwgeom_accum.c 2016-05-04 22:02:48 UTC (rev 14884)
@@ -275,7 +275,9 @@
p = (pgis_abs*) PG_GETARG_POINTER(0);
geometry_array = pgis_accum_finalfn(p, CurrentMemoryContext, fcinfo);
- result = DirectFunctionCall1( polygonize_garray, geometry_array );
+ result = PGISDirectFunctionCall1( polygonize_garray, geometry_array );
+ if (!result)
+ PG_RETURN_NULL();
PG_RETURN_DATUM(result);
}
Modified: branches/2.2/postgis/lwgeom_geos.c
===================================================================
--- branches/2.2/postgis/lwgeom_geos.c 2016-05-04 21:48:46 UTC (rev 14883)
+++ branches/2.2/postgis/lwgeom_geos.c 2016-05-04 22:02:48 UTC (rev 14884)
@@ -3371,7 +3371,6 @@
PG_FUNCTION_INFO_V1(polygonize_garray);
Datum polygonize_garray(PG_FUNCTION_ARGS)
{
- Datum datum;
ArrayType *array;
int is3d = 0;
uint32 nelems, i;
@@ -3379,7 +3378,6 @@
GEOSGeometry *geos_result;
const GEOSGeometry **vgeoms;
int srid=SRID_UNKNOWN;
- size_t offset;
#if POSTGIS_DEBUG_LEVEL >= 3
static int call=1;
#endif
@@ -3388,48 +3386,22 @@
call++;
#endif
- datum = PG_GETARG_DATUM(0);
+ if (PG_ARGISNULL(0))
+ PG_RETURN_NULL();
- /* Null array, null geometry (should be empty?) */
- if ( (Pointer *)datum == NULL ) PG_RETURN_NULL();
+ array = PG_GETARG_ARRAYTYPE_P(0);
+ nelems = array_nelems_not_null(array);
- array = DatumGetArrayTypeP(datum);
+ if (nelems == 0)
+ PG_RETURN_NULL();
- nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
+ POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
- POSTGIS_DEBUGF(3, "polygonize_garray: number of elements: %d", nelems);
-
- if ( nelems == 0 ) PG_RETURN_NULL();
-
/* Ok, we really need geos now ;) */
initGEOS(lwpgnotice, lwgeom_geos_error);
- vgeoms = palloc(sizeof(GEOSGeometry *)*nelems);
- offset = 0;
- for (i=0; i<nelems; i++)
- {
- GEOSGeometry* g;
- GSERIALIZED *geom = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
- offset += INTALIGN(VARSIZE(geom));
- if ( ! is3d ) is3d = gserialized_has_z(geom);
+ vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
- g = (GEOSGeometry *)POSTGIS2GEOS(geom);
- if ( 0 == g ) /* exception thrown at construction */
- {
- HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
- PG_RETURN_NULL();
- }
- vgeoms[i] = g;
- if ( ! i )
- {
- srid = gserialized_get_srid(geom);
- }
- else
- {
- error_if_srid_mismatch(srid, gserialized_get_srid(geom));
- }
- }
-
POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
geos_result = GEOSPolygonize(vgeoms, nelems);
@@ -3450,10 +3422,7 @@
PG_RETURN_NULL(); /*never get here */
}
- /*compressType(result); */
-
PG_RETURN_POINTER(result);
-
}
Modified: branches/2.2/regress/tickets.sql
===================================================================
--- branches/2.2/regress/tickets.sql 2016-05-04 21:48:46 UTC (rev 14883)
+++ branches/2.2/regress/tickets.sql 2016-05-04 22:02:48 UTC (rev 14884)
@@ -943,5 +943,9 @@
UNION ALL
SELECT '#3437e' AS t, count(*) FROM mp INNER JOIN p ON ST_Within(p.geom, mp.geom);
+-- #3470
+SELECT '#3470', ST_Polygonize(ARRAY[NULL]::geometry[]) IS NULL;
+SELECT '#3470b', ST_Area(ST_Polygonize(ARRAY[NULL, 'LINESTRING (0 0, 10 0, 10 10)', NULL, 'LINESTRING (0 0, 10 10)', NULL]::geometry[]));
+
-- Clean up
DELETE FROM spatial_ref_sys;
Modified: branches/2.2/regress/tickets_expected
===================================================================
--- branches/2.2/regress/tickets_expected 2016-05-04 21:48:46 UTC (rev 14883)
+++ branches/2.2/regress/tickets_expected 2016-05-04 22:02:48 UTC (rev 14884)
@@ -289,3 +289,5 @@
#3437c|5
#3437d|5
#3437e|5
+#3470|t
+#3470b|50
More information about the postgis-tickets
mailing list