[GRASS-SVN] r49067 - in grass/trunk: lib/ogsf misc/m.nviz.image

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 3 05:47:57 EDT 2011


Author: martinl
Date: 2011-11-03 02:47:57 -0700 (Thu, 03 Nov 2011)
New Revision: 49067

Modified:
   grass/trunk/lib/ogsf/GP2.c
   grass/trunk/lib/ogsf/Gp3.c
   grass/trunk/lib/ogsf/Gv3.c
   grass/trunk/misc/m.nviz.image/vector.c
Log:
libogsf: fix thematic mapping of features without category or without DB link
m.nviz.image: update module


Modified: grass/trunk/lib/ogsf/GP2.c
===================================================================
--- grass/trunk/lib/ogsf/GP2.c	2011-11-03 08:20:28 UTC (rev 49066)
+++ grass/trunk/lib/ogsf/GP2.c	2011-11-03 09:47:57 UTC (rev 49067)
@@ -295,7 +295,7 @@
    Updates also style for each geopoint.
    
    \param id point set id
-   \param layer layer number for thematic mapping
+   \param layer layer number for thematic mapping (-1 for undefined)
    \param color icon color column name
    \param width icon line width column name
    \param size icon size column name

Modified: grass/trunk/lib/ogsf/Gp3.c
===================================================================
--- grass/trunk/lib/ogsf/Gp3.c	2011-11-03 08:20:28 UTC (rev 49066)
+++ grass/trunk/lib/ogsf/Gp3.c	2011-11-03 09:47:57 UTC (rev 49067)
@@ -173,7 +173,7 @@
     struct Map_info Map;
     struct field_info *Fi;
     
-    int nvals, cat, npts;
+    int nvals, cat, npts, nskipped;
     int red, blu, grn;
     const char *str;
     const char *mapset;
@@ -196,18 +196,19 @@
     }
     
     Fi = Vect_get_field(&Map, gp->tstyle->layer);
-    if (!Fi)
-	G_fatal_error(_("Database connection not defined for layer %d"),
-		      gp->tstyle->layer);
-    
-    driver = db_start_driver_open_database(Fi->driver, Fi->database);
-    if (!driver)
-	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-		      Fi->database, Fi->driver);
-    
+    if (!Fi) {
+	G_warning(_("Database connection not defined for layer %d"),
+		  gp->tstyle->layer);
+    }
+    else {
+	driver = db_start_driver_open_database(Fi->driver, Fi->database);
+	if (!driver)
+	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+			  Fi->database, Fi->driver);
+    }
     G_message(_("Loading thematic points layer <%s>..."),
 	      G_fully_qualified_name(gp->filename, mapset));
-    npts = 0;
+    npts = nskipped = 0;
     for(gpt = gp->points; gpt; gpt = gpt->next) {
 	gpt->style = (gvstyle *) G_malloc(sizeof(gvstyle));
 	G_zero(gpt->style, sizeof(gvstyle));
@@ -218,9 +219,13 @@
 	gpt->style->size   = gp->style->size;
 	gpt->style->width  = gp->style->width;
 	
-	Vect_cat_get(gpt->cats, gp->tstyle->layer, &cat);
-	if (cat < 0)
+	cat = -1;
+	if (gpt->cats)
+	    Vect_cat_get(gpt->cats, gp->tstyle->layer, &cat);
+	if (cat < 0) {
+	    nskipped++;
 	    continue;
+	}
 
 	/* color */
 	if (colors) {
@@ -275,5 +280,9 @@
 	npts++;
     }
     
+    if (nskipped > 0)
+	G_warning(_("%d points without category. "
+		    "Unable to determine color rules for features without category."),
+		  nskipped);
     return npts;
 }

Modified: grass/trunk/lib/ogsf/Gv3.c
===================================================================
--- grass/trunk/lib/ogsf/Gv3.c	2011-11-03 08:20:28 UTC (rev 49066)
+++ grass/trunk/lib/ogsf/Gv3.c	2011-11-03 09:47:57 UTC (rev 49067)
@@ -309,7 +309,7 @@
     struct Map_info Map;
     struct field_info *Fi;
     
-    int nvals, cat, nlines;
+    int nvals, cat, nlines, nskipped;
     int red, blu, grn;
     const char *str;
     const char *mapset;
@@ -332,18 +332,19 @@
     }
     
     Fi = Vect_get_field(&Map, gv->tstyle->layer);
-    if (!Fi)
-	G_fatal_error(_("Database connection not defined for layer %d"),
-		      gv->tstyle->layer);
-    
-    driver = db_start_driver_open_database(Fi->driver, Fi->database);
-    if (!driver)
-	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-		      Fi->database, Fi->driver);
-    
+    if (!Fi) {
+	G_warning(_("Database connection not defined for layer %d"),
+		  gv->tstyle->layer);
+    }
+    else {
+      driver = db_start_driver_open_database(Fi->driver, Fi->database);
+      if (!driver)
+	  G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+			Fi->database, Fi->driver);
+    }
     G_message(_("Loading thematic vector layer <%s>..."),
 	      G_fully_qualified_name(gv->filename, mapset));
-    nlines = 0;
+    nlines = nskipped = 0;
     for(gvt = gv->lines; gvt; gvt = gvt->next) {
 	gvt->style = (gvstyle *) G_malloc(sizeof(gvstyle));
 	G_zero(gvt->style, sizeof(gvstyle));
@@ -353,11 +354,15 @@
 	gvt->style->symbol = gv->style->symbol;
 	gvt->style->size   = gv->style->size;
 	gvt->style->width  = gv->style->width;
+
+	cat = -1;
+	if (gvt->cats)
+	    Vect_cat_get(gvt->cats, gv->tstyle->layer, &cat);
+	if (cat < 0) {
+	    nskipped++;
+	    continue;
+	}
 	
-	Vect_cat_get(gvt->cats, gv->tstyle->layer, &cat);
-	if (cat < 0)
-	    continue;
-
 	/* color */
 	if (colors) {
 	    if (!Rast_get_c_color((const CELL *) &cat, &red, &grn, &blu, colors)) {
@@ -394,6 +399,11 @@
 
 	nlines++;
     }
+
+    if (nskipped > 0)
+	G_warning(_("%d features without category. "
+		    "Unable to determine color rules for features without category."),
+		  nskipped);
     
     return nlines;
 }

Modified: grass/trunk/misc/m.nviz.image/vector.c
===================================================================
--- grass/trunk/misc/m.nviz.image/vector.c	2011-11-03 08:20:28 UTC (rev 49066)
+++ grass/trunk/misc/m.nviz.image/vector.c	2011-11-03 09:47:57 UTC (rev 49067)
@@ -223,6 +223,8 @@
     dbDriver *driver;
     dbColumn *column;
     
+    Fi = NULL;
+    
     if (vlines) {
 	map    = params->vlines;
 	layer  = params->vline_layer;
@@ -244,9 +246,7 @@
 	    G_fatal_error(_("Unable to open vector map <%s>"), map->answers[i]);
 	Fi = Vect_get_field2(&Map, layer->answers[i]);
 	if (!Fi)
-	    G_fatal_error(_("Database connection not defined for layer %s"),
-			  layer->answers[i]);
-
+	    continue;
 	driver = db_start_driver_open_database(Fi->driver, Fi->database);
 	if (!driver)
 	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
@@ -293,5 +293,8 @@
 	}
     }
     
-    return Fi->number;
+    if (Fi) 
+	return Fi->number;
+    
+    return 1;
 }



More information about the grass-commit mailing list