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

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

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

Referenced by LWGEOM_GEOS_makeValid().

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

Here is the call graph for this function:

Here is the caller graph for this function: