PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ lw_dist2d_recursive()

int lw_dist2d_recursive ( const LWGEOM lwg1,
const LWGEOM lwg2,
DISTPTS dl 
)

This is a recursive function delivering every possible combination of subgeometries.

Definition at line 299 of file measures.c.

300 {
301  int i, j;
302  int n1 = 1;
303  int n2 = 1;
304  LWGEOM *g1 = NULL;
305  LWGEOM *g2 = NULL;
306  LWCOLLECTION *c1 = NULL;
307  LWCOLLECTION *c2 = NULL;
308 
309  LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
310 
311  if (lw_dist2d_is_collection(lwg1))
312  {
313  LWDEBUG(3, "First geometry is collection");
314  c1 = lwgeom_as_lwcollection(lwg1);
315  n1 = c1->ngeoms;
316  }
317  if (lw_dist2d_is_collection(lwg2))
318  {
319  LWDEBUG(3, "Second geometry is collection");
320  c2 = lwgeom_as_lwcollection(lwg2);
321  n2 = c2->ngeoms;
322  }
323 
324  for (i = 0; i < n1; i++)
325  {
326 
327  if (lw_dist2d_is_collection(lwg1))
328  g1 = c1->geoms[i];
329  else
330  g1 = (LWGEOM *)lwg1;
331 
332  if (!g1) continue;
333 
334  if (lwgeom_is_empty(g1))
335  continue;
336 
337  if (lw_dist2d_is_collection(g1))
338  {
339  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
340  if (!lw_dist2d_recursive(g1, lwg2, dl))
341  return LW_FALSE;
342  continue;
343  }
344  for (j = 0; j < n2; j++)
345  {
346  if (lw_dist2d_is_collection(lwg2))
347  g2 = c2->geoms[j];
348  else
349  g2 = (LWGEOM *)lwg2;
350 
351  if (!g2) continue;
352 
353  if (lw_dist2d_is_collection(g2))
354  {
355  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
356  if (!lw_dist2d_recursive(g1, g2, dl))
357  return LW_FALSE;
358  continue;
359  }
360 
361  if (!g1->bbox)
362  lwgeom_add_bbox(g1);
363 
364  if (!g2->bbox)
365  lwgeom_add_bbox(g2);
366 
367  /* If one of geometries is empty, skip */
368  if (lwgeom_is_empty(g1) || lwgeom_is_empty(g2))
369  continue;
370 
371  if ((dl->mode != DIST_MAX) && (!lw_dist2d_check_overlap(g1, g2)) &&
372  (g1->type == LINETYPE || g1->type == POLYGONTYPE || g1->type == TRIANGLETYPE) &&
373  (g2->type == LINETYPE || g2->type == POLYGONTYPE || g2->type == TRIANGLETYPE))
374  {
375  if (!lw_dist2d_distribute_fast(g1, g2, dl))
376  return LW_FALSE;
377  }
378  else
379  {
380  if (!lw_dist2d_distribute_bruteforce(g1, g2, dl))
381  return LW_FALSE;
382  LWDEBUGF(2, "Distance so far: %.15g (%.15g tolerated)", dl->distance, dl->tolerance);
383  if (dl->distance <= dl->tolerance && dl->mode == DIST_MIN)
384  return LW_TRUE; /*just a check if the answer is already given*/
385  LWDEBUG(2, "Not below tolerance yet");
386  }
387  }
388  }
389  return LW_TRUE;
390 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LINETYPE
Definition: liblwgeom.h:103
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define TRIANGLETYPE
Definition: liblwgeom.h:115
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:233
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:695
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:106
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:199
static int lw_dist2d_check_overlap(const LWGEOM *lwg1, const LWGEOM *lwg2)
Definition: measures.c:282
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition: measures.c:299
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition: measures.c:257
int lw_dist2d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
Definition: measures.c:393
int lw_dist2d_distribute_fast(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Geometries are distributed for the new faster distance-calculations.
Definition: measures.c:555
#define DIST_MIN
Definition: measures.h:44
#define DIST_MAX
Definition: measures.h:43
double tolerance
Definition: measures.h:56
int mode
Definition: measures.h:54
double distance
Definition: measures.h:51
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575
uint8_t type
Definition: liblwgeom.h:462
GBOX * bbox
Definition: liblwgeom.h:458

References LWGEOM::bbox, DIST_MAX, DIST_MIN, DISTPTS::distance, LWCOLLECTION::geoms, LINETYPE, lw_dist2d_check_overlap(), lw_dist2d_distribute_bruteforce(), lw_dist2d_distribute_fast(), lw_dist2d_is_collection(), LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, lwgeom_add_bbox(), lwgeom_as_lwcollection(), lwgeom_is_empty(), DISTPTS::mode, LWCOLLECTION::ngeoms, POLYGONTYPE, DISTPTS::tolerance, TRIANGLETYPE, and LWGEOM::type.

Referenced by lw_dist2d_comp(), lw_dist2d_curvepoly_curvepoly(), lw_dist2d_line_curvepoly(), lw_dist2d_point_curvepoly(), and lw_dist2d_tri_curvepoly().

Here is the call graph for this function:
Here is the caller graph for this function: