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

Go to the source code of this file.

Functions

static void pgr_fetch_row (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], Delauny_t *delauny)
 
void pgr_get_delauny (char *sql, Delauny_t **delauny, size_t *total_delauny)
 bigint tid, bigint pid, float x, float y, More...
 

Function Documentation

◆ pgr_fetch_row()

static void pgr_fetch_row ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[4],
Delauny_t delauny 
)
static

Definition at line 36 of file delauny_input.c.

40  {
41  delauny->tid = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
42  delauny->pid = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
43  delauny->x = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
44  delauny->y = pgr_SPI_getFloat8(tuple, tupdesc, info[3]);
45 }

References pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), Delauny_t::pid, Delauny_t::tid, Delauny_t::x, and Delauny_t::y.

Referenced by pgr_get_delauny().

◆ pgr_get_delauny()

void pgr_get_delauny ( char *  sql,
Delauny_t **  delauny,
size_t *  total_delauny 
)

bigint tid, bigint pid, float x, float y,

Definition at line 53 of file delauny_input.c.

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

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.

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
Delauny_t
Definition: delauny_t.h:37
pgr_fetch_row
static void pgr_fetch_row(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], Delauny_t *delauny)
Definition: delauny_input.c:36
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
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
Delauny_t::x
double x
Definition: delauny_t.h:40
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
Delauny_t::y
double y
Definition: delauny_t.h:41
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
Delauny_t::tid
int64_t tid
Definition: delauny_t.h:38
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49
Delauny_t::pid
int64_t pid
Definition: delauny_t.h:39