PGROUTING  2.6
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(), 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 #ifndef NDEBUG
79  size_t i;
80  for (i = 0; i< total_points; i++) {
81  PGR_DBG("%ld ", points[i].pid);
82  }
83 #endif
84  char *edges_of_points_query = NULL;
85  char *edges_no_points_query = NULL;
87  edges_sql, points_sql,
88  &edges_of_points_query,
89  &edges_no_points_query);
90 
91 
92  pgr_edge_t *edges_of_points = NULL;
93  size_t total_edges_of_points = 0;
94 
95  pgr_edge_t *edges = NULL;
96  size_t total_edges = 0;
97 
98  if (normal) {
100  edges_of_points_query,
101  &edges_of_points,
102  &total_edges_of_points);
103  pgr_get_edges(edges_no_points_query, &edges, &total_edges);
104 
105  start_pidsArr = (int64_t*)
106  pgr_get_bigIntArray(&size_start_pidsArr, starts);
107  end_pidsArr = (int64_t*)
108  pgr_get_bigIntArray(&size_end_pidsArr, ends);
109  } else {
111  edges_of_points_query,
112  &edges_of_points,
113  &total_edges_of_points);
114  pgr_get_edges_reversed(edges_no_points_query, &edges, &total_edges);
115 
116  end_pidsArr = (int64_t*)
117  pgr_get_bigIntArray(&size_end_pidsArr, starts);
118  start_pidsArr = (int64_t*)
119  pgr_get_bigIntArray(&size_start_pidsArr, ends);
120  }
121 
122 
123  pfree(edges_of_points_query);
124  pfree(edges_no_points_query);
125  edges_of_points_query = NULL;
126  edges_no_points_query = NULL;
127 
128  if ((total_edges + total_edges_of_points) == 0) {
129  pgr_SPI_finish();
130  return;
131  }
132 
133  clock_t start_t = clock();
134  char* log_msg = NULL;
135  char* notice_msg = NULL;
136  char* err_msg = NULL;
137 
139  edges, total_edges,
140  points, total_points,
141  edges_of_points, total_edges_of_points,
142  start_pidsArr, size_start_pidsArr,
143  end_pidsArr, size_end_pidsArr,
144 
145  driving_side[0],
146  details,
147  directed,
148  only_cost,
149  normal,
150 
151  result_tuples, result_count,
152  &log_msg,
153  &notice_msg,
154  &err_msg);
155 
156  if (only_cost) {
157  time_msg("processing pgr_withPointsCost(one to one)", start_t, clock());
158  } else {
159  time_msg("processing pgr_withPoints(one to one)", start_t, clock());
160  }
161 
162  if (err_msg && (*result_tuples)) {
163  pfree(*result_tuples);
164  (*result_count) = 0;
165  (*result_tuples) = NULL;
166  }
167 
168  pgr_global_report(log_msg, notice_msg, err_msg);
169 
170 #if 0
171  if (log_msg) pfree(log_msg);
172  if (notice_msg) pfree(notice_msg);
173  if (err_msg) pfree(err_msg);
174  if (edges) pfree(edges);
175  if (points) pfree(points);
176  if (edges_of_points) pfree(edges_of_points);
177  if (start_pidsArr) pfree(start_pidsArr);
178  if (end_pidsArr) pfree(end_pidsArr);
179 #endif
180  pgr_SPI_finish();
181 }
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:545
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:556

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 185 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.

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