PostGIS  2.2.7dev-r@@SVN_REVISION@@
static LWGEOM* _lwt_toposnap ( LWGEOM src,
LWGEOM tgt,
double  tol 
)
static

Definition at line 424 of file lwgeom_topo.c.

References LWDEBUGF, lwgeom_count_vertices(), lwgeom_free(), lwgeom_remove_repeated_points(), and lwgeom_snap().

Referenced by lwt_AddLine(), and lwt_AddPoint().

425 {
426  LWGEOM *tmp = src;
427  LWGEOM *tmp2;
428  int changed;
429  int iterations = 0;
430 
431  int maxiterations = lwgeom_count_vertices(tgt);
432 
433  /* GEOS snapping can be unstable */
434  /* See https://trac.osgeo.org/geos/ticket/760 */
435  do {
436  LWGEOM *tmp3;
437  tmp2 = lwgeom_snap(tmp, tgt, tol);
438  ++iterations;
439  changed = ( lwgeom_count_vertices(tmp2) != lwgeom_count_vertices(tmp) );
440 #if GEOS_NUMERIC_VERSION < 30309
441  /* Up to GEOS-3.3.8, snapping could duplicate points */
442  if ( changed ) {
443  tmp3 = lwgeom_remove_repeated_points( tmp2, 0 );
444  lwgeom_free(tmp2);
445  tmp2 = tmp3;
446  changed = ( lwgeom_count_vertices(tmp2) != lwgeom_count_vertices(tmp) );
447  }
448 #endif /* GEOS_NUMERIC_VERSION < 30309 */
449  LWDEBUGF(2, "After iteration %d, geometry changed ? %d (%d vs %d vertices)", iterations, changed, lwgeom_count_vertices(tmp2), lwgeom_count_vertices(tmp));
450  if ( tmp != src ) lwgeom_free(tmp);
451  tmp = tmp2;
452  } while ( changed && iterations <= maxiterations );
453 
454  LWDEBUGF(1, "It took %d/%d iterations to properly snap",
455  iterations, maxiterations);
456 
457  return tmp;
458 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
LWGEOM * lwgeom_remove_repeated_points(LWGEOM *in, double tolerance)
Remove repeated points!
Definition: lwgeom.c:1407
LWGEOM * lwgeom_snap(const LWGEOM *geom1, const LWGEOM *geom2, double tolerance)
Snap vertices and segments of a geometry to another using a given tolerance.
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1140
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the call graph for this function:

Here is the caller graph for this function: