[GRASS-SVN] r52425 - grass/trunk/vector/v.what

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 20 07:18:56 PDT 2012


Author: mmetz
Date: 2012-07-20 07:18:56 -0700 (Fri, 20 Jul 2012)
New Revision: 52425

Modified:
   grass/trunk/vector/v.what/main.c
   grass/trunk/vector/v.what/what.c
   grass/trunk/vector/v.what/what.h
Log:
v.what: add type option with default point,line,area

Modified: grass/trunk/vector/v.what/main.c
===================================================================
--- grass/trunk/vector/v.what/main.c	2012-07-20 14:08:48 UTC (rev 52424)
+++ grass/trunk/vector/v.what/main.c	2012-07-20 14:18:56 UTC (rev 52425)
@@ -36,7 +36,7 @@
 	struct Flag *print, *topo, *shell;
     } flag;
     struct {
-	struct Option *map, *field, *coords, *maxdist;
+	struct Option *map, *field, *coords, *maxdist, *type;
     } opt;
     struct Cell_head window;
     struct GModule *module;
@@ -46,7 +46,7 @@
     struct Map_info *Map;
 
     char buf[2000];
-    int i, level, ret;
+    int i, level, ret, type;
     int *field;
     double xval, yval, xres, yres, maxd, x;
     double EW_DIST1, EW_DIST2, NS_DIST1, NS_DIST2;
@@ -67,6 +67,9 @@
     opt.field = G_define_standard_option(G_OPT_V_FIELD_ALL);
     opt.field->multiple = YES;
     
+    opt.type = G_define_standard_option(G_OPT_V3_TYPE);
+    opt.type->answer = "point,line,area,face";
+
     opt.coords = G_define_standard_option(G_OPT_M_COORDS);
     opt.coords->required = YES;
     opt.coords->label = _("Coordinates for query");
@@ -102,6 +105,7 @@
 	vect = opt.map->answers;
 
     maxd = atof(opt.maxdist->answer);
+    type = Vect_option_to_types(opt.type);
 
     if (maxd == 0.0) {
 	G_get_window(&window);
@@ -159,7 +163,7 @@
 	while (fgets(buf, sizeof(buf), stdin) != NULL) {
 	    ret = sscanf(buf, "%lf%c%lf", &xval, &ch, &yval);
 	    if (ret == 3 && (ch == ',' || ch == ' ' || ch == '\t')) {
-		what(Map, nvects, vect, xval, yval, maxd, flag.topo->answer,
+		what(Map, nvects, vect, xval, yval, maxd, type, flag.topo->answer,
 		     flag.print->answer, flag.shell->answer, field);
 	    }
 	    else {
@@ -173,7 +177,7 @@
 	for (i = 0; opt.coords->answers[i] != NULL; i += 2) {
 	    xval = atof(opt.coords->answers[i]);
 	    yval = atof(opt.coords->answers[i + 1]);
-	    what(Map, nvects, vect, xval, yval, maxd, flag.topo->answer,
+	    what(Map, nvects, vect, xval, yval, maxd, type, flag.topo->answer,
 		 flag.print->answer, flag.shell->answer, field);
 	}
     }

Modified: grass/trunk/vector/v.what/what.c
===================================================================
--- grass/trunk/vector/v.what/what.c	2012-07-20 14:08:48 UTC (rev 52424)
+++ grass/trunk/vector/v.what/what.c	2012-07-20 14:18:56 UTC (rev 52425)
@@ -101,7 +101,8 @@
     db_free_string(&str);
 }
 
-void what(struct Map_info *Map, int nvects, char **vect, double east, double north, double maxdist, int topo, int showextra, int script, int *field)
+void what(struct Map_info *Map, int nvects, char **vect, double east, double north,
+          double maxdist, int qtype, int topo, int showextra, int script, int *field)
 {
     int type;
     char east_buf[40], north_buf[40];
@@ -133,12 +134,15 @@
 	Vect_reset_cats(Cats);
 	/* Try to find point first and only if no one was found try lines,
 	 *  otherwise point on line could not be selected and similarly for areas */
+	
+	type = ((GV_POINT | GV_CENTROID) & qtype);
 	line =
 	    Vect_find_line(&Map[i], east, north, 0.0, GV_POINT | GV_CENTROID,
 			   maxdist, 0, 0);
 	if (line == 0) {
+	    type = ((GV_LINE | GV_BOUNDARY | GV_FACE) & qtype);
 	    line = Vect_find_line(&Map[i], east, north, 0.0,
-				  GV_LINE | GV_BOUNDARY | GV_FACE, maxdist, 0, 0);
+				  type, maxdist, 0, 0);
 	}
 
 	if (line == 0) {

Modified: grass/trunk/vector/v.what/what.h
===================================================================
--- grass/trunk/vector/v.what/what.h	2012-07-20 14:08:48 UTC (rev 52424)
+++ grass/trunk/vector/v.what/what.h	2012-07-20 14:18:56 UTC (rev 52425)
@@ -1,3 +1,3 @@
 /* what.c */
 void what(struct Map_info *, int, char **,
-	  double, double, double, int, int, int, int*);
+	  double, double, double, int, int, int, int, int *);



More information about the grass-commit mailing list