PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ coverage_read_partition_into_collection()

static GEOSGeometry * coverage_read_partition_into_collection ( WindowObject  winobj,
coverage_context context 
)
static

Definition at line 519 of file lwgeom_window.c.

522{
523 int64 rowcount = WinGetPartitionRowCount(winobj);
524 GEOSGeometry* geos;
525 GEOSGeometry** geoms;
526 uint32 i, ngeoms = 0, gtype;
527
528 /* Read in all the geometries in this partition */
529 geoms = palloc(rowcount * sizeof(GEOSGeometry*));
530 for (i = 0; i < rowcount; i++)
531 {
532 GSERIALIZED* gser;
533 bool isnull, isout;
534 bool isempty, ispolygonal;
535 Datum d;
536
537 /* Read geometry in first argument */
538 d = WinGetFuncArgInPartition(winobj, 0, i,
539 WINDOW_SEEK_HEAD, false, &isnull, &isout);
540
541 /*
542 * The input to the GEOS function will be smaller than
543 * the input to this window, since we will not feed
544 * GEOS nulls or empties. So we need to maintain a
545 * map (context->idx) from the window position of the
546 * input to the GEOS position, so we can put the
547 * right result in the output stream. Things we want to
548 * skip get an index of -1.
549 */
550
551 /* Skip NULL inputs and move on */
552 if (isnull)
553 {
554 context->idx[i] = -1;
555 continue;
556 }
557
558 gser = (GSERIALIZED*)PG_DETOAST_DATUM(d);
559 gtype = gserialized_get_type(gser);
560 isempty = gserialized_is_empty(gser);
561 ispolygonal = (gtype == MULTIPOLYGONTYPE) || (gtype == POLYGONTYPE);
562
563 /* Skip empty or non-polygonal inputs */
564 if (isempty || !ispolygonal)
565 {
566 context->idx[i] = -1;
567 continue;
568 }
569
570 /* Skip failed inputs */
571 geos = POSTGIS2GEOS(gser);
572 if (!geos)
573 {
574 context->idx[i] = -1;
575 continue;
576 }
577
578 context->idx[i] = ngeoms;
579 geoms[ngeoms] = geos;
580 ngeoms = ngeoms + 1;
581 }
582
583 /*
584 * Create the GEOS input collection! The new
585 * collection takes ownership of the input GEOSGeometry
586 * objects, leaving just the geoms array, which
587 * will be cleaned up on function exit.
588 */
589 geos = GEOSGeom_createCollection(
590 GEOS_GEOMETRYCOLLECTION,
591 geoms, ngeoms);
592
593 /*
594 * If the creation failed, the objects will still be
595 * hanging around, so clean them up first. Should
596 * never happen, really.
597 */
598 if (!geos)
599 {
600 coverage_destroy_geoms(geoms, ngeoms);
601 return NULL;
602 }
603
604 pfree(geoms);
605 return geos;
606}
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:107
#define POLYGONTYPE
Definition liblwgeom.h:104
static void coverage_destroy_geoms(GEOSGeometry **geoms, uint32 ngeoms)
GEOSGeometry * POSTGIS2GEOS(const GSERIALIZED *pglwgeom)

References coverage_destroy_geoms(), gserialized_get_type(), gserialized_is_empty(), coverage_context::idx, MULTIPOLYGONTYPE, POLYGONTYPE, and POSTGIS2GEOS().

Referenced by coverage_window_calculation().

Here is the call graph for this function:
Here is the caller graph for this function: