PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_GEOS_makeValidCollection()

static GEOSGeometry* LWGEOM_GEOS_makeValidCollection ( const GEOSGeometry *  gin)
static

Definition at line 646 of file liblwgeom/lwgeom_geos_clean.c.

References lwalloc(), lwerror(), lwfree(), lwgeom_geos_errmsg, and LWGEOM_GEOS_makeValid().

Referenced by LWGEOM_GEOS_makeValid().

647 {
648  int nvgeoms;
649  GEOSGeometry** vgeoms;
650  GEOSGeom gout;
651  int i;
652 
653  nvgeoms = GEOSGetNumGeometries(gin);
654  if (nvgeoms == -1)
655  {
656  lwerror("GEOSGetNumGeometries: %s", lwgeom_geos_errmsg);
657  return 0;
658  }
659 
660  vgeoms = lwalloc(sizeof(GEOSGeometry*) * nvgeoms);
661  if (!vgeoms)
662  {
663  lwerror("LWGEOM_GEOS_makeValidCollection: out of memory");
664  return 0;
665  }
666 
667  for (i = 0; i < nvgeoms; ++i)
668  {
669  vgeoms[i] = LWGEOM_GEOS_makeValid(GEOSGetGeometryN(gin, i));
670  if (!vgeoms[i])
671  {
672  int j;
673  for (j = 0; j < i - 1; j++)
674  GEOSGeom_destroy(vgeoms[j]);
675  lwfree(vgeoms);
676  /* we expect lwerror being called already by makeValid */
677  return NULL;
678  }
679  }
680 
681  /* Collect areas and lines (if any line) */
682  gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, vgeoms, nvgeoms);
683  if (!gout) /* an exception again */
684  {
685  /* cleanup and throw */
686  for (i = 0; i < nvgeoms; ++i)
687  GEOSGeom_destroy(vgeoms[i]);
688  lwfree(vgeoms);
689  lwerror("GEOSGeom_createCollection() threw an error: %s", lwgeom_geos_errmsg);
690  return NULL;
691  }
692  lwfree(vgeoms);
693 
694  return gout;
695 }
void lwfree(void *mem)
Definition: lwutil.c:244
GEOSGeometry * LWGEOM_GEOS_makeValid(const GEOSGeometry *gin)
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
void * lwalloc(size_t size)
Definition: lwutil.c:229
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: