PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ LWGEOM_GEOS_makeValidCollection()

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  unsigned 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  while (i--) GEOSGeom_destroy(vgeoms[i]);
816  lwfree(vgeoms);
817  /* we expect lwerror being called already by makeValid */
818  return NULL;
819  }
820  }
821 
822  /* Collect areas and lines (if any line) */
823  gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, vgeoms, nvgeoms);
824  if ( ! gout ) /* an exception again */
825  {
826  /* cleanup and throw */
827  for ( i=0; i<nvgeoms; ++i ) GEOSGeom_destroy(vgeoms[i]);
828  lwfree(vgeoms);
829  lwerror("GEOSGeom_createCollection() threw an error: %s",
831  return NULL;
832  }
833  lwfree(vgeoms);
834 
835  return gout;
836 
837 }
void lwfree(void *mem)
Definition: lwutil.c:242
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
static GEOSGeometry * LWGEOM_GEOS_makeValid(const GEOSGeometry *)
void * lwalloc(size_t size)
Definition: lwutil.c:227
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: