[GRASS-SVN] r68111 - grass/branches/releasebranch_7_0/vector/v.select

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 22 13:20:27 PDT 2016


Author: mmetz
Date: 2016-03-22 13:20:27 -0700 (Tue, 22 Mar 2016)
New Revision: 68111

Modified:
   grass/branches/releasebranch_7_0/vector/v.select/main.c
   grass/branches/releasebranch_7_0/vector/v.select/overlap.c
   grass/branches/releasebranch_7_0/vector/v.select/proto.h
   grass/branches/releasebranch_7_0/vector/v.select/select.c
   grass/branches/releasebranch_7_0/vector/v.select/write.c
Log:
v.select: fix reverse selection of areas

Modified: grass/branches/releasebranch_7_0/vector/v.select/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.select/main.c	2016-03-22 20:20:16 UTC (rev 68110)
+++ grass/branches/releasebranch_7_0/vector/v.select/main.c	2016-03-22 20:20:27 UTC (rev 68111)
@@ -33,6 +33,7 @@
     int itype[2], ifield[2];
 
     int *ALines; /* List of lines: 0 do not output, 1 - write to output */
+    int *AAreas; /* List of areas: 0 do not output, 1 - write area boundaries to output */
     int **cats, *ncats, *fields, nfields;
     
     struct GModule *module;
@@ -112,6 +113,9 @@
 
     /* Alloc space for input lines array */
     ALines = (int *)G_calloc(Vect_get_num_lines(&(In[0])) + 1, sizeof(int));
+    AAreas = NULL;
+    if (flag.reverse->answer)
+	AAreas = (int *)G_calloc(Vect_get_num_areas(&(In[0])) + 1, sizeof(int));
 
     /* Read field info */
     IFi = Vect_get_field(&(In[0]), ifield[0]);
@@ -133,13 +137,13 @@
                  &(In[1]), itype[1], ifield[1],
                  flag.cat->answer ? 1 : 0, operator,
                  parm.relate->answer,
-                 ALines, nskipped);
+                 ALines, AAreas, nskipped);
 #else
     select_lines(&(In[0]), itype[0], ifield[0],
                  &(In[1]), itype[1], ifield[1],
                  flag.cat->answer ? 1 : 0, operator,
                  NULL,
-                 ALines, nskipped);
+                 ALines, AAreas, nskipped);
 #endif
     
 #ifdef HAVE_GEOS
@@ -159,7 +163,7 @@
 	Vect_copy_map_dblinks(&(In[0]), &Out, TRUE);
     }
     
-    write_lines(&(In[0]), IFi, ALines,
+    write_lines(&(In[0]), IFi, ALines, AAreas,
 		&Out, flag.table->answer ? 1 : 0, flag.reverse->answer ? 1 : 0,
 		nfields, fields, ncats, cats);
 

Modified: grass/branches/releasebranch_7_0/vector/v.select/overlap.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.select/overlap.c	2016-03-22 20:20:16 UTC (rev 68110)
+++ grass/branches/releasebranch_7_0/vector/v.select/overlap.c	2016-03-22 20:20:27 UTC (rev 68111)
@@ -6,7 +6,7 @@
 #include "proto.h"
 
 /* Add all elements of area A to the list */
-void add_aarea(struct Map_info *In, int aarea, int *ALines)
+void add_aarea(struct Map_info *In, int aarea, int *ALines, int *AAreas)
 {
     int i, j, aline, naisles, aisle, acentroid;
     static struct ilist *BoundList = NULL;
@@ -34,6 +34,8 @@
 	    ALines[aline] = 1;
 	}
     }
+    if (AAreas)
+	AAreas[aarea] = 1;
 }
 
 /* Returns 1 if line1 from Map1 overlaps area2 from Map2,

Modified: grass/branches/releasebranch_7_0/vector/v.select/proto.h
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.select/proto.h	2016-03-22 20:20:16 UTC (rev 68110)
+++ grass/branches/releasebranch_7_0/vector/v.select/proto.h	2016-03-22 20:20:27 UTC (rev 68111)
@@ -38,14 +38,14 @@
 /* select.c */
 void select_lines(struct Map_info *, int, int,
                   struct Map_info *, int, int,
-                  int, int, const char *, int *, int*);
+                  int, int, const char *, int *, int*, int*);
 
 /* overlap.c */
