PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ coverage_read_partition_into_collection()

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

Definition at line 520 of file lwgeom_window.c.

523 {
524  int64 rowcount = WinGetPartitionRowCount(winobj);
525  GEOSGeometry* geos;
526  GEOSGeometry** geoms;
527  uint32 i, ngeoms = 0, gtype;
528 
529  /* Read in all the geometries in this partition */
530  geoms = palloc(rowcount * sizeof(GEOSGeometry*));
531  for (i = 0; i < rowcount; i++)
532  {
533  GSERIALIZED* gser;
534  bool isnull, isout;
535  bool isempty, ispolygonal;
536  Datum d;
537 
538  /* Read geometry in first argument */
539  d = WinGetFuncArgInPartition(winobj, 0, i,
540  WINDOW_SEEK_HEAD, false, &isnull, &isout);
541 
542  /*
543  * The input to the GEOS function will be smaller than
544  * the input to this window, since we will not feed
545  * GEOS nulls or empties. So we need to maintain a
546  * map (context->idx) from the window position of the
547  * input to the GEOS position, so we can put the
548  * right result in the output stream.
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 ngeoms 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.
Definition: gserialized.c:152
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
#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: