6633{
6634 uint64_t i, j;
6642
6643 j = 0;
6644 for (i=0; i<num; ++i)
6645 {
6646 double dist;
6648
6651 if ( dist >= tol ) continue;
6653 sorted[j++].
score = dist;
6654 }
6655 if ( ! j )
6656 {
6658 return 0;
6659 }
6660
6661 num = j;
6664 for (j=0, i=0; i<num; ++i)
6665 {
6666 if ( sorted[i].score == sorted[0].score )
6667 {
6669 }
6670 else
6671 {
6673
6674 }
6675 }
6676 num = j;
6678 edges = edges2;
6679
6680
6682 if ( moved ) *moved =
lwgeom_same(prj, lwpoint) ? 0 : 1;
6684 {{
6685
6686
6687
6688
6690 double z;
6693
6702 prj = tmp;
6703 }}
6704
6705 LWDEBUGG(1, prj,
"Projected point");
6708
6709 for (i=0; i<num; ++i)
6710 {
6711
6712
6713
6714
6715
6720
6721 if ( i )
6722 {{
6724 if ( ret != 0 ) {
6725 lwerror(
"Something went wrong with _lwt_SnapEdgeToExistingNode");
6726 return -1;
6727 }
6728 continue;
6729 }}
6730
6732
6736 {{
6740
6742 " does not contain projected point to it",
6743 edge_id);
6744
6745#if 0
6746
6747
6748 if ( i+1 < num )
6749 {
6750 LWDEBUG(1,
"But there's another to check");
6751
6752 continue;
6753 }
6754#endif
6755
6758
6759 LWDEBUGF(1,
"Edge snapped with tolerance %g", tol);
6760
6761
6762#if POSTGIS_DEBUG_LEVEL > 0
6763 {
6764 size_t sz;
6767 LWDEBUGF(1,
"Edge %s snapped became %s", wkt1, wkt2);
6770 }
6771#endif
6772
6773
6774
6775
6776
6777
6780 LWDEBUGF(1,
"Edge first point is %g %g, "
6781 "snapline first point is %g %g",
6782 p1.
x, p1.
y, p2.
x, p2.
y);
6783 if ( p1.
x != p2.
x || p1.
y != p2.
y )
6784 {
6785 LWDEBUG(1,
"Snapping moved first point, re-adding it");
6787 {
6791 return -1;
6792 }
6793#if POSTGIS_DEBUG_LEVEL > 0
6794 {
6795 size_t sz;
6797 LWDEBUGF(1,
"Tweaked snapline became %s", wkt1);
6799 }
6800#endif
6801 }
6802#if POSTGIS_DEBUG_LEVEL > 0
6803 else {
6804 LWDEBUG(1,
"Snapping did not move first point");
6805 }
6806#endif
6807
6809 {
6810
6813 lwerror(
"lwt_ChangeEdgeGeom failed");
6814 return -1;
6815 }
6817 }}
6818#if POSTGIS_DEBUG_LEVEL > 0
6819 else
6820 {{
6821 size_t sz;
6824 LWDEBUGF(1,
"Edge %s contains projected point %s", wkt1, wkt2);
6827 }}
6828#endif
6829
6830
6833 {
6834
6836 lwerror(
"lwt_ModEdgeSplit failed");
6837 return -1;
6838 }
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853 }
6854
6856
6857 if ( edges2 )
lwfree(edges2);
6859}
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
LWGEOM * lwgeom_closest_point(const LWGEOM *lw1, const LWGEOM *lw2)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwgeom_force_3dz(const LWGEOM *geom, double zval)
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
void * lwalloc(size_t size)
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initializing min distance calculation.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
LWT_INT64 LWT_ELEMID
Identifier of topology element.
Datum contains(PG_FUNCTION_ARGS)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
#define LWDEBUGG(level, geom, msg)
static LWGEOM * _lwt_toposnap(LWGEOM *src, LWGEOM *tgt, double tol)
static int _lwt_SnapEdgeToExistingNode(LWT_TOPOLOGY *topo, LWT_ISO_NODE *node, LWT_ISO_EDGE *edge, double tol)
LWT_ELEMID lwt_ModEdgeSplit(LWT_TOPOLOGY *topo, LWT_ELEMID edge, LWPOINT *pt, int skipISOChecks)
Split an edge by a node, modifying the original edge and adding a new one.
static int compare_scored_pointer(const void *si1, const void *si2)
int lwt_ChangeEdgeGeom(LWT_TOPOLOGY *topo, LWT_ELEMID edge_id, LWLINE *geom)
Changes the shape of an edge without affecting the topology structure.
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
LWT_ELEMID containing_face