6893{
6895 LWPOINT *start_point, *end_point;
6901 uint64_t nn, i;
6902 int moved=0, mm;
6903
6905 LWDEBUGF(1,
"_lwtAddLineEdge with tolerance %g", tol);
6906
6908 if ( ! start_point )
6909 {
6910 lwnotice(
"Empty component of noded line");
6911 return 0;
6912 }
6915 handleFaceSplit, &mm );
6917 if ( nid[0] == -1 ) return -1;
6918 moved += mm;
6919 LWDEBUGF(1,
"node for start point added or found to be %" LWTFMT_ELEMID " (moved ? %d)", nid[0], mm);
6920
6921
6923 if ( ! end_point )
6924 {
6925 lwerror(
"could not get last point of line "
6926 "after successfully getting first point !?");
6927 return -1;
6928 }
6931 handleFaceSplit, &mm );
6933 if ( nid[1] == -1 ) return -1;
6934 moved += mm;
6936
6937
6938
6939
6940
6941 if ( moved )
6942 {
6943
6944 LWDEBUG(1,
"One or both line endpoints moved by snap, updating line");
6945
6946 nn = nid[0] == nid[1] ? 1 : 2;
6949 if (nn == UINT64_MAX)
6950 {
6952 return -1;
6953 }
6954 start_point = NULL; end_point = NULL;
6955 for (i=0; i<nn; ++i)
6956 {
6957 if ( node[i].node_id == nid[0] ) start_point = node[i].
geom;
6958 if ( node[i].node_id == nid[1] ) end_point = node[i].
geom;
6959 }
6960 if ( ! start_point || ! end_point )
6961 {
6965 return -1;
6966 }
6967
6968
6969
6972
6975
6977
6979
6980
6982
6983 LWDEBUGG(2, tmp,
"Made-valid after snap to drifted endpoints");
6984
6986 if ( col )
6987 {{
6988
6990
6991
6992 if ( colex->
ngeoms == 0 )
6993 {
6996 LWDEBUG(1,
"Made-valid snapped edge collapsed");
6997 return 0;
6998 }
6999
7002 tmp = tmp2;
7005 if ( ! edge )
7006 {
7007
7008 lwerror(
"lwcollection_extract(LINETYPE) returned a non-line?");
7009 return -1;
7010 }
7011 }}
7012 else
7013 {
7015 if ( ! edge )
7016 {
7017 LWDEBUGF(1,
"Made-valid snapped edge collapsed to %s",
7020 return 0;
7021 }
7022 }
7023
7024 }
7025
7026
7029 if ( id == -1 )
7030 {
7032 return -1;
7033 }
7034 if ( id )
7035 {
7037 return id;
7038 }
7039
7040
7041
7042
7043
7044 if ( tol )
7045 {{
7047 LWDEBUGG(2, tmp2,
"Repeated-point removed");
7050 tmp = tmp2;
7051
7052
7054 {
7056 LWDEBUG(1,
"Repeated-point removed edge collapsed");
7057 return 0;
7058 }
7059
7060
7063 if ( id == -1 )
7064 {
7066 return -1;
7067 }
7068 if ( id )
7069 {
7071 return id;
7072 }
7073 }}
7074
7075
7076
7077 id =
_lwt_AddEdge( topo, nid[0], nid[1], edge, 0, handleFaceSplit ? 1 : -1 );
7079 if ( id == -1 )
7080 {
7082 return -1;
7083 }
7085
7086 *forward = 1;
7087 return id;
7088}
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
void lwcollection_free(LWCOLLECTION *col)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint)
LWCOLLECTION * lwcollection_extract(const LWCOLLECTION *col, uint32_t type)
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
LWGEOM * lwline_remove_repeated_points(const LWLINE *in, double tolerance)
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_NODE_GEOM
#define LWT_COL_NODE_NODE_ID
Node fields.
#define PGTOPO_BE_ERROR()
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
#define LWDEBUGG(level, geom, msg)
static LWT_ELEMID _lwt_AddEdge(LWT_TOPOLOGY *topo, LWT_ELEMID start_node, LWT_ELEMID end_node, LWLINE *geom, int skipChecks, int modFace)
static void _lwt_release_nodes(LWT_ISO_NODE *nodes, int num_nodes)
static double _lwt_minTolerance(LWGEOM *g)
static LWT_ELEMID _lwt_GetEqualEdge(LWT_TOPOLOGY *topo, LWLINE *edge, int *forward)
static LWT_ELEMID _lwt_AddPoint(LWT_TOPOLOGY *topo, LWPOINT *point, double tol, int findFace, int *moved)
LWT_ISO_NODE * lwt_be_getNodeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.