-void add_aarea(struct Map_info *, int, int *);
+void add_aarea(struct Map_info *, int, int *, int *);
 int line_overlap_area(struct line_pnts *, struct Map_info *, int);
 
 /* write.c */
-void write_lines(struct Map_info *, struct field_info *, int *,
+void write_lines(struct Map_info *, struct field_info *, int *, int *,
 		 struct Map_info *, int, int,
 		 int, int *, int *, int **);
 #endif /* PROTO_H */

Modified: grass/branches/releasebranch_7_0/vector/v.select/select.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.select/select.c	2016-03-22 20:20:16 UTC (rev 68110)
+++ grass/branches/releasebranch_7_0/vector/v.select/select.c	2016-03-22 20:20:27 UTC (rev 68111)
@@ -9,7 +9,7 @@
 void select_lines(struct Map_info *aIn, int atype, int afield,
                   struct Map_info *bIn, int btype, int bfield,
                   int cat_flag, int operator, const char *relate,
-                  int *ALines, int* nskipped)
+                  int *ALines, int *AAreas, int* nskipped)
 {
     int i;
     int nalines, aline, ltype;
@@ -211,7 +211,7 @@
 #ifdef HAVE_GEOS
 			if(line_relate_geos(bIn, AGeom,
 					    bline, operator, relate)) {
-			    add_aarea(aIn, aarea, ALines);
+			    add_aarea(aIn, aarea, ALines, AAreas);
 			    break;
 			}
 #endif
@@ -220,7 +220,7 @@
 			Vect_read_line(bIn, BPoints, NULL, bline);
 
 			if (line_overlap_area(BPoints, aIn, aarea)) {
-			    add_aarea(aIn, aarea, ALines);
+			    add_aarea(aIn, aarea, ALines, AAreas);
 			    continue;
 			}
 		    }
@@ -310,7 +310,7 @@
 			}
 		    }
 		    if (found) {
-			add_aarea(aIn, aarea, ALines);
+			add_aarea(aIn, aarea, ALines, AAreas);
 			break;
 		    }
 		}

Modified: grass/branches/releasebranch_7_0/vector/v.select/write.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.select/write.c	2016-03-22 20:20:16 UTC (rev 68110)
+++ grass/branches/releasebranch_7_0/vector/v.select/write.c	2016-03-22 20:20:27 UTC (rev 68111)
@@ -2,6 +2,7 @@
 #include <grass/glocale.h>
 
 void write_lines(struct Map_info *In, struct field_info *IFi, int *ALines,
+                 int *AAreas,
 		 struct Map_info *Out, int table_flag, int reverse_flag,
 		 int nfields, int *fields, int *ncats, int **cats)
 {
@@ -27,11 +28,33 @@
     for (aline = 1; aline <= nalines; aline++) {
 	G_debug(3, "aline = %d ALines[aline] = %d", aline, ALines[aline]);
 	G_percent(aline, nalines, 2);
-	if ((!reverse_flag && !(ALines[aline])) ||
-	    (reverse_flag && ALines[aline]))
+	if ((!reverse_flag && !(ALines[aline])))
 	    continue;
 
 	atype = Vect_read_line(&(In[0]), APoints, ACats, aline);
+
+	if ((reverse_flag && ALines[aline])) {
+	    if (atype == GV_BOUNDARY && AAreas) {
+		int left, right, skipme;
+
+		skipme = 1;
+		Vect_get_line_areas(&(In[0]), aline, &left, &right);
+		if (left < 0)
+		    left = Vect_get_isle_area(&(In[0]), abs(left));
+		if (left > 0 && !AAreas[left])
+		    skipme = 0;
+		if (right < 0)
+		    right = Vect_get_isle_area(&(In[0]), abs(right));
+		if (right > 0 && !AAreas[right])
+		    skipme = 0;
+		if (skipme)
+		    continue;
+	    }
+	    else
+		continue;
+	}
+
+
 	Vect_write_line(Out, atype, APoints, ACats);
 
 	if (!table_flag && (IFi != NULL)) {



More information about the grass-commit mailing list