PGROUTING  3.2
coordinates_input.c File Reference
Include dependency graph for coordinates_input.c:

Go to the source code of this file.

Functions

static void pgr_fetch_row (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], int64_t *default_id, Coordinate_t *distance)
 
void pgr_get_coordinates (char *sql, Coordinate_t **coordinates, size_t *total_coordinates)
 bigint id, float x, float y, More...
 

Function Documentation

◆ pgr_fetch_row()

static void pgr_fetch_row ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[3],
int64_t *  default_id,
Coordinate_t distance 
)
static

Definition at line 36 of file coordinates_input.c.

41  {
42  if (column_found(info[0].colNumber)) {
43  distance->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
44  } else {
45  distance->id = *default_id;
46  ++(*default_id);
47  }
48  distance->x = pgr_SPI_getFloat8(tuple, tupdesc, info[1]);
49  distance->y = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
50 }

References column_found(), Coordinate_t::id, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), Coordinate_t::x, and Coordinate_t::y.

Referenced by pgr_get_coordinates().

◆ pgr_get_coordinates()

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.

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

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().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
Coordinate_t::y
double y
Definition: coordinate_t.h:40
pgr_fetch_row
static void pgr_fetch_row(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], int64_t *default_id, Coordinate_t *distance)
Definition: coordinates_input.c:36
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:94
pgr_SPI_getBigInt
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in integer type.
Definition: get_check_data.c:216
pgr_fetch_column_info
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.
Definition: get_check_data.c:78
Coordinate_t
Definition: coordinate_t.h:37
Column_info_t::name
char * name
Definition: column_info_t.h:54
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:107
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
pgr_SPI_getFloat8
double pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in double type.
Definition: get_check_data.c:246
Column_info_t::eType
expectType eType
Definition: column_info_t.h:55
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
Coordinate_t::id
int64_t id
Definition: coordinate_t.h:38
Coordinate_t::x
double x
Definition: coordinate_t.h:39
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
column_found
bool column_found(int colNumber)
Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUT...
Definition: get_check_data.c:36
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49