PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

References ARRAY2GEOS(), array_nelems_not_null(), cluster_intersecting(), GEOS2POSTGIS(), LW_SUCCESS, lwgeom_geos_error(), and SRID_UNKNOWN.

Referenced by pgis_geometry_clusterintersecting_finalfn().

3042 {
3043  Datum* result_array_data;
3044  ArrayType *array, *result;
3045  int is3d = 0;
3046  uint32 nelems, nclusters, i;
3047  GEOSGeometry **geos_inputs, **geos_results;
3048  int srid=SRID_UNKNOWN;
3049 
3050  /* Parameters used to construct a result array */
3051  int16 elmlen;
3052  bool elmbyval;
3053  char elmalign;
3054 
3055  /* Null array, null geometry (should be empty?) */
3056  if (PG_ARGISNULL(0))
3057  PG_RETURN_NULL();
3058 
3059  array = PG_GETARG_ARRAYTYPE_P(0);
3060  nelems = array_nelems_not_null(array);
3061 
3062  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
3063 
3064  if ( nelems == 0 ) PG_RETURN_NULL();
3065 
3066  /* TODO short-circuit for one element? */
3067 
3068  /* Ok, we really need geos now ;) */
3069  initGEOS(lwpgnotice, lwgeom_geos_error);
3070 
3071  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
3072  if(!geos_inputs)
3073  {
3074  PG_RETURN_NULL();
3075  }
3076 
3077  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
3078  {
3079  elog(ERROR, "clusterintersecting: Error performing clustering");
3080  PG_RETURN_NULL();
3081  }
3082  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
3083 
3084  if (!geos_results) PG_RETURN_NULL();
3085 
3086  result_array_data = palloc(nclusters * sizeof(Datum));
3087  for (i=0; i<nclusters; ++i)
3088  {
3089  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
3090  GEOSGeom_destroy(geos_results[i]);
3091  }
3092  pfree(geos_results);
3093 
3094  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3095  result = (ArrayType*) construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3096 
3097  if (!result)
3098  {
3099  elog(ERROR, "clusterintersecting: Error constructing return-array");
3100  PG_RETURN_NULL();
3101  }
3102 
3103  PG_RETURN_POINTER(result);
3104 }
GEOSGeometry ** ARRAY2GEOS(ArrayType *array, uint32_t nelems, int *is3d, int *srid)
uint32_t array_nelems_not_null(ArrayType *array)
int cluster_intersecting(GEOSGeometry **geoms, uint32_t num_geoms, GEOSGeometry ***clusterGeoms, uint32_t *num_clusters)
Takes an array of GEOSGeometry* and constructs an array of GEOSGeometry*, where each element in the c...
#define LW_SUCCESS
Definition: liblwgeom.h:79
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: