PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ polygonize_garray()

Datum polygonize_garray ( PG_FUNCTION_ARGS  )

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

3062 {
3063  ArrayType *array;
3064  int is3d = 0;
3065  uint32 nelems, i;
3066  GSERIALIZED *result;
3067  GEOSGeometry *geos_result;
3068  const GEOSGeometry **vgeoms;
3069  int srid=SRID_UNKNOWN;
3070 #if POSTGIS_DEBUG_LEVEL >= 3
3071  static int call=1;
3072 #endif
3073 
3074 #if POSTGIS_DEBUG_LEVEL >= 3
3075  call++;
3076 #endif
3077 
3078  if (PG_ARGISNULL(0))
3079  PG_RETURN_NULL();
3080 
3081  array = PG_GETARG_ARRAYTYPE_P(0);
3082  nelems = array_nelems_not_null(array);
3083 
3084  if (nelems == 0)
3085  PG_RETURN_NULL();
3086 
3087  POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
3088 
3089  /* Ok, we really need geos now ;) */
3090  initGEOS(lwpgnotice, lwgeom_geos_error);
3091 
3092  vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
3093 
3094  POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
3095 
3096  geos_result = GEOSPolygonize(vgeoms, nelems);
3097 
3098  POSTGIS_DEBUG(3, "polygonize_garray: GEOSpolygonize returned");
3099 
3100  for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
3101  pfree(vgeoms);
3102 
3103  if ( ! geos_result ) PG_RETURN_NULL();
3104 
3105  GEOSSetSRID(geos_result, srid);
3106  result = GEOS2POSTGIS(geos_result, is3d);
3107  GEOSGeom_destroy(geos_result);
3108  if ( result == NULL )
3109  {
3110  elog(ERROR, "%s returned an error", __func__);
3111  PG_RETURN_NULL(); /*never get here */
3112  }
3113 
3114  PG_RETURN_POINTER(result);
3115 }
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: