PGROUTING  2.5
withPoints.c File Reference
Include dependency graph for withPoints.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (withPoints)
 
static void process (char *edges_sql, char *points_sql, ArrayType *starts, ArrayType *ends, bool directed, char *driving_side, bool details, bool only_cost, bool normal, General_path_element_t **result_tuples, size_t *result_count)
 
PGDLLEXPORT Datum withPoints (PG_FUNCTION_ARGS)
 

Function Documentation

PG_FUNCTION_INFO_V1 ( withPoints  )
static void process ( char *  edges_sql,
char *  points_sql,
ArrayType *  starts,
ArrayType *  ends,
bool  directed,
char *  driving_side,
bool  details,
bool  only_cost,
bool  normal,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 49 of file withPoints.c.

References do_pgr_withPoints(), edges, estimate_drivingSide(), get_new_queries(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_edges(), pgr_get_edges_reversed(), pgr_get_points(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by withPoints().

63  {
64  driving_side[0] = estimate_drivingSide(driving_side[0]);
65 
67 
68  size_t size_start_pidsArr = 0;
69  int64_t* start_pidsArr = NULL;
70 
71  size_t size_end_pidsArr = 0;
72  int64_t* end_pidsArr = NULL;
73 
74  Point_on_edge_t *points = NULL;
75  size_t total_points = 0;
76  pgr_get_points(points_sql, &points, &total_points);
77 
78 
79  char *edges_of_points_query = NULL;
80  char *edges_no_points_query = NULL;
82  edges_sql, points_sql,
83  &edges_of_points_query,
84  &edges_no_points_query);
85 
86 
87  pgr_edge_t *edges_of_points = NULL;
88  size_t total_edges_of_points = 0;
89 
90  pgr_edge_t *edges = NULL;
91  size_t total_edges = 0;
92 
93  PGR_DBG("normal = %d", normal);
94  if (normal) {
96  edges_of_points_query, &edges_of_points, &total_edges_of_points);
97  pgr_get_edges(edges_no_points_query, &edges, &total_edges);
98 
99  start_pidsArr = (int64_t*)
100  pgr_get_bigIntArray(&size_start_pidsArr, starts);
101  end_pidsArr = (int64_t*)
102  pgr_get_bigIntArray(&size_end_pidsArr, ends);
103  } else {
104 
106  edges_of_points_query, &edges_of_points, &total_edges_of_points);
107  pgr_get_edges_reversed(edges_no_points_query, &edges, &total_edges);
108 
109  end_pidsArr = (int64_t*)
110  pgr_get_bigIntArray(&size_end_pidsArr, starts);
111  start_pidsArr = (int64_t*)
112  pgr_get_bigIntArray(&size_start_pidsArr, ends);
113  }
114 
115 
116  free(edges_of_points_query);
117  free(edges_no_points_query);
118 
119  if ((total_edges + total_edges_of_points) == 0) {
120  pgr_SPI_finish();
121  return;
122  }
123 
124  clock_t start_t = clock();
125  char* log_msg = NULL;
126  char* notice_msg = NULL;
127  char* err_msg = NULL;
128 
130  edges, total_edges,
131  points, total_points,
132  edges_of_points, total_edges_of_points,
133  start_pidsArr, size_start_pidsArr,
134  end_pidsArr, size_end_pidsArr,
135 
136  driving_side[0],
137  details,
138  directed,
139  only_cost,
140  normal,
141 
142  result_tuples, result_count,
143  &log_msg,
144  &notice_msg,
145  &err_msg);
146 
147  if (only_cost) {
148  time_msg("processing pgr_withPointsCost(one to one)", start_t, clock());
149  } else {
150  time_msg("processing pgr_withPoints(one to one)", start_t, clock());
151  }
152 
153  if (err_msg && (*result_tuples)) {
154  pfree(*result_tuples);
155  (*result_count) = 0;
156  (*result_tuples) = NULL;
157  }
158 
159  pgr_global_report(log_msg, notice_msg, err_msg);
160 
161 #if 0
162  if (log_msg) pfree(log_msg);
163  if (notice_msg) pfree(notice_msg);
164  if (err_msg) pfree(err_msg);
165  if (edges) pfree(edges);
166  if (points) pfree(points);
167  if (edges_of_points) pfree(edges_of_points);
168  if (start_pidsArr) pfree(start_pidsArr);
169  if (end_pidsArr) pfree(end_pidsArr);
170 #endif
171  pgr_SPI_finish();
172 }
static edge_t edges[22573]
char estimate_drivingSide(char driving_side)
#define PGR_DBG(...)
Definition: debug_macro.h:34
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:540
void pgr_get_points(char *points_sql, Point_on_edge_t **points, size_t *total_points)
pgr_get_points
Definition: points_input.c:63
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
enforces the input array to be NOT empty
Definition: arrays_input.c:124
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
void pgr_SPI_finish(void)
void get_new_queries(char *edges_sql, char *points_sql, char **edges_of_points_query, char **edges_no_points_query)
void do_pgr_withPoints(pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, int64_t *start_pidsArr, size_t size_start_pidsArr, int64_t *end_pidsArr, size_t size_end_pidsArr, char driving_side, bool details, bool directed, bool only_cost, bool normal, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
void pgr_SPI_connect(void)
void pgr_get_edges_reversed(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
Definition: edges_input.c:551

Here is the call graph for this function:

Here is the caller graph for this function:

PGDLLEXPORT Datum withPoints ( PG_FUNCTION_ARGS  )

Definition at line 176 of file withPoints.c.

References General_path_element_t::agg_cost, General_path_element_t::cost, General_path_element_t::edge, General_path_element_t::end_id, if(), General_path_element_t::node, process(), General_path_element_t::seq, and General_path_element_t::start_id.

176  {
177  FuncCallContext *funcctx;
178  TupleDesc tuple_desc;
179 
180  /**********************************************************************/
181  General_path_element_t *result_tuples = 0;
182  size_t result_count = 0;
183  /**********************************************************************/
184 
185  if (SRF_IS_FIRSTCALL()) {
186  MemoryContext oldcontext;
187  funcctx = SRF_FIRSTCALL_INIT();
188  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
189 
190 
191  /**********************************************************************/
192  // CREATE OR REPLACE FUNCTION pgr_withPoint(
193  // edges_sql TEXT,
194  // points_sql TEXT,
195  // start_pid ANYARRAY,
196  // end_pids ANYARRAY,
197  // driving_side CHAR -- DEFAULT 'b',
198  // details BOOLEAN -- DEFAULT false,
199  // directed BOOLEAN -- DEFAULT true,
200  // only_cost BOOLEAN DEFAULT false,
201  // normal BOOLEAN DEFAULT true,
202 
203 
204  process(
205  text_to_cstring(PG_GETARG_TEXT_P(0)),
206  text_to_cstring(PG_GETARG_TEXT_P(1)),
207  PG_GETARG_ARRAYTYPE_P(2),
208  PG_GETARG_ARRAYTYPE_P(3),
209  PG_GETARG_BOOL(4),
210  text_to_cstring(PG_GETARG_TEXT_P(5)),
211  PG_GETARG_BOOL(6),
212  PG_GETARG_BOOL(7),
213  PG_GETARG_BOOL(8),
214  &result_tuples,
215  &result_count);
216 
217  /**********************************************************************/
218 
219 #if PGSQL_VERSION > 95
220  funcctx->max_calls = result_count;
221 #else
222  funcctx->max_calls = (uint32_t)result_count;
223 #endif
224  funcctx->user_fctx = result_tuples;
225  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
226  != TYPEFUNC_COMPOSITE)
227  ereport(ERROR,
228  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
229  errmsg("function returning record called in context "
230  "that cannot accept type record")));
231 
232  funcctx->tuple_desc = tuple_desc;
233  MemoryContextSwitchTo(oldcontext);
234  }
235 
236  funcctx = SRF_PERCALL_SETUP();
237  tuple_desc = funcctx->tuple_desc;
238  result_tuples = (General_path_element_t*) funcctx->user_fctx;
239 
240  if (funcctx->call_cntr < funcctx->max_calls) {
241  HeapTuple tuple;
242  Datum result;
243  Datum *values;
244  bool* nulls;
245 
246  /**********************************************************************/
247  // OUT seq BIGINT,
248  // OUT path_seq,
249  // OUT node BIGINT,
250  // OUT edge BIGINT,
251  // OUT cost FLOAT,
252  // OUT agg_cost FLOAT)
253 
254 
255  values = palloc(8 * sizeof(Datum));
256  nulls = palloc(8 * sizeof(bool));
257 
258  size_t i;
259  for (i = 0; i < 8; ++i) {
260  nulls[i] = false;
261  }
262 
263 
264  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
265  values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
266  values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id);
267  values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id);
268  values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
269  values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
270  values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
271  values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);
272  /**********************************************************************/
273 
274  tuple = heap_form_tuple(tuple_desc, values, nulls);
275  result = HeapTupleGetDatum(tuple);
276  SRF_RETURN_NEXT(funcctx, result);
277  } else {
278  SRF_RETURN_DONE(funcctx);
279  }
280 }
static void process(char *edges_sql, char *points_sql, ArrayType *starts, ArrayType *ends, bool directed, char *driving_side, bool details, bool only_cost, bool normal, General_path_element_t **result_tuples, size_t *result_count)
Definition: withPoints.c:49
if(DOXYGEN_FOUND) configure_file($
Definition: CMakeLists.txt:13

Here is the call graph for this function: