PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ _lwt_toposnap()

static LWGEOM* _lwt_toposnap ( LWGEOM src,
LWGEOM tgt,
double  tol 
)
static

Definition at line 420 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().

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