[GRASS-SVN] r52578 - grass/trunk/lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 7 07:24:41 PDT 2012
Author: martinl
Date: 2012-08-07 07:24:40 -0700 (Tue, 07 Aug 2012)
New Revision: 52578
Added:
grass/trunk/lib/vector/Vlib/copy.c
Modified:
grass/trunk/lib/vector/Vlib/field.c
grass/trunk/lib/vector/Vlib/map.c
Log:
vlib: move Vect_copy_map_lines() and Vect_copy_tables() to the separate file (copy.c)
simplify Vect_copy_map_lines() code
update Vect_copy_map_lines() for better support of OGR/PostGIS formats
Added: grass/trunk/lib/vector/Vlib/copy.c
===================================================================
--- grass/trunk/lib/vector/Vlib/copy.c (rev 0)
+++ grass/trunk/lib/vector/Vlib/copy.c 2012-08-07 14:24:40 UTC (rev 52578)
@@ -0,0 +1,504 @@
+/*!
+ \file lib/vector/Vlib/copy.c
+
+ \brief Vector library - Copy vector features and attribute tables linked to the map
+
+ Higher level functions for reading/writing/manipulating vectors.
+
+ (C) 2001-2009, 2012 by the GRASS Development Team
+
+ This program is free software under the GNU General Public License
+ (>=v2). Read the file COPYING that comes with GRASS for details.
+
+ \author Original author CERL, probably Dave Gerdes or Mike Higgins.
+ \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
+ \author Update to GRASS 7 by Martin Landa <landa.martin gmail.com> (OGR/PostGIS topology support)
+*/
+
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+static int copy_lines_1(struct Map_info *, int, struct Map_info *);
+static int copy_lines_2(struct Map_info *, int, int, struct Map_info *);
+static int copy_nodes(const struct Map_info *, struct Map_info *);
+static int copy_areas(const struct Map_info *, int, struct Map_info *);
+
+/*!
+ \brief Copy all alive vector features from input vector map to
+ output vector map
+
+ \param In input vector map
+ \param[out] Out output vector map
+
+ \return 0 on success
+ \return 1 on error
+ */
+int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
+{
+ return Vect_copy_map_lines_field(In, -1, Out);
+}
+
+/*!
+ \brief Copy all alive vector features from given layer from input
+ vector map to output vector map
+
+ Note: Try to copy on level 2 otherwise level 1 is used.
+
+ \todo Implement V2_write_area_ogr()
+
+ \param In input vector map
+ \param field layer number (-1 for all layers)
+ \param[out] Out output vector map
+
+ \return 0 on success
+ \return 1 on error
+ */
+int Vect_copy_map_lines_field(struct Map_info *In, int field,
+ struct Map_info *Out)
+{
+ int ret, native, pg_topo;
+
+ if (Vect_level(In) < 1)
+ G_fatal_error("Vect_copy_map_lines(): %s",
+ _("input vector map is not open"));
+
+ /* check for external formats - copy areas/isles as polygons with holes */
+ native = Vect_maptype(Out) == GV_FORMAT_NATIVE;
+ /* check for PostGIS topology */
+ pg_topo = Vect_maptype(Out) == GV_FORMAT_POSTGIS && Out->fInfo.pg.toposchema_name;
+
+ /* Note: sometimes is important to copy on level 2 (pseudotopo
+ centroids) and sometimes on level 1 if build take too
+ long time
+ */
+ if (Vect_level(In) >= 2) {
+ /* -> copy features on level 2 */
+ if (pg_topo)
+ /* PostGIS topology - copy also nodes */
+ copy_nodes(In, Out);
+
+ /* copy features */
+ ret = copy_lines_2(In, field, native, Out);
+
+ if (!native) {
+ copy_areas(In, field, Out);
+ }
+ }
+ else {
+ /* -> copy features on level 1 */
+ if (!native)
+ G_warning(_("Vector map <%s> not open on topological level. "
+ "Areas will be skipped!"), Vect_get_full_name(In));
+
+ ret = copy_lines_1(In, field, Out);
+ }
+
+ return ret;
+}
+
+int copy_lines_1(struct Map_info *In, int field, struct Map_info *Out)
+{
+ int ret, type;
+
+ struct line_pnts *Points;
+ struct line_cats *Cats;
+
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+
+ ret = 0;
+
+ Vect_rewind(In);
+ while (TRUE) {
+ type = Vect_read_next_line(In, Points, Cats);
+ if (type == -1) {
+ G_warning(_("Unable to read vector map <%s>"),
+ Vect_get_full_name(In));
+ ret = 1;
+ break;
+ }
+ else if (type == -2) { /* EOF */
+ break; /* free allocated space and return */
+ }
+ else if (type == 0) { /* dead line */
+ continue;
+ }
+
+ /* don't skip boundaries if field != -1 */
+ if (field != -1 && !(type & GV_BOUNDARY) &&
+ Vect_cat_get(Cats, field, NULL) == 0)
+ continue; /* different layer */
+
+ Vect_write_line(Out, type, Points, Cats);
+ }
+
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+
+ return ret;
+}
+
+int copy_lines_2(struct Map_info *In, int field, int native, struct Map_info *Out)
+{
+ int i, type, nlines;
+ int ret, left, rite, centroid;
+
+ struct line_pnts *Points, *CPoints;
+ struct line_cats *Cats, *CCats;
+
+ Points = Vect_new_line_struct();
+ CPoints = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+ CCats = Vect_new_cats_struct();
+
+ ret = 0;
+ nlines = Vect_get_num_lines(In);
+ if (native)
+ G_message(_("Exporting features..."));
+ else
+ G_message(_("Exporting features (%s)..."),
+ Vect_get_finfo_geometry_type(Out));
+
+ for (i = 1; i <= nlines; i++) {
+ if (!Vect_line_alive(In, i))
+ continue;
+
+ G_percent(i, nlines, 2);
+ type = Vect_read_line(In, Points, Cats, i);
+ if (type == -1) {
+ G_warning(_("Unable to read vector map <%s>"),
+ Vect_get_full_name(In));
+ ret = 1;
+ break; /* free allocated space and return */
+ }
+ if (type == 0)
+ continue; /* dead line */
+
+ if (!native && (type == GV_CENTROID || type == GV_BOUNDARY))
+ /* OGR/PostGIS layers: centroids are stored in topo */
+ /* polygon defined by areas (topo required) */
+ continue;
+
+ /* don't skips boundaries if field != -1 */
+ if (field != -1) {
+ if (type & GV_BOUNDARY) {
+ if (Vect_cat_get(Cats, field, NULL) == 0) {
+ int skip_bndry = TRUE;
+
+ Vect_get_line_areas(In, i, &left, &rite);
+ if (left < 0)
+ left = Vect_get_isle_area(In, abs(left));
+ if (left > 0) {
+ if ((centroid =
+ Vect_get_area_centroid(In, left)) > 0) {
+ Vect_read_line(In, CPoints, CCats, centroid);
+ if (Vect_cat_get(CCats, field, NULL) != 0)
+ skip_bndry = FALSE;
+ }
+ }
+ if (skip_bndry) {
+ if (rite < 0)
+ rite = Vect_get_isle_area(In, abs(rite));
+ if (rite > 0) {
+ if ((centroid =
+ Vect_get_area_centroid(In, rite)) > 0) {
+ Vect_read_line(In, CPoints, CCats,
+ centroid);
+ if (Vect_cat_get(CCats, field, NULL) != 0)
+ skip_bndry = FALSE;
+ }
+ }
+ }
+ if (skip_bndry)
+ continue;
+ }
+ }
+ else if (Vect_cat_get(Cats, field, NULL) == 0)
+ continue; /* different layer */
+ }
+
+ Vect_write_line(Out, type, Points, Cats);
+ }
+
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_line_struct(CPoints);
+ Vect_destroy_cats_struct(Cats);
+ Vect_destroy_cats_struct(CCats);
+
+ return ret;
+}
+
+int copy_nodes(const struct Map_info *In, struct Map_info *Out)
+{
+ int nnodes, node, with_z;
+ double x, y, z;
+ struct line_pnts *Points;
+
+ Points = Vect_new_line_struct();
+
+ with_z = Vect_is_3d(In);
+
+ nnodes = Vect_get_num_nodes(In);
+ G_message(_("Exporting nodes..."));
+ Vect_append_point(Points, 0., 0., 0.);
+ for (node = 1; node <= nnodes; node++) {
+ G_debug(3, "Exporting GRASS node %d", node);
+
+ G_percent(node, nnodes, 5);
+ Vect_get_node_coor(In, node, &x, &y, &z);
+ Points->x[0] = x;
+ Points->y[0] = y;
+ if (with_z)
+ Points->z[0] = z;
+
+ if (-1 == Vect_write_line(Out, GV_POINT, Points, NULL))
+ G_fatal_error(_("Unable to export node %d. Exiting."), node);
+ }
+
+ Vect_destroy_line_struct(Points);
+
+ return nnodes;
+}
+
+int copy_areas(const struct Map_info *In, int field, struct Map_info *Out)
+{
+ int i, area, nareas, cat, isle, nisles, nisles_alloc;
+ int ogr;
+ struct line_pnts *Points, **IPoints;
+ struct line_cats *Cats;
+
+ ogr = Vect_maptype(Out) == GV_FORMAT_OGR_DIRECT;
+
+ IPoints = NULL;
+ nisles_alloc = 0;
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+
+ /* copy areas/polygons */
+ nareas = Vect_get_num_areas(In);
+ G_message(_("Exporting areas..."));
+ for (area = 1; area <= nareas; area++) {
+ G_debug(3, "area = %d", area);
+ G_percent(area, nareas, 3);
+
+ /* get outer ring (area) geometry */
+ Vect_get_area_points(In, area, Points);
+
+ /* get area category */
+ cat = Vect_get_area_cat(In, area, field);
+ if (cat < 0) {
+ G_warning(_("No category defined for area %d. "
+ "Area not exported."),
+ area);
+ continue;
+ }
+ G_debug(3, " -> cat %d", cat);
+ Vect_reset_cats(Cats);
+ Vect_cat_set(Cats, field, cat);
+
+ /* get inner rings (isles) geometry */
+ nisles = Vect_get_area_num_isles(In, area);
+ if (nisles > nisles_alloc) {
+ /* reallocate space for isles */
+ IPoints = (struct line_pnts **) G_realloc(IPoints,
+ nisles *
+ sizeof(struct line_pnts *));
+ for (i = nisles_alloc; i < nisles; i++)
+ IPoints[i] = Vect_new_line_struct();
+ nisles_alloc = nisles;
+ }
+ G_debug(3, " -> nisles=%d", nisles);
+ for (i = 0; i < nisles; i++) {
+ isle = Vect_get_area_isle(In, area, i);
+ Vect_get_isle_points(In, isle, IPoints[i]);
+ }
+
+ if (ogr)
+ Vect_write_line(Out, GV_BOUNDARY, Points, Cats);
+ else
+ V2_write_area_pg(Out, Points, Cats,
+ (const struct line_pnts **) IPoints, nisles);
+ }
+
+ /* free allocated space for isles */
+ for (i = 0; i < nisles_alloc; i++)
+ Vect_destroy_line_struct(IPoints[i]);
+
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+
+ return nareas;
+}
+
+/*!
+ \brief Copy attribute tables linked to vector map.
+
+ Copy all attribute tables linked to the vector map if
+ <em>field</em> is 0, or selected attribute table defined by given
+ field if <em>field</em> > 0.
+
+ Notice, that if input vector map has no tables defined, it will
+ copy nothing and return 0 (success).
+
+ \param In input vector map
+ \param[out] Out output vector map
+ \param field layer number (0 for all tables linked to the vector map)
+
+ \return 0 on success
+ \return -1 on error
+ */
+int Vect_copy_tables(const struct Map_info *In, struct Map_info *Out,
+ int field)
+{
+ int i, n, ret, type;
+ struct field_info *Fi, *Fin;
+ dbDriver *driver;
+
+ n = Vect_get_num_dblinks(In);
+
+ G_debug(2, "Vect_copy_tables(): copying %d tables", n);
+
+ type = GV_1TABLE;
+ if (n > 1)
+ type = GV_MTABLE;
+
+ for (i = 0; i < n; i++) {
+ Fi = Vect_get_dblink(In, i);
+ if (Fi == NULL) {
+ G_warning(_("Database connection not defined for layer %d"),
+ In->dblnk->field[i].number);
+ return -1;
+ }
+ if (field > 0 && Fi->number != field)
+ continue;
+
+ Fin = Vect_default_field_info(Out, Fi->number, Fi->name, type);
+ G_debug(2, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
+ Fi->driver, Fi->database, Fi->table, Fin->driver,
+ Fin->database, Fin->table);
+
+ ret =
+ Vect_map_add_dblink(Out, Fi->number, Fi->name, Fin->table,
+ Fi->key, Fin->database, Fin->driver);
+ if (ret == -1) {
+ G_warning(_("Unable to add database link for vector map <%s>"),
+ Out->name);
+ return -1;
+ }
+
+ ret = db_copy_table(Fi->driver, Fi->database, Fi->table,
+ Fin->driver, Vect_subst_var(Fin->database, Out),
+ Fin->table);
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to copy table <%s>"), Fin->table);
+ return -1;
+ }
+
+ driver =
+ db_start_driver_open_database(Fin->driver,
+ Vect_subst_var(Fin->database, Out));
+ if (driver == NULL) {
+ G_warning(_("Unable to open database <%s> by driver <%s>"),
+ Fin->database, Fin->driver);
+ }
+ else {
+ if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK)
+ G_warning(_("Unable to create index for table <%s>, key <%s>"),
+ Fin->table, Fin->key);
+
+ db_close_database_shutdown_driver(driver);
+ }
+ }
+
+ return 0;
+}
+
+/*!
+ \brief Copy attribute table linked to vector map based on type.
+
+ \param In input vector map
+ \param[out] Out output vector map
+ \param field_in input layer number
+ \param field_out output layer number
+ \param field_name layer name
+ \param type feature type
+
+ \return 0 on success
+ \return -1 on error
+ */
+int Vect_copy_table(const struct Map_info *In, struct Map_info *Out, int field_in,
+ int field_out, const char *field_name, int type)
+{
+ return Vect_copy_table_by_cats(In, Out, field_in, field_out, field_name,
+ type, NULL, 0);
+}
+
+/*!
+ \brief Copy attribute table linked to vector map based on category
+ numbers.
+
+ \param In input vector map
+ \param[out] Out output vector map
+ \param field_in input layer number
+ \param field_out output layer number
+ \param field_name layer name
+ \param type feature type
+ \param cats pointer to array of cats or NULL
+ \param ncats number of cats in 'cats'
+
+ \return 0 on success
+ \return -1 on error
+ */
+int Vect_copy_table_by_cats(const struct Map_info *In, struct Map_info *Out,
+ int field_in, int field_out, const char *field_name,
+ int type, int *cats, int ncats)
+{
+ int ret;
+ struct field_info *Fi, *Fin;
+ const char *name, *key;
+
+ G_debug(2, "Vect_copy_table(): field_in = %d field_out = %d", field_in,
+ field_out);
+
+ Fi = Vect_get_field(In, field_in);
+ if (Fi == NULL) {
+ G_warning(_("Database connection not defined for layer %d"),
+ field_in);
+ return -1;
+ }
+
+ if (field_name != NULL)
+ name = field_name;
+ else
+ name = Fi->name;
+
+ Fin = Vect_default_field_info(Out, field_out, name, type);
+ G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
+ Fi->driver, Fi->database, Fi->table, Fin->driver, Fin->database,
+ Fin->table);
+
+ ret =
+ Vect_map_add_dblink(Out, Fin->number, Fin->name, Fin->table, Fi->key,
+ Fin->database, Fin->driver);
+ if (ret == -1) {
+ G_warning(_("Unable to add database link for vector map <%s>"),
+ Out->name);
+ return -1;
+ }
+
+ if (cats)
+ key = Fi->key;
+ else
+ key = NULL;
+
+ ret = db_copy_table_by_ints(Fi->driver, Fi->database, Fi->table,
+ Fin->driver, Vect_subst_var(Fin->database,
+ Out), Fin->table,
+ key, cats, ncats);
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to copy table <%s>"), Fin->table);
+ return -1;
+ }
+
+ return 0;
+}
Property changes on: grass/trunk/lib/vector/Vlib/copy.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass/trunk/lib/vector/Vlib/field.c
===================================================================
--- grass/trunk/lib/vector/Vlib/field.c 2012-08-07 13:33:16 UTC (rev 52577)
+++ grass/trunk/lib/vector/Vlib/field.c 2012-08-07 14:24:40 UTC (rev 52578)
@@ -161,7 +161,7 @@
\param In pointer to Map_info structure (input)
\param Out pointer to Map_info structure (output)
- \param first_only copy only first link
+ \param first_only TRUE to copy only first link otherwise all DB links are copied
*/
void Vect_copy_map_dblinks(const struct Map_info *In, struct Map_info *Out,
int first_only)
Modified: grass/trunk/lib/vector/Vlib/map.c
===================================================================
--- grass/trunk/lib/vector/Vlib/map.c 2012-08-07 13:33:16 UTC (rev 52577)
+++ grass/trunk/lib/vector/Vlib/map.c 2012-08-07 14:24:40 UTC (rev 52578)
@@ -1,19 +1,18 @@
/*!
- * \file lib/vector/Vlib/map.c
- *
- * \brief Vector library - Manipulate with vector map
- *
- * Higher level functions for reading/writing/manipulating vectors.
- *
- * (C) 2001-2009 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public License
- * (>=v2). Read the file COPYING that comes with GRASS for details.
- *
- * \author Original author CERL, probably Dave Gerdes or Mike
- * Higgins.
- * \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
- */
+ \file lib/vector/Vlib/map.c
+
+ \brief Vector library - Manipulate vector map (copy, rename, delete)
+
+ Higher level functions for reading/writing/manipulating vectors.
+
+ (C) 2001-2009, 2012 by the GRASS Development Team
+
+ This program is free software under the GNU General Public License
+ (>=v2). Read the file COPYING that comes with GRASS for details.
+
+ \author Original author CERL, probably Dave Gerdes or Mike Higgins.
+ \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
+*/
#include <stdlib.h>
#include <stdio.h>
@@ -23,175 +22,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+
#include <grass/glocale.h>
#include <grass/vector.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
/*!
- \brief Copy all alive vector features of opened vector map to
- another opened vector map
-
- \param In input vector map
- \param[out] Out output vector map
-
- \return 0 on success
- \return 1 on error
- */
-int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
-{
- return Vect_copy_map_lines_field(In, -1, Out);
-}
-
-/*!
- \brief Copy all alive vector features from given layer of opened
- vector map to another opened vector map
-
- Note: Try to copy on level 2 otherwise level 1 is used.
-
- \param In input vector map
- \param field layer number (-1 for all layers)
- \param[out] Out output vector map
-
- \return 0 on success
- \return 1 on error
- */
-int Vect_copy_map_lines_field(struct Map_info *In, int field,
- struct Map_info *Out)
-{
- int i, type, nlines, ret, left, rite, centroid, ogr;
- struct line_pnts *Points, *CPoints;
- struct line_cats *Cats, *CCats;
-
- Points = Vect_new_line_struct();
- CPoints = Vect_new_line_struct();
- Cats = Vect_new_cats_struct();
- CCats = Vect_new_cats_struct();
-
- if (Vect_level(In) < 1)
- G_fatal_error("Vect_copy_map_lines(): %s",
- _("input vector map is not open"));
-
- ogr = Vect_maptype(Out) == GV_FORMAT_OGR_DIRECT;
- ret = 0;
- /* Note: sometimes is important to copy on level 2 (pseudotopo centroids)
- * and sometimes on level 1 if build take too long time */
- if (Vect_level(In) >= 2) {
- nlines = Vect_get_num_lines(In);
- for (i = 1; i <= nlines; i++) {
- if (!Vect_line_alive(In, i))
- continue;
-
- type = Vect_read_line(In, Points, Cats, i);
- if (type == -1) {
- G_warning(_("Unable to read vector map <%s>"),
- Vect_get_full_name(In));
- ret = 1;
- break;
- }
- if (type == 0)
- continue; /* dead line */
-
- if (ogr && (type == GV_CENTROID || type == GV_BOUNDARY))
- /* OGR layers: centroids are stored in topo */
- /* polygon defined by areas (topo required) */
- continue;
-
- /* don't skips boundaries if field != -1 */
- if (field != -1) {
- if (type & GV_BOUNDARY) {
- if (Vect_cat_get(Cats, field, NULL) == 0) {
- int skip_bndry = 1;
-
- Vect_get_line_areas(In, i, &left, &rite);
- if (left < 0)
- left = Vect_get_isle_area(In, abs(left));
- if (left > 0) {
- if ((centroid =
- Vect_get_area_centroid(In, left)) > 0) {
- Vect_read_line(In, CPoints, CCats, centroid);
- if (Vect_cat_get(CCats, field, NULL) != 0)
- skip_bndry = 0;
- }
- }
- if (skip_bndry) {
- if (rite < 0)
- rite = Vect_get_isle_area(In, abs(rite));
- if (rite > 0) {
- if ((centroid =
- Vect_get_area_centroid(In, rite)) > 0) {
- Vect_read_line(In, CPoints, CCats,
- centroid);
- if (Vect_cat_get(CCats, field, NULL) != 0)
- skip_bndry = 0;
- }
- }
- }
- if (skip_bndry)
- continue;
- }
- }
- else if (Vect_cat_get(Cats, field, NULL) == 0)
- continue; /* different layer */
- }
-
- Vect_write_line(Out, type, Points, Cats);
- }
-
- if (ogr) {
- int area, nareas;
- /* copy areas/polygons */
- nareas = Vect_get_num_areas(In);
- for (area = 1; area <= nareas; area++) {
- G_debug(3, "area = %d", area);
- Vect_get_area_points(In, area, Points);
- centroid = Vect_get_area_centroid(In, area);
- if (centroid > 0)
- Vect_read_line(In, NULL, CCats, centroid);
- else
- Vect_reset_cats(CCats);
- Vect_write_line(Out, GV_BOUNDARY, Points, CCats);
- }
- }
- }
- else {
- /* Level 1 */
- if (ogr)
- G_warning(_("Topology not available. Polygons will be skipped."));
-
- Vect_rewind(In);
- while (TRUE) {
- type = Vect_read_next_line(In, Points, Cats);
- if (type == -1) {
- G_warning(_("Unable to read vector map <%s>"),
- Vect_get_full_name(In));
- ret = 1;
- break;
- }
- else if (type == -2) { /* EOF */
- break;
- }
- else if (type == 0) { /* dead line */
- continue;
- }
-
- /* don't skip boundaries if field != -1 */
- if (field != -1 && !(type & GV_BOUNDARY) &&
- Vect_cat_get(Cats, field, NULL) == 0)
- continue; /* different layer */
-
- Vect_write_line(Out, type, Points, Cats);
- }
- }
- Vect_destroy_line_struct(Points);
- Vect_destroy_line_struct(CPoints);
- Vect_destroy_cats_struct(Cats);
- Vect_destroy_cats_struct(CCats);
-
- return ret;
-}
-
-/*
\brief Copy file
\param src source file
@@ -208,19 +45,19 @@
int len, len2;
if ((fd = open(src, O_RDONLY)) < 0)
- return 1;
+ return 1;
/* if((fd2 = open(dst, O_CREAT|O_TRUNC|O_WRONLY)) < 0) { */
if ((f2 = fopen(dst, "w")) == NULL) {
- close(fd);
- return 1;
+ close(fd);
+ return 1;
}
fd2 = fileno(f2);
while ((len = read(fd, buf, 1024)) > 0) {
- while (len && (len2 = write(fd2, buf, len)) >= 0)
- len -= len2;
+ while (len && (len2 = write(fd2, buf, len)) >= 0)
+ len -= len2;
}
close(fd);
@@ -228,19 +65,19 @@
fclose(f2);
if (len == -1 || len2 == -1)
- return 1;
+ return 1;
return 0;
}
/*!
- \brief Copy a map including attribute tables
+ \brief Copy vector map including attribute tables
- Old vector is deleted
+ Note: Output vector map is overwritten if exists!
- \param in input vector map name
- \param mapset mapset name
- \param out output vector map name
+ \param in name if vector map to be copied
+ \param mapset mapset name where the input map is located
+ \param out name for output vector map (new map is created in current mapset)
\return -1 error
\return 0 success
@@ -252,9 +89,9 @@
struct field_info *Fi, *Fin;
char old_path[GPATH_MAX], new_path[GPATH_MAX], buf[GPATH_MAX];
const char *files[] = { GV_FRMT_ELEMENT, GV_COOR_ELEMENT,
- GV_HEAD_ELEMENT, GV_HIST_ELEMENT,
- GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
- NULL
+ GV_HEAD_ELEMENT, GV_HIST_ELEMENT,
+ GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
+ NULL
};
const char *inmapset;
char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
@@ -264,29 +101,29 @@
G_debug(2, "Copy vector '%s' in '%s' to '%s'", in, mapset, out);
/* check for [A-Za-z][A-Za-z0-9_]* in name */
if (Vect_legal_filename(out) < 0)
- G_fatal_error(_("Vector map name is not SQL compliant"));
+ G_fatal_error(_("Vector map name is not SQL compliant"));
inmapset = G_find_vector2(in, mapset);
if (!inmapset) {
- G_warning(_("Unable to find vector map <%s> in <%s>"), in, mapset);
- return -1;
+ G_warning(_("Unable to find vector map <%s> in <%s>"), in, mapset);
+ return -1;
}
mapset = inmapset;
/* remove mapset from fully qualified name, confuses G_file_name() */
if (G_name_is_fully_qualified(in, xname, xmapset)) {
- in = xname;
+ in = xname;
}
/* Delete old vector if it exists */
if (G_find_vector2(out, G_mapset())) {
- G_warning(_("Vector map <%s> already exists and will be overwritten"),
- out);
- ret = Vect_delete(out);
- if (ret != 0) {
- G_warning(_("Unable to delete vector map <%s>"), out);
- return -1;
- }
+ G_warning(_("Vector map <%s> already exists and will be overwritten"),
+ out);
+ ret = Vect_delete(out);
+ if (ret != 0) {
+ G_warning(_("Unable to delete vector map <%s>"), out);
+ return -1;
+ }
}
/* Copy the directory */
@@ -296,19 +133,19 @@
i = 0;
while (files[i]) {
- sprintf(buf, "%s/%s", in, files[i]);
- G_file_name(old_path, GV_DIRECTORY, buf, mapset);
- sprintf(buf, "%s/%s", out, files[i]);
- G_file_name(new_path, GV_DIRECTORY, buf, G_mapset());
+ sprintf(buf, "%s/%s", in, files[i]);
+ G_file_name(old_path, GV_DIRECTORY, buf, mapset);
+ sprintf(buf, "%s/%s", out, files[i]);
+ G_file_name(new_path, GV_DIRECTORY, buf, G_mapset());
- if (access(old_path, F_OK) == 0) { /* file exists? */
- G_debug(2, "copy %s to %s", old_path, new_path);
- if (copy_file(old_path, new_path)) {
- G_warning(_("Unable to copy vector map <%s> to <%s>"),
- old_path, new_path);
- }
- }
- i++;
+ if (access(old_path, F_OK) == 0) { /* file exists? */
+ G_debug(2, "copy %s to %s", old_path, new_path);
+ if (copy_file(old_path, new_path)) {
+ G_warning(_("Unable to copy vector map <%s> to <%s>"),
+ old_path, new_path);
+ }
+ }
+ i++;
}
G_file_name(old_path, GV_DIRECTORY, in, mapset);
@@ -318,9 +155,9 @@
Vect_set_open_level(1);
Vect_open_old_head(&In, in, mapset);
- if (In.format != GV_FORMAT_NATIVE) { /* Done */
- Vect_close(&In);
- return 0;
+ if (In.format != GV_FORMAT_NATIVE) { /* Done */
+ Vect_close(&In);
+ return 0;
}
/* Open output */
@@ -331,49 +168,49 @@
n = Vect_get_num_dblinks(&In);
type = GV_1TABLE;
if (n > 1)
- type = GV_MTABLE;
+ type = GV_MTABLE;
for (i = 0; i < n; i++) {
- Fi = Vect_get_dblink(&In, i);
- if (Fi == NULL) {
- G_warning(_("Database connection not defined for layer %d"),
- In.dblnk->field[i].number);
- Vect_close(&In);
- Vect_close(&Out);
- return -1;
- }
- Fin = Vect_default_field_info(&Out, Fi->number, Fi->name, type);
- G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
- Fi->driver, Fi->database, Fi->table, Fin->driver,
- Fin->database, Fin->table);
+ Fi = Vect_get_dblink(&In, i);
+ if (Fi == NULL) {
+ G_warning(_("Database connection not defined for layer %d"),
+ In.dblnk->field[i].number);
+ Vect_close(&In);
+ Vect_close(&Out);
+ return -1;
+ }
+ Fin = Vect_default_field_info(&Out, Fi->number, Fi->name, type);
+ G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
+ Fi->driver, Fi->database, Fi->table, Fin->driver,
+ Fin->database, Fin->table);
- Vect_map_add_dblink(&Out, Fi->number, Fi->name, Fin->table, Fi->key,
- Fin->database, Fin->driver);
+ Vect_map_add_dblink(&Out, Fi->number, Fi->name, Fin->table, Fi->key,
+ Fin->database, Fin->driver);
- ret = db_copy_table(Fi->driver, Fi->database, Fi->table,
- Fin->driver, Vect_subst_var(Fin->database, &Out),
- Fin->table);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to copy table <%s>"), Fin->table);
- Vect_close(&In);
- Vect_close(&Out);
- return -1;
- }
+ ret = db_copy_table(Fi->driver, Fi->database, Fi->table,
+ Fin->driver, Vect_subst_var(Fin->database, &Out),
+ Fin->table);
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to copy table <%s>"), Fin->table);
+ Vect_close(&In);
+ Vect_close(&Out);
+ return -1;
+ }
- driver =
- db_start_driver_open_database(Fin->driver,
- Vect_subst_var(Fin->database,
- &Out));
- if (driver == NULL) {
- G_warning(_("Unable to open database <%s> by driver <%s>"),
- Fin->database, Fin->driver);
- }
- else {
- if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK)
- G_warning(_("Unable to create index for table <%s>, key <%s>"),
- Fi->table, Fi->key);
+ driver =
+ db_start_driver_open_database(Fin->driver,
+ Vect_subst_var(Fin->database,
+ &Out));
+ if (driver == NULL) {
+ G_warning(_("Unable to open database <%s> by driver <%s>"),
+ Fin->database, Fin->driver);
+ }
+ else {
+ if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK)
+ G_warning(_("Unable to create index for table <%s>, key <%s>"),
+ Fi->table, Fi->key);
- db_close_database_shutdown_driver(driver);
- }
+ db_close_database_shutdown_driver(driver);
+ }
}
Vect_close(&In);
@@ -383,16 +220,17 @@
}
/*!
- \brief Rename a map.
+ \brief Rename existing vector map (in the current mapset).
Attribute tables are created in the same database where input tables were stored.
- The original format (native/OGR) is used.
- Old map ('out') is deleted!!!
+ The origial format (native/OGR) is used.
- \param in input vector map name
- \param out output vector map name
+ Note: Output vector map is overwritten if exists!
+ \param in name of vector map to be renamed
+ \param out name for output vector map
+
\return -1 error
\return 0 success
*/
@@ -408,111 +246,111 @@
G_debug(2, "Rename vector '%s' to '%s'", in, out);
/* check for [A-Za-z][A-Za-z0-9_]* in name */
if (Vect_legal_filename(out) < 0)
- G_fatal_error(_("Vector map name is not SQL compliant"));
+ G_fatal_error(_("Vector map name is not SQL compliant"));
/* Delete old vector if it exists */
if (G_find_vector2(out, G_mapset())) {
- G_warning(_("Vector map <%s> already exists and will be overwritten"),
- out);
- Vect_delete(out);
+ G_warning(_("Vector map <%s> already exists and will be overwritten"),
+ out);
+ Vect_delete(out);
}
/* remove mapset from fully qualified name */
if (G_name_is_fully_qualified(in, xname, xmapset)) {
- in = xname;
+ in = xname;
}
/* Move the directory */
ret = G_rename(GV_DIRECTORY, in, out);
if (ret == 0) {
- G_warning(_("Vector map <%s> not found"), in);
- return -1;
+ G_warning(_("Vector map <%s> not found"), in);
+ return -1;
}
else if (ret == -1) {
- G_warning(_("Unable to copy vector map <%s> to <%s>"), in, out);
- return -1;
+ G_warning(_("Unable to copy vector map <%s> to <%s>"), in, out);
+ return -1;
}
/* Rename all tables if the format is native */
Vect_set_open_level(1);
Vect_open_update_head(&Map, out, G_mapset());
- if (Map.format != GV_FORMAT_NATIVE) { /* Done */
- Vect_close(&Map);
- return 0;
+ if (Map.format != GV_FORMAT_NATIVE) { /* Done */
+ Vect_close(&Map);
+ return 0;
}
/* Copy tables */
n = Vect_get_num_dblinks(&Map);
type = GV_1TABLE;
if (n > 1)
- type = GV_MTABLE;
+ type = GV_MTABLE;
/* Make the list of fields */
fields = (int *)G_malloc(n * sizeof(int));
for (i = 0; i < n; i++) {
- Fin = Vect_get_dblink(&Map, i);
- fields[i] = Fin->number;
+ Fin = Vect_get_dblink(&Map, i);
+ fields[i] = Fin->number;
}
for (i = 0; i < n; i++) {
- G_debug(3, "field[%d] = %d", i, fields[i]);
+ G_debug(3, "field[%d] = %d", i, fields[i]);
- Fin = Vect_get_field(&Map, fields[i]);
- if (Fin == NULL) {
- G_warning(_("Database connection not defined for layer %d"),
- fields[i]);
- Vect_close(&Map);
- return -1;
- }
+ Fin = Vect_get_field(&Map, fields[i]);
+ if (Fin == NULL) {
+ G_warning(_("Database connection not defined for layer %d"),
+ fields[i]);
+ Vect_close(&Map);
+ return -1;
+ }
- Fout = Vect_default_field_info(&Map, Fin->number, Fin->name, type);
- G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
- Fin->driver, Fin->database, Fin->table, Fout->driver,
- Fout->database, Fout->table);
+ Fout = Vect_default_field_info(&Map, Fin->number, Fin->name, type);
+ G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
+ Fin->driver, Fin->database, Fin->table, Fout->driver,
+ Fout->database, Fout->table);
- /* TODO: db_rename_table instead of db_copy_table */
- ret = db_copy_table(Fin->driver, Fin->database, Fin->table,
- Fout->driver, Vect_subst_var(Fout->database,
- &Map), Fout->table);
+ /* TODO: db_rename_table instead of db_copy_table */
+ ret = db_copy_table(Fin->driver, Fin->database, Fin->table,
+ Fout->driver, Vect_subst_var(Fout->database,
+ &Map), Fout->table);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to copy table <%s>"), Fin->table);
- Vect_close(&Map);
- return -1;
- }
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to copy table <%s>"), Fin->table);
+ Vect_close(&Map);
+ return -1;
+ }
- /* Change the link */
- Vect_map_del_dblink(&Map, Fin->number);
+ /* Change the link */
+ Vect_map_del_dblink(&Map, Fin->number);
- Vect_map_add_dblink(&Map, Fout->number, Fout->name, Fout->table,
- Fin->key, Fout->database, Fout->driver);
+ Vect_map_add_dblink(&Map, Fout->number, Fout->name, Fout->table,
+ Fin->key, Fout->database, Fout->driver);
- /* Delete old table */
- ret = db_delete_table(Fin->driver, Fin->database, Fin->table);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to delete table <%s>"), Fin->table);
- Vect_close(&Map);
- return -1;
- }
+ /* Delete old table */
+ ret = db_delete_table(Fin->driver, Fin->database, Fin->table);
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to delete table <%s>"), Fin->table);
+ Vect_close(&Map);
+ return -1;
+ }
- driver =
- db_start_driver_open_database(Fout->driver,
- Vect_subst_var(Fout->database,
- &Map));
- if (driver == NULL) {
- G_warning(_("Unable to open database <%s> by driver <%s>"),
- Fout->database, Fout->driver);
- }
- else {
- if (db_create_index2(driver, Fout->table, Fin->key) != DB_OK)
- G_warning(_("Unable to create index for table <%s>, key <%s>"),
- Fout->table, Fout->key);
+ driver =
+ db_start_driver_open_database(Fout->driver,
+ Vect_subst_var(Fout->database,
+ &Map));
+ if (driver == NULL) {
+ G_warning(_("Unable to open database <%s> by driver <%s>"),
+ Fout->database, Fout->driver);
+ }
+ else {
+ if (db_create_index2(driver, Fout->table, Fin->key) != DB_OK)
+ G_warning(_("Unable to create index for table <%s>, key <%s>"),
+ Fout->table, Fout->key);
- db_close_database_shutdown_driver(driver);
- }
+ db_close_database_shutdown_driver(driver);
+ }
}
Vect_close(&Map);
@@ -524,7 +362,9 @@
/*!
\brief Delete vector map including attribute tables
- \param map pointer to Map_info structure
+ Vector map must be located in current mapset.
+
+ \param map name of vector map to be delete
\return -1 error
\return 0 success
@@ -544,69 +384,69 @@
/* remove mapset from fully qualified name */
if (G_name_is_fully_qualified(map, xname, xmapset)) {
- map = xname;
+ map = xname;
}
if (map == NULL || strlen(map) == 0) {
- G_warning(_("Invalid vector map name <%s>"), map ? map : "null");
- return -1;
+ G_warning(_("Invalid vector map name <%s>"), map ? map : "null");
+ return -1;
}
sprintf(buf, "%s/%s/%s/%s/%s/%s", G_gisdbase(), G_location(),
- G_mapset(), GV_DIRECTORY, map, GV_DBLN_ELEMENT);
+ G_mapset(), GV_DIRECTORY, map, GV_DBLN_ELEMENT);
G_debug(1, "dbln file: %s", buf);
if (access(buf, F_OK) == 0) {
- /* Open input */
- Vect_set_open_level(1); /* Topo not needed */
- ret = Vect_open_old_head(&Map, map, G_mapset());
- if (ret < 1) {
- G_warning(_("Unable to open header file for vector map <%s>"),
- map);
- return -1;
- }
+ /* Open input */
+ Vect_set_open_level(1); /* Topo not needed */
+ ret = Vect_open_old_head(&Map, map, G_mapset());
+ if (ret < 1) {
+ G_warning(_("Unable to open header file for vector map <%s>"),
+ map);
+ return -1;
+ }
- /* Delete all tables, NOT external (OGR) */
- if (Map.format == GV_FORMAT_NATIVE) {
+ /* Delete all tables, NOT external (OGR) */
+ if (Map.format == GV_FORMAT_NATIVE) {
- n = Vect_get_num_dblinks(&Map);
- for (i = 0; i < n; i++) {
- Fi = Vect_get_dblink(&Map, i);
- if (Fi == NULL) {
- G_warning(_("Database connection not defined for layer %d"),
- Map.dblnk->field[i].number);
- Vect_close(&Map);
- return -1;
- }
- G_debug(3, "Delete drv:db:table '%s:%s:%s'", Fi->driver,
- Fi->database, Fi->table);
+ n = Vect_get_num_dblinks(&Map);
+ for (i = 0; i < n; i++) {
+ Fi = Vect_get_dblink(&Map, i);
+ if (Fi == NULL) {
+ G_warning(_("Database connection not defined for layer %d"),
+ Map.dblnk->field[i].number);
+ Vect_close(&Map);
+ return -1;
+ }
+ G_debug(3, "Delete drv:db:table '%s:%s:%s'", Fi->driver,
+ Fi->database, Fi->table);
- ret = db_table_exists(Fi->driver, Fi->database, Fi->table);
- if (ret == -1) {
- G_warning(_("Unable to find table <%s> linked to vector map <%s>"),
- Fi->table, map);
- Vect_close(&Map);
- return -1;
- }
+ ret = db_table_exists(Fi->driver, Fi->database, Fi->table);
+ if (ret == -1) {
+ G_warning(_("Unable to find table <%s> linked to vector map <%s>"),
+ Fi->table, map);
+ Vect_close(&Map);
+ return -1;
+ }
- if (ret == 1) {
- ret =
- db_delete_table(Fi->driver, Fi->database, Fi->table);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to delete table <%s>"),
- Fi->table);
- Vect_close(&Map);
- return -1;
- }
- }
- else {
- G_warning(_("Table <%s> linked to vector map <%s> does not exist"),
- Fi->table, map);
- }
- }
- }
- Vect_close(&Map);
+ if (ret == 1) {
+ ret =
+ db_delete_table(Fi->driver, Fi->database, Fi->table);
+ if (ret == DB_FAILED) {
+ G_warning(_("Unable to delete table <%s>"),
+ Fi->table);
+ Vect_close(&Map);
+ return -1;
+ }
+ }
+ else {
+ G_warning(_("Table <%s> linked to vector map <%s> does not exist"),
+ Fi->table, map);
+ }
+ }
+ }
+ Vect_close(&Map);
}
/* Delete all files from vector/name directory */
@@ -614,24 +454,24 @@
G_debug(3, "opendir '%s'", buf);
dir = opendir(buf);
if (dir == NULL) {
- G_warning(_("Unable to open directory '%s'"), buf);
- return -1;
+ G_warning(_("Unable to open directory '%s'"), buf);
+ return -1;
}
while ((ent = readdir(dir))) {
- G_debug(3, "file = '%s'", ent->d_name);
- if ((strcmp(ent->d_name, ".") == 0) ||
- (strcmp(ent->d_name, "..") == 0))
- continue;
- sprintf(buf, "%s/%s/vector/%s/%s", G_location_path(), G_mapset(), map,
- ent->d_name);
- G_debug(3, "delete file '%s'", buf);
- ret = unlink(buf);
- if (ret == -1) {
- G_warning(_("Unable to delete file '%s'"), buf);
- closedir(dir);
- return -1;
- }
+ G_debug(3, "file = '%s'", ent->d_name);
+ if ((strcmp(ent->d_name, ".") == 0) ||
+ (strcmp(ent->d_name, "..") == 0))
+ continue;
+ sprintf(buf, "%s/%s/vector/%s/%s", G_location_path(), G_mapset(), map,
+ ent->d_name);
+ G_debug(3, "delete file '%s'", buf);
+ ret = unlink(buf);
+ if (ret == -1) {
+ G_warning(_("Unable to delete file '%s'"), buf);
+ closedir(dir);
+ return -1;
+ }
}
closedir(dir);
@@ -645,200 +485,27 @@
ret = rename(buf, tmp);
if (ret == -1) {
- G_warning(_("Unable to rename directory '%s' to '%s'"), buf, tmp);
- return -1;
+ G_warning(_("Unable to rename directory '%s' to '%s'"), buf, tmp);
+ return -1;
}
G_debug(3, "remove directory '%s'", tmp);
/* Warning: remove() fails on Windows */
ret = rmdir(tmp);
if (ret == -1) {
- G_warning(_("Unable to remove directory '%s'"), tmp);
- return -1;
+ G_warning(_("Unable to remove directory '%s'"), tmp);
+ return -1;
}
return 0;
}
/*!
- \brief Copy tables linked to vector map.
-
- All if field = 0, or table defined by given field if field > 0
- Notice, that if input map has no tables defined, it will copy
- nothing and return 0 (success).
-
- \param In input vector map
- \param[out] Out output vector map
- \param field layer number
-
- \return 0 on success
- \return -1 on error
- */
-int Vect_copy_tables(const struct Map_info *In, struct Map_info *Out,
- int field)
-{
- int i, n, ret, type;
- struct field_info *Fi, *Fin;
- dbDriver *driver;
-
- n = Vect_get_num_dblinks(In);
-
- G_debug(2, "Vect_copy_tables(): copying %d tables", n);
-
- type = GV_1TABLE;
- if (n > 1)
- type = GV_MTABLE;
-
- for (i = 0; i < n; i++) {
- Fi = Vect_get_dblink(In, i);
- if (Fi == NULL) {
- G_warning(_("Database connection not defined for layer %d"),
- In->dblnk->field[i].number);
- return -1;
- }
- if (field > 0 && Fi->number != field)
- continue;
-
- Fin = Vect_default_field_info(Out, Fi->number, Fi->name, type);
- G_debug(2, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
- Fi->driver, Fi->database, Fi->table, Fin->driver,
- Fin->database, Fin->table);
-
- ret =
- Vect_map_add_dblink(Out, Fi->number, Fi->name, Fin->table,
- Fi->key, Fin->database, Fin->driver);
- if (ret == -1) {
- G_warning(_("Unable to add database link for vector map <%s>"),
- Out->name);
- return -1;
- }
-
- ret = db_copy_table(Fi->driver, Fi->database, Fi->table,
- Fin->driver, Vect_subst_var(Fin->database, Out),
- Fin->table);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to copy table <%s>"), Fin->table);
- return -1;
- }
-
- driver =
- db_start_driver_open_database(Fin->driver,
- Vect_subst_var(Fin->database, Out));
- if (driver == NULL) {
- G_warning(_("Unable to open database <%s> by driver <%s>"),
- Fin->database, Fin->driver);
- }
- else {
- if (db_create_index2(driver, Fin->table, Fi->key) != DB_OK)
- G_warning(_("Unable to create index for table <%s>, key <%s>"),
- Fin->table, Fin->key);
-
- db_close_database_shutdown_driver(driver);
- }
- }
-
- return 0;
-}
-
-/*!
- \brief Copy table linked to vector map based on type.
-
- \param In input vector map
- \param[out] Out output vector map
- \param field_in input layer number
- \param field_out output layer number
- \param field_name layer name
- \param type feature type
-
- \return 0 on success
- \return -1 on error
- */
-int
-Vect_copy_table(const struct Map_info *In, struct Map_info *Out, int field_in,
- int field_out, const char *field_name, int type)
-{
- return Vect_copy_table_by_cats(In, Out, field_in, field_out, field_name,
- type, NULL, 0);
-}
-
-/*!
- \brief Copy table linked to vector map based on category numbers.
-
- \param In input vector map
- \param[out] Out output vector map
- \param field_in input layer number
- \param field_out output layer number
- \param field_name layer name
- \param type feature type
- \param cats pointer to array of cats or NULL
- \param ncats number of cats in 'cats'
-
- \return 0 on success
- \return -1 on error
- */
-int
-Vect_copy_table_by_cats(const struct Map_info *In, struct Map_info *Out,
- int field_in, int field_out, const char *field_name,
- int type, int *cats, int ncats)
-{
- int ret;
- struct field_info *Fi, *Fin;
- const char *name, *key;
-
- G_debug(2, "Vect_copy_table(): field_in = %d field_out = %d", field_in,
- field_out);
-
- Fi = Vect_get_field(In, field_in);
- if (Fi == NULL) {
- G_warning(_("Database connection not defined for layer %d"),
- field_in);
- return -1;
- }
-
- if (field_name != NULL)
- name = field_name;
- else
- name = Fi->name;
-
- Fin = Vect_default_field_info(Out, field_out, name, type);
- G_debug(3, "Copy drv:db:table '%s:%s:%s' to '%s:%s:%s'",
- Fi->driver, Fi->database, Fi->table, Fin->driver, Fin->database,
- Fin->table);
-
- ret =
- Vect_map_add_dblink(Out, Fin->number, Fin->name, Fin->table, Fi->key,
- Fin->database, Fin->driver);
- if (ret == -1) {
- G_warning(_("Unable to add database link for vector map <%s>"),
- Out->name);
- return -1;
- }
-
- if (cats)
- key = Fi->key;
- else
- key = NULL;
-
- ret = db_copy_table_by_ints(Fi->driver, Fi->database, Fi->table,
- Fin->driver, Vect_subst_var(Fin->database,
- Out), Fin->table,
- key, cats, ncats);
- if (ret == DB_FAILED) {
- G_warning(_("Unable to copy table <%s>"), Fin->table);
- return -1;
- }
-
- return 0;
-}
-
-/*!
\brief Set spatial index to be realease when vector is closed.
By default, the memory occupied by spatial index is not released.
\param Map vector map
-
- \return
*/
void Vect_set_release_support(struct Map_info *Map)
{
@@ -846,16 +513,16 @@
}
/*!
- \brief By default, category index is not updated if vector is
- changed, this function sets category index update.
+ \brief Set category index to be updated when vector is changed.
- WARNING: currently only category for elements is updated
- not for areas
+ By default, category index is not updated if vector is changed,
+ this function sets category index update.
- \param Map vector map
+ WARNING: currently only category for elements is updated not for
+ areas
- \return
- */
+ \param Map vector map
+*/
void Vect_set_category_index_update(struct Map_info *Map)
{
Map->plus.update_cidx = TRUE;
More information about the grass-commit
mailing list