On 17/11/16 18:06, Moritz Lennert wrote:
On 17/11/16 14:11, Luca Delucchi wrote:
Hi devs,

this morning I got a problem with v.select, I don't understand if is a
bug or what... I repeated the procedure with north carolina dataset

g.region vect=zipcodes -ap

v.mkgrid map=zipcodes_grid box=10000,10000

v.category zipcodes_grid opt=report
Layer/table: 1/zipcodes_grid
type       count        min        max
point          0          0          0
line           0          0          0
boundary       0          0          0
centroid      42          1         42
area           0          0          0
face           0          0          0
kernel         0          0          0
all           42          1         42

v.select ain=zipcodes_grid bin=zipcodes operator=touches
out=zipcodes_grid_final --o
WARNING: Vector map <zipcodes_grid_final> already exists and will be
         overwritten
Processing features...
 100%
Processing areas...
 100%
Writing selected features...
 100%
Writing attributes...
WARNING: Array of values to select from column <cat> is empty

i.e. no features found which is logical, as there are no zipcode areas
that touch a grid area. 'touches' is normally defined as [1]

"a touches b: they have at least one boundary point in common, but no
interior points."

Try with intersects, overlaps, etc.

I agree though that the error message is very unclear. After the "Array
of values ... is empty" it should just stop. After a very rapid look at
main.c of v.select it seems to me that it doesn't check the result of
the selection and just goes on trying to write a new file...

Try the attached patch. Not very elegant and not well tested, but seems to work for me.

Moritz
Index: vector/v.select/main.c
===================================================================
--- vector/v.select/main.c	(révision 69689)
+++ vector/v.select/main.c	(copie de travail)
@@ -29,7 +29,7 @@
 {
     int iopt;
     int operator;
-    int nskipped[2], native;
+    int nskipped[2], native, nfound;
     int itype[2], ifield[2];
 
     int *ALines; /* List of lines: 0 do not output, 1 - write to output */
@@ -133,13 +133,13 @@
     
     /* Select features */
 #ifdef HAVE_GEOS
-    select_lines(&(In[0]), itype[0], ifield[0],
+    nfound = select_lines(&(In[0]), itype[0], ifield[0],
                  &(In[1]), itype[1], ifield[1],
                  flag.cat->answer ? 1 : 0, operator,
                  parm.relate->answer,
                  ALines, AAreas, nskipped);
 #else
-    select_lines(&(In[0]), itype[0], ifield[0],
+    nfound = select_lines(&(In[0]), itype[0], ifield[0],
                  &(In[1]), itype[1], ifield[1],
                  flag.cat->answer ? 1 : 0, operator,
                  NULL,
@@ -150,6 +150,8 @@
     finishGEOS();
 #endif
 
+    if (nfound != 0) {
+
     native = Vect_maptype(&Out) == GV_FORMAT_NATIVE;
 
     nfields = Vect_cidx_get_num_fields(&(In[0]));
@@ -186,6 +188,9 @@
     Vect_close(&Out);
 
     G_done_msg(_("%d features written to output."), Vect_get_num_lines(&Out));
+    } else {
+    G_done_msg(_("No features found !"));
+    }
 
     exit(EXIT_SUCCESS);
 }
Index: vector/v.select/proto.h
===================================================================
--- vector/v.select/proto.h	(révision 69689)
+++ vector/v.select/proto.h	(copie de travail)
@@ -36,7 +36,7 @@
 #endif
 
 /* select.c */
-void select_lines(struct Map_info *, int, int,
+int select_lines(struct Map_info *, int, int,
                   struct Map_info *, int, int,
                   int, int, const char *, int *, int*, int*);
 
Index: vector/v.select/select.c
===================================================================
--- vector/v.select/select.c	(révision 69689)
+++ vector/v.select/select.c	(copie de travail)
@@ -6,7 +6,7 @@
 
 #include "proto.h"
 
-void select_lines(struct Map_info *aIn, int atype, int afield,
+int 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 *AAreas, int* nskipped)
@@ -13,6 +13,7 @@
 {
     int i;
     int nalines, aline, ltype;
+    int nfound = 0;
     
     struct line_pnts *APoints, *BPoints;
     struct ilist *BoundList, *LList;
@@ -115,6 +116,7 @@
 		
 		if (found) {
 		    ALines[aline] = 1;
+		    nfound += 1;
 		    continue;	/* Go to next A line */
 		}
 	    }
@@ -139,6 +141,7 @@
 			if(area_relate_geos(bIn, AGeom,
 					    barea, operator, relate)) {
 			    ALines[aline] = 1;
+			    nfound += 1;
 			    break;
 			}
 #endif
@@ -146,6 +149,7 @@
 		    else {
 			if (line_overlap_area(APoints, bIn, barea)) {
 			    ALines[aline] = 1;
+			    nfound += 1;
 			    break;
 			}
 		    }
@@ -212,6 +216,7 @@
 			if(line_relate_geos(bIn, AGeom,
 					    bline, operator, relate)) {
 			    add_aarea(aIn, aarea, ALines, AAreas);
+			    nfound += 1;
 			    break;
 			}
 #endif
@@ -221,6 +226,7 @@
 
 			if (line_overlap_area(BPoints, aIn, aarea)) {
 			    add_aarea(aIn, aarea, ALines, AAreas);
+			    nfound += 1;
 			    continue;
 			}
 		    }
@@ -311,6 +317,7 @@
 		    }
 		    if (found) {
 			add_aarea(aIn, aarea, ALines, AAreas);
+		        nfound += 1;
 			break;
 		    }
 		}
@@ -331,5 +338,5 @@
     Vect_destroy_boxlist(List);
     Vect_destroy_boxlist(TmpList);
 
-    return;
+    return nfound;
 }
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to