浏览代码

v.edit: new tool to delete areas

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50296 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 年之前
父节点
当前提交
347d8c4da3
共有 4 个文件被更改,包括 70 次插入51 次删除
  1. 26 21
      vector/v.edit/args.c
  2. 1 0
      vector/v.edit/global.h
  3. 41 28
      vector/v.edit/main.c
  4. 2 2
      vector/v.edit/snap.c

+ 26 - 21
vector/v.edit/args.c

@@ -53,7 +53,8 @@ int parser(int argc, char *argv[], struct GParams *params,
 	       "flip;%s;"
 	       "connect;%s;"
 	       "zbulk;%s;"
-	       "chtype;%s",
+	       "chtype;%s;"
+	       "areadel;%s",
 	       _("Create new (empty) vector map"),
 	       _("Add new features to existing vector map"),
 	       _("Delete selected features from vector map"),
@@ -74,11 +75,12 @@ int parser(int argc, char *argv[], struct GParams *params,
 	       _("Connect two lines"),
 	       _("Z bulk-labeling (automated assignment of z coordinate to "
 		 "vector lines)"),
-	       _("Change feature type (point<->centroid, line<->boundary)"));
+	       _("Change feature type (point<->centroid, line<->boundary)"),
+	       _("Delete selected areas from vector map (based on selected centroids)"));
     params->tool->descriptions = desc;
     params->tool->options = "create,add,delete,copy,move,flip,catadd,catdel,"
 	"merge,break,snap,connect,chtype,"
-	"vertexadd,vertexdel,vertexmove,zbulk,select";
+	"vertexadd,vertexdel,vertexmove,areadel,zbulk,select";
 
     params->in = G_define_standard_option(G_OPT_F_INPUT);
     params->in->required = NO;
@@ -221,60 +223,63 @@ int parser(int argc, char *argv[], struct GParams *params,
     /*
        check that the given arguments makes sense together
      */
-    if (G_strcasecmp(params->tool->answer, "create") == 0) {
+    if (strcmp(params->tool->answer, "create") == 0) {
 	*action_mode = MODE_CREATE;
     }
-    else if (G_strcasecmp(params->tool->answer, "add") == 0) {
+    else if (strcmp(params->tool->answer, "add") == 0) {
 	*action_mode = MODE_ADD;
     }
-    else if (G_strcasecmp(params->tool->answer, "delete") == 0) {
+    else if (strcmp(params->tool->answer, "delete") == 0) {
 	*action_mode = MODE_DEL;
     }
-    else if (G_strcasecmp(params->tool->answer, "move") == 0) {
+    else if (strcmp(params->tool->answer, "move") == 0) {
 	*action_mode = MODE_MOVE;
     }
-    else if (G_strcasecmp(params->tool->answer, "merge") == 0) {
+    else if (strcmp(params->tool->answer, "merge") == 0) {
 	*action_mode = MODE_MERGE;
     }
-    else if (G_strcasecmp(params->tool->answer, "break") == 0) {
+    else if (strcmp(params->tool->answer, "break") == 0) {
 	*action_mode = MODE_BREAK;
     }
-    else if (G_strcasecmp(params->tool->answer, "connect") == 0) {
+    else if (strcmp(params->tool->answer, "connect") == 0) {
 	*action_mode = MODE_CONNECT;
     }
-    else if (G_strcasecmp(params->tool->answer, "vertexadd") == 0) {
+    else if (strcmp(params->tool->answer, "vertexadd") == 0) {
 	*action_mode = MODE_VERTEX_ADD;
     }
-    else if (G_strcasecmp(params->tool->answer, "vertexdel") == 0) {
+    else if (strcmp(params->tool->answer, "vertexdel") == 0) {
 	*action_mode = MODE_VERTEX_DELETE;
     }
-    else if (G_strcasecmp(params->tool->answer, "vertexmove") == 0) {
+    else if (strcmp(params->tool->answer, "vertexmove") == 0) {
 	*action_mode = MODE_VERTEX_MOVE;
     }
-    else if (G_strcasecmp(params->tool->answer, "select") == 0) {
+    else if (strcmp(params->tool->answer, "select") == 0) {
 	*action_mode = MODE_SELECT;
     }
-    else if (G_strcasecmp(params->tool->answer, "catadd") == 0) {
+    else if (strcmp(params->tool->answer, "catadd") == 0) {
 	*action_mode = MODE_CATADD;
     }
-    else if (G_strcasecmp(params->tool->answer, "catdel") == 0) {
+    else if (strcmp(params->tool->answer, "catdel") == 0) {
 	*action_mode = MODE_CATDEL;
     }
-    else if (G_strcasecmp(params->tool->answer, "copy") == 0) {
+    else if (strcmp(params->tool->answer, "copy") == 0) {
 	*action_mode = MODE_COPY;
     }
-    else if (G_strcasecmp(params->tool->answer, "snap") == 0) {
+    else if (strcmp(params->tool->answer, "snap") == 0) {
 	*action_mode = MODE_SNAP;
     }
-    else if (G_strcasecmp(params->tool->answer, "flip") == 0) {
+    else if (strcmp(params->tool->answer, "flip") == 0) {
 	*action_mode = MODE_FLIP;
     }
-    else if (G_strcasecmp(params->tool->answer, "zbulk") == 0) {
+    else if (strcmp(params->tool->answer, "zbulk") == 0) {
 	*action_mode = MODE_ZBULK;
     }
-    else if (G_strcasecmp(params->tool->answer, "chtype") == 0) {
+    else if (strcmp(params->tool->answer, "chtype") == 0) {
 	*action_mode = MODE_CHTYPE;
     }
+    else if (strcmp(params->tool->answer, "areadel") == 0) {
+	*action_mode = MODE_AREA_DEL;
+    }
     else {
 	G_fatal_error(_("Operation '%s' not implemented"),
 		      params->tool->answer);

+ 1 - 0
vector/v.edit/global.h

@@ -43,6 +43,7 @@ enum mode
     MODE_ZBULK,
     /* change feature type (point<->centroid, line<->boundary) */
     MODE_CHTYPE,
+    MODE_AREA_DEL,              /* delete area */
 };
 
 struct GParams

+ 41 - 28
vector/v.edit/main.c

@@ -121,14 +121,14 @@ int main(int argc, char *argv[])
 	    ret = Vect_open_update2(&Map, params.map->answer, G_mapset(), params.fld->answer);
 	else			/* read-only -- select features */
 	    ret = Vect_open_old2(&Map, params.map->answer, G_mapset(), params.fld->answer);
-
+	
 	if (ret < 2)
 	    G_fatal_error(_("Unable to open vector map <%s> at topological level %d"),
 			  params.map->answer, 2);
     }
 
     G_debug(1, "Map opened");
-
+    
     /* open backgroud maps */
     if (params.bmaps->answer) {
 	i = 0;
@@ -365,35 +365,48 @@ int main(int argc, char *argv[])
 	break;
     case MODE_NONE:
 	break;
-    case MODE_ZBULK:{
-	    double start, step;
-	    double x1, y1, x2, y2;
-
-	    start = atof(params.zbulk->answers[0]);
-	    step = atof(params.zbulk->answers[1]);
-
-	    x1 = atof(params.bbox->answers[0]);
-	    y1 = atof(params.bbox->answers[1]);
-	    x2 = atof(params.bbox->answers[2]);
-	    y2 = atof(params.bbox->answers[3]);
-
-	    ret = Vedit_bulk_labeling(&Map, List,
-				      x1, y1, x2, y2, start, step);
-
-	    G_message(_("%d lines labeled"), ret);
-	    break;
+    case MODE_ZBULK: {
+	double start, step;
+	double x1, y1, x2, y2;
+	
+	start = atof(params.zbulk->answers[0]);
+	step = atof(params.zbulk->answers[1]);
+	
+	x1 = atof(params.bbox->answers[0]);
+	y1 = atof(params.bbox->answers[1]);
+	x2 = atof(params.bbox->answers[2]);
+	y2 = atof(params.bbox->answers[3]);
+	
+	ret = Vedit_bulk_labeling(&Map, List,
+				  x1, y1, x2, y2, start, step);
+	
+	G_message(_("%d lines labeled"), ret);
+	break;
+    }
+    case MODE_CHTYPE:
+	ret = Vedit_chtype_lines(&Map, List);
+	
+	if (ret > 0) {
+	    G_message(_("%d features converted"), ret);
 	}
-    case MODE_CHTYPE:{
-	    ret = Vedit_chtype_lines(&Map, List);
-
-	    if (ret > 0) {
-		G_message(_("%d features converted"), ret);
-	    }
-	    else {
-		G_message(_("No feature modified"));
+	else {
+	    G_message(_("No feature modified"));
+	}
+	break;
+    case MODE_AREA_DEL: {
+	ret = 0;
+	for (i = 0; i < List->n_values; i++) {
+	    if (Vect_get_line_type(&Map, List->value[i]) != GV_CENTROID) {
+		G_warning(_("Select feature %d is not centroid, ignoring..."),
+			  List->value[i]);
+		continue;
 	    }
-	    break;
+	    
+	    ret += Vedit_delete_area_centroid(&Map, List->value[i]);
 	}
+	G_message(_("%d areas removed"), ret);
+	break;
+    }
     default:
 	G_warning(_("Operation not implemented"));
 	ret = -1;

+ 2 - 2
vector/v.edit/snap.c

@@ -58,7 +58,7 @@ int snap_line2(struct Map_info *Map, int line1, int line2, double thresh)
 {
     struct line_pnts *Points1, *Points2;
     struct line_cats *Cats2;
-    int type1, type2;
+    int type2;
     int newline;
     double mindist;
     int mindistidx;
@@ -67,7 +67,7 @@ int snap_line2(struct Map_info *Map, int line1, int line2, double thresh)
     Points2 = Vect_new_line_struct();
     Cats2 = Vect_new_cats_struct();
 
-    type1 = Vect_read_line(Map, Points1, NULL, line1);
+    Vect_read_line(Map, Points1, NULL, line1);
     type2 = Vect_read_line(Map, Points2, Cats2, line2);
 
     /* find mininal distance and its indexes */