[GRASS-SVN] r29755 - grass/trunk/vector/v.drape

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 20 17:38:27 EST 2008


Author: martinl
Date: 2008-01-20 17:38:27 -0500 (Sun, 20 Jan 2008)
New Revision: 29755

Modified:
   grass/trunk/vector/v.drape/description.html
   grass/trunk/vector/v.drape/main.c
Log:
v.drape: New option 'scale' added (scale raster values).
Message standardization.
Check if the current region include the entire input vector map.
Check if the elevation raster cover the entire are of the vector map.


Modified: grass/trunk/vector/v.drape/description.html
===================================================================
--- grass/trunk/vector/v.drape/description.html	2008-01-20 22:25:43 UTC (rev 29754)
+++ grass/trunk/vector/v.drape/description.html	2008-01-20 22:38:27 UTC (rev 29755)
@@ -1,31 +1,35 @@
 <h2>DESCRIPTION</h2>
 
-<em>v.drape</em> converts 2D vector point or line data into 3D vector
-format via sampling of an elevation surface. Three sampling algorithms
-adapted from<em>v v.sample</em> were incorporated into this module:
-nearest neighbor, bilinear, and cubic convultion.
+<em>v.drape</em> converts 2D/3D vector data into 3D vector format via
+sampling of an elevation surface. Three sampling algorithms adapted
+from <a href="v.sample.html">v.sample</a> were incorporated into this
+module: nearest neighbor, bilinear, and cubic convultion.
 
 <h2>NOTES</h2>
 
 Please run beforehand
+
 <div class="code"><pre>
 g.region vect=2D_vector
 </pre></div>
+
 and make sure that the extent of the elevation raster is at least as
 big as the vector to convert.
 
 <P>
-Additional vertices can be added to the input 2D vector with <em>v.split</em>.
+Additional vertices can be added to the input 2D vector map
+with <a href="v.split.html">v.split</a>.
+
 <P>
+The module can be used in conjunction
+with <a href="v.out.pov.html">v.out.pov</a> and
+<a href="r.out.pov.html">r.out.pov</a> to export a complete set of
+vector and raster data for display in POVRAY.
 
-The module can be used in conjunction with <em>v.out.pov</em> and
-<em>r.out.pov</em> to export a complete set of vector and raster data
-for display in POVRAY.
-
 <h2>EXAMPLE</h2>
 
 Spearfish example:
-<P>
+
 <div class="code"><pre>
 g.region -p vect=roads align=elevation.10m
 v.drape in=roads rast=elevation.10m method=bilinear out=roads3d
@@ -52,10 +56,25 @@
 If the following error message appears
 
 <div class="code"><pre>
- WARNING: [demname in mapset] - read request for row -1 is outside region
- ERROR: problem reading raster cell file
+WARNING: Current region does not include the entire input vector map
+WARNING: Reading raster map request for row 466 is outside region
+ERROR: Problem reading raster map
 </pre></div>
 
+it indicates that the vector map is spatially larger than the current
+region settings. To avoid this problem, set region from the input
+vector map and re-run <em>v.drape</em>.
+
+<div class="code"><pre>
+g.region vect=vectmap
+</pre></div>
+
+If the following error message appears
+
+<div class="code"><pre>
+WARNING: Elevation raster map does not cover the entire area of the input vector map.
+</pre></div>
+
 it indicates that the vector map is spatially larger than the raster map.
 To avoid this problem, the vector map needs to be clipped to the raster
 map extent, for example:
@@ -69,7 +88,6 @@
 
 Then <em>v.drape</em> should perform the draping.
 
-
 <h2>SEE ALSO</h2>
 
 <EM>
@@ -78,13 +96,12 @@
 <A HREF="v.out.pov.html">v.out.pov</A>,
 <A HREF="v.overlay.html">v.overlay</A>,
 <A HREF="v.split.html">v.split</A>,
-<A HREF="v.what.rast.html">v.what.rast</A>
+<A HREF="v.what.rast.html">v.what.rast</A>,
+<A HREF="v.extrude.html">v.extrude</A>
 </EM>
 
 <h2>AUTHOR</h2>
 
 Dylan Beaudette, University of California at Davis.
-<br>
-Raster sampling routines borrowed from v.sample.
 
 <p><i>Last changed: $Date$</i>

Modified: grass/trunk/vector/v.drape/main.c
===================================================================
--- grass/trunk/vector/v.drape/main.c	2008-01-20 22:25:43 UTC (rev 29754)
+++ grass/trunk/vector/v.drape/main.c	2008-01-20 22:38:27 UTC (rev 29755)
@@ -1,4 +1,3 @@
-
 /**********************************************************
  *
  * MODULE:       v.drape
@@ -17,7 +16,7 @@
  **********************************************************/
 
 
- /** Doxygen Style Comments
+/** Doxygen Style Comments
 \file main.c
 \brief v.drape module for converting 2D vectors into 3D vectors by means of sampling an elevation raster.
  
@@ -26,47 +25,39 @@
 \date 2005.09.20
  
 \todo add support for areas
-\todo Enhanced error checking such as
-	\li does the elevation raster cover the entire are of the vector map?
-	\li does the current region include the entire input vector map ?
-\todo Make a description.html for documentation
+*/
 
- */
-
-
-
 #include <stdlib.h>
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/Vect.h>
 #include <grass/glocale.h>
 
-
 int main(int argc, char *argv[])
 {
     struct GModule *module;
-    struct Option *in_opt, *out_opt, *type_opt, *rast_opt, *method_opt;	
+    struct Option *in_opt, *out_opt, *type_opt, *rast_opt, *method_opt, *scale_opt;
+
     struct Map_info In, Out;
     struct line_pnts *Points;
     struct line_cats *Cats;
     /* int    layer; */
     int line, nlines, otype, ltype;
+    BOUND_BOX in_bbox, region_bbox, rast_bbox;
 
-    /* Raster stuff from v.sample::main.c */
     char *mapset;
     int j;
     double scale, estimated_elevation;
     INTERP_TYPE method = UNKNOWN;
     int fdrast;			/* file descriptor for raster map is int */
-    struct Cell_head window;
-    /* end raster stuff */
+    struct Cell_head window, rast_window;
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("vector");
+    module->keywords = _("vector, geometry, sampling");
     module->description =
-      _("Converts 2D vector to 3D vector by sampling of elevation raster. Default sampling by nearest neighbor.");
+      _("Converts vector map to 3D by sampling of elevation raster map.");
 
     in_opt = G_define_standard_option(G_OPT_V_INPUT);
 
@@ -75,12 +66,17 @@
     type_opt->answer = "point,centroid,line,boundary,face,kernel";
 
     /* raster sampling */
-    rast_opt = G_define_option();
+    rast_opt = G_define_standard_option(G_OPT_R_MAP);
     rast_opt->key = "rast";
-    rast_opt->type = TYPE_STRING;
     rast_opt->required = NO;
-    rast_opt->description = _("Elevation raster for height extraction");
+    rast_opt->description = _("Elevation raster map for height extraction");
 
+    scale_opt = G_define_option();
+    scale_opt->key = "scale";
+    scale_opt->type = TYPE_DOUBLE;
+    scale_opt->description = _("Scale sampled raster values");
+    scale_opt->answer = "1.0";
+
     method_opt = G_define_option();
     method_opt->key = "method";
     method_opt->type = TYPE_STRING;
@@ -105,7 +101,6 @@
 	method = CUBIC;
     else
     {
-        G_message(_("defaulting to nearest neighbor sampling"));
         method = NEAREST;
     }
 
@@ -114,6 +109,12 @@
     /* setup the region */
     G_get_window(&window);
 
+    /* used to scale sampled raster values*/
+    scale = atof(scale_opt->answer);
+
+    /* Check output type */
+    otype = Vect_option_to_types(type_opt);
+
     /* check for the elev raster, and check for error condition */
     if ((mapset = G_find_cell(rast_opt->answer, "")) == NULL) {
 	G_fatal_error(_("Raster map <%s> not found"), rast_opt->answer);
@@ -124,19 +125,47 @@
 	G_fatal_error(_("Unable to open raster map <%s>"), rast_opt->answer);
     }
 
-    /* used to scale sampled raster values: will need to add an option to modify this later */
-    scale = 1;
+    /* read raster header */
+    G_get_cellhd(rast_opt->answer, mapset, &rast_window);
 
+    Vect_set_open_level(2);
 
-    /* Check output type */
-    otype = Vect_option_to_types(type_opt);
+    /* check input/output vector maps */
+    Vect_check_input_output_name(in_opt->answer, out_opt->answer, GV_FATAL_EXIT);
 
-    Vect_set_open_level(2);
-    Vect_open_old(&In, in_opt->answer, "");
+    mapset = G_find_vector2(in_opt->answer, "");
+    if (!mapset) {
+	G_fatal_error(_("Vector map <%s> not found"), in_opt->answer);
+    }
 
+    Vect_open_old(&In, in_opt->answer, mapset);
+
+    /* checks 
+       does the elevation raster cover the entire are of the vector map?
+       does the current region include the entire input vector map ?
+    */
+    Vect_get_map_box(&In, &in_bbox);
+    Vect_region_box(&window, &region_bbox);
+    Vect_region_box(&rast_window, &rast_bbox);
+    if (in_bbox.W < region_bbox.W ||
+	in_bbox.E > region_bbox.E ||
+	in_bbox.S < region_bbox.S ||
+	in_bbox.N > region_bbox.N) {
+	G_warning (_("Current region does not include the entire input vector map <%s>"),
+		   in_opt->answer);
+    }
+    if (in_bbox.W < rast_bbox.W ||
+	in_bbox.E > rast_bbox.E ||
+	in_bbox.S < rast_bbox.S ||
+	in_bbox.N > rast_bbox.N) {	
+	G_warning (_("Elevation raster map <%s> does not cover the entire area "
+		     "of the input vector map <%s>. "),
+		   rast_opt->answer, in_opt->answer);
+    }
+
     /* setup the new vector map */
-    /* remember to open the new vector map as 3D:  Vect_open_new(,,1) */
-    Vect_open_new(&Out, out_opt->answer, 1);
+    /* remember to open the new vector map as 3D */
+    Vect_open_new(&Out, out_opt->answer, WITH_Z);
     Vect_copy_head_data(&In, &Out);
     Vect_hist_copy(&In, &Out);
     Vect_hist_command(&Out);
@@ -158,7 +187,7 @@
 	for (line = 1; line <= nlines; line++) {
 
 	    /* progress feedback */
-	    G_percent(line, nlines, 1);
+	    G_percent(line, nlines, 2);
 
 	    /* get the line type */
 	    ltype = Vect_read_line(&In, Points, Cats, line);
@@ -224,7 +253,13 @@
     /* close input vector */
     Vect_close(&In);
     /* build topology for output vector */
-    Vect_build(&Out, stderr);
+    if (G_verbose() > G_verbose_min()) {
+	Vect_build(&Out, stderr);
+    }
+    else {
+	Vect_build(&Out, NULL);
+    }
+
     /* close output vector */
     Vect_close(&Out);
 



More information about the grass-commit mailing list