PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
testXYedges.c
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: testXYedges.c
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2015 Celia Virginia Vergara Castillo
10 Mail:
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28 ********************************************************************PGR-GNU*/
29 
31 
32 #include "./testXYedges_driver.h"
33 #include "c_common/edges_input.h"
34 #include "c_common/debug_macro.h"
35 
36 
37 PGDLLEXPORT Datum testXYedges(PG_FUNCTION_ARGS);
38 
39 
40 static
41 void
42 process(char* edges_sql,
43  bool *result_bool) {
45 
46  PGR_DBG("Load data");
47  Pgr_edge_xy_t *edges = NULL;
48  size_t total_edges = 0;
49  pgr_get_edges_xy(edges_sql, &edges, &total_edges);
50 
51  if (total_edges == 0) {
52  PGR_DBG("No edges found");
53  (*result_bool) = true;
54  pfree(edges);
56  return;
57  }
58  PGR_DBG("Total %ld tuples in query:", total_edges);
59  size_t i;
60  for (i = 0; i < total_edges; ++i) {
61  PGR_DBG("id = %li \t source = %li \t target = %ld cost = %lf reverse_cost = %lf",
62  edges[i].id, edges[i].source, edges[i].target, edges[i].cost, edges[i].reverse_cost);
63  PGR_DBG(" (x1,y1) = (%.32lf ,%.32lf) (x2,y2) = (%.32lf,.%.32lf)",
64  edges[i].x1, edges[i].y1, edges[i].x2, edges[i].y2);
65  }
66 
67 
68  PGR_DBG("Starting processing");
69  char *err_msg = NULL;
70  char *log_msg = NULL;
71  (*result_bool) = do_pgr_testXYedges(
72  edges,
73  total_edges,
74  &log_msg,
75  &err_msg);
76 
77  pfree(edges);
78  PGR_DBG("Returned log message = %s\n", log_msg);
79  if (log_msg) {
80  elog(DEBUG1, "%s", log_msg);
81  free(log_msg);
82  }
83  PGR_DBG("Returned error message = %s\n", err_msg);
84 
85  if (err_msg) {
87  elog(ERROR, "%s", err_msg);
88  free(err_msg);
89  }
90 
92 }
93 
95 PGDLLEXPORT Datum
96 testXYedges(PG_FUNCTION_ARGS) {
97  bool result_bool = false;
98  process(
99  text_to_cstring(PG_GETARG_TEXT_P(0)),
100  &result_bool);
101 
102  PG_RETURN_BOOL(result_bool);
103 }
104 
static edge_t edges[22573]
PG_FUNCTION_INFO_V1(testXYedges)
#define PGR_DBG(...)
Definition: debug_macro.h:34
void pgr_SPI_finish(void)
void pgr_get_edges_xy(char *edges_sql, Pgr_edge_xy_t **edges, size_t *total_edges)
Edges with x, y vertices values.
Definition: edges_input.c:573
void pgr_SPI_connect(void)
bool do_pgr_testXYedges(Pgr_edge_xy_t *data_edges, size_t total_edges, char **log_msg, char **err_msg)
PGDLLEXPORT Datum testXYedges(PG_FUNCTION_ARGS)
Definition: testXYedges.c:96
static void process(char *edges_sql, bool *result_bool)
Definition: testXYedges.c:42