PGROUTING  2.6
coordinates_input.h File Reference
Include dependency graph for coordinates_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_coordinates (char *sql, Coordinate_t **coordinates, size_t *total_coordinates)
 bigint id, float x, float y, More...
 

Function Documentation

void pgr_get_coordinates ( char *  sql,
Coordinate_t **  coordinates,
size_t *  total_coordinates 
)

bigint id, float x, float y,

Definition at line 57 of file coordinates_input.c.

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

Referenced by process().

60  {
61  clock_t start_t = clock();
62 
63  const int tuple_limit = 1000000;
64 
65  size_t ntuples;
66  size_t total_tuples = 0;
67 
68  Column_info_t info[3];
69 
70  int i;
71  for (i = 0; i < 3; ++i) {
72  info[i].colNumber = -1;
73  info[i].type = 0;
74  info[i].strict = true;
75  info[i].eType = ANY_NUMERICAL;
76  }
77  info[0].name = "id";
78  info[1].name = "x";
79  info[2].name = "y";
80 
81  info[0].eType = ANY_INTEGER;
82  info[0].strict = false;
83 
84 
85  void *SPIplan;
86  SPIplan = pgr_SPI_prepare(sql);
87 
88  Portal SPIportal;
89  SPIportal = pgr_SPI_cursor_open(SPIplan);
90 
91 
92  bool moredata = true;
93  (*total_coordinates) = total_tuples;
94 
95  int64_t default_id = 1;
96 
97  while (moredata == true) {
98  SPI_cursor_fetch(SPIportal, true, tuple_limit);
99  if (total_tuples == 0)
100  pgr_fetch_column_info(info, 3);
101 
102  ntuples = SPI_processed;
103  total_tuples += ntuples;
104 
105  if (ntuples > 0) {
106  if ((*coordinates) == NULL)
107  (*coordinates) = (Coordinate_t *)
108  palloc0(total_tuples * sizeof(Coordinate_t));
109  else
110  (*coordinates) = (Coordinate_t *)
111  repalloc((*coordinates),
112  total_tuples * sizeof(Coordinate_t));
113 
114  if ((*coordinates) == NULL) {
115  elog(ERROR, "Out of memory");
116  }
117 
118  SPITupleTable *tuptable = SPI_tuptable;
119  TupleDesc tupdesc = SPI_tuptable->tupdesc;
120  PGR_DBG("Processing %ld coordinates tupĺes", ntuples);
121 
122  size_t t;
123  for (t = 0; t < ntuples; t++) {
124  HeapTuple tuple = tuptable->vals[t];
125  pgr_fetch_row(&tuple, &tupdesc, info,
126  &default_id,
127  &(*coordinates)[total_tuples - ntuples + t]);
128  }
129  SPI_freetuptable(tuptable);
130  } else {
131  moredata = false;
132  }
133  }
134 
135  SPI_cursor_close(SPIportal);
136 
137 
138  if (total_tuples == 0) {
139  (*total_coordinates) = 0;
140  PGR_DBG("NO coordinates");
141  return;
142  }
143 
144  (*total_coordinates) = total_tuples;
145  time_msg(" reading coordinates:", start_t, clock());
146 }
static void pgr_fetch_row(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], int64_t *default_id, Coordinate_t *distance)
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Function tells expected type of each column and then check the correspondence type of each column...
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: