PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

3083 {
3084  Datum* result_array_data;
3085  ArrayType *array, *result;
3086  int is3d = 0;
3087  uint32 nelems, nclusters, i;
3088  GEOSGeometry **geos_inputs, **geos_results;
3089  int srid=SRID_UNKNOWN;
3090 
3091  /* Parameters used to construct a result array */
3092  int16 elmlen;
3093  bool elmbyval;
3094  char elmalign;
3095 
3096  /* Null array, null geometry (should be empty?) */
3097  if (PG_ARGISNULL(0))
3098  PG_RETURN_NULL();
3099 
3100  array = PG_GETARG_ARRAYTYPE_P(0);
3101  nelems = array_nelems_not_null(array);
3102 
3103  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
3104 
3105  if ( nelems == 0 ) PG_RETURN_NULL();
3106 
3107  /* TODO short-circuit for one element? */
3108 
3109  /* Ok, we really need geos now ;) */
3110  initGEOS(lwpgnotice, lwgeom_geos_error);
3111 
3112  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
3113  if(!geos_inputs)
3114  {
3115  PG_RETURN_NULL();
3116  }
3117 
3118  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
3119  {
3120  elog(ERROR, "clusterintersecting: Error performing clustering");
3121  PG_RETURN_NULL();
3122  }
3123  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
3124 
3125  if (!geos_results) PG_RETURN_NULL();
3126 
3127  result_array_data = palloc(nclusters * sizeof(Datum));
3128  for (i=0; i<nclusters; ++i)
3129  {
3130  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
3131  GEOSGeom_destroy(geos_results[i]);
3132  }
3133  pfree(geos_results);
3134 
3135  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
3136  result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
3137 
3138  if (!result)
3139  {
3140  elog(ERROR, "clusterintersecting: Error constructing return-array");
3141  PG_RETURN_NULL();
3142  }
3143 
3144  PG_RETURN_POINTER(result);
3145 }
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: