PostGIS  2.2.7dev-r@@SVN_REVISION@@
int lw_dist2d_recursive ( const LWGEOM lwg1,
const LWGEOM lwg2,
DISTPTS dl 
)

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

Definition at line 263 of file measures.c.

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_dist2d_recursive(), LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, lwgeom_add_bbox(), lwgeom_as_lwcollection(), lwgeom_is_empty(), DISTPTS::mode, LWCOLLECTION::ngeoms, POLYGONTYPE, DISTPTS::tolerance, and LWGEOM::type.

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

264 {
265  int i, j;
266  int n1=1;
267  int n2=1;
268  LWGEOM *g1 = NULL;
269  LWGEOM *g2 = NULL;
270  LWCOLLECTION *c1 = NULL;
271  LWCOLLECTION *c2 = NULL;
272 
273  LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
274 
275  if (lw_dist2d_is_collection(lwg1))
276  {
277  LWDEBUG(3, "First geometry is collection");
278  c1 = lwgeom_as_lwcollection(lwg1);
279  n1 = c1->ngeoms;
280  }
281  if (lw_dist2d_is_collection(lwg2))
282  {
283  LWDEBUG(3, "Second geometry is collection");
284  c2 = lwgeom_as_lwcollection(lwg2);
285  n2 = c2->ngeoms;
286  }
287 
288  for ( i = 0; i < n1; i++ )
289  {
290 
291  if (lw_dist2d_is_collection(lwg1))
292  {
293  g1 = c1->geoms[i];
294  }
295  else
296  {
297  g1 = (LWGEOM*)lwg1;
298  }
299 
300  if (lwgeom_is_empty(g1)) return LW_TRUE;
301 
302  if (lw_dist2d_is_collection(g1))
303  {
304  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
305  if (!lw_dist2d_recursive(g1, lwg2, dl)) return LW_FALSE;
306  continue;
307  }
308  for ( j = 0; j < n2; j++ )
309  {
310  if (lw_dist2d_is_collection(lwg2))
311  {
312  g2 = c2->geoms[j];
313  }
314  else
315  {
316  g2 = (LWGEOM*)lwg2;
317  }
318  if (lw_dist2d_is_collection(g2))
319  {
320  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
321  if (!lw_dist2d_recursive(g1, g2, dl)) return LW_FALSE;
322  continue;
323  }
324 
325  if ( ! g1->bbox )
326  {
327  lwgeom_add_bbox(g1);
328  }
329  if ( ! g2->bbox )
330  {
331  lwgeom_add_bbox(g2);
332  }
333 
334  /*If one of geometries is empty, return. True here only means continue searching. False would have stoped the process*/
335  if (lwgeom_is_empty(g1)||lwgeom_is_empty(g2)) return LW_TRUE;
336 
337  if ( (dl->mode != DIST_MAX) &&
338  (! lw_dist2d_check_overlap(g1, g2)) &&
339  (g1->type == LINETYPE || g1->type == POLYGONTYPE) &&
340  (g2->type == LINETYPE || g2->type == POLYGONTYPE) )
341  {
342  if (!lw_dist2d_distribute_fast(g1, g2, dl)) return LW_FALSE;
343  }
344  else
345  {
346  if (!lw_dist2d_distribute_bruteforce(g1, g2, dl)) return LW_FALSE;
347  if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE; /*just a check if the answer is already given*/
348  }
349  }
350  }
351  return LW_TRUE;
352 }
#define LINETYPE
Definition: liblwgeom.h:71
GBOX * bbox
Definition: liblwgeom.h:382
int lw_dist2d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
This is a recursive function delivering every possible combinatin of subgeometries.
Definition: measures.c:263
#define POLYGONTYPE
Definition: liblwgeom.h:72
int mode
Definition: measures.h:27
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double tolerance
Definition: measures.h:29
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition: measures.c:239
#define DIST_MIN
Definition: measures.h:17
#define LW_FALSE
Definition: liblwgeom.h:62
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
LWGEOM ** geoms
Definition: liblwgeom.h:493
int lw_dist2d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS *dl)
Definition: measures.c:356
double distance
Definition: measures.h:24
#define DIST_MAX
Definition: measures.h:16
int lw_dist2d_check_overlap(LWGEOM *lwg1, LWGEOM *lwg2)
We have to check for overlapping bboxes.
Definition: measures.c:484
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
uint8_t type
Definition: liblwgeom.h:380
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1297
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
int lw_dist2d_distribute_fast(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Here the geometries are distributed for the new faster distance-calculations.
Definition: measures.c:508

Here is the call graph for this function:

Here is the caller graph for this function: