GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
vector/Vlib/copy.c
Go to the documentation of this file.
1/*!
2 \file lib/vector/Vlib/copy.c
3
4 \brief Vector library - Copy vector features and attribute tables linked to
5 the map
6
7 Higher level functions for reading/writing/manipulating vectors.
8
9 SPDX-FileCopyrightText: 2001-2009, 2012-2013 GRASS Development Team
10 SPDX-License-Identifier: GPL-2.0-or-later
11
12 \author Original author CERL, probably Dave Gerdes or Mike Higgins.
13 \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
14 \author Update to GRASS 7 by Martin Landa <landa.martin gmail.com>
15 (OGR/PostGIS topology support)
16 */
17
18#include <grass/vector.h>
19#include <grass/glocale.h>
20
21#include "local_proto.h"
22
23/*!
24 \brief Copy topological elements
25
26 - simple features (None)
27 - native topo (GRASS)
28 - PostGIS Topo
29 */
30#define TOPO_NONE -1
31#define TOPO_NATIVE 1
32#define TOPO_POSTGIS 2
33
34#ifdef HAVE_POSTGRES
35#include "pg_local_proto.h"
36#define NOPG_UNUSED
37#else
38#define NOPG_UNUSED G_UNUSED
39#endif
40
41static int copy_lines_1(struct Map_info *, int, struct Map_info *);
42static int copy_lines_2(struct Map_info *, int, int, struct Map_info *);
43
44#if 0
45static int copy_nodes(struct Map_info *, struct Map_info *);
46#endif
47static int copy_line_nodes(struct Map_info *, int, int, struct line_pnts *,
48 struct Map_info *);
49static int is_isle(struct Map_info *, int);
50
51/*!
52 \brief Copy all alive vector features from input vector map to
53 output vector map
54
55 \param In input vector map
56 \param[out] Out output vector map
57
58 \return 0 on success
59 \return 1 on error
60 */
61int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
62{
63 return Vect_copy_map_lines_field(In, -1, Out);
64}
65
66/*!
67 \brief Copy all alive vector features from given layer from input
68 vector map to output vector map
69
70 Note: Try to copy on level 2 otherwise level 1 is used.
71
72 \param In input vector map
73 \param field layer number (-1 for all layers)
74 \param[out] Out output vector map
75
76 \return 0 on success
77 \return 1 on error
78 */
79int Vect_copy_map_lines_field(struct Map_info *In, int field,
80 struct Map_info *Out)
81{
82 int ret, format, topo;
83 const char *geometry_type = NULL;
84 const char *map_name = NULL;
85
86 if (Vect_level(In) < 1)
88 _("Unable to copy features. Input vector map <%s> is not open"),
90
91 format = Out->format; /* do not use Vect_maptype(), we need native
92 format for temporary maps here */
93 topo = TOPO_NONE;
94 if (format == GV_FORMAT_NATIVE) {
95 topo = TOPO_NATIVE;
96 }
97 else if (format == GV_FORMAT_POSTGIS && Out->fInfo.pg.toposchema_name) {
98 int type;
99
100 topo = TOPO_POSTGIS;
101
102 /* get type of first feature from input vector map */
103 Vect_rewind(In);
105 type = Vect_read_next_line(In, NULL, NULL);
106
107 /* create feature table with given feature type */
108 if (0 > Vect_write_line(Out, type, NULL, NULL)) {
109 G_warning(_("Unable to create PostGIS layer <%s>"),
111 return 1;
112 }
113 }
114
115 /* Note: sometimes is important to copy on level 2 (pseudotopo
116 centroids) and sometimes on level 1 if build take too long time
117 */
118 ret = 0;
119 if (Vect_level(In) >= 2) {
120 /* -> copy features on level 2 */
121#if 0
122 if (topo == TOPO_POSTGIS) {
123 /* PostGIS topology - copy also nodes */
124 copy_nodes(In, Out);
125 }
126#endif
127 /* copy features */
128 ret += copy_lines_2(In, field, topo, Out);
129
130 if (topo == TOPO_NONE) {
131 /* check output feature type, centroids can be exported as
132 * points; boundaries as linestrings */
134 if (geometry_type && strcmp(geometry_type, "polygon") == 0) {
135 /* copy areas - external formats and simple features access only
136 */
137 ret += Vect__copy_areas(In, field, Out);
138 }
139 G_free((void *)geometry_type);
140 }
141 }
142 else {
143 /* -> copy features on level 1 */
144 if (topo == TOPO_NONE) {
145 map_name = Vect_get_full_name(In);
146 G_warning(_("Vector map <%s> not open on topological level. "
147 "Areas will be skipped!"),
148 map_name);
149 G_free((void *)map_name);
150 }
151
152 ret += copy_lines_1(In, field, Out);
153 }
154 return ret > 0 ? 1 : 0;
155}
156
157/*!
158 \brief Copy vector features on level 1
159
160 \param In input vector map
161 \param field layer number (-1 for all layers)
162 \param Out output vector map
163
164 \return 0 on success
165 \return 1 on error
166 */
167int copy_lines_1(struct Map_info *In, int field, struct Map_info *Out)
168{
169 int ret, type;
170 const char *map_name = NULL;
171
172 struct line_pnts *Points;
173 struct line_cats *Cats;
174
175 Points = Vect_new_line_struct();
177
178 ret = 0;
179
180 Vect_rewind(In);
181 while (TRUE) {
182 type = Vect_read_next_line(In, Points, Cats);
183 if (type == -1) {
184 map_name = Vect_get_full_name(In);
185 G_warning(_("Unable to read vector map <%s>"), map_name);
186 G_free((void *)map_name);
187 ret = 1;
188 break;
189 }
190 else if (type == -2) { /* EOF */
191 break; /* free allocated space and return */
192 }
193 else if (type == 0) { /* dead line */
194 continue;
195 }
196
197 /* don't skip boundaries if field != -1 */
198 if (field != -1 && !(type & GV_BOUNDARY) &&
199 Vect_cat_get(Cats, field, NULL) == 0)
200 continue; /* different layer */
201
202 Vect_write_line(Out, type, Points, Cats);
203 }
206
207 return ret;
208}
209
210/*!
211 \brief Copy vector features on level 2
212
213 \param In input vector map
214 \param field layer number (-1 for all layers)
215 \param topo topo access (none, native, postgis)
216 \param Out output vector map
217
218 \return 0 on success
219 \return 1 on error
220 */
221int copy_lines_2(struct Map_info *In, int field, int topo, struct Map_info *Out)
222{
223 int i, type, nlines, nskipped;
224 int ret, left, rite, centroid, with_z;
225
226 struct line_pnts *Points, *CPoints, *NPoints;
227 struct line_cats *Cats, *CCats;
228
229 const char *ftype = NULL;
230 const char *map_name = NULL;
231
232 Points = Vect_new_line_struct();
237
238 with_z = Vect_is_3d(In);
239
240 ret = 0;
241 nlines = Vect_get_num_lines(In);
242 if (topo == TOPO_NONE) {
244 G_debug(2, "feature type: %s", ftype ? ftype : "?");
245 if (!ftype)
246 G_message(_("Copying features..."));
247 else
248 G_message(_("Copying features (%s)..."), ftype);
249 }
250 else
251 G_message(_("Copying features..."));
252
253 Vect_append_point(NPoints, 0., 0., 0.);
254 nskipped = 0;
255 for (i = 1; i <= nlines; i++) {
256 if (!Vect_line_alive(In, i))
257 continue;
258
259 G_percent(i, nlines, 2);
260 type = Vect_read_line(In, Points, Cats, i);
261 if (type == -1) {
262 map_name = Vect_get_full_name(In);
263 G_warning(_("Unable to read vector map <%s>"), map_name);
264 G_free((void *)map_name);
265 ret = 1;
266 break; /* free allocated space and return */
267 }
268 if (type == 0)
269 continue; /* dead line */
270 if (In->constraint.type_flag) {
271 /* skip feature by type */
272 if (!(type & In->constraint.type))
273 continue;
274 }
275
276 if (topo == TOPO_NONE) {
277 /* OGR/PostGIS layers (simple features) */
278 int skip = FALSE;
279
280 if (type == GV_BOUNDARY)
281 /* boundaries are written as linestrings when output
282 * feature type is defined as 'linestring', otherwise
283 * they are skipped */
284 if (ftype && strcmp(ftype, "linestring") != 0)
285 skip = TRUE;
286
287 /* centroids are stored in topo polygon defined by areas
288 (topo required) */
289 if (type == GV_CENTROID) {
290 /* centroids are written as points when output feature
291 * type is defined as 'point', otherwise they are
292 * skipped */
293 if (ftype && strcmp(ftype, "point") != 0)
294 skip = TRUE;
295 }
296
297 if (skip)
298 continue;
299 }
300
301 /* don't skips boundaries if field != -1 */
302 if (field != -1) {
303 if (type & GV_BOUNDARY) {
304 if (Vect_cat_get(Cats, field, NULL) == 0) {
305 int skip_bndry = TRUE;
306
307 Vect_get_line_areas(In, i, &left, &rite);
308 if (left < 0)
309 left = Vect_get_isle_area(In, abs(left));
310 if (left > 0) {
311 if ((centroid = Vect_get_area_centroid(In, left)) > 0) {
312 Vect_read_line(In, CPoints, CCats, centroid);
313 if (Vect_cat_get(CCats, field, NULL) != 0)
315 }
316 }
317 if (skip_bndry) {
318 if (rite < 0)
319 rite = Vect_get_isle_area(In, abs(rite));
320 if (rite > 0) {
321 if ((centroid = Vect_get_area_centroid(In, rite)) >
322 0) {
323 Vect_read_line(In, CPoints, CCats, centroid);
324 if (Vect_cat_get(CCats, field, NULL) != 0)
326 }
327 }
328 }
329 if (skip_bndry)
330 continue;
331 }
332 }
333 else if (Vect_cat_get(Cats, field, NULL) == 0) {
334 nskipped++;
335 continue; /* different layer */
336 }
337 }
338
339 /* copy also nodes connected to the line (PostGIS Topology
340 * mode only) */
341 if (topo == TOPO_POSTGIS && (type & GV_LINES)) {
342 int n1, n2;
343
344 struct P_line *Line;
345 struct Format_info_offset *offset;
346
347 offset = &(Out->fInfo.pg.offset);
348
349 n1 = n2 = -1;
350 Line = In->plus.Line[i];
351 if (Line) {
352 if (type == GV_LINE) {
353 struct P_topo_l *topo = (struct P_topo_l *)Line->topo;
354
355 n1 = topo->N1;
356 n2 = topo->N2;
357 }
358 else if (type == GV_BOUNDARY) {
359 struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
360
361 n1 = topo->N1;
362 n2 = topo->N2;
363 }
364 }
365
366 if (n1 > 0 &&
367 (n1 > offset->array_num || offset->array[n1 - 1] == 0))
368 copy_line_nodes(In, n1, with_z, NPoints, Out);
369 if (n2 > 0 &&
370 (n2 > offset->array_num || offset->array[n2 - 1] == 0))
371 copy_line_nodes(In, n2, with_z, NPoints, Out);
372 }
373
374 if (-1 == Vect_write_line(Out, type, Points, Cats)) {
375 G_warning(_("Writing new feature failed"));
376 ret = 1;
377 goto free_exit;
378 }
379 }
380
381 if (nskipped > 0)
383 _("%d features without category or from different layer skipped"),
384 nskipped);
391 G_free((void *)ftype);
392
393 return ret;
394}
395
396#if 0
397/*!
398 \brief Copy nodes as points (PostGIS Topology only)
399
400 \param In input vector map
401 \param Out output vector map
402
403 \return 0 on success
404 \return 1 on error
405 */
406int copy_nodes(struct Map_info *In, struct Map_info *Out)
407{
408 int nnodes, node, with_z;
409
410 struct line_pnts *Points;
411
412 Points = Vect_new_line_struct();
413
414 with_z = Vect_is_3d(In);
415
417 G_message(_("Exporting nodes..."));
418 Vect_append_point(Points, 0., 0., 0.);
419 for (node = 1; node <= nnodes; node++) {
420 G_debug(3, "Exporting GRASS node %d", node);
421
422 G_percent(node, nnodes, 5);
423 copy_line_nodes(In, node, with_z, Points, Out);
424 }
425
427
428 return 0;
429}
430#endif
431
432int copy_line_nodes(struct Map_info *In, int node, int with_z,
433 struct line_pnts *Points, struct Map_info *Out NOPG_UNUSED)
434{
435 double x, y, z;
436
437 Vect_get_node_coor(In, node, &x, &y, &z);
438 Points->x[0] = x;
439 Points->y[0] = y;
440 if (with_z)
441 Points->z[0] = z;
442
443#ifdef HAVE_POSTGRES
444 if (-1 == V2__write_node_pg(Out, Points)) {
445 G_warning(_("Writing node %d failed"), node);
446 return 1;
447 }
448#else
449 G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
450 return 1;
451#endif
452
453 return 0;
454}
455
456/*!
457 \brief Check if area is part of an isle
458
459 Check for areas that are part of isles which in turn are inside
460 another area.
461
462 \param Map pointer to Map_info struct
463 \param area area id
464
465 \return TRUE if area forms an isle otherwise FALSE
466 */
467int is_isle(struct Map_info *Map, int area)
468{
469 int i, line, left, right, isle, is_isle;
470
471 struct ilist *List;
472
475
476 is_isle = FALSE;
477 /* do we need to check all boundaries ? no */
478 for (i = 0; i < List->n_values && !is_isle; i++) {
479 line = List->value[i];
480 if (1 != Vect_get_line_areas(Map, abs(line), &left, &right))
481 continue;
482
483 isle = line > 0 ? left : right;
484
485 if (isle < 0 && Vect_get_isle_area(Map, abs(isle)) > 0) {
486 is_isle = TRUE;
487 break;
488 }
489 }
490
491 G_debug(3, "is_isle(): area %d skip? -> %s", area, is_isle ? "yes" : "no");
493
494 return is_isle;
495}
496
497/*!
498 \brief Copy areas as polygons (OGR/PostGIS simple features access only)
499
500 \param In input vector map
501 \param field layer number (-1 for all layers)
502 \param Out output vector map
503
504 \return 0 on success
505 \return 1 on error
506 */
507int Vect__copy_areas(struct Map_info *In, int field, struct Map_info *Out)
508{
509 int i, area, nareas, cat, isle, nisles, nparts_alloc, nskipped;
510 int ret = 0;
511 struct line_pnts **Points;
512 struct line_cats *Cats;
513
514 /* allocate points & cats */
515 Points = (struct line_pnts **)G_malloc(sizeof(struct line_pnts *));
516 Points[0] = Vect_new_line_struct();
517 nparts_alloc = 1;
519
520 /* copy areas */
521 nskipped = 0;
523 if (nareas > 0)
524 G_message(_("Exporting areas..."));
525 for (area = 1; area <= nareas; area++) {
526 G_debug(2, "area = %d", area);
527 G_percent(area, nareas, 3);
528
529 /* get category */
531 if (field > 0) {
532 cat = Vect_get_area_cat(In, area, field);
533 /* skip area without category in given layer
534 if (cat == -1) {
535 nskipped++;
536 continue;
537 }
538 */
539
540 if (cat > 0)
541 Vect_cat_set(Cats, field, cat);
542 }
543
544 /* skip isles */
545 if (Vect_get_area_centroid(In, area) == 0) {
546 /* no centroid - check if area forms an isle */
547 /* this check does not make sense because the area is also
548 * not exported if it is part of an isle inside another
549 * area: the isle gets exported as an inner ring
550 if (!is_isle(In, area))
551 G_warning(_("No centroid defined for area %d. "
552 "Area not exported."),
553 area);
554 */
555 G_debug(3, "Area %d: is_isle() -> %d", area, is_isle(In, area));
556 continue;
557 }
558
559 /* get outer ring (area) */
560 Vect_get_area_points(In, area, Points[0]);
561
562 /* get inner rings (isles) */
564 if (nisles + 1 > nparts_alloc) {
565 /* reallocate space for isles */
566 Points = (struct line_pnts **)G_realloc(
567 Points, (nisles + 1) * sizeof(struct line_pnts *));
568 for (i = nparts_alloc; i < nisles + 1; i++)
569 Points[i] = Vect_new_line_struct();
570 nparts_alloc = nisles + 1;
571 }
572 G_debug(3, "\tcat=%d, nisles=%d", cat, nisles);
573 for (i = 0; i < nisles; i++) {
574 isle = Vect_get_area_isle(In, area, i);
575 Vect_get_isle_points(In, isle, Points[i + 1]);
576 }
577
578 if (In != Out) {
579 if (0 > V2__write_area_sfa(Out, (const struct line_pnts **)Points,
580 nisles + 1, Cats)) {
581 G_warning(_("Writing area %d failed"), area);
582 ret = -1;
583 goto free_exit;
584 }
585 }
586#ifdef HAVE_POSTGRES
587 else { /* building simple features geometry from topogeometry data */
588 if (0 > V2__update_area_pg(Out, (const struct line_pnts **)Points,
589 nisles + 1, cat)) {
590 G_warning(_("Writing area %d failed"), area);
591 ret = -1;
592 goto free_exit;
593 }
594 }
595#endif
596 }
597
598 if (nskipped > 0)
600 _("%d areas without category or from different layer skipped"),
601 nskipped);
602
603 /* free allocated space for isles */
605 for (i = 0; i < nparts_alloc; i++)
606 Vect_destroy_line_struct(Points[i]);
608 G_free(Points);
609
610 return ret;
611}
612
613/*!
614 \brief Copy attribute tables linked to vector map.
615
616 Copy all attribute tables linked to the vector map if
617 <em>field</em> is 0, or selected attribute table defined by given
618 field if <em>field</em> > 0.
619
620 Notice, that if input vector map has no tables defined, it will
621 copy nothing and return 0 (success).
622
623 \param In input vector map
624 \param[out] Out output vector map
625 \param field layer number (0 for all tables linked to the vector map)
626
627 \return 0 on success
628 \return -1 on error
629 */
630int Vect_copy_tables(struct Map_info *In, struct Map_info *Out, int field)
631{
632 int i, n, type;
633 struct field_info *Fi;
634 const char *map_name = NULL;
635
636 n = Vect_get_num_dblinks(In);
637
638 G_debug(2, "Vect_copy_tables(): copying %d tables", n);
639
640 type = GV_1TABLE;
641 if (field < 1 && n > 1)
642 type = GV_MTABLE;
643
644 for (i = 0; i < n; i++) {
645 Fi = Vect_get_dblink(In, i);
646 if (Fi == NULL) {
647 G_warning(_("Database connection not defined for layer %d"),
648 In->dblnk->field[i].number);
649 return -1;
650 }
651 if (field > 0 && Fi->number != field) {
653 continue;
654 }
655
656 if (Vect_copy_table(In, Out, Fi->number, Fi->number, Fi->name, type) !=
657 0) {
658 map_name = Vect_get_full_name(In);
659 G_warning(
660 _("Unable to copy table <%s> for layer %d from <%s> to <%s>"),
661 Fi->table, Fi->number, map_name, Vect_get_name(Out));
662 G_free((void *)map_name);
664 return -1;
665 }
667 }
668 return 0;
669}
670
671/*!
672 \brief Copy attribute table linked to vector map based on type.
673
674 \param In input vector map
675 \param[out] Out output vector map
676 \param field_in input layer number
677 \param field_out output layer number
678 \param field_name layer name (can be NULL)
679 \param type how many tables are linked to map: GV_1TABLE / GV_MTABLE
680
681 \return 0 on success
682 \return -1 on error
683 */
684int Vect_copy_table(struct Map_info *In, struct Map_info *Out, int field_in,
685 int field_out, const char *field_name, int type)
686{
688 type, NULL, 0);
689}
690
691/*!
692 \brief Copy attribute table linked to vector map based on category
693 list.
694
695 If <em>cat_list</em> is NULL, then Vect_copy_table() is called.
696
697 \param In input vector map
698 \param[out] Out output vector map
699 \param field_in input layer number
700 \param field_out output layer number
701 \param field_name layer name (can be NULL)
702 \param type how many tables are linked to map: GV_1TABLE / GV_MTABLE
703 \param cat_list pointer to cat_list struct (can be NULL)
704
705 \return 0 on success
706 \return -1 on error
707 */
709 int field_in, int field_out,
710 const char *field_name, int type,
711 const struct cat_list *cat_list)
712{
713 int *cats;
714 int ncats, ret;
715
716 if (cat_list) {
717 if (Vect_cat_list_to_array(cat_list, &cats, &ncats) != 0)
718 return -1;
719
721 type, cats, ncats);
722
723 G_free(cats);
724 }
725 else {
726 ret = Vect_copy_table(In, Out, field_in, field_out, field_name, type);
727 }
728
729 return ret;
730}
731
732/*!
733 \brief Copy attribute table linked to vector map based on category
734 numbers.
735
736 \param In input vector map
737 \param[out] Out output vector map
738 \param field_in input layer number
739 \param field_out output layer number
740 \param field_name layer name (can be NULL)
741 \param type how many tables are linked to map: GV_1TABLE / GV_MTABLE
742 \param cats pointer to array of cats or NULL
743 \param ncats number of cats in 'cats'
744
745 \return 0 on success
746 \return -1 on error
747 */
748int Vect_copy_table_by_cats(struct Map_info *In, struct Map_info *Out,
749 int field_in, int field_out, const char *field_name,
750 int type, int *cats, int ncats)
751{
752 int ret = 0;
753 struct field_info *Fi, *Fin;
754 const char *name, *key;
756
757 G_debug(2, "Vect_copy_table_by_cats(): field_in = %d field_out = %d",
759
761 if (Fi == NULL) {
762 G_warning(_("Database connection not defined for layer %d"), field_in);
763 return -1;
764 }
765
766 if (field_name != NULL)
768 else
769 name = Fi->name;
770
772 G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'", Fi->driver,
773 Fi->database, Fi->table, Fin->driver, Fin->database, Fin->table);
774
775 ret = Vect_map_add_dblink(Out, Fin->number, Fin->name, Fin->table, Fi->key,
776 Fin->database, Fin->driver);
777 if (ret == -1) {
778 G_warning(_("Unable to add database link for vector map <%s>"),
779 Out->name);
780 goto free_exit;
781 }
782
783 if (cats)
784 key = Fi->key;
785 else
786 key = NULL;
787
788 ret = db_copy_table_by_ints(Fi->driver, Fi->database, Fi->table,
789 Fin->driver, Vect_subst_var(Fin->database, Out),
790 Fin->table, key, cats, ncats);
791 if (ret == DB_FAILED) {
792 G_warning(_("Unable to copy table <%s>"), Fin->table);
793 ret = -1;
794 goto free_exit;
795 }
796
798 Vect_subst_var(Fin->database, Out));
799
800 if (!driver) {
801 G_warning(_("Unable to open database <%s> with driver <%s>"),
802 Fin->database, Fin->driver);
803 ret = -1;
804 goto free_exit;
805 }
806
807 /* do not allow duplicate keys */
808 if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK) {
809 G_warning(_("Unable to create index"));
810 ret = -1;
812 }
813
815 DB_GROUP | DB_PUBLIC) != DB_OK) {
816 G_warning(_("Unable to grant privileges on table <%s>"), Fin->table);
817 ret = -1;
819 }
820
823
827
828 return ret;
829}
#define NULL
Definition ccmath.h:32
AMI_err name(char **stream_name)
Definition ami_stream.h:426
#define DB_FAILED
Definition dbmi.h:70
#define DB_PUBLIC
Definition dbmi.h:133
#define DB_GROUP
Definition dbmi.h:132
#define DB_PRIV_SELECT
Definition dbmi.h:130
#define DB_OK
Definition dbmi.h:69
int db_copy_table_by_ints(const char *, const char *, const char *, const char *, const char *, const char *, const char *, int *, int)
Copy a table (by keys)
Definition copy_tab.c:511
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
Definition db.c:58
int db_create_index2(dbDriver *, const char *, const char *)
Create unique index.
int db_grant_on_table(dbDriver *, const char *, int, int)
Grant privileges on table.
Definition c_priv.c:26
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
Definition db.c:25
void G_percent(long, long, int)
Print percent complete messages.
Definition percent.c:59
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
#define G_realloc(p, n)
Definition defs/gis.h:138
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
#define G_malloc(n)
Definition defs/gis.h:136
void void void G_important_message(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
struct field_info * Vect_default_field_info(struct Map_info *, int, const char *, int)
Get default information about link to database for new dblink.
Definition field.c:351
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
Definition line.c:75
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
Definition level_two.c:272
char * Vect_subst_var(const char *, struct Map_info *)
Substitute variable in string.
Definition field.c:921
plus_t Vect_get_num_lines(struct Map_info *)
Fetch number of features (points, lines, boundaries, centroids) in vector map.
Definition level_two.c:73
plus_t Vect_get_num_areas(struct Map_info *)
Get number of areas in vector map.
Definition level_two.c:85
int Vect_reset_cats(struct line_cats *)
Reset category structure to make sure cats structure is clean to be re-used.
int Vect_cat_set(struct line_cats *, int, int)
Add new field/cat to category structure if doesn't exist yet.
int Vect_get_area_boundaries(struct Map_info *, int, struct ilist *)
Creates list of boundaries for given area.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
int Vect_get_isle_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
const char * Vect_get_name(struct Map_info *)
Get name of vector map.
int Vect_get_area_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
int Vect_level(struct Map_info *)
Returns level that Map is opened at.
Definition level.c:27
void Vect_destroy_cats_struct(struct line_cats *)
Frees all memory associated with line_cats structure, including the struct itself.
struct field_info * Vect_get_field(struct Map_info *, int)
Get information about link to database (by layer number)
Definition field.c:508
int Vect_get_area_isle(struct Map_info *, int, int)
Returns isle id for area.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_get_area_num_isles(struct Map_info *, int)
Returns number of isles for given area.
int Vect_cat_list_to_array(const struct cat_list *, int **, int *)
Convert cat_list struct to ordered array of unique integers.
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
const char * Vect_get_finfo_geometry_type(struct Map_info *)
Get geometry type as string (relevant only for non-native formats)
struct field_info * Vect_get_dblink(struct Map_info *, int)
Get information about link to database.
Definition field.c:468
int Vect_get_num_dblinks(struct Map_info *)
Get number of defined dblinks.
Definition level_two.c:157
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
const char * Vect_get_full_name(struct Map_info *)
Get fully qualified name of vector map.
int Vect_get_area_cat(struct Map_info *, int, int)
Find FIRST category of given field and area.
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *, const struct line_cats *)
Writes a new feature.
void Vect_destroy_field_info(struct field_info *)
Free a struct field_info and all memory associated with it.
Definition field.c:626
plus_t Vect_get_num_nodes(struct Map_info *)
Get number of nodes in vector map.
Definition level_two.c:32
int Vect_get_area_centroid(struct Map_info *, int)
Returns centroid id for given area.
int Vect_map_add_dblink(struct Map_info *, int, const char *, const char *, const char *, const char *, const char *)
Add new db connection to Map_info structure.
Definition field.c:113
int Vect_rewind(struct Map_info *)
Rewind vector map to cause reads to start at beginning.
int Vect_read_next_line(struct Map_info *, struct line_pnts *, struct line_cats *)
Read next vector feature.
int Vect_set_constraint_type(struct Map_info *, int)
Set constraint type.
Definition constraint.c:104
char * Vect_get_finfo_layer_name(struct Map_info *)
Get layer name (relevant only for non-native formats)
int Vect_get_line_areas(struct Map_info *, int, int *, int *)
Get area id on the left and right side of the boundary.
Definition level_two.c:345
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
Definition line.c:43
int Vect_is_3d(struct Map_info *)
Check if vector map is 3D.
int Vect_append_point(struct line_pnts *, double, double, double)
Appends one point to the end of a line.
Definition line.c:146
int Vect_get_isle_area(struct Map_info *, int)
Returns area id for isle.
#define GV_CENTROID
#define GV_FORMAT_POSTGIS
PostGIS format.
Definition dig_defines.h:89
#define GV_LINE
#define GV_LINES
#define GV_BOUNDARY
#define GV_1TABLE
One table linked to vector map.
Definition dig_defines.h:99
#define GV_MTABLE
More tables linked to vector map.
#define GV_POINTS
#define GV_FORMAT_NATIVE
Geometry data formats supported by lib Don't change GV_FORMAT_* values, this order is hardcoded in li...
Definition dig_defines.h:83
#define TRUE
Definition gis.h:75
#define FALSE
Definition gis.h:79
#define _(str)
Definition glocale.h:10
const char * name
Definition named_colr.c:6
Data structure used for building pseudo-topology.
int * array
Offset list.
int array_num
Number of items in offset list.
Vector map info.
char * name
Map name (for 4.0)
int format
Map format (native, ogr, postgis)
struct Map_info::@11 constraint
Constraints for sequential feature access.
struct dblinks * dblnk
Array of DB links.
struct Format_info fInfo
Format info for non-native formats.
struct Plus_head plus
Plus info (topology, version, ...)
Vector geometry.
void * topo
Topology info.
Boundary topology.
Line topology.
Category list.
Layer (old: field) information.
char * key
Name of key column (usually 'cat')
List of integers.
Definition gis.h:712
Feature category info.
int * field
Array of layers (fields)
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
double * z
Array of Z coordinates.
#define TOPO_POSTGIS
#define NOPG_UNUSED
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 attribute table linked to vector map based on type.
int Vect_copy_tables(struct Map_info *In, struct Map_info *Out, int field)
Copy attribute tables linked to vector map.
#define TOPO_NONE
Copy topological elements.
int Vect_copy_table_by_cat_list(struct Map_info *In, struct Map_info *Out, int field_in, int field_out, const char *field_name, int type, const struct cat_list *cat_list)
Copy attribute table linked to vector map based on category list.
int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
Copy all alive vector features from input vector map to output vector map.
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 attribute table linked to vector map based on category numbers.
int Vect__copy_areas(struct Map_info *In, int field, struct Map_info *Out)
Copy areas as polygons (OGR/PostGIS simple features access only)
int Vect_copy_map_lines_field(struct Map_info *In, int field, struct Map_info *Out)
Copy all alive vector features from given layer from input vector map to output vector map.
#define TOPO_NATIVE
int V2__update_area_pg(struct Map_info *Map, const struct line_pnts **points, int nparts, int cat)
Updates simple features geometry from GRASS-like topo.
Definition write_pg.c:556
off_t V2__write_node_pg(struct Map_info *Map, const struct line_pnts *points)
Writes node on topological level (PostGIS Topology interface, internal use only)
Definition write_pg.c:515
off_t V2__write_area_sfa(struct Map_info *Map, const struct line_pnts **points, int nparts, const struct line_cats *cats)
Writes area on topological level (Simple Features interface, internal use only)
Definition write_sfa.c:275