PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

Definition at line 2889 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_abs_out(), pgis_geometry_clusterintersecting_finalfn(), and polygonize_garray().

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