PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

3191 {
3192  Datum* result_array_data;
3193  ArrayType *array, *result;
3194  int is3d = 0;
3195  uint32 nelems, nclusters, i;
3196  GEOSGeometry **geos_inputs, **geos_results;
3197  int srid=SRID_UNKNOWN;
3198 
3199  /* Parameters used to construct a result array */
3200  int16 elmlen;
3201  bool elmbyval;
3202  char elmalign;
3203 
3204  /* Null array, null geometry (should be empty?) */
3205  if (PG_ARGISNULL(0))
3206  PG_RETURN_NULL();
3207 
3208  array = PG_GETARG_ARRAYTYPE_P(0);
3209  nelems = array_nelems_not_null(array);
3210 
3211  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
3212 
3213  if ( nelems == 0 ) PG_RETURN_NULL();
3214 
3215  /* TODO short-circuit for one element? */
3216 
3217  /* Ok, we really need geos now ;) */
3218  initGEOS(lwpgnotice, lwgeom_geos_error);
3219 
3220  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
3221  if(!geos_inputs)
3222  {
3223  PG_RETURN_NULL();
3224  }
3225 
3226  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
3227  {
3228  elog(ERROR, "clusterintersecting: Error performing clustering");
3229  PG_RETURN_NULL();
3230  }
3231  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
3232 
3233  if (!geos_results) PG_RETURN_NULL();
3234 
3235  result_array_data = palloc(nclusters * sizeof(Datum));
3236  for (i=0; i<nclusters; ++i)
3237  {
3238  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
3239  GEOSGeom_destroy(geos_results[i]);
3240  }
3241  pfree(geos_results);
3242 
3243  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3244  result = (ArrayType*) construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3245 
3246  if (!result)
3247  {
3248  elog(ERROR, "clusterintersecting: Error constructing return-array");
3249  PG_RETURN_NULL();
3250  }
3251 
3252  PG_RETURN_POINTER(result);
3253 }
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:80
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: