[GRASS-SVN] r50296 - grass/trunk/vector/v.edit

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 19 09:28:02 EST 2012


Author: martinl
Date: 2012-01-19 06:28:02 -0800 (Thu, 19 Jan 2012)
New Revision: 50296

Modified:
   grass/trunk/vector/v.edit/args.c
   grass/trunk/vector/v.edit/global.h
   grass/trunk/vector/v.edit/main.c
   grass/trunk/vector/v.edit/snap.c
Log:
v.edit: new tool to delete areas


Modified: grass/trunk/vector/v.edit/args.c
===================================================================
--- grass/trunk/vector/v.edit/args.c	2012-01-19 14:26:38 UTC (rev 50295)
+++ grass/trunk/vector/v.edit/args.c	2012-01-19 14:28:02 UTC (rev 50296)
@@ -53,7 +53,8 @@
 	       "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 @@
 	       _("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 @@
     /*
        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);

Modified: grass/trunk/vector/v.edit/global.h
===================================================================
--- grass/trunk/vector/v.edit/global.h	2012-01-19 14:26:38 UTC (rev 50295)
+++ grass/trunk/vector/v.edit/global.h	2012-01-19 14:28:02 UTC (rev 50296)
@@ -43,6 +43,7 @@
     MODE_ZBULK,
     /* change feature type (point<->centroid, line<->boundary) */
     MODE_CHTYPE,
+    MODE_AREA_DEL,              /* delete area */
 };
 
 struct GParams

Modified: grass/trunk/vector/v.edit/main.c
===================================================================
--- grass/trunk/vector/v.edit/main.c	2012-01-19 14:26:38 UTC (rev 50295)
+++ grass/trunk/vector/v.edit/main.c	2012-01-19 14:28:02 UTC (rev 50296)
@@ -121,14 +121,14 @@
 	    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 @@
 	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"));
+	}
+	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;
 	    }
-	    else {
-		G_message(_("No feature modified"));
-	    }
-	    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;

Modified: grass/trunk/vector/v.edit/snap.c
===================================================================
--- grass/trunk/vector/v.edit/snap.c	2012-01-19 14:26:38 UTC (rev 50295)
+++ grass/trunk/vector/v.edit/snap.c	2012-01-19 14:28:02 UTC (rev 50296)
@@ -58,7 +58,7 @@
 {
     struct line_pnts *Points1, *Points2;
     struct line_cats *Cats2;
-    int type1, type2;
+    int type2;
     int newline;
     double mindist;
     int mindistidx;
@@ -67,7 +67,7 @@
     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 */



More information about the grass-commit mailing list