Просмотр исходного кода

v.what: add type option with default point,line,area

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52425 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 12 лет назад
Родитель
Сommit
412a6baf74
3 измененных файлов с 15 добавлено и 7 удалено
  1. 8 4
      vector/v.what/main.c
  2. 6 2
      vector/v.what/what.c
  3. 1 1
      vector/v.what/what.h

+ 8 - 4
vector/v.what/main.c

@@ -36,7 +36,7 @@ int main(int argc, char **argv)
 	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 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
 	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 @@ int main(int argc, char **argv)
 	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 @@ int main(int argc, char **argv)
 	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);
 	}
     }

+ 6 - 2
vector/v.what/what.c

@@ -101,7 +101,8 @@ static void F_generate(const char *drvname, const char *dbname,
     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 @@ void what(struct Map_info *Map, int nvects, char **vect, double east, double nor
 	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) {

+ 1 - 1
vector/v.what/what.h

@@ -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 *);