PostGIS  2.5.0dev-r@@SVN_REVISION@@
static GEOSGeometry* LWGEOM_GEOS_makeValidCollection ( const GEOSGeometry *  gin)
static

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

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

Referenced by LWGEOM_GEOS_makeValid().

794 {
795  int nvgeoms;
796  GEOSGeometry **vgeoms;
797  GEOSGeom gout;
798  int i;
799 
800  nvgeoms = GEOSGetNumGeometries(gin);
801  if ( nvgeoms == -1 ) {
802  lwerror("GEOSGetNumGeometries: %s", lwgeom_geos_errmsg);
803  return 0;
804  }
805 
806  vgeoms = lwalloc( sizeof(GEOSGeometry*) * nvgeoms );
807  if ( ! vgeoms ) {
808  lwerror("LWGEOM_GEOS_makeValidCollection: out of memory");
809  return 0;
810  }
811 
812  for ( i=0; i<nvgeoms; ++i ) {
813  vgeoms[i] = LWGEOM_GEOS_makeValid( GEOSGetGeometryN(gin, i) );
814  if ( ! vgeoms[i] ) {
815  int j;
816  for (j = 0; j<i-1; j++)
817  GEOSGeom_destroy(vgeoms[j]);
818  lwfree(vgeoms);
819  /* we expect lwerror being called already by makeValid */
820  return NULL;
821  }
822  }
823 
824  /* Collect areas and lines (if any line) */
825  gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, vgeoms, nvgeoms);
826  if ( ! gout ) /* an exception again */
827  {
828  /* cleanup and throw */
829  for ( i=0; i<nvgeoms; ++i ) GEOSGeom_destroy(vgeoms[i]);
830  lwfree(vgeoms);
831  lwerror("GEOSGeom_createCollection() threw an error: %s",
833  return NULL;
834  }
835  lwfree(vgeoms);
836 
837  return gout;
838 
839 }
void lwfree(void *mem)
Definition: lwutil.c:244
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
static GEOSGeometry * LWGEOM_GEOS_makeValid(const GEOSGeometry *)
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: