PostGIS  2.1.10dev-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 237 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().

238 {
239  int i, j;
240  int n1=1;
241  int n2=1;
242  LWGEOM *g1 = NULL;
243  LWGEOM *g2 = NULL;
244  LWCOLLECTION *c1 = NULL;
245  LWCOLLECTION *c2 = NULL;
246 
247  LWDEBUGF(2, "lw_dist2d_comp is called with type1=%d, type2=%d", lwg1->type, lwg2->type);
248 
249  if (lw_dist2d_is_collection(lwg1))
250  {
251  LWDEBUG(3, "First geometry is collection");
252  c1 = lwgeom_as_lwcollection(lwg1);
253  n1 = c1->ngeoms;
254  }
255  if (lw_dist2d_is_collection(lwg2))
256  {
257  LWDEBUG(3, "Second geometry is collection");
258  c2 = lwgeom_as_lwcollection(lwg2);
259  n2 = c2->ngeoms;
260  }
261 
262  for ( i = 0; i < n1; i++ )
263  {
264 
265  if (lw_dist2d_is_collection(lwg1))
266  {
267  g1 = c1->geoms[i];
268  }
269  else
270  {
271  g1 = (LWGEOM*)lwg1;
272  }
273 
274  if (lwgeom_is_empty(g1)) return LW_TRUE;
275 
276  if (lw_dist2d_is_collection(g1))
277  {
278  LWDEBUG(3, "Found collection inside first geometry collection, recursing");
279  if (!lw_dist2d_recursive(g1, lwg2, dl)) return LW_FALSE;
280  continue;
281  }
282  for ( j = 0; j < n2; j++ )
283  {
284  if (lw_dist2d_is_collection(lwg2))
285  {
286  g2 = c2->geoms[j];
287  }
288  else
289  {
290  g2 = (LWGEOM*)lwg2;
291  }
292  if (lw_dist2d_is_collection(g2))
293  {
294  LWDEBUG(3, "Found collection inside second geometry collection, recursing");
295  if (!lw_dist2d_recursive(g1, g2, dl)) return LW_FALSE;
296  continue;
297  }
298 
299  if ( ! g1->bbox )
300  {
301  lwgeom_add_bbox(g1);
302  }
303  if ( ! g2->bbox )
304  {
305  lwgeom_add_bbox(g2);
306  }
307 
308  /*If one of geometries is empty, return. True here only means continue searching. False would have stoped the process*/
309  if (lwgeom_is_empty(g1)||lwgeom_is_empty(g2)) return LW_TRUE;
310 
311  if ( (dl->mode != DIST_MAX) &&
312  (! lw_dist2d_check_overlap(g1, g2)) &&
313  (g1->type == LINETYPE || g1->type == POLYGONTYPE) &&
314  (g2->type == LINETYPE || g2->type == POLYGONTYPE) )
315  {
316  if (!lw_dist2d_distribute_fast(g1, g2, dl)) return LW_FALSE;
317  }
318  else
319  {
320  if (!lw_dist2d_distribute_bruteforce(g1, g2, dl)) return LW_FALSE;
321  if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE; /*just a check if the answer is already given*/
322  }
323  }
324  }
325  return LW_TRUE;
326 }
#define LINETYPE
Definition: liblwgeom.h:61
GBOX * bbox
Definition: liblwgeom.h:354
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:237
#define DIST_MAX
#define POLYGONTYPE
Definition: liblwgeom.h:62
int mode
Definition: measures.h:26
#define DIST_MIN
int lw_dist2d_distribute_bruteforce(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS *dl)
Definition: measures.c:330
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double tolerance
Definition: measures.h:28
static int lw_dist2d_is_collection(const LWGEOM *g)
Definition: measures.c:213
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
LWGEOM ** geoms
Definition: liblwgeom.h:465
double distance
Definition: measures.h:23
int lw_dist2d_check_overlap(LWGEOM *lwg1, LWGEOM *lwg2)
We have to check for overlapping bboxes.
Definition: measures.c:458
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:555
uint8_t type
Definition: liblwgeom.h:352
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:1229
#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:482

Here is the call graph for this function:

Here is the caller graph for this function: