PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

2895 {
2896  Datum* result_array_data;
2897  ArrayType *array, *result;
2898  int is3d = 0;
2899  uint32 nelems, nclusters, i;
2900  GEOSGeometry **geos_inputs, **geos_results;
2901  int32_t srid = SRID_UNKNOWN;
2902 
2903  /* Parameters used to construct a result array */
2904  int16 elmlen;
2905  bool elmbyval;
2906  char elmalign;
2907 
2908  /* Null array, null geometry (should be empty?) */
2909  if (PG_ARGISNULL(0))
2910  PG_RETURN_NULL();
2911 
2912  array = PG_GETARG_ARRAYTYPE_P(0);
2913  nelems = array_nelems_not_null(array);
2914 
2915  POSTGIS_DEBUGF(3, "clusterintersecting_garray: number of non-null elements: %d", nelems);
2916 
2917  if ( nelems == 0 ) PG_RETURN_NULL();
2918 
2919  /* TODO short-circuit for one element? */
2920 
2921  /* Ok, we really need geos now ;) */
2922  initGEOS(lwpgnotice, lwgeom_geos_error);
2923 
2924  geos_inputs = ARRAY2GEOS(array, nelems, &is3d, &srid);
2925  if(!geos_inputs)
2926  {
2927  PG_RETURN_NULL();
2928  }
2929 
2930  if (cluster_intersecting(geos_inputs, nelems, &geos_results, &nclusters) != LW_SUCCESS)
2931  {
2932  elog(ERROR, "clusterintersecting: Error performing clustering");
2933  PG_RETURN_NULL();
2934  }
2935  pfree(geos_inputs); /* don't need to destroy items because GeometryCollections have taken ownership */
2936 
2937  if (!geos_results) PG_RETURN_NULL();
2938 
2939  result_array_data = palloc(nclusters * sizeof(Datum));
2940  for (i=0; i<nclusters; ++i)
2941  {
2942  result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
2943  GEOSGeom_destroy(geos_results[i]);
2944  }
2945  lwfree(geos_results);
2946 
2947  get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
2948  result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
2949 
2950  if (!result)
2951  {
2952  elog(ERROR, "clusterintersecting: Error constructing return-array");
2953  PG_RETURN_NULL();
2954  }
2955 
2956  PG_RETURN_POINTER(result);
2957 }
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:111
void lwfree(void *mem)
Definition: lwutil.c:242
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
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(), 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: