PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

3431 {
3432  Datum* result_array_data;
3433  ArrayType *array, *result;
3434  int is3d = 0;
3435  uint32 nelems, nclusters, i;
3436  GEOSGeometry **geos_inputs, **geos_results;
3437  int srid=SRID_UNKNOWN;
3438 
3439  /* Parameters used to construct a result array */
3440  int16 elmlen;
3441  bool elmbyval;
3442  char elmalign;
3443 
3444  /* Null array, null geometry (should be empty?) */
3445  if (PG_ARGISNULL(0))
3446  PG_RETURN_NULL();
3447 
3448  array = PG_GETARG_ARRAYTYPE_P(0);
3449  nelems = array_nelems_not_null(array);
3450 
3451  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
3452 
3453  if ( nelems == 0 ) PG_RETURN_NULL();
3454 
3455  /* TODO short-circuit for one element? */
3456 
3457  /* Ok, we really need geos now ;) */
3458  initGEOS(lwpgnotice, lwgeom_geos_error);
3459 
3460  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
3461  if(!geos_inputs)
3462  {
3463  PG_RETURN_NULL();
3464  }
3465 
3466  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
3467  {
3468  elog(ERROR, "clusterintersecting: Error performing clustering");
3469  PG_RETURN_NULL();
3470  }
3471  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
3472 
3473  if (!geos_results) PG_RETURN_NULL();
3474 
3475  result_array_data = palloc(nclusters * sizeof(Datum));
3476  for (i=0; i<nclusters; ++i)
3477  {
3478  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
3479  GEOSGeom_destroy(geos_results[i]);
3480  }
3481  pfree(geos_results);
3482 
3483  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3484  result = (ArrayType*) construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3485 
3486  if (!result)
3487  {
3488  elog(ERROR, "clusterintersecting: Error constructing return-array");
3489  PG_RETURN_NULL();
3490  }
3491 
3492  PG_RETURN_POINTER(result);
3493 }
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:65
void lwgeom_geos_error(const char *fmt,...)
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
GSERIALIZED * GEOS2POSTGIS(GEOSGeom geom, char want3d)
Here is the call graph for this function:
Here is the caller graph for this function: