[GRASS-SVN] r50295 - in grass/trunk: include/defs lib/vector/vedit

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 19 09:26:38 EST 2012


Author: martinl
Date: 2012-01-19 06:26:38 -0800 (Thu, 19 Jan 2012)
New Revision: 50295

Modified:
   grass/trunk/include/defs/vedit.h
   grass/trunk/lib/vector/vedit/delete.c
   grass/trunk/lib/vector/vedit/merge.c
   grass/trunk/lib/vector/vedit/veditlib.dox
Log:
vedit: new subroutines to delete areas
	+ Vedit_delete_area_centroid()
	+ Vedit_delete_area()
	+ Vedit_delete_areas_cat()


Modified: grass/trunk/include/defs/vedit.h
===================================================================
--- grass/trunk/include/defs/vedit.h	2012-01-19 13:43:46 UTC (rev 50294)
+++ grass/trunk/include/defs/vedit.h	2012-01-19 14:26:38 UTC (rev 50295)
@@ -17,8 +17,10 @@
 int Vedit_chtype_lines(struct Map_info *, struct ilist *);
 
 /* delete.c */
-
 int Vedit_delete_lines(struct Map_info *, struct ilist *);
+int Vedit_delete_area_centroid(struct Map_info *, int);
+int Vedit_delete_area(struct Map_info *, int);
+int Vedit_delete_areas_cat(struct Map_info *, int, int);
 
 /* distance.c */
 double Vedit_get_min_distance(struct line_pnts *, struct line_pnts *,

Modified: grass/trunk/lib/vector/vedit/delete.c
===================================================================
--- grass/trunk/lib/vector/vedit/delete.c	2012-01-19 13:43:46 UTC (rev 50294)
+++ grass/trunk/lib/vector/vedit/delete.c	2012-01-19 14:26:38 UTC (rev 50295)
@@ -1,25 +1,27 @@
 /*!
   \file lib/vector/vedit/delete.c
 
-  \brief Vedit library - delete primitives
+  \brief Vedit library - delete vector features
 
-  (C) 2007-2008 by the GRASS Development Team
+  (C) 2007-2008, 2012 by the GRASS Development Team
 
   This program is free software under the GNU General Public License
-  (>=v2).  Read the file COPYING that comes with GRASS for details.
+  (>=v2). Read the file COPYING that comes with GRASS for details.
   
   \author Martin Landa <landa.martin gmail.com>
 */
 
 #include <grass/vedit.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
 
 /*!
-  \brief Delete selected primitives
+  \brief Delete selected features
   
   \param Map pointer to Map_info
-  \param List list of primitives to be deleted
+  \param List list of features to be deleted
   
-  \return number of deleted primitives
+  \return number of deleted features
   \return -1 on on error
 */
 int Vedit_delete_lines(struct Map_info *Map, struct ilist *List)
@@ -29,19 +31,122 @@
 
     nlines_removed = 0;
 
-    /* delete */
     for (i = 0; i < List->n_values; i++) {
 	line = List->value[i];
 
-	if (Vect_line_alive(Map, line)) {
-	    if (Vect_delete_line(Map, line) < 0) {
-		return -1;
-	    }
+	if (!Vect_line_alive(Map, line)) {
+	    G_warning(_("Attempt to delete dead feature (%d)"), line);
+	    continue;
+	}
+	 
+	if (Vect_delete_line(Map, line) < 0) {
+	    return -1;
+	}
 
-	    G_debug(3, "Vedit_delete_lines(): line=%d", line);
-	    nlines_removed++;
-	}
+	G_debug(3, "Vedit_delete_lines(): line=%d", line);
+	nlines_removed++;
     }
 
     return nlines_removed;
 }
