[GRASS-SVN] r58802 - grass/trunk/vector/v.overlay

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 29 10:09:47 PST 2014


Author: mmetz
Date: 2014-01-29 10:09:47 -0800 (Wed, 29 Jan 2014)
New Revision: 58802

Modified:
   grass/trunk/vector/v.overlay/main.c
Log:
v.overlay: fix copy attributes

Modified: grass/trunk/vector/v.overlay/main.c
===================================================================
--- grass/trunk/vector/v.overlay/main.c	2014-01-29 17:56:29 UTC (rev 58801)
+++ grass/trunk/vector/v.overlay/main.c	2014-01-29 18:09:47 UTC (rev 58802)
@@ -31,6 +31,8 @@
 
 #include "local.h"
 
+void copy_table(struct Map_info *, struct Map_info *, int, int);
+
 int main(int argc, char *argv[])
 {
     int i, j, input, line, nlines, operator;
@@ -190,7 +192,7 @@
 
     /* Create dblinks */
     if (ofield[0] > 0) {
-	Fi = Vect_default_field_info(&Out, ofield[0], NULL, GV_1TABLE);
+	Fi = Vect_default_field_info(&Out, ofield[0], NULL, GV_MTABLE);
     }
 
     db_init_string(&sql);
@@ -578,20 +580,15 @@
 	db_close_database_shutdown_driver(driver);
     }
     if (ofield[0] < 1 && !table_flag->answer) {
-	int otype;
 	
-	if (type[0] == GV_AREA)
-	    otype = GV_CENTROID;
-	else
-	    otype = GV_LINE;
-	
+	/* TODO: copy only valid attributes */
 	/* copy attributes from ainput */
 	if (ofield[1] > 0 && field[0] > 0) {
-	    Vect_copy_table(&In[0], &Out, field[0], ofield[1], NULL, otype);
+	    copy_table(&In[0], &Out, field[0], ofield[1]);
 	}
 	/* copy attributes from binput */
 	if (ofield[2] > 0 && field[1] > 0 && ofield[1] != ofield[2]) {
-	    Vect_copy_table(&In[1], &Out, field[1], ofield[2], NULL, otype);
+	    copy_table(&In[1], &Out, field[1], ofield[2]);
 	}
     }
 
@@ -603,3 +600,18 @@
 
     exit(EXIT_SUCCESS);
 }
+
+void copy_table(struct Map_info *In, struct Map_info *Out, int infield, 
+                int outfield)
+{
+    struct ilist *list;
+    int findex;
+    
+    list = Vect_new_list();
+    findex = Vect_cidx_get_field_index(Out, outfield);
+    
+    Vect_cidx_get_unique_cats_by_index(Out, findex, list);
+    Vect_copy_table_by_cats(In, Out, infield, outfield, NULL, GV_MTABLE, list->value, list->n_values);
+    
+    Vect_destroy_list(list);
+}



More information about the grass-commit mailing list