PostGIS  2.2.7dev-r@@SVN_REVISION@@
static int union_pairs_within_distance ( LWGEOM **  geoms,
uint32_t  num_geoms,
UNIONFIND uf,
double  tolerance 
)
static

Definition at line 236 of file lwgeom_geos_cluster.c.

References destroy_strtree(), UnionIfDWithinContext::error, GBOX2GEOS(), gbox_clone(), gbox_expand(), UnionIfDWithinContext::geoms, LW_FAILURE, LW_SUCCESS, lwfree(), lwgeom_get_bbox(), make_strtree(), STRTree::num_geoms, STRTree::tree, UnionIfDWithinContext::uf, and union_if_dwithin().

Referenced by cluster_within_distance().

237 {
238  uint32_t i;
239 
240  if (num_geoms <= 1)
241  {
242  return LW_SUCCESS;
243  }
244 
245  struct STRTree tree = make_strtree((void**) geoms, num_geoms, 1);
246  if (tree.tree == NULL)
247  {
248  destroy_strtree(tree);
249  return LW_FAILURE;
250  }
251 
252  for (i = 0; i < num_geoms; i++)
253  {
254  struct UnionIfDWithinContext cxt =
255  {
256  .uf = uf,
257  .error = 0,
258  .p = &i,
259  .geoms = geoms,
260  .tolerance = tolerance
261  };
262 
263  const GBOX* geom_extent = lwgeom_get_bbox(geoms[i]);
264  if (!geom_extent)
265  {
266  /* Empty geometry */
267  continue;
268  }
269  GBOX* query_extent = gbox_clone(geom_extent);
270  gbox_expand(query_extent, tolerance);
271  GEOSGeometry* query_envelope = GBOX2GEOS(query_extent);
272 
273  if (!query_envelope)
274  {
275  destroy_strtree(tree);
276  return LW_FAILURE;
277  }
278 
279  GEOSSTRtree_query(tree.tree, query_envelope, &union_if_dwithin, &cxt);
280 
281  lwfree(query_extent);
282  GEOSGeom_destroy(query_envelope);
283  if (cxt.error)
284  {
285  return LW_FAILURE;
286  }
287  }
288 
289  destroy_strtree(tree);
290  return LW_SUCCESS;
291 }
void lwfree(void *mem)
Definition: lwutil.c:214
void gbox_expand(GBOX *g, double d)
Move the box minimums down and the maximums up by the distance provided.
Definition: g_box.c:93
static void destroy_strtree(struct STRTree tree)
Clean up STRTree after use.
#define LW_SUCCESS
Definition: liblwgeom.h:65
GEOSGeometry * GBOX2GEOS(const GBOX *box)
GEOSSTRtree * tree
#define LW_FAILURE
Definition: liblwgeom.h:64
static void union_if_dwithin(void *item, void *userdata)
static struct STRTree make_strtree(void **geoms, uint32_t num_geoms, char is_lwgeom)
Make a GEOSSTRtree of either GEOSGeometry* or LWGEOM* pointers.
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition: lwgeom.c:640
GBOX * gbox_clone(const GBOX *gbox)
Definition: g_box.c:41
uint32_t num_geoms

Here is the call graph for this function:

Here is the caller graph for this function: