PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

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

Referenced by pgis_geometry_clusterintersecting_finalfn(), and polygonize_garray().

3120 {
3121  Datum* result_array_data;
3122  ArrayType *array, *result;
3123  int is3d = 0;
3124  uint32 nelems, nclusters, i;
3125  GEOSGeometry **geos_inputs, **geos_results;
3126  int srid=SRID_UNKNOWN;
3127 
3128  /* Parameters used to construct a result array */
3129  int16 elmlen;
3130  bool elmbyval;
3131  char elmalign;
3132 
3133  /* Null array, null geometry (should be empty?) */
3134  if (PG_ARGISNULL(0))
3135  PG_RETURN_NULL();
3136 
3137  array = PG_GETARG_ARRAYTYPE_P(0);
3138  nelems = array_nelems_not_null(array);
3139 
3140  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
3141 
3142  if ( nelems == 0 ) PG_RETURN_NULL();
3143 
3144  /* TODO short-circuit for one element? */
3145 
3146  /* Ok, we really need geos now ;) */
3147  initGEOS(lwpgnotice, lwgeom_geos_error);
3148 
3149  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
3150  if(!geos_inputs)
3151  {
3152  PG_RETURN_NULL();
3153  }
3154 
3155  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
3156  {
3157  elog(ERROR, "clusterintersecting: Error performing clustering");
3158  PG_RETURN_NULL();
3159  }
3160  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
3161 
3162  if (!geos_results) PG_RETURN_NULL();
3163 
3164  result_array_data = palloc(nclusters * sizeof(Datum));
3165  for (i=0; i<nclusters; ++i)
3166  {
3167  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
3168  GEOSGeom_destroy(geos_results[i]);
3169  }
3170  pfree(geos_results);
3171 
3172  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3173  result = (ArrayType*) construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3174 
3175  if (!result)
3176  {
3177  elog(ERROR, "clusterintersecting: Error constructing return-array");
3178  PG_RETURN_NULL();
3179  }
3180 
3181  PG_RETURN_POINTER(result);
3182 }
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: