PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

3052 {
3053  Datum* result_array_data;
3054  ArrayType *array, *result;
3055  int is3d = 0;
3056  uint32 nelems, nclusters, i;
3057  GEOSGeometry **geos_inputs, **geos_results;
3058  int32_t srid = SRID_UNKNOWN;
3059 
3060  /* Parameters used to construct a result array */
3061  int16 elmlen;
3062  bool elmbyval;
3063  char elmalign;
3064 
3065  /* Null array, null geometry (should be empty?) */
3066  if (PG_ARGISNULL(0))
3067  PG_RETURN_NULL();
3068 
3069  array = PG_GETARG_ARRAYTYPE_P(0);
3070  nelems = array_nelems_not_null(array);
3071 
3072  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
3073 
3074  if ( nelems == 0 ) PG_RETURN_NULL();
3075 
3076  /* TODO short-circuit for one element? */
3077 
3078  /* Ok, we really need geos now ;) */
3079  initGEOS(lwpgnotice, lwgeom_geos_error);
3080 
3081  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
3082  if(!geos_inputs)
3083  {
3084  PG_RETURN_NULL();
3085  }
3086 
3087  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
3088  {
3089  elog(ERROR, "clusterintersecting: Error performing clustering");
3090  PG_RETURN_NULL();
3091  }
3092  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
3093 
3094  if (!geos_results) PG_RETURN_NULL();
3095 
3096  result_array_data = palloc(nclusters * sizeof(Datum));
3097  for (i=0; i<nclusters; ++i)
3098  {
3099  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
3100  GEOSGeom_destroy(geos_results[i]);
3101  }
3102  lwfree(geos_results);
3103 
3104  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3105  result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3106 
3107  if (!result)
3108  {
3109  elog(ERROR, "clusterintersecting: Error constructing return-array");
3110  PG_RETURN_NULL();
3111  }
3112 
3113  PG_RETURN_POINTER(result);
3114 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void lwgeom_geos_error(const char *fmt,...)
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:111
void lwfree(void *mem)
Definition: lwutil.c:242
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
uint32_t array_nelems_not_null(ArrayType *array)
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
GEOSGeometry ** ARRAY2GEOS(ArrayType *array, uint32_t nelems, int *is3d, int *srid)

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

Referenced by pgis_geometry_clusterintersecting_finalfn().

Here is the call graph for this function:
Here is the caller graph for this function: