GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sites.c
Go to the documentation of this file.
1 
2 /*-
3  * These functions and definitions support the site format for 5.0
4  * (format proposed by Dave Gerdes):
5  *
6  * easting|northing|[z|[d4|]...][#category_int] [ [@attr_text OR %flt] ... ]
7  *
8  * to allow multidimensions (everything preceding the last '|') and any
9  * number of text or numeric attribute fields.
10  *
11  * Author: James Darrell McCauley <mccauley@ecn.purdue.edu>
12  * 31 Jan 1994
13  */
14 
15 #include <ctype.h>
16 #include <string.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <errno.h>
20 #include <grass/gis.h>
21 #include <grass/site.h>
22 #include <grass/dbmi.h>
23 #include <grass/Vect.h>
24 #include <grass/glocale.h>
25 
26 
27 #define DQUOTE '"'
28 #define SPACE ' '
29 #define BSLASH 92
30 #define PIPE '|'
31 
32 #define ispipe(c) (c==PIPE)
33 #define isnull(c) (c=='\0')
34 #define isquote(c) (c==DQUOTE)
35 #define isbslash(c) (c==BSLASH)
36 
37 static int format_double(double, char *);
38 static char *next_att(const char *);
39 static int cleanse_string(char *);
40 
41 static int site_att_cmp(const void *pa, const void *pb)
42 {
43  const SITE_ATT *a = pa, *b = pb;
44 
45  return a->cat - b->cat;
46 }
47 
48 
49 /*-
50  * Reads ptr and returns 0 on success,
51  * -1 on EOF,
52  * -2 on other fatal error or insufficient data,
53  * 1 on format mismatch (extra data)
54  */
55 int G_site_get(struct Map_info *Map, Site * s)
56 {
57  int i, type, cat;
58  static struct line_pnts *Points = NULL;
59  static struct line_cats *Cats = NULL;
60  SITE_ATT *sa;
61 
62  if (Points == NULL)
63  Points = Vect_new_line_struct();
64  if (Cats == NULL)
65  Cats = Vect_new_cats_struct();
66 
67  while (1) {
68  type = Vect_read_next_line(Map, Points, Cats);
69 
70  if (type == -1)
71  return -2; /* Error */
72  if (type == -2)
73  return -1; /* EOF */
74  if (type != GV_POINT)
75  continue; /* Is not point */
76 
77  Vect_cat_get(Cats, 1, &cat);
78 
79  G_debug(4, "Site: %f|%f|%f|#%d", Points->x[0], Points->y[0],
80  Points->z[0], cat);
81 
82  s->east = Points->x[0];
83  s->north = Points->y[0];
84  if (Vect_is_3d(Map))
85  s->dim[0] = Points->z[0];
86 
87  s->ccat = cat;
88 
89  /* find att */
90 
91  if (Map->n_site_att > 0) {
92  sa = (SITE_ATT *) bsearch((void *)&cat, (void *)Map->site_att,
93  Map->n_site_att, sizeof(SITE_ATT),
94  site_att_cmp);
95 
96  if (sa == NULL) {
97  G_warning(_("Attributes for category %d not found"), cat);
98  for (i = 0; i < Map->n_site_dbl; i++)
99  s->dbl_att[i] = 0;
100  for (i = 0; i < Map->n_site_str; i++)
101  G_strncpy(s->str_att[i], "", MAX_SITE_STRING);
102  }
103  else {
104  for (i = 0; i < Map->n_site_dbl; i++)
105  s->dbl_att[i] = sa->dbl[i];
106  for (i = 0; i < Map->n_site_str; i++)
107  G_strncpy(s->str_att[i], sa->str[i], MAX_SITE_STRING);
108  }
109  }
110 
111  return 0;
112  }
113 }
114 
115 
116 /* Writes a site to file open on fptr. */
117 int G_site_put(struct Map_info *Map, const Site * s)
118 {
119  static struct line_pnts *Points = NULL;
120  static struct line_cats *Cats = NULL;
121 
122  if (Points == NULL)
123  Points = Vect_new_line_struct();
124  if (Cats == NULL)
125  Cats = Vect_new_cats_struct();
126 
127  Vect_reset_line(Points);
128  Vect_reset_cats(Cats);
129 
130  /* no 3D support so far: s->dim[0] */
131  Vect_append_point(Points, s->east, s->north, 0.0);
132 
133  G_debug(4, "cattype = %d", s->cattype);
134 
135  if (s->cattype == FCELL_TYPE || s->cattype == DCELL_TYPE)
136  G_fatal_error(_("Category must be integer"));
137 
138  if (s->cattype == CELL_TYPE)
139  Vect_cat_set(Cats, 1, s->ccat);
140 
141  Vect_write_line(Map, GV_POINT, Points, Cats);
142 
143  return 0;
144 }
145 
146 
147 /*-
148  * Tries to guess the format of a sites list (the dimensionality,
149  * the presence/type of a category, and the number of string and decimal
150  * attributes) by reading the first record in the file.
151  * Reads ptr and returns 0 on success,
152  * -1 on EOF,
153  * -2 for other error.
154  */
155 int G_site_describe(struct Map_info *Map, int *dims, int *cat, int *strs,
156  int *dbls)
157 {
158  if (Vect_is_3d(Map)) {
159  G_debug(1, "Vector is 3D -> number of site dimensions is 3");
160  *dims = 3;
161  }
162  else {
163  G_debug(1, "Vector is 2D -> number of site dimensions is 2");
164  *dims = 2;
165  }
166 
167  *cat = CELL_TYPE;
168 
169  /* attributes ignored for now, later read from DB */
170  *dbls = Map->n_site_dbl;
171  *strs = Map->n_site_str;
172 
173  return 0;
174 }
175 
176 
177 /*-
178  * Writes site_head struct.
179  */
180 int G_site_put_head(struct Map_info *Map, Site_head * head)
181 {
182  static char buf[128];
183 
184  if (head->name != NULL)
185  Vect_set_map_name(Map, head->name);
186 
187  /* crashes:
188  if (head->desc!=NULL)
189  Vect_set_comment (Map, head->desc);
190  */
191 
192  /*
193  if (head->form!=NULL)
194  fprintf(ptr,"form|%s\n",head->form);
195  if (head->labels!=NULL)
196  fprintf(ptr,"labels|%s\n",head->labels);
197  */
198  /* time could be in (char *) stime, (struct TimeStamp *) time,
199  both, or neither */
200  if (head->stime != NULL || head->time != NULL) {
201  if (head->time != NULL) { /* TimeStamp struct has precendence */
202  G_format_timestamp(head->time, buf);
203  Vect_set_date(Map, buf);
204  }
205  else if (head->stime != NULL) { /* next check string */
206  if (head->time == NULL) {
207  if ((head->time =
208  (struct TimeStamp *)G_malloc(sizeof(struct TimeStamp)))
209  == NULL)
210  G_fatal_error(_("Memory error in writing timestamp"));
211  else if (G_scan_timestamp(head->time, head->stime) < 0) {
212  G_warning(_("Illegal TimeStamp string"));
213  return -1; /* added to prevent crash 5/2000 MN */
214  }
215  }
216  G_format_timestamp(head->time, buf);
217  head->stime = G_store(buf);
218  Vect_set_date(Map, head->stime);
219  }
220  }
221  return 0;
222 }
223 
224 
225 /*-
226  * Fills in site_head struct.
227  */
228 int G_site_get_head(struct Map_info *Map, Site_head * head)
229 {
230  head->name = Vect_get_name(Map);
231  head->desc = Vect_get_comment(Map);
232  head->form = NULL;
233  head->labels = NULL;
234  /* head->stime = Vect_get_date(Map); *//* crashes, G_scan_timestamp() needed? */
235  head->stime = NULL;
236  head->time = NULL;
237 
238  if (head->stime && strlen(head->stime) > 0) {
239  if ((head->time =
240  (struct TimeStamp *)G_malloc(sizeof(struct TimeStamp))) == NULL)
241  G_fatal_error(_("Memory error in allocating timestamp"));
242  if (G_scan_timestamp(head->time, head->stime) < 0) {
244 
245  head->time = NULL;
246  head->stime = NULL;
247  }
248  }
249 
250  return 0;
251 }
252 
253 /*-************************************************************************
254  * char *
255  * G_ask_sites_new(prompt, name))
256  * asks user to input name of a new site list file
257  *
258  * char *
259  * G_ask_sites_old(prompt, name)
260  * asks user to input name of an existing site list file
261  *
262  * char *
263  * G_ask_sites_any(prompt, name)
264  * asks user to input any site list name
265  *
266  * char *
267  * G_ask_sites_in_mapset(prompt, name)
268  * asks user to input name of an existing site list file in
269  * current mapset
270  *
271  * parms:
272  * char *prompt optional prompt for user
273  * char *name buffer to hold name of map found
274  *
275  * returns:
276  * char *pointer to a string with name of mapset
277  * where file was found, or NULL if not found
278  *
279  * note:
280  * rejects all names that begin with .
281  **********************************************************************
282  *
283  * struct Map_info *
284  * G_sites_open_old (name, mapset)
285  * opens the existing site list file 'name' in the 'mapset'
286  *
287  * struct Map_info *
288  * G_sites_open_new (name)
289  * opens a new site list file 'name' in the current mapset
290  *
291  * parms
292  * char *name map file name
293  * char *mapset mapset containing map "name"
294  *
295  **********************************************************************/
296 
297 char *G_find_sites(char *name, const char *mapset)
298 {
299  return G_find_vector(name, mapset);
300 }
301 
302 
303 char *G_find_sites2(const char *name, const char *mapset)
304 {
305  return G_find_vector2(name, mapset);
306 }
307 
308 
309 char *G_ask_sites_new(const char *prompt, char *name)
310 {
311  return G_ask_new(prompt, name, "vector", "vector");
312 }
313 
314 
315 char *G_ask_sites_old(const char *prompt, char *name)
316 {
317  return G_ask_old(prompt, name, "vector", "vector");
318 }
319 
320 
321 char *G_ask_sites_any(const char *prompt, char *name)
322 {
323  return G_ask_any(prompt, name, "vector", "vector", 1);
324 }
325 
326 
327 char *G_ask_sites_in_mapset(const char *prompt, char *name)
328 {
329  return G_ask_in_mapset(prompt, name, "vector", "vector");
330 }
331 
332 
333 struct Map_info *G_sites_open_old(const char *name, const char *mapset)
334 {
335  struct Map_info *Map;
336  struct field_info *fi;
337  int more, nrows, row, ncols, col, ndbl, nstr, adbl, astr, ctype;
338  SITE_ATT *sa;
339 
340  dbDriver *driver;
341  dbString stmt;
342  dbCursor cursor;
343  dbTable *table;
344  dbColumn *column;
345  dbValue *value;
346 
347  G_message(
348  _("Dev note: Adapted sites library used for vector points. "
349  "(module should be updated to GRASS 6 vector library)"));
350 
351  Map = (struct Map_info *)G_malloc(sizeof(struct Map_info));
352 
354  Vect_open_old(Map, name, mapset);
355 
356  G_debug(1, "Vector map opened");
357 
358  /* Load attributes */
359  Map->site_att = NULL;
360  Map->n_site_att = 0;
361  Map->n_site_dbl = 0;
362  Map->n_site_str = 0;
363 
364  fi = Vect_get_field(Map, 1);
365  if (fi == NULL) { /* not attribute table */
366  G_debug(1, "No attribute table");
367  return Map;
368  }
369 
370  driver = db_start_driver_open_database(fi->driver, fi->database);
371  if (driver == NULL)
372  G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
373  fi->database,
374  fi->driver);
375 
376  db_init_string(&stmt);
377  db_set_string(&stmt, "select * from ");
378  db_append_string(&stmt, fi->table);
379 
380  if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
381  G_fatal_error(_("Unable to open select cursor: '%s'"),
382  db_get_string(&stmt));
383 
384  nrows = db_get_num_rows(&cursor);
385  G_debug(1, "%d rows selected from vector attribute table", nrows);
386 
387  Map->site_att = (SITE_ATT *) malloc(nrows * sizeof(SITE_ATT));
388  Map->n_site_att = nrows;
389 
390  table = db_get_cursor_table(&cursor);
391  ncols = db_get_table_number_of_columns(table);
392 
393  row = 0;
394  adbl = astr = 0;
395  while (1) {
396  if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK)
397  G_fatal_error(_("Cannot fetch row"));
398 
399  if (!more)
400  break;
401 
402  /* Get number of each type */
403  if (row == 0) {
404  for (col = 0; col < ncols; col++) {
405  column = db_get_table_column(table, col);
407 
408  if (strcmp(db_get_column_name(column), fi->key) == 0)
409  continue;
410 
411  switch (ctype) {
412  case DB_C_TYPE_INT:
413  case DB_C_TYPE_DOUBLE:
414  adbl++;
415  break;
416  case DB_C_TYPE_STRING:
417  case DB_C_TYPE_DATETIME:
418  astr++;
419  break;
420  }
421  }
422  Map->n_site_dbl = adbl;
423  Map->n_site_str = astr;
424  G_debug(1, "adbl = %d astr = %d", adbl, astr);
425  }
426 
427  sa = &(Map->site_att[row]);
428  sa->dbl = (double *)malloc(adbl * sizeof(double));
429  sa->str = (char **)malloc(astr * sizeof(char *));
430 
431  ndbl = nstr = 0;
432  for (col = 0; col < ncols; col++) {
433  column = db_get_table_column(table, col);
435  value = db_get_column_value(column);
436 
437  if (strcmp(db_get_column_name(column), fi->key) == 0) {
438  sa->cat = db_get_value_int(value);
439  }
440  else {
441  switch (ctype) {
442  case DB_C_TYPE_INT:
443  sa->dbl[ndbl] = db_get_value_int(value);
444  ndbl++;
445  break;
446  case DB_C_TYPE_DOUBLE:
447  sa->dbl[ndbl] = db_get_value_double(value);
448  ndbl++;
449  break;
450  case DB_C_TYPE_STRING:
451  sa->str[nstr] = G_store(db_get_value_string(value));
452  nstr++;
453  break;
454  case DB_C_TYPE_DATETIME:
455  sa->str[nstr] = ""; /* TODO */
456  nstr++;
457  break;
458  }
459  }
460  }
461  row++;
462  }
464 
465  /* sort attributes */
466  qsort((void *)Map->site_att, Map->n_site_att, sizeof(SITE_ATT),
467  site_att_cmp);
468 
469  return Map;
470 }
471 
472 
473 struct Map_info *G_sites_open_new(const char *name)
474 {
475  struct Map_info *Map;
476 
477  G_message(
478  _("Dev note: Adapted sites library used for vector points. "
479  "(module should be updated to GRASS 6 vector library)"));
480  G_warning("Site/vector attributes ignored.");
481 
482  Map = (struct Map_info *)G_malloc(sizeof(struct Map_info));
483 
484  Vect_open_new(Map, name, 0);
485 
486  G_debug(1, "New vector map opened");
487 
488  return Map;
489 }
490 
491 
492 void G_sites_close(struct Map_info *Map)
493 {
494  int i, j;
495 
496  if (Map->mode == GV_MODE_WRITE || Map->mode == GV_MODE_RW)
497  Vect_build(Map);
498 
499  Vect_close(Map);
500 
501  for (i = 0; i < Map->n_site_att; i++) {
502  free(Map->site_att[i].dbl);
503 
504  for (j = 0; j < Map->n_site_str; j++)
505  free(Map->site_att[i].str[j]);
506 
507  free(Map->site_att[i].str);
508  }
509  free(Map->site_att);
510 
511  G_free(Map);
512 }
513 
514 
515 /*********************************************/
516 /* The following functions are obsolete. */
517 /* They are retained here only for backwards */
518 /* compatability while porting applications */
519 
520 /*********************************************/
521 struct Map_info *G_fopen_sites_old(const char *name, const char *mapset)
522 {
523  return G_sites_open_old(name, mapset);
524 }
525 
526 
527 struct Map_info *G_fopen_sites_new(const char *name)
528 {
529  return G_sites_open_new(name);
530 }
531 
532 
533 int G_get_site(struct Map_info *fd, double *east, double *north, char **desc)
534 {
535  /* TODO ? */
536  G_fatal_error("G_get_site() not yet updated.");
537 
538  return -1;
539 }
540 
541 
542 int G_put_site(struct Map_info *fd, double east, double north,
543  const char *desc)
544 {
545  /* TODO ? */
546  G_fatal_error("G_put_site() not yet updated.");
547 
548  return 0;
549 }
550 
551 
552 /* Functions moved here from lib/gis/sites.c */
553 
554 void G_site_free_struct(Site * s)
555 /* Free memory for a Site struct */
556 {
557  if (s->dim_alloc)
558  G_free(s->dim);
559  if (s->str_alloc)
560  G_free(s->str_att);
561  if (s->dbl_alloc)
562  G_free(s->dbl_att);
563  G_free(s);
564 
565  return;
566 }
567 
568 Site *G_site_new_struct(RASTER_MAP_TYPE cattype,
569  int n_dim, int n_s_att, int n_d_att)
570 /* Allocate memory for a Site struct. Returns a properly allocated
571  site struct or NULL on error.
572  cattype= -1 (no cat), CELL_TYPE, FCELL_TYPE, or DCELL_TYPE
573  */
574 {
575  int i;
576  Site *s;
577 
578  if (n_dim < 2 || n_s_att < 0 || n_d_att < 0)
579  G_fatal_error(_("G_oldsite_new_struct: invalid # dims or fields"));
580 
581  if ((s = (Site *) G_malloc(sizeof(Site))) == NULL)
582  return (Site *) NULL;
583 
584  s->cattype = cattype;
585  s->ccat = s->fcat = s->dcat = 0;
586 
587  if (n_dim > 2) {
588  if ((s->dim =
589  (double *)G_malloc((n_dim - 2) * sizeof(double))) == NULL) {
590  G_free(s);
591  return (Site *) NULL;
592  }
593  }
594  s->dim_alloc = n_dim - 2;
595 
596  if (n_d_att > 0) {
597  if ((s->dbl_att =
598  (double *)G_malloc(n_d_att * sizeof(double))) == NULL) {
599  if (n_dim > 2)
600  G_free(s->dim);
601  G_free(s);
602  return (Site *) NULL;
603  }
604  }
605  s->dbl_alloc = n_d_att;
606 
607  if (n_s_att > 0) {
608  if ((s->str_att =
609  (char **)G_malloc(n_s_att * sizeof(char *))) == NULL) {
610  if (n_d_att > 0)
611  G_free(s->dbl_att);
612  if (n_dim > 2)
613  G_free(s->dim);
614  G_free(s);
615  return (Site *) NULL;
616  }
617  else
618  for (i = 0; i < n_s_att; ++i)
619  if ((s->str_att[i] =
620  (char *)G_malloc(MAX_SITE_STRING * sizeof(char))) ==
621  NULL) {
622  while (--i)
623  G_free(s->str_att[i]);
624  G_free(s->str_att);
625  if (n_d_att > 0)
626  G_free(s->dbl_att);
627  if (n_dim > 2)
628  G_free(s->dim);
629  G_free(s);
630  return (Site *) NULL;
631  }
632  }
633  s->str_alloc = n_s_att;
634 
635  return s;
636 }
637 
638 #define FOUND_ALL(s,n,dim,c,d) (((s->cattype != -1 && !n) || \
639  (dim < s->dim_alloc) || \
640  (c < s->str_alloc) || \
641  (d < s->dbl_alloc))?0:1)
642 
643 int G_oldsite_get(FILE * fptr, Site * s)
644 /* Writes a site to file open on fptr. */
645 {
646  return G__oldsite_get(fptr, s, G_projection());
647 }
648 
649 
650 int G__oldsite_get(FILE * ptr, Site * s, int fmt)
651 
652 /*-
653  * Reads ptr and returns 0 on success,
654  * -1 on EOF,
655  * -2 on other fatal error or insufficient data,
656  * 1 on format mismatch (extra data)
657  */
658 {
659  char sbuf[MAX_SITE_LEN], *buf, *last, *p1, *p2;
660  char ebuf[128], nbuf[128];
661  int n = 0, d = 0, c = 0, dim = 0, err = 0, tmp;
662 
663  buf = sbuf;
664 
665  if ((buf = fgets(sbuf, 1024, ptr)) == (char *)NULL)
666  return EOF;
667 
668  while ((*buf == '#' || !isdigit(*buf)) && *buf != '-' && *buf != '+')
669  if ((buf = fgets(sbuf, 1024, ptr)) == (char *)NULL)
670  return EOF;
671 
672  if (buf[strlen(buf) - 1] == '\n')
673  buf[strlen(buf) - 1] = '\0';
674 
675  if (sscanf(buf, "%[^|]|%[^|]|%*[^\n]", ebuf, nbuf) < 2) {
676  fprintf(stderr, "ERROR: ebuf %s nbuf %s\n", ebuf, nbuf);
677  return -2;
678  }
679 
680  if (!G_scan_northing(nbuf, &(s->north), fmt) ||
681  !G_scan_easting(ebuf, &(s->east), fmt)) {
682  fprintf(stderr, "ERROR: ebuf %s nbuf %s\n", ebuf, nbuf);
683  return -2;
684  }
685 
686  /* move pointer past easting and northing fields */
687  if (NULL == (buf = G_index(buf, PIPE)))
688  return -2;
689  if (NULL == (buf = G_index(buf + 1, PIPE)))
690  return -2;
691 
692  /* check for remaining dimensional fields */
693  do {
694  buf++;
695  if (isnull(*buf))
696  return (FOUND_ALL(s, n, dim, c, d) ? 0 : -2);
697  last = buf;
698  if (dim < s->dim_alloc) { /* should be more dims to read */
699  if (sscanf(buf, "%lf|", &(s->dim[dim++])) < 1)
700  return -2; /* no more dims, though expected */
701  }
702  else if (NULL != (p1 = G_index(buf, PIPE))) {
703  if (NULL == (p2 = G_index(buf, DQUOTE)))
704  err = 1; /* more dims, though none expected */
705  else if (strlen(p1) > strlen(p2))
706  err = 1; /* more dims, though none expected */
707  }
708  } while ((buf = G_index(buf, PIPE)) != NULL);
709  buf = last;
710 
711  /* no more dimensions-now we parse attribute fields */
712  while (!isnull(*buf)) {
713  switch (*buf) {
714  case '#': /* category field */
715  if (n == 0) {
716  switch (s->cattype) {
717  case CELL_TYPE:
718  if (sscanf(buf, "#%d", &s->ccat) == 1)
719  n++;
720  break;
721  case FCELL_TYPE:
722  if (sscanf(buf, "#%f", &s->fcat) == 1)
723  n++;
724  break;
725  case DCELL_TYPE:
726  if (sscanf(buf, "#%lf", &s->dcat) == 1)
727  n++;
728  break;
729  default:
730  err = 1; /* has cat, none expected */
731  break;
732  }
733  }
734  else {
735  err = 1; /* extra cat */
736  }
737 
738  /* move to beginning of next attribute */
739  if ((buf = next_att(buf)) == (char *)NULL)
740  return (FOUND_ALL(s, n, dim, c, d) ? err : -2);
741  break;
742 
743  case '%': /* decimal attribute */
744  if (d < s->dbl_alloc) {
745  p1 = ++buf;
746  errno = 0;
747  s->dbl_att[d++] = strtod(buf, &p1);
748  if (p1 == buf || errno == ERANGE) {
749  /* replace with:
750  * s->dbl_att[d - 1] = NAN
751  * when we add NULL attribute support
752  */
753  return -2;
754  }
755  /* err = 0; Make sure this is zeroed */
756  }
757  else {
758  err = 1; /* extra decimal */
759  }
760 
761  if ((buf = next_att(buf)) == (char *)NULL) {
762  return (FOUND_ALL(s, n, dim, c, d)) ? err : -2;
763  }
764  break;
765  case '@': /* string attribute */
766  if (isnull(*buf) || isnull(*(buf + 1)))
767  return (FOUND_ALL(s, n, dim, c, d) ? err : -2);
768  else
769  buf++;
770  default: /* defaults to string attribute */
771  /* allow both prefixed and unprefixed strings */
772  if (c < s->str_alloc) {
773  if ((tmp = cleanse_string(buf)) > 0) {
774  G_strncpy(s->str_att[c++], buf, tmp);
775  buf += tmp;
776  }
777  else
778  return (FOUND_ALL(s, n, dim, c, d) ? err : -2);
779  }
780  if ((buf = next_att(buf)) == (char *)NULL) {
781  return (FOUND_ALL(s, n, dim, c, d) ? err : -2);
782  }
783  break;
784  }
785  }
786 
787  return (FOUND_ALL(s, n, dim, c, d) ? err : -2);
788 }
789 
790 int G_oldsite_describe(FILE * ptr, int *dims, int *cat, int *strs, int *dbls)
791 
792 /*-
793  * Tries to guess the format of a sites list (the dimensionality,
794  * the presence/type of a category, and the number of string and decimal
795  * attributes) by reading the first record in the file.
796  * Reads ptr and returns 0 on success,
797  * -1 on EOF,
798  * -2 for other error.
799  */
800 {
801  char sbuf[MAX_SITE_LEN], *buf;
802  char ebuf[128], nbuf[128];
803  int err;
804  int itmp;
805  float ftmp;
806 
807  if (ftell(ptr) != 0L) {
808  fprintf(stderr,
809  "\nPROGRAMMER ERROR: G_oldsite_describe() must be called\n");
810  fprintf(stderr, " immediately after G_fopen_sites_old()\n");
811  return -2;
812  }
813 
814  *dims = *strs = *dbls = 0;
815  *cat = -1;
816  buf = sbuf;
817 
818  if ((buf = fgets(sbuf, 1024, ptr)) == (char *)NULL) {
819  rewind(ptr);
820  return EOF;
821  }
822  /* skip over comment & header lines */
823  while ((*buf == '#' || !isdigit(*buf)) && *buf != '-' && *buf != '+')
824  if ((buf = fgets(sbuf, 1024, ptr)) == (char *)NULL) {
825  rewind(ptr);
826  return EOF;
827  }
828 
829  if (buf[strlen(buf) - 1] == '\n')
830  buf[strlen(buf) - 1] = '\0';
831 
832  if ((err = sscanf(buf, "%[^|]|%[^|]|%*[^\n]", ebuf, nbuf)) < 2) {
833  fprintf(stderr, "ERROR: ebuf %s nbuf %s\n", ebuf, nbuf);
834  rewind(ptr);
835  return -2;
836  }
837  *dims = 2;
838 
839  /* move pointer past easting and northing fields */
840  while (!ispipe(*buf) && !isnull(*buf))
841  buf++;
842  if (!isnull(*buf) && !isnull(*(buf + 1)))
843  buf++;
844  else {
845  rewind(ptr);
846  return -2;
847  }
848  while (!ispipe(*buf) && !isnull(*buf))
849  buf++;
850  if (!isnull(*buf) && !isnull(*(buf + 1)))
851  buf++;
852  else {
853  rewind(ptr);
854  return 0;
855  }
856 
857  /* check for remaining dimensional fields */
858  while (G_index(buf, PIPE) != (char *)NULL) {
859  (*dims)++;
860  while (!ispipe(*buf) && !isnull(*buf))
861  buf++;
862  if (isnull(*buf) || isnull(*(buf + 1))) {
863  rewind(ptr);
864  return 0;
865  }
866  if (!isnull(*(buf + 1)))
867  buf++;
868  else {
869  rewind(ptr);
870  return -2;
871  }
872  }
873 
874  /* no more dimensions-now we parse attribute fields */
875  while (!isnull(*buf)) {
876  switch (*buf) {
877  case '#': /* category field */
878  sscanf(buf, "#%s ", ebuf);
879  if (G_strstr(ebuf, ".") == NULL && sscanf(ebuf, "%d", &itmp) == 1)
880  *cat = CELL_TYPE;
881  else if (G_strstr(ebuf, ".") != NULL &&
882  sscanf(ebuf, "%f", &ftmp) == 1)
883  *cat = FCELL_TYPE;
884  else
885  *cat = -1;
886 
887  /* move to beginning of next attribute */
888  while (!isspace(*buf) && !isnull(*buf))
889  buf++;
890  if (isnull(*buf) || isnull(*(buf + 1))) {
891  rewind(ptr);
892  return 0;
893  }
894  else
895  buf++;
896  break;
897  case '%': /* decimal attribute */
898  (*dbls)++;
899  /* move to beginning of next attribute */
900  while (!isspace(*buf) && !isnull(*buf))
901  buf++;
902  if (isnull(*buf) || isnull(*(buf + 1))) {
903  rewind(ptr);
904  return 0;
905  }
906  else
907  buf++;
908  break;
909  case '@': /* string attribute */
910  if (isnull(*buf) || isnull(*(buf + 1))) {
911  rewind(ptr);
912  return 0;
913  }
914  else
915  buf++;
916  default: /* defaults to string attribute */
917  /* allow both prefixed and unprefixed strings */
918  if ((err = cleanse_string(buf)) > 0) {
919  (*strs)++;
920  buf += err;
921  }
922 
923  /* move to beginning of next attribute */
924  while (!isspace(*buf) && !isnull(*buf))
925  buf++;
926  if (isnull(*buf) || isnull(*(buf + 1))) {
927  rewind(ptr);
928  return 0;
929  }
930  else
931  buf++;
932  break;
933  }
934  }
935 
936  rewind(ptr);
937  return 0;
938 }
939 
940 int G_site_in_region(const Site * site, const struct Cell_head *region)
941 /* returns 1 if site is contained within region, 0 otherwise */
942 {
943  /* northwest corner is in region, southeast corner is not. */
944  double e_ing;
945 
946  e_ing = G_adjust_easting(site->east, region);
947  if (e_ing >= region->west &&
948  e_ing < region->east &&
949  site->north <= region->north && site->north > region->south)
950  return 1;
951 
952  return 0;
953 }
954 
955 static int format_double(double value, char *buf)
956 {
957  sprintf(buf, "%.8f", value);
958  G_trim_decimal(buf);
959  return 0;
960 }
961 
962 int cleanse_string(char *buf)
963 {
964  char *stop, *p, *p2;
965 
966  p = buf;
967 
968  /*
969  * get rid of any SPACEs at beginning while ( !isspace(*buf) && *buf !=
970  * (char) NULL) buf++; if (*buf == (char) NULL) return -1;
971  */
972 
973  /* find where this string terminates */
974  if (*buf != DQUOTE) { /* if no DQUOTEs, */
975  stop = G_index(buf, SPACE); /* then SPACE separates */
976  if (stop == (char *)NULL)
977  return strlen(buf);
978  else
979  return (int)(stop - buf);
980  }
981  else { /* otherwise string is in DQUOTEs */
982  /* but we must skip over escaped */
983  /* (BSLASHed) DQUOTEs */
984  if (*p == DQUOTE) {
985  while (*p != (char)NULL) { /* get rid of first DQUOTE */
986  *p = *(p + 1);
987  p++;
988  }
989  p = buf;
990  stop = G_index(p + 1, DQUOTE);
991  while (*(stop - 1) == BSLASH)
992  stop = G_index(++stop, DQUOTE);
993  }
994  }
995  /* remove backslashes between buf and stop */
996  p = buf;
997  while ((p = G_index(p, BSLASH)) != (char *)NULL && p <= stop) {
998  p2 = p + 1;
999  if (*p2 != (char)NULL && (*p2 == DQUOTE || *p2 == BSLASH)) {
1000  while (*p != (char)NULL) {
1001  *p = *(p + 1);
1002  p++;
1003  }
1004  stop--;
1005  }
1006  p = p2;
1007  }
1008  return (int)(stop - buf);
1009 }
1010 
1011 static char *next_att(const char *buf)
1012 {
1013  while (!isspace(*buf) && !isnull(*buf))
1014  buf++;
1015  if (isnull(*buf) || isnull(*(buf + 1)))
1016  return NULL;
1017  else
1018  while (isspace(*(buf + 1)) && !isnull(*(buf + 1)))
1019  buf++;
1020  buf++;
1021  return (char *)buf;
1022 }
1023 
1024 int G_site_c_cmp(const void *a, const void *b)
1025 /* qsort() comparison function for sorting an array of
1026  site structures by category. */
1027 {
1028  int result = 0; /* integer to be returned */
1029  double diff = 0;
1030 
1031  switch ((*(Site **) a)->cattype) {
1032  case CELL_TYPE:
1033  diff = (double)(*(Site **) a)->ccat - (*(Site **) b)->ccat;
1034  break;
1035  case FCELL_TYPE:
1036  diff = (double)(*(Site **) a)->fcat - (*(Site **) b)->fcat;
1037  break;
1038  case DCELL_TYPE:
1039  diff = (double)(*(Site **) a)->dcat - (*(Site **) b)->dcat;
1040  break;
1041  }
1042  if (diff < 0.0)
1043  result = -1;
1044  else if (diff > 0.0)
1045  result = 1;
1046  return result;
1047 }
1048 
1049 int G_site_d_cmp(const void *a, const void *b)
1050 /* qsort() comparison function for sorting an array of
1051  site structures by first decimal attribute. */
1052 {
1053  int result = 0; /* integer to be returned */
1054  double diff;
1055 
1056  diff = (*(Site **) a)->dbl_att[0] - (*(Site **) b)->dbl_att[0];
1057  if (diff < 0.0)
1058  result = -1;
1059  else if (diff > 0.0)
1060  result = 1;
1061  return result;
1062 }
1063 
1064 int G_oldsite_s_cmp(const void *a, const void *b)
1065 /* qsort() comparison function for sorting an array of
1066  site structures by first decimal attribute. */
1067 {
1068  return strcmp((*(char **)((*(Site **) a)->str_att)),
1069  (*(char **)((*(Site **) b)->str_att)));
1070 }
1071 
1072 /*-************************************************************************
1073  *
1074  * FILE *
1075  * G_oldsites_open_old (name, mapset)
1076  * opens the existing site list file 'name' in the 'mapset'
1077  *
1078  * parms
1079  * char *name map file name
1080  * char *mapset mapset containing map "name"
1081  *
1082  **********************************************************************/
1083 
1084 FILE *G_oldsites_open_old(const char *name, const char *mapset)
1085 {
1086  return G_fopen_old("site_lists", name, mapset);
1087 }
1088 
1089 FILE *G_oldsites_open_new(const char *name)
1090 {
1091  return G_fopen_new("site_lists", name);
1092 }
1093 
1094 /*********************************************/
1095 /* The following functions are obsolete. */
1096 /* They are retained here only for backwards */
1097 /* compatability while porting applications */
1098 
1099 /*********************************************/
1100 
1101 char *G_site_format(const Site * s, const char *fs, int id)
1102 /* sprintf analog to G_site_put with the addition of a field separator fs
1103  and option of printing site attribute identifiers
1104  */
1105 {
1106  char ebuf[MAX_SITE_STRING], nbuf[MAX_SITE_STRING];
1107  char xbuf[MAX_SITE_STRING];
1108  const char *nfs;
1109  char *buf;
1110  int fmt, i, j, k;
1111 
1112  buf = (char *)G_malloc(MAX_SITE_LEN * sizeof(char));
1113 
1114  fmt = G_projection();
1115 
1116  G_format_northing(s->north, nbuf, fmt);
1117  G_format_easting(s->east, ebuf, fmt);
1118 
1119  nfs = (char *)((fs == (char *)NULL) ? "|" : fs);
1120 
1121  sprintf(buf, "%s%s%s", ebuf, nfs, nbuf);
1122 
1123  for (i = 0; i < s->dim_alloc; ++i) {
1124  format_double(s->dim[i], nbuf);
1125  sprintf(xbuf, "%s%s", nfs, nbuf);
1126  G_strcat(buf, xbuf);
1127  }
1128 
1129  nfs = (fs == NULL) ? " " : fs;
1130 
1131  switch (s->cattype) {
1132  case CELL_TYPE:
1133  sprintf(xbuf, "%s%s%d ", nfs, ((id == 0) ? "" : "#"), (int)s->ccat);
1134  G_strcat(buf, xbuf);
1135  break;
1136  case FCELL_TYPE:
1137  case DCELL_TYPE:
1138  sprintf(xbuf, "%s%s%g ", nfs, ((id == 0) ? "" : "#"), (float)s->fcat);
1139  G_strcat(buf, xbuf);
1140  break;
1141  }
1142 
1143  for (i = 0; i < s->dbl_alloc; ++i) {
1144  format_double(s->dbl_att[i], nbuf);
1145  sprintf(xbuf, "%s%s%s", nfs, ((id == 0) ? "" : "%"), nbuf);
1146  G_strcat(buf, xbuf);
1147  }
1148 
1149  for (i = 0; i < s->str_alloc; ++i) {
1150  if (strlen(s->str_att[i]) != 0) {
1151  /* escape double quotes */
1152  j = k = 0;
1153 
1154  /* do not uncomment this code because sites file was created
1155  * as we want. So it's enough to print them out as it is.
1156  *
1157  if (G_index (s->str_att[i], DQUOTE) != (char *) NULL)
1158  {
1159  while (!isnull(s->str_att[i][j]))
1160  {
1161  if (isquote(s->str_att[i][j]))
1162  {
1163  xbuf[k++] = BSLASH;
1164  xbuf[k++] = DQUOTE;
1165  }
1166  else
1167  xbuf[k++] = s->str_att[i][j];
1168  j++;
1169  }
1170  xbuf[k] = (char) NULL;
1171  }
1172  else
1173  */
1174 
1175  G_strcpy(xbuf, s->str_att[i]);
1176 
1177  G_strcpy(s->str_att[i], xbuf);
1178 
1179  if (G_index(s->str_att[i], SPACE) != (char *)NULL)
1180  sprintf(xbuf, "%s%s\"%s\"", nfs, ((id == 0) ? "" : "@"),
1181  s->str_att[i]);
1182  else
1183  sprintf(xbuf, "%s%s%s", nfs, ((id == 0) ? "" : "@"),
1184  s->str_att[i]);
1185  G_strcat(buf, xbuf);
1186  }
1187  }
1188  return buf;
1189 }
1190 
1191 /*******************************************************************************/
1192 
1193 /*******************************************************************************/
1194 
1195 /*** ACS_MODIFY_BEGIN - sites_attribute management *****************************/
1196 /*
1197  These functions are used in visualization/nviz/src/site_attr_commands.c
1198 
1199  Functions to obtain fields in order to draw sites with each point having a
1200  geometric property depending from database values.
1201  */
1202 
1203 /*
1204  Returns a pointer to the SITE_ATT in Map_info *ptr and with category cat
1205  */
1206 SITE_ATT *G_sites_get_atts(struct Map_info * Map, int *cat)
1207 {
1208  return (SITE_ATT *) bsearch((void *)cat, (void *)Map->site_att,
1209  Map->n_site_att, sizeof(SITE_ATT),
1210  site_att_cmp);
1211 }
1212 
1213 /*
1214  Returns field names, types and indexes in double and string Map_info arrays
1215 
1216  WARNING: user is responsible to free allocated memory, directly or calling G_sites_free_fields()
1217  */
1218 int G_sites_get_fields(struct Map_info *Map, char ***cnames, int **ctypes,
1219  int **ndx)
1220 {
1221  struct field_info *fi;
1222  int nrows, row, ncols, col, ndbl, nstr, ctype;
1223 
1224  const char *name;
1225  dbDriver *driver;
1226  dbString stmt;
1227  dbCursor cursor;
1228  dbTable *table;
1229  dbColumn *column;
1230 
1231  /*dbValue *value; */
1232 
1233  /* warning: we are using "1" as cat field in Vect_get_field because G_sites_open_old
1234  (in lib/sites/sites.c), that we use here to open sites, does the same and then
1235  queries the db in the same way we do here.
1236  Should it be not true in the future, maybe we'll have to change this by choosing
1237  appropriate fields and multiple categories */
1238 
1239  fi = (struct field_info *)Vect_get_field(Map, 1);
1240 
1241 
1242  if (fi == NULL) { /* not attribute table */
1243  G_debug(1, "No attribute table");
1244  return -1;
1245  }
1246 
1247  driver = db_start_driver_open_database(fi->driver, fi->database);
1248  if (driver == NULL)
1249  G_fatal_error(_("Cannot open database %s by driver %s"), fi->database,
1250  fi->driver);
1251 
1252  db_init_string(&stmt);
1253  db_set_string(&stmt, "select * from ");
1254  db_append_string(&stmt, fi->table);
1255 
1256  if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
1257  G_fatal_error(_("Cannot select attributes"));
1258 
1259  nrows = db_get_num_rows(&cursor);
1260  G_debug(1, "%d rows selected from vector attribute table", nrows);
1261 
1262  table = db_get_cursor_table(&cursor);
1263  ncols = db_get_table_number_of_columns(table);
1264 
1265  if (ncols <= 0)
1266  return ncols;
1267 
1268  row = 0;
1269 
1270  /* Get number of each type */
1271  ndbl = nstr = 0;
1272 
1273  *cnames = (char **)malloc(ncols * sizeof(char *));
1274  *ctypes = (int *)malloc(ncols * sizeof(int));
1275  *ndx = (int *)malloc(ncols * sizeof(int));
1276 
1277  for (col = 0; col < ncols; col++) {
1278  column = db_get_table_column(table, col);
1279  ctype = db_sqltype_to_Ctype(db_get_column_sqltype(column));
1280 
1281  name = db_get_column_name(column);
1282 
1283  *(*cnames + col) = (char *)malloc(strlen(name) + 1);
1284  strcpy(*(*cnames + col), db_get_column_name(column));
1285 
1286  /* ctypes is 'c' for cat, 'd' for double, 's' for string */
1287  if (strcmp(name, fi->key) == 0) {
1288  *(*ctypes + col) = 'c';
1289  *(*ndx + col) = -1;
1290  }
1291  else {
1292  switch (ctype) {
1293  case DB_C_TYPE_INT:
1294  case DB_C_TYPE_DOUBLE:
1295  *(*ctypes + col) = 'd';
1296  *(*ndx + col) = ndbl;
1297  ndbl++;
1298  break;
1299  case DB_C_TYPE_STRING:
1300  case DB_C_TYPE_DATETIME:
1301  *(*ctypes + col) = 's';
1302  *(*ndx + col) = nstr;
1303  nstr++;
1304  break;
1305  }
1306  }
1307  }
1308 
1310  return ncols;
1311 }
1312 
1313 
1314 /* Frees fields allocated with G_sites_get_fields */
1315 void G_sites_free_fields(int ncols, char **cnames, int *ctypes, int *ndx)
1316 {
1317  for (; ncols > 0; ncols--)
1318  free(*(cnames + ncols - 1));
1319  free(cnames);
1320  free(ctypes);
1321  free(ndx);
1322 }
1323 
1324 /*** ACS_MODIFY_END - sites_attribute management *******************************/
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
Definition: db.c:28
dbColumn * db_get_table_column(dbTable *table, int n)
returns column structure for given table and column number
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
struct driver * driver
Definition: driver/init.c:26
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
char * G_find_vector(char *name, const char *mapset)
Definition: find_vect.c:55
struct field_info * Vect_get_field(struct Map_info *Map, int field)
Get information about link to database.
Definition: field.c:404
float b
Definition: named_colr.c:8
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
const char * db_get_column_name(dbColumn *column)
returns column name for given column
int G_site_put(struct Map_info *Map, const Site *s)
Definition: sites.c:117
int G_site_describe(struct Map_info *Map, int *dims, int *cat, int *strs, int *dbls)
Definition: sites.c:155
const char * Vect_get_name(struct Map_info *Map)
Get map name.
int G_site_c_cmp(const void *a, const void *b)
Definition: sites.c:1024
int Vect_read_next_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c)
Read next vector feature (level 1 and 2)
char * G_strcat(char *T, const char *F)
This copies characters from the string F into the string T.
Definition: strings.c:153
FILE * fd
Definition: g3dcolor.c:368
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
Definition: db.c:62
string name
Definition: render.py:1314
char * G_index(const char *str, int delim)
delimiter
Definition: gis/index.c:16
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
Definition: line.c:57
#define DQUOTE
Definition: sites.c:27
void G_sites_free_fields(int ncols, char **cnames, int *ctypes, int *ndx)
Definition: sites.c:1315
char * G_ask_in_mapset(const char *prompt, char *name, char *element, char *desc)
prompt for existing database file
Definition: ask.c:222
FILE * G_oldsites_open_old(const char *name, const char *mapset)
Definition: sites.c:1084
int G_site_get_head(struct Map_info *Map, Site_head *head)
Definition: sites.c:228
int G_scan_timestamp(struct TimeStamp *ts, const char *buf)
Fill a TimeStamp structure from a datetime string.
Definition: timestamp.c:207
int Vect_set_date(struct Map_info *Map, const char *str)
Set date of digitization string in map header.
const char * err
Definition: g3dcolor.c:50
int Vect_reset_line(struct line_pnts *Points)
Reset line.
Definition: line.c:148
char * G_ask_sites_old(const char *prompt, char *name)
Definition: sites.c:315
int G_oldsite_s_cmp(const void *a, const void *b)
Definition: sites.c:1064
int Vect_reset_cats(struct line_cats *Cats)
Reset category structure to make sure cats structure is clean to be re-used.
struct Map_info * G_sites_open_new(const char *name)
Definition: sites.c:473
char * G_find_vector2(const char *name, const char *mapset)
find a vector map (look but don&#39;t touch)
Definition: find_vect.c:75
struct Map_info * G_fopen_sites_new(const char *name)
Definition: sites.c:527
int G_trim_decimal(char *buf)
Removes trailing zeros from decimal number.
Definition: trim_dec.c:30
#define isnull(c)
Definition: sites.c:33
Site * G_site_new_struct(RASTER_MAP_TYPE cattype, int n_dim, int n_s_att, int n_d_att)
Definition: sites.c:568
char * G_ask_new(const char *prompt, char *name, char *element, char *desc)
prompt for new database file
Definition: ask.c:132
char * G_strcpy(char *T, const char *F)
Copies characters from the string F into the string T.
Definition: strings.c:46
const char * Vect_get_comment(struct Map_info *Map)
Get comment or other info string from map header.
struct Map_info * G_sites_open_old(const char *name, const char *mapset)
Definition: sites.c:333
#define PIPE
Definition: sites.c:30
int G_sites_get_fields(struct Map_info *Map, char ***cnames, int **ctypes, int **ndx)
Definition: sites.c:1218
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
Appends one point to the end of a line.
Definition: line.c:168
int db_append_string(dbString *x, const char *s)
Definition: string.c:193
int db_sqltype_to_Ctype(int sqltype)
Definition: sqlCtype.c:9
int Vect_cat_set(struct line_cats *Cats, int field, int cat)
Add new field/cat to category structure if doesn&#39;t exist yet.
int db_fetch(dbCursor *cursor, int position, int *more)
Fetch data.
Definition: c_fetch.c:28
int Vect_is_3d(struct Map_info *Map)
Check if vector map is 3D (with z)
dbTable * db_get_cursor_table(dbCursor *cursor)
Definition: cursor.c:55
#define FOUND_ALL(s, n, dim, c, d)
Definition: sites.c:638
double db_get_value_double(dbValue *value)
Definition: value.c:32
int G_site_put_head(struct Map_info *Map, Site_head *head)
Definition: sites.c:180
int db_get_column_sqltype(dbColumn *column)
returns column sqltype for column (the function db_sqltype_name() returns sqltype description) ...
int Vect_set_open_level(int level)
Predetermine level at which a map will be opened for reading.
int Vect_build(struct Map_info *Map)
Build topology for vector map.
Definition: build.c:53
int G_site_get(struct Map_info *Map, Site *s)
Definition: sites.c:55
void * malloc(YYSIZE_T)
int db_get_table_number_of_columns(dbTable *table)
void G_message(const char *msg,...)
Print a message to stderr.
Definition: lib/gis/error.c:74
#define SPACE
Definition: sites.c:28
char * G_ask_old(const char *prompt, char *name, char *element, char *desc)
prompt for existing database file
Definition: ask.c:161
struct Map_info * G_fopen_sites_old(const char *name, const char *mapset)
Definition: sites.c:521
dbValue * db_get_column_value(dbColumn *column)
returns column value for given column structure
FILE * G_oldsites_open_new(const char *name)
Definition: sites.c:1089
int Vect_set_map_name(struct Map_info *Map, const char *str)
Set map name string in map header.
int G_oldsite_describe(FILE *ptr, int *dims, int *cat, int *strs, int *dbls)
Definition: sites.c:790
int db_get_num_rows(dbCursor *cursor)
Get number of selected rows.
Definition: c_rows.c:26
char * value
Definition: env.c:30
char * G_strncpy(char *T, const char *F, int n)
This function is similar to G_chrcpy() but always copies at least n characters into the string T...
Definition: strings.c:90
SITE_ATT * G_sites_get_atts(struct Map_info *Map, int *cat)
Definition: sites.c:1206
char * datetime_error_msg(void)
returns an error message
char * G_ask_sites_in_mapset(const char *prompt, char *name)
Definition: sites.c:327
int Vect_open_old(struct Map_info *Map, const char *name, const char *mapset)
Open existing vector for reading.
char * G_ask_sites_new(const char *prompt, char *name)
Definition: sites.c:309
#define BSLASH
Definition: sites.c:29
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int Vect_close(struct Map_info *Map)
Close vector data file.
Definition: close.c:64
int G_get_site(struct Map_info *fd, double *east, double *north, char **desc)
Definition: sites.c:533
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
Definition: wind_scan.c:37
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
Definition: gis/open.c:197
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
return NULL
Definition: dbfopen.c:1394
char * G_find_sites2(const char *name, const char *mapset)
Definition: sites.c:303
void G_site_free_struct(Site *s)
Definition: sites.c:554
char * G_ask_any(const char *prompt, char *name, char *element, char *desc, int warn)
prompt for any valid file name
Definition: ask.c:190
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G__oldsite_get(FILE *ptr, Site *s, int fmt)
Definition: sites.c:650
char * G_strstr(const char *mainString, const char *subString)
Finds the first occurrence of the character C in the null-terminated string beginning at mainString...
Definition: strings.c:230
char * db_get_string(dbString *x)
Definition: string.c:131
int G_format_easting(double east, char *buf, int projection)
Easting to ASCII.
Definition: wind_format.c:61
tuple Map
Definition: render.py:1310
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
char * G_ask_sites_any(const char *prompt, char *name)
Definition: sites.c:321
void free(void *)
int db_set_string(dbString *x, const char *s)
Definition: string.c:33
char * G_site_format(const Site *s, const char *fs, int id)
Definition: sites.c:1101
for(cat=0;;cat++)
Definition: g3dcats.c:140
int db_get_value_int(dbValue *value)
Definition: value.c:21
long Vect_write_line(struct Map_info *Map, int type, struct line_pnts *points, struct line_cats *cats)
Writes new feature to the end of file (table)
int G_oldsite_get(FILE *fptr, Site *s)
Definition: sites.c:643
CELL cat
Definition: g3dcats.c:90
int errno
int Vect_open_new(struct Map_info *Map, const char *name, int with_z)
Open new vector for reading/writing.
char * G_find_sites(char *name, const char *mapset)
Definition: sites.c:297
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
Definition: gis/open.c:226
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_format_northing(double north, char *buf, int projection)
Northing to ASCII.
Definition: wind_format.c:36
int G_put_site(struct Map_info *fd, double east, double north, const char *desc)
Definition: sites.c:542
int G_site_in_region(const Site *site, const struct Cell_head *region)
Definition: sites.c:940
int G_site_d_cmp(const void *a, const void *b)
Definition: sites.c:1049
int G_format_timestamp(const struct TimeStamp *ts, char *buf)
Create text string from TimeStamp structure.
Definition: timestamp.c:171
int n
Definition: dataquad.c:291
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.
Definition: wind_scan.c:65
double G_adjust_easting(double east, const struct Cell_head *window)
Returns east larger than west.
Definition: window_map.c:174
int G_projection(void)
query cartographic projection
Definition: proj1.c:33
const char * db_get_value_string(dbValue *value)
Definition: value.c:70
void G_sites_close(struct Map_info *Map)
Definition: sites.c:492
#define ispipe(c)
Definition: sites.c:32
int db_open_select_cursor(dbDriver *driver, dbString *select, dbCursor *cursor, int mode)
Open select cursor.
Definition: c_openselect.c:29
void db_init_string(dbString *x)
Definition: string.c:11
int Vect_cat_get(struct line_cats *Cats, int field, int *cat)
Get first found category of given field.