PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_GEOS_makeValidCollection()

static GEOSGeometry* LWGEOM_GEOS_makeValidCollection ( const GEOSGeometry *  gin)
static

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

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

Referenced by LWGEOM_GEOS_makeValid().

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