PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum polygonize_garray ( PG_FUNCTION_ARGS  )

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

References GEOS2POSTGIS(), gserialized_get_srid(), gserialized_has_z(), lwerror(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwnotice(), POSTGIS2GEOS(), result, and SRID_UNKNOWN.

Referenced by pgis_geometry_polygonize_finalfn().

3247 {
3248  Datum datum;
3249  ArrayType *array;
3250  int is3d = 0;
3251  uint32 nelems, i;
3253  GEOSGeometry *geos_result;
3254  const GEOSGeometry **vgeoms;
3255  int srid=SRID_UNKNOWN;
3256  size_t offset;
3257 #if POSTGIS_DEBUG_LEVEL >= 3
3258  static int call=1;
3259 #endif
3260 
3261 #if POSTGIS_DEBUG_LEVEL >= 3
3262  call++;
3263 #endif
3264 
3265  datum = PG_GETARG_DATUM(0);
3266 
3267  /* Null array, null geometry (should be empty?) */
3268  if ( (Pointer *)datum == NULL ) PG_RETURN_NULL();
3269 
3270  array = DatumGetArrayTypeP(datum);
3271 
3272  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
3273 
3274  POSTGIS_DEBUGF(3, "polygonize_garray: number of elements: %d", nelems);
3275 
3276  if ( nelems == 0 ) PG_RETURN_NULL();
3277 
3278  /* Ok, we really need geos now ;) */
3279  initGEOS(lwnotice, lwgeom_geos_error);
3280 
3281  vgeoms = palloc(sizeof(GEOSGeometry *)*nelems);
3282  offset = 0;
3283  for (i=0; i<nelems; i++)
3284  {
3285  GEOSGeometry* g;
3286  GSERIALIZED *geom = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
3287  offset += INTALIGN(VARSIZE(geom));
3288  if ( ! is3d ) is3d = gserialized_has_z(geom);
3289 
3290  g = (GEOSGeometry *)POSTGIS2GEOS(geom);
3291  if ( 0 == g ) /* exception thrown at construction */
3292  {
3293  lwerror("Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
3294  PG_RETURN_NULL();
3295  }
3296  vgeoms[i] = g;
3297  if ( ! i )
3298  {
3299  srid = gserialized_get_srid(geom);
3300  }
3301  else
3302  {
3303  if ( srid != gserialized_get_srid(geom) )
3304  {
3305  elog(ERROR, "polygonize: operation on mixed SRID geometries");
3306  PG_RETURN_NULL();
3307  }
3308  }
3309  }
3310 
3311  POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
3312 
3313  geos_result = GEOSPolygonize(vgeoms, nelems);
3314 
3315  POSTGIS_DEBUG(3, "polygonize_garray: GEOSpolygonize returned");
3316 
3317  for (i=0; i<nelems; ++i) GEOSGeom_destroy((GEOSGeometry *)vgeoms[i]);
3318  pfree(vgeoms);
3319 
3320  if ( ! geos_result ) PG_RETURN_NULL();
3321 
3322  GEOSSetSRID(geos_result, srid);
3323  result = GEOS2POSTGIS(geos_result, is3d);
3324  GEOSGeom_destroy(geos_result);
3325  if ( result == NULL )
3326  {
3327  elog(ERROR, "GEOS2POSTGIS returned an error");
3328  PG_RETURN_NULL(); /*never get here */
3329  }
3330 
3331  /*compressType(result); */
3332 
3333  PG_RETURN_POINTER(result);
3334 
3335 }
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
int gserialized_has_z(const GSERIALIZED *gser)
Check if a GSERIALIZED has a Z ordinate.
Definition: g_serialized.c:25
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
unsigned int uint32
Definition: shpopen.c:274
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:70

Here is the call graph for this function:

Here is the caller graph for this function: