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

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

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

Referenced by LWGEOM_GEOS_makeValid().

805 {
806  int nvgeoms;
807  GEOSGeometry **vgeoms;
808  GEOSGeom gout;
809  unsigned int i;
810 
811  nvgeoms = GEOSGetNumGeometries(gin);
812  if ( nvgeoms == -1 ) {
813  lwerror("GEOSGetNumGeometries: %s", lwgeom_geos_errmsg);
814  return 0;
815  }
816 
817  vgeoms = lwalloc( sizeof(GEOSGeometry*) * nvgeoms );
818  if ( ! vgeoms ) {
819  lwerror("LWGEOM_GEOS_makeValidCollection: out of memory");
820  return 0;
821  }
822 
823  for ( i=0; i<nvgeoms; ++i ) {
824  vgeoms[i] = LWGEOM_GEOS_makeValid( GEOSGetGeometryN(gin, i) );
825  if ( ! vgeoms[i] ) {
826  while (i--) GEOSGeom_destroy(vgeoms[i]);
827  lwfree(vgeoms);
828  /* we expect lwerror being called already by makeValid */
829  return NULL;
830  }
831  }
832 
833  /* Collect areas and lines (if any line) */
834  gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, vgeoms, nvgeoms);
835  if ( ! gout ) /* an exception again */
836  {
837  /* cleanup and throw */
838  for ( i=0; i<nvgeoms; ++i ) GEOSGeom_destroy(vgeoms[i]);
839  lwfree(vgeoms);
840  lwerror("GEOSGeom_createCollection() threw an error: %s",
842  return NULL;
843  }
844  lwfree(vgeoms);
845 
846  return gout;
847 
848 }
void lwfree(void *mem)
Definition: lwutil.c:214
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
static GEOSGeometry * LWGEOM_GEOS_makeValid(const GEOSGeometry *)
void * lwalloc(size_t size)
Definition: lwutil.c:199
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: