[GRASS-SVN] r48914 - grass/branches/develbranch_6/vector/v.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 22 16:39:05 EDT 2011


Author: martinl
Date: 2011-10-22 13:39:05 -0700 (Sat, 22 Oct 2011)
New Revision: 48914

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


Modified: grass/branches/develbranch_6/vector/v.out.ascii/b2a.c
===================================================================
--- grass/branches/develbranch_6/vector/v.out.ascii/b2a.c	2011-10-22 20:03:25 UTC (rev 48913)
+++ grass/branches/develbranch_6/vector/v.out.ascii/b2a.c	2011-10-22 20:39:05 UTC (rev 48914)
@@ -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 header)
 {
-    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;
@@ -63,16 +64,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) {
@@ -91,22 +92,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);
@@ -325,7 +334,6 @@
 	    }
 	}
     }
-
     /* not reached */
 }
 
@@ -340,3 +348,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/develbranch_6/vector/v.out.ascii/out.c
===================================================================
--- grass/branches/develbranch_6/vector/v.out.ascii/out.c	2011-10-22 20:03:25 UTC (rev 48913)
+++ grass/branches/develbranch_6/vector/v.out.ascii/out.c	2011-10-22 20:39:05 UTC (rev 48914)
@@ -146,10 +146,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