pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 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 
30 #include "postgres.h"
31 #include "executor/spi.h"
32 #include "funcapi.h"
33 #include "utils/array.h"
34 #include "catalog/pg_type.h"
35 #if PGSQL_VERSION > 92
36 #include "access/htup_details.h"
37 #endif
38 
39 /*
40  Uncomment when needed
41 */
42 // #define DEBUG
43 
44 #include "fmgr.h"
45 #include "./../../common/src/debug_macro.h"
46 #include "./../../common/src/pgr_types.h"
47 #include "./../../common/src/postgres_connection.h"
48 #include "./../../common/src/edges_input.h"
49 
50 #include "./testXYedges_driver.h"
51 
52 PGDLLEXPORT Datum testXYedges(PG_FUNCTION_ARGS);
53 
54 
55 static
56 void
57 process(char* edges_sql,
58  bool *result_bool) {
60 
61  PGR_DBG("Load data");
62  Pgr_edge_xy_t *edges = NULL;
63  size_t total_edges = 0;
64  pgr_get_edges_xy(edges_sql, &edges, &total_edges);
65 
66  if (total_edges == 0) {
67  PGR_DBG("No edges found");
68  (*result_bool) = true;
69  pfree(edges);
71  return;
72  }
73  PGR_DBG("Total %ld tuples in query:", total_edges);
74  size_t i;
75  for (i = 0; i < total_edges; ++i) {
76  PGR_DBG("id = %li \t source = %li \t target = %ld cost = %lf reverse_cost = %lf",
77  edges[i].id, edges[i].source, edges[i].target, edges[i].cost, edges[i].reverse_cost);
78  PGR_DBG(" (x1,y1) = (%.32lf ,%.32lf) (x2,y2) = (%.32lf,.%.32lf)",
79  edges[i].x1, edges[i].y1, edges[i].x2, edges[i].y2);
80  }
81 
82 
83  PGR_DBG("Starting processing");
84  char *err_msg = NULL;
85  char *log_msg = NULL;
86  (*result_bool) = do_pgr_testXYedges(
87  edges,
88  total_edges,
89  &log_msg,
90  &err_msg);
91 
92  pfree(edges);
93  PGR_DBG("Returned log message = %s\n", log_msg);
94  if (log_msg) {
95  elog(DEBUG1, "%s", log_msg);
96  free(log_msg);
97  }
98  PGR_DBG("Returned error message = %s\n", err_msg);
99 
100  if (err_msg) {
101  elog(ERROR, "%s", err_msg);
102  free(err_msg);
103  }
104 
105  pgr_SPI_finish();
106 }
107 
109 PGDLLEXPORT Datum
110 testXYedges(PG_FUNCTION_ARGS) {
111  bool result_bool = false;
112  process(
113  pgr_text2char(PG_GETARG_TEXT_P(0)),
114  &result_bool);
115 
116  PG_RETURN_BOOL(result_bool);
117 }
118 
PG_FUNCTION_INFO_V1(testXYedges)
#define PGR_DBG(...)
Definition: debug_macro.h:33
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:553
edge_astar_t * edges
Definition: BDATester.cpp:46
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)
char * err_msg
Definition: BDATester.cpp:50
char * pgr_text2char(text *in)
PGDLLEXPORT Datum testXYedges(PG_FUNCTION_ARGS)
Definition: testXYedges.c:110
static void process(char *edges_sql, bool *result_bool)
Definition: testXYedges.c:57