[GRASS-SVN] r50981 - grass/branches/releasebranch_6_4/vector/v.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 4 06:37:09 EST 2012


Author: martinl
Date: 2012-03-04 03:37:09 -0800 (Sun, 04 Mar 2012)
New Revision: 50981

Modified:
   grass/branches/releasebranch_6_4/vector/v.out.ascii/b2a.c
   grass/branches/releasebranch_6_4/vector/v.out.ascii/out.c
Log:
#1470 (v.out.ascii with sql where option exports only centroids and not areas)
      (merge r48914 from devbr6)


Modified: grass/branches/releasebranch_6_4/vector/v.out.ascii/b2a.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.out.ascii/b2a.c	2012-03-03 14:54:22 UTC (rev 50980)
+++ grass/branches/releasebranch_6_4/vector/v.out.ascii/b2a.c	2012-03-04 11:37:09 UTC (rev 50981)
@@ -5,16 +5,17 @@
 #include "local_proto.h"
 
 static int srch(const void *pa, const void *pb);
+static int check_cat(const struct line_cats *, const int *, int);
 
 int bin_to_asc(FILE *ascii,
 	       FILE *att, struct Map_info *Map, int ver,
 	       int format, int dp, char *fs, int region_flag,
 	       int field, char* where, char **columns)
 {
-    int type, ctype, i, cat, proj;
+    int type, ctype, i, cat, line, left, right, found; 
     double *xptr, *yptr, *zptr, x, y;
     static struct line_pnts *Points;
-    struct line_cats *Cats;
+    struct line_cats *Cats, *ACats;
     char *xstring = NULL, *ystring = NULL, *zstring = NULL;
     struct Cell_head window;
     struct ilist *fcats;
@@ -62,16 +63,16 @@
     
     Points = Vect_new_line_struct();	/* init line_pnts struct */
     Cats = Vect_new_cats_struct();
+    ACats = Vect_new_cats_struct();
     fcats = Vect_new_list();
 
-    proj = Vect_get_proj(Map);
-
     /* by default, read_next_line will NOT read Dead lines */
     /* but we can override that (in Level I only) by specifying */
     /* the type  -1, which means match all line types */
 
     Vect_rewind(Map);
 
+    line = 0;
     while (1) {
 	if (-1 == (type = Vect_read_next_line(Map, Points, Cats))) {
 	    if (columns) {
@@ -90,22 +91,30 @@
 	    return 0;
 	}
 
+	line++;
+	
 	if (format == FORMAT_POINT && !(type & GV_POINTS))
 	    continue;
-
-	if (cats) {
-	    /* check category */
-	    for (i = 0; i < Cats->n_cats; i++) {
-		if ((int *)bsearch((void *) &(Cats->cat[i]), cats, ncats, sizeof(int),
-				   srch)) {
-		    /* found */
-		    break;
-		}
+	
+	found = check_cat(Cats, cats, ncats);
+	if (!found && type == GV_BOUNDARY && Vect_level(Map) > 1) {
+	    Vect_get_line_areas(Map, line, &left, &right);
+	    if (left < 0) 
+		left = Vect_get_isle_area(Map, abs(left));
+	    if (left > 0) {
+		Vect_get_area_cats(Map, left, ACats);
+		found = check_cat(ACats, cats, ncats);
 	    }
-	    
-	    if (i == Cats->n_cats) 
-		continue;
+	    if (right < 0) 
+		right = Vect_get_isle_area(Map, abs(right));
+	    if (!found && right > 0) {
+		Vect_get_area_cats(Map, right, ACats);
+		found = check_cat(ACats, cats, ncats);
+	    }
 	}
+	
+	if (!found)
+	    continue;
 
 	if (ver < 5) {
 	    Vect_cat_get(Cats, 1, &cat);
@@ -300,7 +309,6 @@
 	    }
 	}
     }
-
     /* not reached */
 }
 
@@ -315,3 +323,24 @@
 	return 1;
     return 0;
 }
+
+/* check category */
+int check_cat(const struct line_cats *Cats, const int *cats, int ncats)
+{
+    int i;
+    
+    if (cats) {
+	for (i = 0; i < Cats->n_cats; i++) {
+	    if ((int *)bsearch((void *) &(Cats->cat[i]), cats, ncats, sizeof(int),
+			       srch)) {
+		/* found */
+		break;
+	    }
+	}
+	
+	if (i == Cats->n_cats)
+	    return FALSE;
+    }
+    
+    return TRUE;
+}

Modified: grass/branches/releasebranch_6_4/vector/v.out.ascii/out.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.out.ascii/out.c	2012-03-03 14:54:22 UTC (rev 50980)
+++ grass/branches/releasebranch_6_4/vector/v.out.ascii/out.c	2012-03-04 11:37:09 UTC (rev 50981)
@@ -141,10 +141,18 @@
     }
 
 
-    Vect_set_open_level(1);	/* only need level I */
-    if (Vect_open_old(&Map, input->answer, "") < 0)
-	G_fatal_error(_("Unable to open vector map <%s>"),
+    /* open with topology only if needed */
+    if (format == FORMAT_ALL && where_opt->answer) {
+	if (Vect_open_old(&Map, input->answer, "") < 2) /* topology required for areas */
+	    G_warning(_("Unable to open vector map <%s> at topology level. "
+			"Areas will not be processed."),
 		      input->answer);
+    }
+    else {
+	Vect_set_open_level(1); /* topology not needed */ 
+	if (Vect_open_old(&Map, input->answer, "") < 0) 
+	    G_fatal_error(_("Unable to open vector map <%s>"), input->answer); 
+    }
     
     if (output->answer) {
 	if (ver == 4) {



More information about the grass-commit mailing list