PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

2028 {
2029  Datum* result_array_data;
2030  ArrayType *array, *result;
2031  int is3d = 0;
2032  uint32 nelems, nclusters, i;
2033  GEOSGeometry **geos_inputs, **geos_results;
2034  int32_t srid = SRID_UNKNOWN;
2035 
2036  /* Parameters used to construct a result array */
2037  int16 elmlen;
2038  bool elmbyval;
2039  char elmalign;
2040 
2041  /* Null array, null geometry (should be empty?) */
2042  if (PG_ARGISNULL(0))
2043  PG_RETURN_NULL();
2044 
2045  array = PG_GETARG_ARRAYTYPE_P(0);
2046  nelems = array_nelems_not_null(array);
2047 
2048  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
2049 
2050  if ( nelems == 0 ) PG_RETURN_NULL();
2051 
2052  /* TODO short-circuit for one element? */
2053 
2054  /* Ok, we really need geos now ;) */
2055  initGEOS(lwpgnotice, lwgeom_geos_error);
2056 
2057  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
2058  if(!geos_inputs)
2059  {
2060  PG_RETURN_NULL();
2061  }
2062 
2063  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
2064  {
2065  elog(ERROR, "clusterintersecting: Error performing clustering");
2066  PG_RETURN_NULL();
2067  }
2068  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
2069 
2070  if (!geos_results) PG_RETURN_NULL();
2071 
2072  result_array_data = palloc(nclusters * sizeof(Datum));
2073  for (i=0; i<nclusters; ++i)
2074  {
2075  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
2076  GEOSGeom_destroy(geos_results[i]);
2077  }
2078  lwfree(geos_results);
2079 
2080  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
2081  result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
2082 
2083  if (!result)
2084  {
2085  elog(ERROR, "clusterintersecting: Error constructing return-array");
2086  PG_RETURN_NULL();
2087  }
2088 
2089  PG_RETURN_POINTER(result);
2090 }
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:97
void lwfree(void *mem)
Definition: lwutil.c:248
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
static 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: