1 /*
2  lwn_network.h -- Topology-Network abstract multi-backend interface
3 
4  version 5.0, 2020 August 1
5 
6  Author: Sandro Furieri a.furieri@lqt.it
7 
8  ------------------------------------------------------------------------------
9 
10  Version: MPL 1.1/GPL 2.0/LGPL 2.1
11 
12  The contents of this file are subject to the Mozilla Public License Version
13  1.1 (the "License"); you may not use this file except in compliance with
14  the License. You may obtain a copy of the License at
15  http://www.mozilla.org/MPL/
16 
17 Software distributed under the License is distributed on an "AS IS" basis,
18 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
19 for the specific language governing rights and limitations under the
20 License.
21 
22 The Original Code is the SpatiaLite library
23 
24 The Initial Developer of the Original Code is Alessandro Furieri
25 
26 Portions created by the Initial Developer are Copyright (C) 2015-2021
27 the Initial Developer. All Rights Reserved.
28 
29 Contributor(s):
30 
31 Alternatively, the contents of this file may be used under the terms of
32 either the GNU General Public License Version 2 or later (the "GPL"), or
33 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
34 in which case the provisions of the GPL or the LGPL are applicable instead
35 of those above. If you wish to allow use of your version of this file only
36 under the terms of either the GPL or the LGPL, and not to allow others to
37 use your version of this file under the terms of the MPL, indicate your
38 decision by deleting the provisions above and replace them with the notice
39 and other provisions required by the GPL or the LGPL. If you do not delete
40 the provisions above, a recipient may use your version of this file under
41 the terms of any one of the MPL, the GPL or the LGPL.
42 
43 */
44 
45 #ifndef LWN_NETWORK_H
46 #define LWN_NETWORK_H 1
47 
48 #include <stdint.h>
49 
50 /* INT64 */
51 typedef int64_t LWN_INT64;
52 
53 /** Identifier of network element */
54 typedef LWN_INT64 LWN_ELEMID;
55 
56 /*
57  * Geometry elements
58  */
59 
60 typedef struct
61 {
62     int srid;
63     double x;
64     double y;
65     double z;
66     int has_z;
67 }
68 LWN_POINT;
69 
70 typedef struct
71 {
72     int srid;
73     int points;
74     double *x;
75     double *y;
76     double *z;
77     int has_z;
78 }
79 LWN_LINE;
80 
81 typedef struct
82 {
83     double min_x;
84     double min_y;
85     double max_x;
86     double max_y;
87 }
88 LWN_BBOX;
89 
90 /*
91  * ISO primitive elements
92  */
93 
94 /** NODE */
95 typedef struct
96 {
97     LWN_ELEMID node_id;
98     LWN_POINT *geom;
99 }
100 LWN_NET_NODE;
101 
102 /** Node fields */
103 #define LWN_COL_NODE_NODE_ID         1<<0
104 #define LWN_COL_NODE_GEOM            1<<1
105 #define LWN_COL_NODE_ALL            (1<<2)-1
106 
107 /** LINK */
108 typedef struct
109 {
110     LWN_ELEMID link_id;
111     LWN_ELEMID start_node;
112     LWN_ELEMID end_node;
113     LWN_LINE *geom;
114 }
115 LWN_LINK;
116 
117 /** Link fields */
118 #define LWN_COL_LINK_LINK_ID         1<<0
119 #define LWN_COL_LINK_START_NODE      1<<1
120 #define LWN_COL_LINK_END_NODE        1<<2
121 #define LWN_COL_LINK_GEOM            1<<3
122 #define LWN_COL_LINK_ALL            (1<<4)-1
123 
124 /*
125  * Backend handling functions
126  */
127 
128 /* opaque pointers referencing native backend objects */
129 
130 /**
131  * Backend private data pointer
132  *
133  * Only the backend handler needs to know what it really is.
134  * It will be passed to all registered callback functions.
135  */
136 typedef struct LWN_BE_DATA_T LWN_BE_DATA;
137 
138 /**
139  * Backend interface handler
140  *
141  * Embeds all registered backend callbacks and private data pointer.
142  * Will need to be passed (directly or indirectly) to al public facing
143  * APIs of this library.
144  */
145 typedef struct LWN_BE_IFACE_T LWN_BE_IFACE;
146 
147 /**
148  * Network handler.
149  *
150  * Embeds backend interface handler.
151  * Will need to be passed to all network manipulation APIs
152  * of this library.
153  */
154 typedef struct LWN_BE_NETWORK_T LWN_BE_NETWORK;
155 
156 /**
157  * Structure containing base backend callbacks
158  *
159  * Used for registering into the backend iface
160  */
161 typedef struct LWN_BE_CALLBACKS_T
162 {
163 
164   /**
165    * Create a new network in the backend
166    *
167    * @param name the network name
168    * @param srid the network SRID
169    * @param hasZ non-zero if network primitives should have a Z ordinate
170    * @param spatial determines if this is a Logical or SpatialNetwork
171    * @param coincident_nodes determines if they should de tolerated or not.
172    * @param geos_handle handle to GEOS context.
173    *
174    * @return a network handler, which embeds the backend data/params
175    *         or NULL on error (@see lastErrorMessage)
176    */
177     LWN_BE_NETWORK *(*createNetwork) (const LWN_BE_DATA * be,
178 				      const char *name, int srid, int hasZ,
179 				      int spatial, int coincident_nodes,
180 				      const void *geos_handle);
181 
182   /**
183    * Load a network from the backend
184    *
185    * @param name the network name
186    * @return a network handler, which embeds the backend data/params
187    *         or NULL on error (@see lastErrorMessage)
188    */
189     LWN_BE_NETWORK *(*loadNetworkByName) (const LWN_BE_DATA * be,
190 					  const char *name);
191 
192   /**
193    * Release memory associated to a backend network
194    *
195    * @param net the backend network handler
196    * @return 1 on success, 0 on error (@see lastErrorMessage)
197    */
198     int (*freeNetwork) (LWN_BE_NETWORK * net);
199 
200   /**
201    * Get nodes within distance by point
202    *
203    * @param net the network to act upon
204    * @param pt the query point
205    * @param dist the distance
206    * @param numelems output parameter, gets number of elements found
207    *                 if the return is not null, otherwise see @return
208    *                 section for semantic.
209    * @param fields fields to be filled in the returned structure, see
210    *               LWN_COL_NODE_* macros
211    * @param limit max number of nodes to return, 0 for no limit, -1
212    *              to only check for existance if a matching row.
213    *
214    * @return an array of nodes or null in the following cases:
215    *         - limit=-1 ("numelems" is set to 1 if found, 0 otherwise)
216    *         - limit>0 and no records found ("numelems" is set to 0)
217    *         - error ("numelems" is set to -1)
218    *
219    */
220     LWN_NET_NODE *(*getNetNodeWithinDistance2D) (const LWN_BE_NETWORK * net,
221 						 const LWN_POINT * pt,
222 						 double dist, int *numelems,
223 						 int fields, int limit);
224 
225   /**
226    * Get links that start or end on any of the given node identifiers
227    *
228    * @param net the network to act upon
229    * @param ids an array of node identifiers
230    * @param numelems input/output parameter, pass number of node identifiers
231    *                 in the input array, gets number of edges in output array
232    *                 if the return is not null, otherwise see @return
233    *                 section for semantic.
234    * @param fields fields to be filled in the returned structure, see
235    *               LWN_COL_LINK_* macros
236    *
237    * @return an array of links that are incident to a node
238    *         or NULL in the following cases:
239    *         - no link found ("numelems" is set to 0)
240    *         - error ("numelems" is set to -1)
241    *           (@see lastErrorMessage)
242    */
243     LWN_LINK *(*getLinkByNetNode) (const LWN_BE_NETWORK * net,
244 				   const LWN_ELEMID * ids, int *numelems,
245 				   int fields);
246 
247   /**
248    * Get links within distance by point
249    *
250    * @param net the network to act upon
251    * @param pt the query point
252    * @param dist the distance
253    * @param numelems output parameter, gets number of elements found
254    *                 if the return is not null, otherwise see @return
255    *                 section for semantic.
256    * @param fields fields to be filled in the returned structure, see
257    *               LWN_COL_LINK_* macros
258    * @param limit max number of links to return, 0 for no limit, -1
259    *              to only check for existance if a matching row.
260    *
261    * @return an array of links or null in the following cases:
262    *         - limit=-1 ("numelems" is set to 1 if found, 0 otherwise)
263    *         - limit>0 and no records found ("numelems" is set to 0)
264    *         - error ("numelems" is set to -1)
265    *
266    */
267     LWN_LINK *(*getLinkWithinDistance2D) (const LWN_BE_NETWORK * net,
268 					  const LWN_POINT * pt, double dist,
269 					  int *numelems, int fields, int limit);
270 
271   /**
272    * Insert nodes
273    *
274    * Insert node primitives in the network
275    *
276    * @param net the network to act upon
277    * @param nodes the nodes to insert. Those with a node_id set to -1
278    *              it will be replaced to an automatically assigned identifier
279    * @param nelems number of elements in the nodes array
280    *
281    * @return 1 on success, 0 on error (@see lastErrorMessage)
282    */
283     int (*insertNetNodes) (const LWN_BE_NETWORK * net,
284 			   LWN_NET_NODE * nodes, int numelems);
285 
286   /**
287    * Get nodes by id
288    *
289    * @param net the network to act upon
290    * @param ids an array of element identifiers
291    * @param numelems input/output parameter, pass number of node identifiers
292    *                 in the input array, gets number of node in output array.
293    * @param fields fields to be filled in the returned structure, see
294    *               LWN_COL_NODE_* macros
295    *
296    * @return an array of nodes
297    *         or NULL in the following cases:
298    *         - no node found ("numelems" is set to 0)
299    *         - error ("numelems" is set to -1)
300    *           (@see lastErrorMessage)
301    *
302    */
303     LWN_NET_NODE *(*getNetNodeById) (const LWN_BE_NETWORK * topo,
304 				     const LWN_ELEMID * ids, int *numelems,
305 				     int fields);
306 
307   /**
308    * Update nodes by id
309    *
310    * @param net the network to act upon
311    * @param nodes an array of LWN_NET_NODE objects with selecting id
312    *              and updating fields.
313    * @param numnodes number of nodes in the "nodes" array
314    * @param upd_fields fields to be updated for the selected edges,
315    *                   see LWN_COL_NODE_* macros
316    *
317    * @return number of nodes being updated or -1 on error
318    *         (@see lastErroMessage)
319    */
320     int (*updateNetNodesById) (const LWN_BE_NETWORK * net,
321 			       const LWN_NET_NODE * nodes, int numnodes,
322 			       int upd_fields);
323 
324   /**
325    * Delete nodes by id
326    *
327    * @param net the network to act upon
328    * @param ids an array of node identifiers
329    * @param numelems number of node identifiers in the ids array
330    *
331    * @return number of nodes being deleted or -1 on error
332    *         (@see lastErroMessage)
333    */
334     int (*deleteNetNodesById) (const LWN_BE_NETWORK * net,
335 			       const LWN_ELEMID * ids, int numelems);
336 
337   /**
338    * Get next available link identifier
339    *
340    * Identifiers returned by this function should not be considered
341    * available anymore.
342    *
343    * @param net the network to act upon
344    *
345    * @return next available link identifier or -1 on error
346    */
347       LWN_ELEMID (*getNextLinkId) (const LWN_BE_NETWORK * net);
348 
349   /**
350    * Get nodes within a 2D bounding box
351    *
352    * @param net the network to act upon
353    * @param box the query box
354    * @param numelems output parameter, gets number of elements found
355    *                 if the return is not null, otherwise see @return
356    *                 section for semantic.
357    * @param fields fields to be filled in the returned structure, see
358    *               LWN_COL_NODE_* macros
359    * @param limit max number of nodes to return, 0 for no limit, -1
360    *              to only check for existance if a matching row.
361    *
362    * @return an array of nodes or null in the following cases:
363    *         - limit=-1 ("numelems" is set to 1 if found, 0 otherwise)
364    *         - limit>0 and no records found ("numelems" is set to 0)
365    *         - error ("numelems" is set to -1)
366    *
367    */
368     LWN_NET_NODE *(*getNetNodeWithinBox2D) (const LWN_BE_NETWORK * net,
369 					    const LWN_BBOX * box,
370 					    int *numelems, int fields,
371 					    int limit);
372 
373   /**
374    * Get next available link identifier
375    *
376    * Identifiers returned by this function should not be considered
377    * available anymore.
378    *
379    * @param net the network to act upon
380    *
381    * @return next available link identifier or -1 on error
382    */
383       LWN_ELEMID (*getNexLinkId) (const LWN_BE_NETWORK * net);
384 
385   /**
386    * Insert links
387    *
388    * Insert link primitives in the network
389    *
390    * @param net the network to act upon
391    * @param links the links to insert. Those with a link_id set to -1
392    *              it will be replaced to an automatically assigned identifier
393    * @param nelems number of elements in the links array
394    *
395    * @return number of inserted links, or -1 (@see lastErrorMessage)
396    */
397     int (*insertLinks) (const LWN_BE_NETWORK * net,
398 			LWN_LINK * links, int numelems);
399 
400   /**
401    * Update links by id
402    *
403    * @param net the network to act upon
404    * @param links an array of LWN_LINK object with selecting id
405    *              and updating fields.
406    * @param numedges number of links in the "links" array
407    * @param upd_fields fields to be updated for the selected links,
408    *                   see LWN_COL_LINK_* macros
409    *
410    * @return number of links being updated or -1 on error
411    *         (@see lastErroMessage)
412    */
413     int (*updateLinksById) (const LWN_BE_NETWORK * net,
414 			    const LWN_LINK * links, int numlinks,
415 			    int upd_fields);
416 
417   /**
418    * Get link by id
419    *
420    * @param net the network to act upon
421    * @param ids an array of element identifiers
422    * @param numelems input/output parameter, pass number of link identifiers
423    *                 in the input array, gets number of links in output array
424    *                 if the return is not null, otherwise see @return
425    *                 section for semantic.
426    * @param fields fields to be filled in the returned structure, see
427    *               LWN_COL_LINK_* macros
428    *
429    * @return an array of links or NULL in the following cases:
430    *         - none found ("numelems" is set to 0)
431    *         - error ("numelems" is set to -1)
432    */
433     LWN_LINK *(*getLinkById) (const LWN_BE_NETWORK * net,
434 			      const LWN_ELEMID * ids, int *numelems,
435 			      int fields);
436 
437   /**
438    * Delete links by id
439    *
440    * @param net the network to act upon
441    * @param ids an array of link identifiers
442    * @param numelems number of link identifiers in the ids array
443    *
444    * @return number of links being deleted or -1 on error
445    *         (@see lastErroMessage)
446    */
447     int (*deleteLinksById) (const LWN_BE_NETWORK * net,
448 			    const LWN_ELEMID * ids, int numelems);
449 
450 
451   /**
452    * Get network SRID
453    * @return 0 for unknown
454    */
455     int (*netGetSRID) (const LWN_BE_NETWORK * net);
456 
457   /**
458    * Get network Z flag
459    * @return 1 if network elements do have Z value, 0 otherwise
460    */
461     int (*netHasZ) (const LWN_BE_NETWORK * net);
462 
463   /**
464    * Get network type flag
465    * @return 0 if network is of the Logical Type, 1 otherwise (Spatial)
466    */
467     int (*netIsSpatial) (const LWN_BE_NETWORK * net);
468 
469   /**
470    * Get CoincidentNodes flag
471    * @return 1 if newtwork tolerates Coincident Nodes, 0 otherwise (Spatial)
472    */
473     int (*netAllowCoincident) (const LWN_BE_NETWORK * net);
474 
475   /**
476    * Get GEOS Handle
477    * @return current GEOS Handle, NULL otherwise
478    */
479     const void *(*netGetGEOS) (const LWN_BE_NETWORK * net);
480 
481 
482 } LWN_BE_CALLBACKS;
483 
484 
485 /**
486  * Create a new backend interface
487  *
488  * Ownership to caller delete with lwn_FreeBackendIface
489  *
490  * @param ctx librtgeom context, create with rtgeom_init
491  * @param data Backend data, passed as first parameter to all callback functions
492  */
493 LWN_BE_IFACE *lwn_CreateBackendIface (const RTCTX * ctx,
494 				      const LWN_BE_DATA * data);
495 
496 /**
497  * Register backend callbacks into the opaque iface handler
498  *
499  * @param iface the backend interface handler (see lwn_CreateBackendIface)
500  * @param cb a pointer to the callbacks structure; ownership left to caller.
501  */
502 void lwn_BackendIfaceRegisterCallbacks (LWN_BE_IFACE * iface,
503 					const LWN_BE_CALLBACKS * cb);
504 
505 /** Release memory associated with an LWB_BE_IFACE */
506 void lwn_FreeBackendIface (LWN_BE_IFACE * iface);
507 
508 /********************************************************************
509  *
510  * End of BE interface
511  *
512  *******************************************************************/
513 
514 
515 /*
516  * Network functions
517  */
518 
519 /** Opaque network structure
520  *
521  * Embeds backend interface and network
522  */
523 typedef struct LWN_NETWORK_T LWN_NETWORK;
524 
525 
526 /********************************************************************
527  *
528  * Error handling functions
529  *
530  *******************************************************************/
531 
532 /**
533  * Reset the last backend error message
534  *
535  * @oaram iface the backend interface handler (see lwn_CreateBackendIface)
536  */
537 void lwn_ResetErrorMsg (LWN_BE_IFACE * iface);
538 
539 /**
540  * Set the last backend error message
541  *
542  * @oaram iface the backend interface handler (see lwn_CreateBackendIface)
543  *
544  * @return NULL-terminated error string
545  */
546 void lwn_SetErrorMsg (LWN_BE_IFACE * iface, const char *message);
547 
548 /**
549  * Read last error message from backend
550  *
551  * @oaram iface the backend interface handler (see lwn_CreateBackendIface)
552  *
553  * @return NULL-terminated error string
554  */
555 const char *lwn_GetErrorMsg (LWN_BE_IFACE * iface);
556 
557 
558 /*******************************************************************
559  *
560  * Backend independent Linestring auxiliary functions
561  *
562  *******************************************************************/
563 
564 /**
565  * Creates a backend independent 2D Point
566  *
567  * @param srid the network SRID
568  * @param x the X coordinate
569  * @param y the Y coordinate
570  *
571  * @return pointer to a new LWN_POINT
572  */
573 LWN_POINT *lwn_create_point2d (int srid, double x, double y);
574 
575 /**
576  * Creates a backend independent 3D Point
577  *
578  * @param srid the network SRID
579  * @param x the X coordinate
580  * @param y the Y coordinate
581  * @param z the Z coordinate
582  *
583  * @return pointer to a new LWN_POINT
584  */
585 LWN_POINT *lwn_create_point3d (int srid, double x, double y, double z);
586 
587 /**
588  * Free a backend independent Point
589  *
590  * @param ptr pointer to the LWN_POINT to be freed
591  */
592 void lwn_free_point (LWN_POINT * ptr);
593 
594 /**
595  * Initializes a backend independent Linestring
596  *
597  * @param points total number of points
598  * @param srid the network SRID
599  * @param hasz non-zero if network primitives should have a Z ordinate
600  *
601  * @return pointer to a new LWN_LINE
602  */
603 LWN_LINE *lwn_alloc_line (int points, int srid, int hasz);
604 
605 /**
606  * Free a backend independent Linestring
607  *
608  * @param ptr pointer to the LWN_LINE to be freed
609  */
610 void lwn_free_line (LWN_LINE * ptr);
611 
612 
613 /*******************************************************************
614  *
615  * Non-ISO signatures here
616  *
617  *******************************************************************/
618 
619 /**
620  * Initializes a new network
621  *
622  * @param iface the backend interface handler (see lwn_CreateBackendIface)
623  * @param name name of the new network
624  * @param srid the network SRID
625  * @param hasz non-zero if network primitives should have a Z ordinate
626  * @param spatial determines if this is a Logical or SpatialNetwork
627  * @param coincident_nodes determines if they should de tolerated or not.
628  *
629  * @return the handler of the network, or NULL on error
630  *         (lwn error handler will be invoked with error message)
631  */
632 LWN_NETWORK *lwn_CreateNetwork (LWN_BE_IFACE * iface, const char *name,
633 				int srid, int hasz, int spatial,
634 				int coincident_nodes);
635 
636 /**
637  * Loads an existing network by name from the database
638  *
639  * @param iface the backend interface handler (see lwt_CreateBackendIface)
640  * @param name name of the network to load
641  *
642  * @return the handler of the network, or NULL on error
643  *         (lwn error handler will be invoked with error message)
644  */
645 LWN_NETWORK *lwn_LoadNetwork (LWN_BE_IFACE * iface, const char *name);
646 
647 /**
648  * Drop a network and all its associated objects from the database
649  *
650  * @param net the network to drop
651  */
652 void lwn_DropNetwork (LWN_NETWORK * net);
653 
654 /** Release memory associated with an LWN_NETWORK
655  *
656  * @param net the network to release (it's not removed from db)
657  */
658 void lwn_FreeNetwork (LWN_NETWORK * net);
659 
660 
661 /*******************************************************************
662  *
663  * ISO signatures here
664  *
665  *******************************************************************/
666 
667 /**
668  * Add an isolated node
669  *
670  * For ST_AddIsoNetNode
671  *
672  * @param net the network to operate on
673  * @param pt the node position
674  *
675  * @return ID of the newly added node
676  *
677  */
678 LWN_ELEMID lwn_AddIsoNetNode (LWN_NETWORK * net, LWN_POINT * pt);
679 
680 /**
681  * Move an isolated node
682  *
683  * For ST_MoveIsoNetNode
684  *
685  * @param net the network to operate on
686  * @param node the identifier of the nod to be moved
687  * @param pt the new node position
688  * @return 0 on success, -1 on error
689  *         (lwn error handler will be invoked with error message)
690  *
691  */
692 int lwn_MoveIsoNetNode (LWN_NETWORK * net, LWN_ELEMID node,
693 			const LWN_POINT * pt);
694 
695 /**
696  * Remove an isolated node
697  *
698  * For ST_RemIsoNetNode
699  *
700  * @param net the network to operate on
701  * @param node the identifier of the node to be moved
702  * @return 0 on success, -1 on error
703  *         (lwn error handler will be invoked with error message)
704  *
705  */
706 int lwn_RemIsoNetNode (LWN_NETWORK * net, LWN_ELEMID node);
707 
708 /**
709  * Add a link connecting two existing nodes
710  *
711  * For ST_AddLink
712  *
713  * @param net the network to operate on
714  * @param start_node identifier of the starting node
715  * @param end_node identifier of the ending node
716  * @param geom the link geometry
717  * @return ID of the newly added link, or -1 on error
718  *         (lwn error handler will be invoked with error message)
719  *
720  */
721 LWN_ELEMID lwn_AddLink (LWN_NETWORK * net,
722 			LWN_ELEMID startNode, LWN_ELEMID endNode,
723 			LWN_LINE * geom);
724 
725 /**
726  * Changes the shape of a link without affecting the network structure.
727  *
728  * For ST_ChangeLinkGeom
729  *
730  * @param net the network to operate on
731  * @param link the identifier of the link to be changed
732  * @param curve the link geometry
733  * @return 0 on success, -1 on error
734  *         (lwn error handler will be invoked with error message)
735  *
736  */
737 int lwn_ChangeLinkGeom (LWN_NETWORK * net, LWN_ELEMID link,
738 			const LWN_LINE * curve);
739 
740 /**
741  * Remove a link.
742  *
743  * For ST_RemoveLink
744  *
745  * @param net the network to operate on
746  * @param link the identifier of the link to be removed
747  * @return 0 on success, -1 on error
748  *         (lwn error handler will be invoked with error message)
749  *
750  */
751 int lwn_RemoveLink (LWN_NETWORK * net, LWN_ELEMID link);
752 
753 /**
754  * Split a logical link, replacing it with two new links.
755  *
756  * For ST_NewLogLinkSplit
757  *
758  * @param net the network to operate on
759  * @param link the identifier of the link to be split.
760  * @return the ID of the inserted Node; a negative number on failure.
761  *         (lwn error handler will be invoked with error message)
762  *
763  */
764 LWN_INT64 lwn_NewLogLinkSplit (LWN_NETWORK * net, LWN_ELEMID link);
765 
766 /**
767  * Split a logical link, modifying the original link and adding a new one.
768  *
769  * For ST:ModLogLinkSplit
770  *
771  * @param net the network to operate on
772  * @param link the identifier of the link to be split.
773  * @return the ID of the inserted Node; a negative number on failure.
774  *         (lwn error handler will be invoked with error message)
775  *
776  */
777 LWN_INT64 lwn_ModLogLinkSplit (LWN_NETWORK * net, LWN_ELEMID link);
778 
779 /**
780  * Split a spatial link by a node, replacing it with two new links.
781  *
782  * For ST_NewGeoLinkSplit
783  *
784  * @param net the network to operate on
785  * @param link the identifier of the link to be split.
786  * @param pt the point geometry
787  * @return the ID of the inserted Node; a negative number on failure.
788  *         (lwn error handler will be invoked with error message)
789  *
790  */
791 LWN_INT64 lwn_NewGeoLinkSplit (LWN_NETWORK * net, LWN_ELEMID link,
792 			       const LWN_POINT * pt);
793 
794 /**
795  * Split a spatial link by a node, modifying the original link and adding
796  * a new one.
797  *
798  * For ST_ModGeoLinkSplit
799  *
800  * @param net the network to operate on
801  * @param link the identifier of the link to be split.
802  * @param pt the point geometry
803  * @return the ID of the inserted Node; a negative number on failure.
804  *         (lwn error handler will be invoked with error message)
805  *
806  */
807 LWN_INT64 lwn_ModGeoLinkSplit (LWN_NETWORK * net, LWN_ELEMID link,
808 			       const LWN_POINT * pt);
809 
810 /**
811  * Heal two links by deleting the node connecting them, deleting both links,
812  * and replacing them with a new link whose direction is the same as the
813  * first link provided.
814  *
815  * For ST_NewLinkHeal
816  *
817  * @param net the network to operate on
818  * @param link the identifier of a first link.
819  * @param anotherlink the identifier of a second link.
820  * @return the ID of the rmove Node; a negative number on failure.
821  *         (lwn error handler will be invoked with error message)
822  *
823  */
824 LWN_INT64 lwn_NewLinkHeal (LWN_NETWORK * net, LWN_ELEMID link,
825 			   LWN_ELEMID anotherlink);
826 
827 /**
828  * Heal two links by deleting the node connecting them, modfying the first
829  * link provided, and deleting the second link.
830  *
831  * For ST_ModLinkHeal
832  *
833  * @param net the network to operate on
834  * @param link the identifier of a first link.
835  * @param anotherlink the identifier of a second link.
836  * @return the ID of the rmove Node; a negative number on failure.
837  *         (lwn error handler will be invoked with error message)
838  *
839  */
840 LWN_INT64 lwn_ModLinkHeal (LWN_NETWORK * net, LWN_ELEMID link,
841 			   LWN_ELEMID anotherlink);
842 
843 /**
844  * Retrieve the id of a net-node at a point location
845  *
846  * For GetNetNodeByNode
847  *
848  * @param net the network to operate on
849  * @param point the point to use for query
850  * @param tol max distance around the given point to look for a net-node
851  * @return a net-node identifier if one is found, 0 if none is found, -1
852  *         on error (multiple net-nodes within distance).
853  *         (lwn error handler will be invoked with error message)
854  */
855 LWN_ELEMID lwn_GetNetNodeByPoint (LWN_NETWORK * net, const LWN_POINT * pt,
856 				  double tol);
857 
858 /**
859  * Find the edge-id of a link that intersects a given point
860  *
861  * For GetLinkByPoint
862  *
863  * @param net the network to operate on
864  * @param point the point to use for query
865  * @param tol max distance around the given point to look for an
866  *            intersecting link
867  * @return a link identifier if one is found, 0 if none is found, -1
868  *         on error (multiple links within distance).
869  *         (lwn error handler will be invoked with error message)
870  */
871 LWN_ELEMID lwn_GetLinkByPoint (LWN_NETWORK * net, const LWN_POINT * pt,
872 			       double tol);
873 
874 #endif /* LWN_NETWORK_H */
875