PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ polygonize_garray()

Datum polygonize_garray ( PG_FUNCTION_ARGS  )

Definition at line 3372 of file postgis/lwgeom_geos.c.

References ARRAY2GEOS(), array_nelems_not_null(), clusterintersecting_garray(), GEOS2POSTGIS(), lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), and SRID_UNKNOWN.

Referenced by GEOSnoop(), and pgis_geometry_polygonize_finalfn().

3373 {
3374  ArrayType *array;
3375  int is3d = 0;
3376  uint32 nelems, i;
3377  GSERIALIZED *result;
3378  GEOSGeometry *geos_result;
3379  const GEOSGeometry **vgeoms;
3380  int srid=SRID_UNKNOWN;
3381 #if POSTGIS_DEBUG_LEVEL >= 3
3382  static int call=1;
3383 #endif
3384 
3385 #if POSTGIS_DEBUG_LEVEL >= 3
3386  call++;
3387 #endif
3388 
3389  if (PG_ARGISNULL(0))
3390  PG_RETURN_NULL();
3391 
3392  array = PG_GETARG_ARRAYTYPE_P(0);
3393  nelems = array_nelems_not_null(array);
3394 
3395  if (nelems == 0)
3396  PG_RETURN_NULL();
3397 
3398  POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
3399 
3400  /* Ok, we really need geos now ;) */
3401  initGEOS(lwpgnotice, lwgeom_geos_error);
3402 
3403  vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
3404 
3405  POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
3406 
3407  geos_result = GEOSPolygonize(vgeoms, nelems);
3408 
3409  POSTGIS_DEBUG(3, "polygonize_garray: GEOSpolygonize returned");
3410 
3411  for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
3412  pfree(vgeoms);
3413 
3414  if ( ! geos_result ) PG_RETURN_NULL();
3415 
3416  GEOSSetSRID(geos_result, srid);
3417  result = GEOS2POSTGIS(geos_result, is3d);
3418  GEOSGeom_destroy(geos_result);
3419  if ( result == NULL )
3420  {
3421  elog(ERROR, "%s returned an error", __func__);
3422  PG_RETURN_NULL(); /*never get here */
3423  }
3424 
3425  PG_RETURN_POINTER(result);
3426 }
GEOSGeometry ** ARRAY2GEOS(ArrayType *array, uint32_t nelems, int *is3d, int *srid)
uint32_t array_nelems_not_null(ArrayType *array)
void lwgeom_geos_error(const char *fmt,...)
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
Here is the call graph for this function:
Here is the caller graph for this function: