PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ polygonize_garray()

Datum polygonize_garray ( PG_FUNCTION_ARGS  )

Definition at line 3024 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().

3025 {
3026  ArrayType *array;
3027  int is3d = 0;
3028  uint32 nelems, i;
3029  GSERIALIZED *result;
3030  GEOSGeometry *geos_result;
3031  const GEOSGeometry **vgeoms;
3032  int srid=SRID_UNKNOWN;
3033 #if POSTGIS_DEBUG_LEVEL >= 3
3034  static int call=1;
3035 #endif
3036 
3037 #if POSTGIS_DEBUG_LEVEL >= 3
3038  call++;
3039 #endif
3040 
3041  if (PG_ARGISNULL(0))
3042  PG_RETURN_NULL();
3043 
3044  array = PG_GETARG_ARRAYTYPE_P(0);
3045  nelems = array_nelems_not_null(array);
3046 
3047  if (nelems == 0)
3048  PG_RETURN_NULL();
3049 
3050  POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
3051 
3052  /* Ok, we really need geos now ;) */
3053  initGEOS(lwpgnotice, lwgeom_geos_error);
3054 
3055  vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
3056 
3057  POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
3058 
3059  geos_result = GEOSPolygonize(vgeoms, nelems);
3060 
3061  POSTGIS_DEBUG(3, "polygonize_garray: GEOSpolygonize returned");
3062 
3063  for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
3064  pfree(vgeoms);
3065 
3066  if ( ! geos_result ) PG_RETURN_NULL();
3067 
3068  GEOSSetSRID(geos_result, srid);
3069  result = GEOS2POSTGIS(geos_result, is3d);
3070  GEOSGeom_destroy(geos_result);
3071  if (!result)
3072  {
3073  elog(ERROR, "%s returned an error", __func__);
3074  PG_RETURN_NULL(); /*never get here */
3075  }
3076 
3077  PG_RETURN_POINTER(result);
3078 }
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:187
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
Here is the call graph for this function:
Here is the caller graph for this function: