2306{
2314 const LWPOINT *start_node_geom = NULL;
2315 const LWPOINT *end_node_geom = NULL;
2316 uint64_t num_nodes;
2318 uint64_t i;
2323
2324 if ( ! skipChecks )
2325 {
2326
2328 {
2329 lwerror(
"SQL/MM Spatial exception - curve not simple");
2330 return -1;
2331 }
2332 }
2333
2336 newedge.
geom = geom;
2339
2341
2345 lwerror(
"Invalid edge (no two distinct vertices exist)");
2346 return -1;
2347 }
2348
2349
2352
2353
2356 {
2358 lwerror(
"Invalid edge (no two distinct vertices exist)");
2359 return -1;
2360 }
2363 lwerror(
"error computing azimuth of first edgeend [%.15g %.15g,%.15g %.15g]",
2364 p1.
x, p1.
y, pn.
x, pn.
y);
2365 return -1;
2366 }
2367 LWDEBUGF(1,
"edge's start node is %g,%g", p1.
x, p1.
y);
2368
2369
2372 {
2374
2375 lwerror(
"Invalid clean edge (no two distinct vertices exist) - should not happen");
2376 return -1;
2377 }
2380 lwerror(
"error computing azimuth of last edgeend [%.15g %.15g,%.15g %.15g]",
2381 p2.
x, p2.
y, pn.
x, pn.
y);
2382 return -1;
2383 }
2384 LWDEBUGF(1,
"edge's end node is %g,%g", p2.
x, p2.
y);
2385
2386
2387
2388
2389
2390
2391 if ( start_node != end_node ) {
2392 num_nodes = 2;
2393 node_ids[0] = start_node;
2394 node_ids[1] = end_node;
2395 } else {
2396 num_nodes = 1;
2397 node_ids[0] = start_node;
2398 }
2399
2401 if (num_nodes == UINT64_MAX)
2402 {
2404 return -1;
2405 }
2406 for ( i=0; i<num_nodes; ++i )
2407 {
2410 {
2412 {
2414 }
2416 {
2418 lwerror(
"SQL/MM Spatial exception - geometry crosses an edge"
2421 }
2422 }
2423
2427 if ( node->
node_id == start_node ) {
2428 start_node_geom = node->
geom;
2429 }
2430 if ( node->
node_id == end_node ) {
2431 end_node_geom = node->
geom;
2432 }
2433 }
2434
2435 if ( ! skipChecks )
2436 {
2437 if ( ! start_node_geom )
2438 {
2440 lwerror(
"SQL/MM Spatial exception - non-existent node");
2441 return -1;
2442 }
2443 else
2444 {
2445 pa = start_node_geom->
point;
2448 {
2450 lwerror(
"SQL/MM Spatial exception"
2451 " - start node not geometry start point."
2452
2453 );
2454 return -1;
2455 }
2456 }
2457
2458 if ( ! end_node_geom )
2459 {
2461 lwerror(
"SQL/MM Spatial exception - non-existent node");
2462 return -1;
2463 }
2464 else
2465 {
2466 pa = end_node_geom->
point;
2469 {
2471 lwerror(
"SQL/MM Spatial exception"
2472 " - end node not geometry end point."
2473
2474 );
2475 return -1;
2476 }
2477 }
2478
2480
2482 return -1;
2483
2484 }
2485
2486
2487
2488
2489
2491 if ( newedge.
edge_id == -1 ) {
2493 return -1;
2494 }
2495
2496
2497 int isclosed = start_node == end_node;
2498 int found;
2500 isclosed ? &epan : NULL, -1 );
2501 if ( found ) {
2509 if ( modFace != -1 )
2510 {
2513 }
2516 }
2517 }
2518 } else {
2526 }
2527
2529 isclosed ? &span : NULL, -1 );
2530 if ( found ) {
2538 if ( modFace != -1 )
2539 {
2543
2544 lwerror(
"Side-location conflict: "
2545 "new edge starts in face"
2549 );
2550 return -1;
2551 }
2555
2556 lwerror(
"Side-location conflict: "
2557 "new edge starts in face"
2561 );
2562 return -1;
2563 }
2564 }
2565 } else {
2573 }
2574
2575
2576
2577
2578
2579
2580 if ( modFace > -1 )
2581 {
2583 {
2585 " faces mismatch: invalid topology ?",
2587 return -1;
2588 }
2590 {
2591 lwerror(
"Could not derive edge face from linked primitives:"
2592 " invalid topology ?");
2593 return -1;
2594 }
2595 }
2596
2597
2598
2599
2600
2602 if ( ret == -1 ) {
2604 return -1;
2605 } else if ( ret == 0 ) {
2606 lwerror(
"Insertion of split edge failed (no reason)");
2607 return -1;
2608 }
2609
2610 int updfields;
2611
2612
2613
2614 if ( llabs(prev_left) != newedge.
edge_id )
2615 {
2616 if ( prev_left > 0 )
2617 {
2618
2622 }
2623 else
2624 {
2625
2629 }
2630
2633 &updedge, updfields,
2634 NULL, 0);
2635 if ( ret == -1 ) {
2637 return -1;
2638 }
2639 }
2640
2641
2642
2643 if ( llabs(prev_right) != newedge.
edge_id )
2644 {
2645 if ( prev_right > 0 )
2646 {
2647
2651 }
2652 else
2653 {
2654
2657 seledge.
edge_id = -prev_right;
2658 }
2659
2662 &updedge, updfields,
2663 NULL, 0);
2664 if ( ret == -1 ) {
2666 return -1;
2667 }
2668 }
2669
2670
2671
2672
2673
2674
2678 {
2683 NULL, 0);
2684 if ( ret == -1 ) {
2686 return -1;
2687 }
2688 }
2690 {
2695 NULL, 0);
2696 if ( ret == -1 ) {
2698 return -1;
2699 }
2700 }
2701
2702
2703
2704 if ( modFace > -1 ) {
2705
2707 {
2708 LWDEBUG(1,
"New edge is dangling, so it cannot split any face");
2710 }
2711
2712 int newface1 = -1;
2713
2714
2715
2716
2717 if ( ! modFace )
2718 {
2720 if ( newface1 == 0 ) {
2721 LWDEBUG(1,
"New edge does not split any face");
2723 }
2724 }
2725
2728 if ( modFace )
2729 {
2730 if ( newface == 0 ) {
2731 LWDEBUG(1,
"New edge does not split any face");
2733 }
2734
2735 if ( newface < 0 )
2736 {
2737
2738
2741 if ( newface < 0 )
return newedge.
edge_id;
2742 }
2743 else
2744 {
2746 }
2747 }
2748
2749
2750
2751
2753 {
2755 newface, newface1);
2756 if ( ret == 0 ) {
2758 return -1;
2759 }
2760
2761 if ( ! modFace )
2762 {
2763
2765 if ( ret == -1 ) {
2767 return -1;
2768 }
2769 }
2770 }
2771
2772 }
2773
2775}
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
void lwgeom_free(LWGEOM *geom)
int lwgeom_is_simple(const LWGEOM *lwgeom)
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
LWGEOM * lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
#define P2D_SAME_STRICT(a, b)
LWT_INT64 LWT_ELEMID
Identifier of topology element.
#define LWT_COL_EDGE_NEXT_RIGHT
#define LWT_COL_NODE_CONTAINING_FACE
#define LWT_COL_EDGE_EDGE_ID
Edge fields.
#define LWT_COL_EDGE_NEXT_LEFT
#define LWT_COL_NODE_NODE_ID
Node fields.
#define PGTOPO_BE_ERROR()
#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.
static int lwt_be_deleteFacesById(const LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems)
LWT_ELEMID lwt_be_getNextEdgeId(LWT_TOPOLOGY *topo)
static int lwt_be_updateTopoGeomFaceSplit(LWT_TOPOLOGY *topo, LWT_ELEMID split_face, LWT_ELEMID new_face1, LWT_ELEMID new_face2)
static int _lwt_CheckEdgeCrossing(LWT_TOPOLOGY *topo, LWT_ELEMID start_node, LWT_ELEMID end_node, const LWLINE *geom, LWT_ELEMID myself)
static void _lwt_release_nodes(LWT_ISO_NODE *nodes, int num_nodes)
int lwt_be_updateEdges(LWT_TOPOLOGY *topo, const LWT_ISO_EDGE *sel_edge, int sel_fields, const LWT_ISO_EDGE *upd_edge, int upd_fields, const LWT_ISO_EDGE *exc_edge, int exc_fields)
static LWT_ELEMID _lwt_AddFaceSplit(LWT_TOPOLOGY *topo, LWT_ELEMID sedge, LWT_ELEMID face, int mbr_only)
int lwt_be_insertEdges(LWT_TOPOLOGY *topo, LWT_ISO_EDGE *edge, uint64_t numelems)
static int _lwt_FirstDistinctVertex2D(const POINTARRAY *pa, const POINT2D *ref, int from, int dir, POINT2D *op)
LWT_ISO_NODE * lwt_be_getNodeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields)
static int lwt_be_updateNodes(LWT_TOPOLOGY *topo, const LWT_ISO_NODE *sel_node, int sel_fields, const LWT_ISO_NODE *upd_node, int upd_fields, const LWT_ISO_NODE *exc_node, int exc_fields)
static int _lwt_FindAdjacentEdges(LWT_TOPOLOGY *topo, LWT_ELEMID node, edgeend *data, edgeend *other, LWT_ELEMID myedge_id)
LWT_ELEMID containing_face