PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ clusterintersecting_garray()

Datum clusterintersecting_garray ( PG_FUNCTION_ARGS  )

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

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