PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ polygonize_garray()

Datum polygonize_garray ( PG_FUNCTION_ARGS  )

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

3133 {
3134  ArrayType *array;
3135  int is3d = 0;
3136  uint32 nelems, i;
3137  GSERIALIZED *result;
3138  GEOSGeometry *geos_result;
3139  const GEOSGeometry **vgeoms;
3140  int srid=SRID_UNKNOWN;
3141 #if POSTGIS_DEBUG_LEVEL >= 3
3142  static int call=1;
3143 #endif
3144 
3145 #if POSTGIS_DEBUG_LEVEL >= 3
3146  call++;
3147 #endif
3148 
3149  if (PG_ARGISNULL(0))
3150  PG_RETURN_NULL();
3151 
3152  array = PG_GETARG_ARRAYTYPE_P(0);
3153  nelems = array_nelems_not_null(array);
3154 
3155  if (nelems == 0)
3156  PG_RETURN_NULL();
3157 
3158  POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
3159 
3160  /* Ok, we really need geos now ;) */
3161  initGEOS(lwpgnotice, lwgeom_geos_error);
3162 
3163  vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
3164 
3165  POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
3166 
3167  geos_result = GEOSPolygonize(vgeoms, nelems);
3168 
3169  POSTGIS_DEBUG(3, "polygonize_garray: GEOSpolygonize returned");
3170 
3171  for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
3172  pfree(vgeoms);
3173 
3174  if ( ! geos_result ) PG_RETURN_NULL();
3175 
3176  GEOSSetSRID(geos_result, srid);
3177  result = GEOS2POSTGIS(geos_result, is3d);
3178  GEOSGeom_destroy(geos_result);
3179  if ( result == NULL )
3180  {
3181  elog(ERROR, "%s returned an error", __func__);
3182  PG_RETURN_NULL(); /*never get here */
3183  }
3184 
3185  PG_RETURN_POINTER(result);
3186 }
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:188
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
Here is the call graph for this function:
Here is the caller graph for this function: