PGROUTING  2.6-dev
points_input.h File Reference
Include dependency graph for points_input.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pgr_get_points (char *points_sql, Point_on_edge_t **points, size_t *total_points)
 pgr_get_points More...
 

Function Documentation

void pgr_get_points ( char *  points_sql,
Point_on_edge_t **  points,
size_t *  total_points 
)

pgr_get_points

For queries of the type:

SELECT pid, edge_id, fraction, [side]
FROM edge_table;
Parameters
[in]points_sql
[out]points
[out]total_points

Definition at line 63 of file points_input.c.

References ANY_INTEGER, ANY_NUMERICAL, CHAR1, Column_info_t::colNumber, Column_info_t::eType, fetch_point(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, and Column_info_t::type.

Referenced by process().

66  {
67  const int tuple_limit = 1000;
68 
69  size_t ntuples;
70  size_t total_tuples;
71  Column_info_t info[4];
72 
73  int i;
74  for (i = 0; i < 4; ++i) {
75  info[i].colNumber = -1;
76  info[i].type = 0;
77  info[i].strict = true;
78  info[i].eType = ANY_INTEGER;
79  }
80 
81  info[0].name = "pid";
82  info[1].name = "edge_id";
83  info[2].name = "fraction";
84  info[3].name = "side";
85 
86  info[0].strict = false;
87  info[3].strict = false;
88  info[2].eType = ANY_NUMERICAL;
89  info[3].eType = CHAR1;
90 
91 
92  void *SPIplan;
93  SPIplan = pgr_SPI_prepare(points_sql);
94 
95  Portal SPIportal;
96  SPIportal = pgr_SPI_cursor_open(SPIplan);
97 
98  bool moredata = TRUE;
99  (*total_points) = total_tuples = 0;
100 
101  int64_t default_pid = 1;
102  char default_side = 'b';
103 
104  while (moredata == TRUE) {
105  SPI_cursor_fetch(SPIportal, TRUE, tuple_limit);
106  if (total_tuples == 0) {
107  /* on the first tuple get the column information */
108  pgr_fetch_column_info(info, 4);
109  }
110 
111  ntuples = SPI_processed;
112  total_tuples += ntuples;
113 
114  if (ntuples > 0) {
115  if ((*points) == NULL)
116  (*points) = (Point_on_edge_t *)
117  palloc0(total_tuples * sizeof(Point_on_edge_t));
118  else
119  (*points) = (Point_on_edge_t *)
120  repalloc((*points), total_tuples * sizeof(Point_on_edge_t));
121 
122  if ((*points) == NULL) {
123  elog(ERROR, "Out of memory");
124  }
125 
126  SPITupleTable *tuptable = SPI_tuptable;
127  TupleDesc tupdesc = SPI_tuptable->tupdesc;
128  size_t t;
129 
130  PGR_DBG("processing %ld points tuples", ntuples);
131  for (t = 0; t < ntuples; t++) {
132  HeapTuple tuple = tuptable->vals[t];
133  fetch_point(&tuple, &tupdesc, info,
134  &default_pid, default_side,
135  &(*points)[total_tuples - ntuples + t]);
136  }
137  SPI_freetuptable(tuptable);
138  } else {
139  moredata = FALSE;
140  }
141  }
142  SPI_cursor_close(SPIportal);
143 
144 
145  if (total_tuples == 0) {
146  (*total_points) = 0;
147  PGR_DBG("NO points");
148  return;
149  }
150 
151  (*total_points) = total_tuples;
152  PGR_DBG("Finish reading %ld points, %ld", total_tuples, (*total_points));
153 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73
void pgr_fetch_column_info(Column_info_t info[], int info_size)
static void fetch_point(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], int64_t *default_pid, char default_side, Point_on_edge_t *point)
Definition: points_input.c:35
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
SPIPlanPtr pgr_SPI_prepare(char *sql)
expectType eType
Definition: column_info_t.h:76

Here is the call graph for this function:

Here is the caller graph for this function: