[GRASS-SVN] r54002 - grass/trunk/vector/v.generalize

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 23 12:41:06 PST 2012


Author: mmetz
Date: 2012-11-23 12:41:06 -0800 (Fri, 23 Nov 2012)
New Revision: 54002

Modified:
   grass/trunk/vector/v.generalize/displacement.c
   grass/trunk/vector/v.generalize/main.c
   grass/trunk/vector/v.generalize/misc.c
   grass/trunk/vector/v.generalize/misc.h
   grass/trunk/vector/v.generalize/operators.h
   grass/trunk/vector/v.generalize/simplification.c
Log:
v.generalize: fix cats and where options

Modified: grass/trunk/vector/v.generalize/displacement.c
===================================================================
--- grass/trunk/vector/v.generalize/displacement.c	2012-11-23 20:02:56 UTC (rev 54001)
+++ grass/trunk/vector/v.generalize/displacement.c	2012-11-23 20:41:06 UTC (rev 54002)
@@ -32,14 +32,14 @@
 int snakes_displacement(struct Map_info *In, struct Map_info *Out,
 			double threshold, double alpha, double beta,
 			double gama, double delta, int iterations,
-			struct varray * varray)
+			struct cat_list *cat_list, int layer)
 {
 
     int n_points;
     int n_lines;
     int i, j, index, pindex, iter, type;
     int with_z = 0;
-    struct line_pnts *Points, *Write;
+    struct line_pnts *Points;
     struct line_cats *Cats;
     MATRIX k, dx, dy, fx, fy, kinv, dx_old, dy_old;
     POINT *parray;
@@ -51,14 +51,13 @@
 
     /* initialize structrures and read the number of points */
     Points = Vect_new_line_struct();
-    Write = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
     n_lines = Vect_get_num_lines(In);
     n_points = 0;
 
     for (i = 1; i <= n_lines; i++) {
-	type = Vect_read_line(In, Points, NULL, i);
-	if (varray && !varray->c[i])
+	type = Vect_read_line(In, Points, Cats, i);
+	if (layer > 0 && !Vect_cats_in_constraint(Cats, layer, cat_list))
 	    continue;
 	if (type & GV_LINE)
 	    n_points += Points->n_points;
@@ -81,9 +80,12 @@
     pindex = 0;
     for (i = 1; i <= n_lines; i++) {
 	G_percent(i, n_lines, 1);
-	type = Vect_read_line(In, Points, NULL, i);
-	if (type != GV_LINE || (varray && !varray->c[i]))
+	type = Vect_read_line(In, Points, Cats, i);
+	if (type != GV_LINE)
 	    continue;
+	if (layer > 0 && !Vect_cats_in_constraint(Cats, layer, cat_list))
+	    continue;
+
 	for (j = 0; j < Points->n_points; j++) {
 	    int q, findex;
 	    POINT cur;
@@ -290,7 +292,8 @@
     for (i = 1; i <= n_lines; i++) {
 	int type = Vect_read_line(In, Points, Cats, i);
 
-	if (type != GV_LINE || (varray && !varray->c[i])) {
+	if (type != GV_LINE ||
+	    (layer > 0 && !Vect_cats_in_constraint(Cats, layer, cat_list))) {
 	    Vect_write_line(Out, type, Points, Cats);
 	    continue;
 	}
@@ -318,5 +321,6 @@
     matrix_free(fy);
     matrix_free(dx_old);
     matrix_free(dy_old);
+
     return 0;
 }

Modified: grass/trunk/vector/v.generalize/main.c
===================================================================
--- grass/trunk/vector/v.generalize/main.c	2012-11-23 20:02:56 UTC (rev 54001)
+++ grass/trunk/vector/v.generalize/main.c	2012-11-23 20:41:06 UTC (rev 54002)
@@ -61,11 +61,10 @@
     double degree_thresh, closeness_thresh, betweeness_thresh;
     int method;
     int look_ahead, iterations;
-    int chcat;
     int layer;
     int n_lines;
     int simplification, mask_type;
-    struct varray *varray;
+    struct cat_list *cat_list = NULL;
     char *s, *descriptions;
 
     /* initialize GIS environment */
@@ -326,20 +325,18 @@
 
     total_input = total_output = 0;
 
-    chcat = 0;
-    varray = NULL;
     layer = Vect_get_field_number(&In, field_opt->answer);
-    /* parse filter option and select appropriate lines */
-    if (method == DISPLACEMENT)
-	varray = parse_filter_options(&In, layer, mask_type,
-			      where_opt->answer, cat_opt->answer, &chcat);
+    /* parse filter options */
+    if (layer > 0)
+	cat_list = Vect_cats_set_constraint(&In, layer, 
+			      where_opt->answer, cat_opt->answer);
 
     if (method == DISPLACEMENT) {
 	/* modifies only lines, all other features including boundaries are preserved */
 	/* options where, cats, and layer are respected */
 	G_message(_("Displacement..."));
 	snakes_displacement(&In, &Out, thresh, alpha, beta, 1.0, 10.0,
-			    iterations, varray);
+			    iterations, cat_list, layer);
     }
 
     /* TODO: rearrange code below. It's really messy */
@@ -373,11 +370,6 @@
 
 	Vect_copy_map_lines(&In, &Out);
 	Vect_build_partial(&Out, GV_BUILD_CENTROIDS);
-	/* varray needs to be retrieved from Out vector and not from In vector
-	 * because identical lines can have different ids
-	 * if dead lines are still registered in topo of In */
-	varray = parse_filter_options(&Out, layer, mask_type,
-			      where_opt->answer, cat_opt->answer, &chcat);
 
 	if ((mask_type & GV_AREA) && !(mask_type & GV_BOUNDARY))
 	    mask_type |= GV_BOUNDARY;
@@ -398,28 +390,50 @@
 
 	    if (!(type & GV_LINES) || !(mask_type & type))
 		continue;
-		
-	    if ((type & GV_LINE) && chcat && !varray->c[i])
-		continue;
-	    else if ((type & GV_BOUNDARY) && chcat) {
-		int do_line = varray->c[i];
 
-		if ((mask_type & GV_AREA) && !do_line) {
+	    if (layer > 0) {
+		if ((type & GV_LINE) &&
+		    !Vect_cats_in_constraint(Cats, layer, cat_list))
+		    continue;
+		else if ((type & GV_BOUNDARY)) {
+		    int do_line = 0;
 		    int left, right;
 		    
-		    /* check if any of the centroids is selected */
-		    Vect_get_line_areas(&Out, i, &left, &right);
-		    if (left > 0) {
-			left = Vect_get_area_centroid(&Out, left);
-			do_line = varray->c[left];
+		    do_line = Vect_cats_in_constraint(Cats, layer, cat_list);
+
+		    if (!do_line) {
+			
+			/* check if any of the centroids is selected */
+			Vect_get_line_areas(&Out, i, &left, &right);
+			if (left > 0) {
+			    Vect_get_area_cats(&Out, left, Cats);
+			    do_line = Vect_cats_in_constraint(Cats, layer, cat_list);
+			}
+			else if (left < 0) {
+			    left = Vect_get_isle_area(&Out, abs(left));
+			    if (left > 0) {
+				Vect_get_area_cats(&Out, left, Cats);
+				do_line = Vect_cats_in_constraint(Cats, layer, cat_list);
+			    }
+			}
+			
+			if (!do_line) {
+			    if (right > 0) {
+				Vect_get_area_cats(&Out, right, Cats);
+				do_line = Vect_cats_in_constraint(Cats, layer, cat_list);
+			    }
+			    else if (right < 0) {
+				right = Vect_get_isle_area(&Out, abs(right));
+				if (right > 0) {
+				    Vect_get_area_cats(&Out, right, Cats);
+				    do_line = Vect_cats_in_constraint(Cats, layer, cat_list);
+				}
+			    }
+			}
 		    }
-		    if (!do_line && right > 0) {
-			right = Vect_get_area_centroid(&Out, right);
-			do_line = varray->c[right];
-		    }
+		    if (!do_line)
+			continue;
 		}
-		if (!do_line)
-		    continue;
 	    }
 
 	    Vect_line_prune(APoints);

Modified: grass/trunk/vector/v.generalize/misc.c
===================================================================
--- grass/trunk/vector/v.generalize/misc.c	2012-11-23 20:02:56 UTC (rev 54001)
+++ grass/trunk/vector/v.generalize/misc.c	2012-11-23 20:41:06 UTC (rev 54002)
@@ -87,12 +87,10 @@
     int ttype, ntabs = 0;
     struct field_info *IFi, *OFi;
     struct line_cats *Cats;
-    struct line_pnts *Points;
     int **ocats, *nocats, *fields;
     int i;
 
     /* Collect list of output cats */
-    Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
     nfields = Vect_cidx_get_num_fields(In);
     ocats = (int **)G_malloc(nfields * sizeof(int *));
@@ -189,69 +187,6 @@
     return 1;
 }
 
-/* parse filter option and select appropriate lines */
-/* return array with selected lines or NULL */
-struct varray *parse_filter_options(struct Map_info *Map, int layer,
-                      int mask_type, char *where, char *cats, int *chcat)
-{
-    struct varray *varray;
-
-    /* allow selection of areas and other types */
-    if (mask_type & GV_AREA) {
-	mask_type &= ~(GV_AREA);
-	mask_type |= GV_CENTROID;
-    }
-
-    if (where) {
-	if (layer < 1)
-	    G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", "where");
-	if (cats)
-	    G_warning(_("'where' and 'cats' parameters were supplied, cat will be ignored"));
-	*chcat = 1;
-	varray = Vect_new_varray(Vect_get_num_lines(Map));
-
-	if (Vect_set_varray_from_db
-	    (Map, layer, where, mask_type, 1, varray) == -1) {
-	    G_warning(_("Unable to load data from database"));
-	}
-    }
-    else if (cats) {
-	if (layer < 1)
-	    G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", GV_KEY_COLUMN);
-	*chcat = 1;
-	varray = Vect_new_varray(Vect_get_num_lines(Map));
-
-	if (Vect_set_varray_from_cat_string
-	    (Map, layer, cats, mask_type, 1, varray) == -1) {
-	    G_warning(_("Problem loading category values"));
-	}
-    }
-    else if (layer > 0) {
-	int i, type, cat, nlines;
-	struct line_cats *Cats = Vect_new_cats_struct();
-
-	nlines = Vect_get_num_lines(Map);
-	varray = Vect_new_varray(nlines);
-	*chcat = 1;
-	
-	for (i = 1; i <= nlines; i++) {
-	    varray->c[i] = 0;
-	    type = Vect_read_line(Map, NULL, Cats, i);
-	    
-	    if (!(type & mask_type))
-		continue;
-		
-	    if (Vect_cat_get(Cats, layer, &cat))
-		varray->c[i] = 1;
-	}
-	Vect_destroy_cats_struct(Cats);
-    }
-    else
-	return NULL;
-	
-    return varray;
-}
-
 /* check topology corruption by boundary modification
  * return 0 on corruption, 1 if modification is ok */
 int check_topo(struct Map_info *Out, int line, struct line_pnts *APoints,

Modified: grass/trunk/vector/v.generalize/misc.h
===================================================================
--- grass/trunk/vector/v.generalize/misc.h	2012-11-23 20:02:56 UTC (rev 54001)
+++ grass/trunk/vector/v.generalize/misc.h	2012-11-23 20:41:06 UTC (rev 54002)
@@ -19,11 +19,6 @@
 /* returns 1 on success, 0 on failure */
 extern int copy_tables_by_cats(struct Map_info *In, struct Map_info *Out);
 
-/* parse filter option and select appropriate lines */
-/* return array with selected lines or NULL */
-struct varray *parse_filter_options(struct Map_info *Map, int layer, 
-                      int mask_type, char *where, char *cats, int *chcat);
-
 /* check topology corruption by boundary modification
  * return 0 on corruption, 1 if modification is ok */
 int check_topo(struct Map_info *, int, struct line_pnts *, 

Modified: grass/trunk/vector/v.generalize/operators.h
===================================================================
--- grass/trunk/vector/v.generalize/operators.h	2012-11-23 20:02:56 UTC (rev 54001)
+++ grass/trunk/vector/v.generalize/operators.h	2012-11-23 20:41:06 UTC (rev 54002)
@@ -29,4 +29,4 @@
 int snakes_displacement(struct Map_info *In, struct Map_info *Out,
 			double threshold, double alpha, double beta,
 			double gama, double delta, int iterations,
-			struct varray * varray);
+			struct cat_list *cat_list, int layer);

Modified: grass/trunk/vector/v.generalize/simplification.c
===================================================================
--- grass/trunk/vector/v.generalize/simplification.c	2012-11-23 20:02:56 UTC (rev 54001)
+++ grass/trunk/vector/v.generalize/simplification.c	2012-11-23 20:41:06 UTC (rev 54002)
@@ -225,7 +225,6 @@
  */
 int reumann_witkam(struct line_pnts *Points, double thresh, int with_z)
 {
-    int seg1, seg2;
     int i, count;
     POINT x0, x1, x2, sub, diff;
     double subd, diffd, sp, dist;
@@ -238,8 +237,6 @@
 
     thresh *= thresh;
 
-    seg1 = 0;
-    seg2 = 1;
     count = 1;
 
     point_assign(Points, 0, with_z, &x1);



More information about the grass-commit mailing list