GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
map.c
Go to the documentation of this file.
1 
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <dirent.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <grass/glocale.h>
30 #include <grass/gis.h>
31 #include <grass/Vect.h>
32 #include <grass/dbmi.h>
33 #include <grass/glocale.h>
34 
44 int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
45 {
46  int i, type, nlines, ret;
47  struct line_pnts *Points;
48  struct line_cats *Cats;
49 
50  Points = Vect_new_line_struct();
51  Cats = Vect_new_cats_struct();
52 
53  if (Vect_level(In) < 1)
54  G_fatal_error("Vect_copy_map_lines(): %s",
55  _("input vector map is not open"));
56 
57  ret = 0;
58  /* Note: sometimes is important to copy on level 2 (pseudotopo centroids)
59  * and sometimes on level 1 if build take too long time */
60  if (Vect_level(In) >= 2) {
61  nlines = Vect_get_num_lines(In);
62  for (i = 1; i <= nlines; i++) {
63  if (!Vect_line_alive(In, i))
64  continue;
65 
66  type = Vect_read_line(In, Points, Cats, i);
67  if (type == -1) {
68  G_warning(_("Unable to read vector map <%s>"),
69  Vect_get_full_name(In));
70  ret = 1;
71  break;
72  }
73  if (type == 0)
74  continue; /* dead line */
75 
76  Vect_write_line(Out, type, Points, Cats);
77  }
78  }
79  else { /* Level 1 */
80  Vect_rewind(In);
81  while (1) {
82  type = Vect_read_next_line(In, Points, Cats);
83  if (type == -1) {
84  G_warning(_("Unable to read vector map <%s>"),
85  Vect_get_full_name(In));
86  ret = 1;
87  break;
88  }
89  else if (type == -2) { /* EOF */
90  break;
91  }
92  else if (type == 0) { /* dead line */
93  continue;
94  }
95  Vect_write_line(Out, type, Points, Cats);
96  }
97  }
100 
101  return ret;
102 }
103 
104 /*
105  \brief Copy file
106 
107  \param[in] src source file
108  \param[out] dst destination file
109 
110  \return 0 OK
111  \return 1 error
112  */
113 static int copy_file(const char *src, const char *dst)
114 {
115  char buf[1024];
116  int fd, fd2;
117  FILE *f2;
118  int len, len2;
119 
120  if ((fd = open(src, O_RDONLY)) < 0)
121  return 1;
122 
123  /* if((fd2 = open(dst, O_CREAT|O_TRUNC|O_WRONLY)) < 0) */
124  if ((f2 = fopen(dst, "w")) == NULL) {
125  close(fd);
126  return 1;
127  }
128 
129  fd2 = fileno(f2);
130 
131  while ((len = read(fd, buf, 1024)) > 0) {
132  while (len && (len2 = write(fd2, buf, len)) >= 0)
133  len -= len2;
134  }
135 
136  close(fd);
137  /* close(fd2); */
138  fclose(f2);
139 
140  if (len == -1 || len2 == -1)
141  return 1;
142 
143  return 0;
144 }
145 
158 int
159 Vect_copy(const char *in, const char *mapset, const char *out)
160 {
161  int i, n, ret, type;
162  struct Map_info In, Out;
163  struct field_info *Fi, *Fin;
164  char old_path[GPATH_MAX], new_path[GPATH_MAX], buf[GPATH_MAX];
165  struct stat info;
166  const char *files[] = { GRASS_VECT_FRMT_ELEMENT, GRASS_VECT_COOR_ELEMENT,
167  GRASS_VECT_HEAD_ELEMENT, GRASS_VECT_HIST_ELEMENT,
168  GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
169  NULL
170  };
171  const char *xmapset;
172 
173  dbDriver *driver;
174 
175  G_debug(2, "Copy vector '%s' in '%s' to '%s'", in, mapset, out);
176  /* check for [A-Za-z][A-Za-z0-9_]* in name */
177  if (Vect_legal_filename(out) < 0)
178  G_fatal_error(_("Vector map name is not SQL compliant"));
179 
180  xmapset = G_find_vector2(in, mapset);
181  if (!xmapset) {
182  G_warning(_("Unable to find vector map <%s> in <%s>"), in, mapset);
183  return -1;
184  }
185  mapset = xmapset;
186 
187  /* Delete old vector if it exists */
188  if (G_find_vector2(out, G_mapset())) {
189  G_warning(_("Vector map <%s> already exists and will be overwritten"),
190  out);
191  ret = Vect_delete(out);
192  if (ret != 0) {
193  G_warning(_("Unable to delete vector map <%s>"), out);
194  return -1;
195  }
196  }
197 
198  /* Copy the directory */
199  G__make_mapset_element(GRASS_VECT_DIRECTORY);
200  sprintf(buf, "%s/%s", GRASS_VECT_DIRECTORY, out);
202 
203  i = 0;
204  while (files[i]) {
205  sprintf(buf, "%s/%s", in, files[i]);
206  G__file_name(old_path, GRASS_VECT_DIRECTORY, buf, mapset);
207  sprintf(buf, "%s/%s", out, files[i]);
208  G__file_name(new_path, GRASS_VECT_DIRECTORY, buf, G_mapset());
209 
210  if (stat(old_path, &info) == 0) { /* file exists? */
211  G_debug(2, "copy %s to %s", old_path, new_path);
212  if (copy_file(old_path, new_path)) {
213  G_warning(_("Unable to copy vector map <%s> to <%s>"),
214  old_path, new_path);
215  }
216  }
217  i++;
218  }
219 
220  G__file_name(old_path, GRASS_VECT_DIRECTORY, in, mapset);
221  G__file_name(new_path, GRASS_VECT_DIRECTORY, out, G_mapset());
222 
223  /* Open input */
225  Vect_open_old_head(&In, in, mapset);
226 
227  if (In.format != GV_FORMAT_NATIVE) { /* Done */
228  Vect_close(&In);
229  return 0;
230  }
231 
232  /* Open output */
233  Vect_open_update_head(&Out, out, G_mapset());
234 
235  /* Copy tables */
236  n = Vect_get_num_dblinks(&In);
237  type = GV_1TABLE;
238  if (n > 1)
239  type = GV_MTABLE;
240  for (i = 0; i < n; i++) {
241  Fi = Vect_get_dblink(&In, i);
242  if (Fi == NULL) {
243  G_warning(_("Database connection not defined for layer %d"),
244  In.dblnk->field[i].number);
245  Vect_close(&In);
246  Vect_close(&Out);
247  return -1;
248  }
249  Fin = Vect_default_field_info(&Out, Fi->number, Fi->name, type);
250  G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
251  Fi->driver, Fi->database, Fi->table, Fin->driver,
252  Fin->database, Fin->table);
253  Vect_map_add_dblink(&Out, Fi->number, Fi->name, Fin->table, Fi->key,
254  Fin->database, Fin->driver);
255 
256  ret = db_copy_table(Fi->driver, Fi->database, Fi->table,
257  Fin->driver, Vect_subst_var(Fin->database, &Out),
258  Fin->table);
259  if (ret == DB_FAILED) {
260  G_warning(_("Unable to copy table <%s>"), Fin->table);
261  Vect_close(&In);
262  Vect_close(&Out);
263  return -1;
264  }
265 
266  driver =
267  db_start_driver_open_database(Fin->driver,
268  Vect_subst_var(Fin->database,
269  &Out));
270  if (driver == NULL) {
271  G_warning(_("Unable to open database <%s> by driver <%s>"),
272  Fin->database, Fin->driver);
273  }
274  else {
275  if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK)
276  G_warning(_("Unable to create index for table <%s>, key <%s>"),
277  Fi->table, Fi->key);
278 
280  }
281  }
282 
283  Vect_close(&In);
284  Vect_close(&Out);
285 
286  return 0;
287 }
288 
303 int Vect_rename(const char *in, const char *out)
304 {
305  int i, n, ret, type;
306  struct Map_info Map;
307  struct field_info *Fin, *Fout;
308  int *fields;
309  dbDriver *driver;
310 
311  G_debug(2, "Rename vector '%s' to '%s'", in, out);
312  /* check for [A-Za-z][A-Za-z0-9_]* in name */
313  if (Vect_legal_filename(out) < 0)
314  G_fatal_error(_("Vector map name is not SQL compliant"));
315 
316  /* Delete old vector if it exists */
317  if (G_find_vector2(out, G_mapset())) {
318  G_warning(_("Vector map <%s> already exists and will be overwritten"),
319  out);
320  Vect_delete(out);
321  }
322 
323  /* Move the directory */
324  ret = G_rename(GRASS_VECT_DIRECTORY, in, out);
325 
326  if (ret == 0) {
327  G_warning(_("Vector map <%s> not found"), in);
328  return -1;
329  }
330  else if (ret == -1) {
331  G_warning(_("Unable to copy vector map <%s> to <%s>"), in, out);
332  return -1;
333  }
334 
335  /* Rename all tables if the format is native */
337  Vect_open_update_head(&Map, out, G_mapset());
338 
339  if (Map.format != GV_FORMAT_NATIVE) { /* Done */
340  Vect_close(&Map);
341  return 0;
342  }
343 
344  /* Copy tables */
345  n = Vect_get_num_dblinks(&Map);
346  type = GV_1TABLE;
347  if (n > 1)
348  type = GV_MTABLE;
349 
350  /* Make the list of fields */
351  fields = (int *)G_malloc(n * sizeof(int));
352 
353  for (i = 0; i < n; i++) {
354  Fin = Vect_get_dblink(&Map, i);
355 
356  fields[i] = Fin->number;
357  }
358 
359  for (i = 0; i < n; i++) {
360  G_debug(3, "field[%d] = %d", i, fields[i]);
361 
362  Fin = Vect_get_field(&Map, fields[i]);
363  if (Fin == NULL) {
364  G_warning(_("Database connection not defined for layer %d"),
365  fields[i]);
366  Vect_close(&Map);
367  return -1;
368  }
369 
370  Fout = Vect_default_field_info(&Map, Fin->number, Fin->name, type);
371  G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
372  Fin->driver, Fin->database, Fin->table, Fout->driver,
373  Fout->database, Fout->table);
374 
375  /* TODO: db_rename_table instead of db_copy_table */
376  ret = db_copy_table(Fin->driver, Fin->database, Fin->table,
377  Fout->driver, Vect_subst_var(Fout->database,
378  &Map), Fout->table);
379 
380  if (ret == DB_FAILED) {
381  G_warning(_("Unable to copy table <%s>"), Fin->table);
382  Vect_close(&Map);
383  return -1;
384  }
385 
386  /* Change the link */
387  Vect_map_del_dblink(&Map, Fin->number);
388 
389  Vect_map_add_dblink(&Map, Fout->number, Fout->name, Fout->table,
390  Fin->key, Fout->database, Fout->driver);
391 
392  /* Delete old table */
393  ret = db_delete_table(Fin->driver, Fin->database, Fin->table);
394  if (ret == DB_FAILED) {
395  G_warning(_("Unable to delete table <%s>"), Fin->table);
396  Vect_close(&Map);
397  return -1;
398  }
399 
400  driver =
401  db_start_driver_open_database(Fout->driver,
402  Vect_subst_var(Fout->database,
403  &Map));
404  if (driver == NULL) {
405  G_warning(_("Unable to open database <%s> by driver <%s>"),
406  Fout->database, Fout->driver);
407  }
408  else {
409  if (db_create_index2(driver, Fout->table, Fin->key) != DB_OK)
410  G_warning(_("Unable to create index for table <%s>, key <%s>"),
411  Fout->table, Fout->key);
412 
414  }
415  }
416 
417  Vect_close(&Map);
418  free(fields);
419 
420  return 0;
421 }
422 
431 int Vect_delete(const char *map)
432 {
433  int i, n, ret;
434  struct Map_info Map;
435  struct field_info *Fi;
436  char buf[GPATH_MAX];
437  DIR *dir;
438  struct dirent *ent;
439  const char *tmp;
440 
441  G_debug(3, "Delete vector '%s'", map);
442 
443  if (map == NULL || strlen(map) == 0) {
444  G_warning(_("Invalid vector map name <%s>"), map ? map : "null");
445  return -1;
446  }
447 
448  sprintf(buf, "%s/%s/%s/%s/%s/%s", G_gisdbase(), G_location(),
449  G_mapset(), GRASS_VECT_DIRECTORY, map, GRASS_VECT_DBLN_ELEMENT);
450 
451  G_debug(1, "dbln file: %s", buf);
452 
453  if (access(buf, F_OK) == 0) {
454  /* Open input */
455  Vect_set_open_level(1); /* Topo not needed */
456  ret = Vect_open_old_head(&Map, map, G_mapset());
457  if (ret < 1) {
458  G_warning(_("Unable to open header file for vector map <%s>"),
459  map);
460  return -1;
461  }
462 
463  /* Delete all tables, NOT external (OGR) */
464  if (Map.format == GV_FORMAT_NATIVE) {
465 
466  n = Vect_get_num_dblinks(&Map);
467  for (i = 0; i < n; i++) {
468  Fi = Vect_get_dblink(&Map, i);
469  if (Fi == NULL) {
470  G_warning(_("Database connection not defined for layer %d"),
471  Map.dblnk->field[i].number);
472  Vect_close(&Map);
473  return -1;
474  }
475  G_debug(3, "Delete drv:db:table '%s:%s:%s'", Fi->driver,
476  Fi->database, Fi->table);
477 
478  ret = db_table_exists(Fi->driver, Fi->database, Fi->table);
479  if (ret == -1) {
480  G_warning(_("Unable to find table <%s> linked to vector map <%s>"),
481  Fi->table, map);
482  Vect_close(&Map);
483  return -1;
484  }
485 
486  if (ret == 1) {
487  ret =
488  db_delete_table(Fi->driver, Fi->database, Fi->table);
489  if (ret == DB_FAILED) {
490  G_warning(_("Unable to delete table <%s>"),
491  Fi->table);
492  Vect_close(&Map);
493  return -1;
494  }
495  }
496  else {
497  G_warning(_("Table <%s> linked to vector map <%s> does not exist"),
498  Fi->table, map);
499  }
500  }
501  }
502 
503  Vect_close(&Map);
504  }
505 
506  /* Delete all files from vector/name directory */
507  sprintf(buf, "%s/%s/vector/%s", G_location_path(), G_mapset(), map);
508  G_debug(3, "opendir '%s'", buf);
509  dir = opendir(buf);
510  if (dir == NULL) {
511  G_warning(_("Unable to open directory '%s'"), buf);
512  return -1;
513  }
514 
515  while ((ent = readdir(dir))) {
516  G_debug(3, "file = '%s'", ent->d_name);
517  if ((strcmp(ent->d_name, ".") == 0) ||
518  (strcmp(ent->d_name, "..") == 0))
519  continue;
520  sprintf(buf, "%s/%s/vector/%s/%s", G_location_path(), G_mapset(), map,
521  ent->d_name);
522  G_debug(3, "delete file '%s'", buf);
523  ret = unlink(buf);
524  if (ret == -1) {
525  G_warning(_("Unable to delete file '%s'"), buf);
526  closedir(dir);
527  return -1;
528  }
529  }
530  closedir(dir);
531 
532  /* NFS can create .nfsxxxxxxxx files for those deleted
533  * -> we have to move the directory to ./tmp before it is deleted */
534  sprintf(buf, "%s/%s/vector/%s", G_location_path(), G_mapset(), map);
535 
536  tmp = G_tempfile();
537 
538  G_debug(3, "rename '%s' to '%s'", buf, tmp);
539  ret = rename(buf, tmp);
540 
541  if (ret == -1) {
542  G_warning(_("Unable to rename directory '%s' to '%s'"), buf, tmp);
543  return -1;
544  }
545 
546  G_debug(3, "remove directory '%s'", tmp);
547  /* Warning: remove() fails on Windows */
548  ret = rmdir(tmp);
549  if (ret == -1) {
550  G_warning(_("Unable to remove directory '%s'"), tmp);
551  return -1;
552  }
553 
554  return 0;
555 }
556 
571 int Vect_copy_tables(struct Map_info *In, struct Map_info *Out, int field)
572 {
573  int i, n, ret, type;
574  struct field_info *Fi, *Fin;
575  dbDriver *driver;
576 
577  n = Vect_get_num_dblinks(In);
578 
579  G_debug(2, "Vect_copy_tables(): copying %d tables",n);
580 
581  type = GV_1TABLE;
582  if (n > 1)
583  type = GV_MTABLE;
584 
585  for (i = 0; i < n; i++) {
586  Fi = Vect_get_dblink(In, i);
587  if (Fi == NULL) {
588  G_warning(_("Database connection not defined for layer %d"),
589  In->dblnk->field[i].number);
590  return -1;
591  }
592  if (field > 0 && Fi->number != field)
593  continue;
594 
595  Fin = Vect_default_field_info(Out, Fi->number, Fi->name, type);
596  G_debug(2, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
597  Fi->driver, Fi->database, Fi->table, Fin->driver,
598  Fin->database, Fin->table);
599 
600  ret =
601  Vect_map_add_dblink(Out, Fi->number, Fi->name, Fin->table,
602  Fi->key, Fin->database, Fin->driver);
603  if (ret == -1) {
604  G_warning(_("Unable to add database link for vector map <%s>"),
605  Out->name);
606  return -1;
607  }
608 
609  ret = db_copy_table(Fi->driver, Fi->database, Fi->table,
610  Fin->driver, Vect_subst_var(Fin->database, Out),
611  Fin->table);
612  if (ret == DB_FAILED) {
613  G_warning(_("Unable to copy table <%s>"), Fin->table);
614  return -1;
615  }
616 
617  driver =
618  db_start_driver_open_database(Fin->driver,
619  Vect_subst_var(Fin->database, Out));
620  if (driver == NULL) {
621  G_warning(_("Unable to open database <%s> by driver <%s>"),
622  Fin->database, Fin->driver);
623  }
624  else {
625  if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK)
626  G_warning(_("Unable to create index for table <%s>, key <%s>"),
627  Fin->table, Fin->key);
628 
630  }
631  }
632 
633  return 0;
634 }
635 
649 int
650 Vect_copy_table(struct Map_info *In, struct Map_info *Out, int field_in,
651  int field_out, const char *field_name, int type)
652 {
653  return Vect_copy_table_by_cats(In, Out, field_in, field_out, field_name,
654  type, NULL, 0);
655 }
656 
672 int
673 Vect_copy_table_by_cats(struct Map_info *In, struct Map_info *Out,
674  int field_in, int field_out, const char *field_name,
675  int type, int *cats, int ncats)
676 {
677  int ret;
678  struct field_info *Fi, *Fin;
679  const char *name, *key;
680 
681  G_debug(2, "Vect_copy_table(): field_in = %d field_out = %d", field_in,
682  field_out);
683 
684  Fi = Vect_get_field(In, field_in);
685  if (Fi == NULL) {
686  G_warning(_("Database connection not defined for layer %d"),
687  field_in);
688  return -1;
689  }
690 
691  if (field_name != NULL)
692  name = field_name;
693  else
694  name = Fi->name;
695 
696  Fin = Vect_default_field_info(Out, field_out, name, type);
697  G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
698  Fi->driver, Fi->database, Fi->table, Fin->driver, Fin->database,
699  Fin->table);
700 
701  ret =
702  Vect_map_add_dblink(Out, Fin->number, Fin->name, Fin->table, Fi->key,
703  Fin->database, Fin->driver);
704  if (ret == -1) {
705  G_warning(_("Unable to add database link for vector map <%s>"),
706  Out->name);
707  return -1;
708  }
709 
710  if (cats)
711  key = Fi->key;
712  else
713  key = NULL;
714 
715  ret = db_copy_table_by_ints(Fi->driver, Fi->database, Fi->table,
716  Fin->driver, Vect_subst_var(Fin->database,
717  Out), Fin->table,
718  key, cats, ncats);
719  if (ret == DB_FAILED) {
720  G_warning(_("Unable to copy table <%s>"), Fin->table);
721  return -1;
722  }
723 
724  return 0;
725 }
726 
736 void Vect_set_release_support(struct Map_info *Map)
737 {
738  Map->plus.release_support = 1;
739 }
740 
751 void Vect_set_category_index_update(struct Map_info *Map)
752 {
753  Map->plus.update_cidx = 1;
754 }
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
Definition: db.c:28
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
int Vect_rename(const char *in, const char *out)
Rename a map.
Definition: map.c:303
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
DIR * opendir()
int db_copy_table(const char *from_drvname, const char *from_dbname, const char *from_tblname, const char *to_drvname, const char *to_dbname, const char *to_tblname)
Copy a table.
Definition: copy_tab.c:403
struct driver * driver
Definition: driver/init.c:26
int Vect_copy_table_by_cats(struct Map_info *In, struct Map_info *Out, int field_in, int field_out, const char *field_name, int type, int *cats, int ncats)
Copy table linked to vector map based on category numbers.
Definition: map.c:673
struct field_info * Vect_get_field(struct Map_info *Map, int field)
Get information about link to database.
Definition: field.c:404
char xmapset[512]
Definition: g3dcats.c:89
char * Vect_subst_var(const char *in, struct Map_info *Map)
Substitute variable in string.
Definition: field.c:741
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)
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
struct line_pnts * Vect_new_line_struct()
Creates and initializes a struct line_pnts.
Definition: line.c:57
void Vect_set_category_index_update(struct Map_info *Map)
By default, category index is not updated if vector is changed, this function sets category index upd...
Definition: map.c:751
int Vect_level(struct Map_info *Map)
Returns level that Map is opened at.
Definition: level.c:33
char * G_tempfile(void)
Returns a temporary file name.
Definition: tempfile.c:47
int G_rename(const char *element, const char *oldname, const char *newname)
Rename a database file.
Definition: rename.c:62
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
const char * Vect_get_full_name(struct Map_info *Map)
Get full map name.
dir_entry * readdir()
int Vect_map_add_dblink(struct Map_info *Map, int number, const char *name, const char *table, const char *key, const char *db, const char *driver)
Add new db connection to Map_info structure.
Definition: field.c:86
int stat
Definition: g3dcolor.c:369
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition: file_name.c:33
char * G_location_path(void)
Get current location directory.
Definition: location.c:37
int Vect_set_open_level(int level)
Predetermine level at which a map will be opened for reading.
int db_copy_table_by_ints(const char *from_drvname, const char *from_dbname, const char *from_tblname, const char *to_drvname, const char *to_dbname, const char *to_tblname, const char *selcol, int *ivals, int nvals)
Copy a table (by keys)
Definition: copy_tab.c:476
int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
Delete table.
Definition: delete_tab.c:29
int Vect_get_num_dblinks(struct Map_info *map)
Get number of defined dblinks.
Definition: level_two.c:158
char * G_gisdbase(void)
Get name of top level database directory.
Definition: gisdbase.c:29
int Vect_open_old_head(struct Map_info *Map, const char *name, const char *mapset)
Reads only info about vector from headers of &#39;head&#39;, &#39;dbln&#39;, &#39;topo&#39; and &#39;cidx&#39; file.
int Vect_copy_tables(struct Map_info *In, struct Map_info *Out, int field)
Copy tables linked to vector map.
Definition: map.c:571
int Vect_destroy_cats_struct(struct line_cats *p)
Frees all memory associated with line_cats structure, including the struct itself.
int Vect_delete(const char *map)
Delete vector map including attribute tables.
Definition: map.c:431
char * G_location(void)
Get current location name.
Definition: location.c:61
int Vect_open_update_head(struct Map_info *Map, const char *name, const char *mapset)
Open old vector head for updating (mostly for database link updates)
int Vect_line_alive(struct Map_info *Map, int line)
Check if feature is alive or dead.
int db_create_index2(dbDriver *driver, const char *table_name, const char *column_name)
Create unique index.
Definition: c_create_idx.c:61
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
struct field_info * Vect_get_dblink(struct Map_info *Map, int link)
Get information about link to database.
Definition: field.c:364
struct line_cats * Vect_new_cats_struct()
Creates and initializes line_cats structure.
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int Vect_get_num_lines(struct Map_info *map)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
Definition: level_two.c:69
int Vect_copy(const char *in, const char *mapset, const char *out)
Copy a map including attribute tables.
Definition: map.c:159
int db_table_exists(const char *drvname, const char *dbname, const char *tabname)
Check if table exists.
tuple Map
Definition: render.py:1310
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
fclose(fd)
void free(void *)
int G__make_mapset_element(const char *p_element)
Create element in the current mapset.
Definition: mapset_msc.c:34
struct field_info * Vect_default_field_info(struct Map_info *Map, int field, const char *field_name, int type)
Get default information about link to database for new dblink.
Definition: field.c:278
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 Vect_map_del_dblink(struct Map_info *Map, int field)
Delete db connection from Map_info structure.
Definition: field.c:125
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void Vect_set_release_support(struct Map_info *Map)
Set spatial index to be realease when vector is closed.
Definition: map.c:736
int n
Definition: dataquad.c:291
int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
Copy all alive elements of opened vector map to another opened vector map.
Definition: map.c:44
int Vect_copy_table(struct Map_info *In, struct Map_info *Out, int field_in, int field_out, const char *field_name, int type)
Copy table linked to vector map based on type.
Definition: map.c:650
int Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a struct line_pnts, including the struct itself. ...
Definition: line.c:90
int Vect_read_line(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line)
Read vector feature.
int Vect_rewind(struct Map_info *Map)
Rewind vector data file to cause reads to start at beginning.