+
+/*!
+  \brief Delete area (centroid and set of boundaries) by centroid
+
+  \param Map pointer to Map_info struct
+  \param centroid
+
+  \return 0 no area deleted
+  \return 1 area deleted
+*/
+int Vedit_delete_area_centroid(struct Map_info *Map, int centroid)
+{
+    int area;
+
+    G_debug(1, "Vedit_delete_area_centroid(): centroid = %d", centroid);
+    
+    area = Vect_get_centroid_area(Map, centroid);
+    if (area == 0) {
+	G_warning(_("No area found for centroid %d"), centroid);
+	return 0;
+    }
+    if (area < 0) {
+	G_warning(_("Duplicate centroid %d, unable to delete area"), centroid);
+	return 0;
+    }
+
+    return Vedit_delete_area(Map, area);
+}
+
+/*!
+  \brief Delete area (centroid + set of boundaries) by id
+
+  \param Map pointer to Map_info struct
+  \param area id
+
+  \return 0 no area deleted
+  \return 1 area deleted
+*/
+int Vedit_delete_area(struct Map_info *Map, int area)
+{
+    int i, centroid, left, right;
+    struct ilist *list;
+
+    list   = Vect_new_list();
+    
+    G_debug(3, "Vedit_delete_area(): area=%d", area);
+    centroid = Vect_get_area_centroid(Map, area);
+    if (centroid != 0) {
+	Vect_delete_line(Map, centroid);
+    }
+    else {
+	G_warning(_("Area %d without centroid"), area);
+	return 0;
+    }
+    Vect_get_area_boundaries(Map, area, list);
+    if (list->n_values > 0) {
+	for (i = 0; i < list->n_values; i++) {
+	    Vect_get_line_areas(Map, abs(list->value[i]), &left, &right);
+	    if (left > 0 && right > 0)
+		/* do not delete common boundaries */
+		continue;
+	    
+	    Vect_delete_line(Map, list->value[i]);
+	}
+    }
+    else {
+	G_warning(_("Area %d has no boundaries"), area);
+	return 0;
+    }
+
+    Vect_destroy_list(list);
+    
+    return 1;
+}
+
+/*!
+  \brief Delete vector areas of given category
+
+  \param Map pointer to Map_info struct
+  \param field layer number
+  \param cat category number
+
+  \return number of deleted areas
+*/
+int Vedit_delete_areas_cat(struct Map_info *Map, int field, int cat)
+{
+    int area, nareas, nremoved;
+    
+    G_debug(1, "Vedit_delete_areas(): field = %d cat = %d", field, cat);
+    nareas = Vect_get_num_areas(Map);
+    nremoved = 0;
+    for (area = 1; area <= nareas; area++) {
+	if (Vect_get_area_cat(Map, area, field) != cat)
+	    continue;
+	
+	if (Vedit_delete_area(Map, area))
+	    nremoved++;
+    }
+
+    return nremoved;
+}

Modified: grass/trunk/lib/vector/vedit/merge.c
===================================================================
--- grass/trunk/lib/vector/vedit/merge.c	2012-01-19 13:43:46 UTC (rev 50294)
+++ grass/trunk/lib/vector/vedit/merge.c	2012-01-19 14:26:38 UTC (rev 50295)
@@ -52,11 +52,11 @@
     struct line_cats *Cats1, *Cats2;
 
     int line_i, i, j;
-    int line, line1, type1, line2, type2;
+    int line, line1, type1, line2;
     int do_merge;
 
     /* number of lines (original, selected, merged) */
-    int nlines, nlines_selected, nlines_merged;
+    int nlines, nlines_merged;
 
     nlines_merged = 0;
 
@@ -73,8 +73,7 @@
     List_in_box = Vect_new_list();
 
     nlines = Vect_get_num_lines(Map);
-    nlines_selected = List->n_values;
-
+    
     /* merge lines */
     for (line_i = 0; line_i < List->n_values; line_i++) {
 	line1 = List->value[line_i];
@@ -136,7 +135,7 @@
 		if (!do_merge || line2 < 0)
 		    continue;
 
-		type2 = Vect_read_line(Map, Points2, Cats2, line2);
+		Vect_read_line(Map, Points2, Cats2, line2);
 
 		merge_lines(Points1, Cats1, Points2, Cats2, -1.0, &Points);	/* do not use threshold value */
 

Modified: grass/trunk/lib/vector/vedit/veditlib.dox
===================================================================
--- grass/trunk/lib/vector/vedit/veditlib.dox	2012-01-19 13:43:46 UTC (rev 50294)
+++ grass/trunk/lib/vector/vedit/veditlib.dox	2012-01-19 14:26:38 UTC (rev 50295)
@@ -12,7 +12,7 @@
 
 \section veditFn Functions
 
-\subsection veditModify Modify primitives
+\subsection veditModify Modify features
 
  - Vedit_split_lines()
 
@@ -28,16 +28,25 @@
 
  - Vedit_move_lines()
 
+\subsection veditArea Modify areas
+
+ - Vedit_delete_area_centroid()
+ - Vedit_delete_area()
+ - Vedit_delete_areas_cat()
+
 \subsection veditCats Manipulate feature categories
 
  - Vedit_modify_cats()
 
-\subsection veditCopy Copy primitives
+\subsection veditCopy Copy features
 
  - Vedit_copy_lines()
 
-\subsection veditSelect Select primitives
+\subsection veditSelect Select features
 
+
+
+
  - Vedit_select_by_query()
 
 \subsection veditSnap Snapping



More information about the grass-commit mailing list