[GRASS-SVN] r56263 - grass/trunk/vector/v.extrude
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 15 06:35:15 PDT 2013
Author: martinl
Date: 2013-05-15 06:35:12 -0700 (Wed, 15 May 2013)
New Revision: 56263
Modified:
grass/trunk/vector/v.extrude/extrude.c
grass/trunk/vector/v.extrude/local_proto.h
grass/trunk/vector/v.extrude/main.c
Log:
v.extrude: sync with v.drape
add scale and null options
Modified: grass/trunk/vector/v.extrude/extrude.c
===================================================================
--- grass/trunk/vector/v.extrude/extrude.c 2013-05-15 13:29:38 UTC (rev 56262)
+++ grass/trunk/vector/v.extrude/extrude.c 2013-05-15 13:35:12 UTC (rev 56263)
@@ -29,7 +29,8 @@
*/
int extrude(struct Map_info *In, struct Map_info *Out,
const struct line_cats *Cats, const struct line_pnts *Points,
- int fdrast, int trace, int interp_method, double objheight, double voffset,
+ int fdrast, int trace, int interp_method, double scale, int null_defined,
+ double null_val, double objheight, double voffset,
const struct Cell_head *window, int type, int centroid)
{
int k; /* Points->n_points */
@@ -61,11 +62,15 @@
/* do not trace -> calculate minimum dem offset */
if (fdrast >= 0 && !trace) {
for (k = 0; k < Points->n_points; k++) {
- voffset_curr = Rast_get_sample(fdrast, window, NULL,
- Points->y[k], Points->x[k], 0, /* north, east */
- interp_method);
- if (Rast_is_d_null_value(&voffset_curr))
- continue; /* skip null values */
+ voffset_curr = scale * Rast_get_sample(fdrast, window, NULL,
+ Points->y[k], Points->x[k], /* north, east */
+ 0, interp_method);
+ if (Rast_is_d_null_value(&voffset_curr)) {
+ if (null_defined)
+ voffset_curr = null_val;
+ else
+ voffset_curr = 0.;
+ }
if (k == 0) {
voffset_dem = voffset_curr;
@@ -82,25 +87,30 @@
voffset_curr = voffset_next = 0.0;
if (fdrast >= 0 && trace) {
- voffset_curr = Rast_get_sample(fdrast, window, NULL,
- Points->y[k], Points->x[k], 0, /* north, east */
- interp_method);
+ voffset_curr = scale * Rast_get_sample(fdrast, window, NULL,
+ Points->y[k], Points->x[k], /* north, east */
+ 0, interp_method);
if (type != GV_POINT) {
- voffset_next = Rast_get_sample(fdrast, window, NULL,
- Points->y[k + 1], /* north, east */
- Points->x[k + 1], 0,
- interp_method);
+ voffset_next = scale * Rast_get_sample(fdrast, window, NULL,
+ Points->y[k + 1], /* north, east */
+ Points->x[k + 1], 0,
+ interp_method);
}
}
- if (Rast_is_d_null_value(&voffset_curr) ||
- Rast_is_d_null_value(&voffset_next)) {
- if (k >= Points->n_points - 2)
- break;
+ if (Rast_is_d_null_value(&voffset_curr)) {
+ if (null_defined)
+ voffset_curr = null_val;
else
- continue;
+ voffset_curr = 0.;
}
+ if (Rast_is_d_null_value(&voffset_next)) {
+ if (null_defined)
+ voffset_next = null_val;
+ else
+ voffset_next = 0.;
+ }
if (trace) {
voffset_curr += voffset;
@@ -147,6 +157,7 @@
Points->z[k] + voffset_curr);
}
}
+
if (k >= Points->n_points - 2)
break;
}
Modified: grass/trunk/vector/v.extrude/local_proto.h
===================================================================
--- grass/trunk/vector/v.extrude/local_proto.h 2013-05-15 13:29:38 UTC (rev 56262)
+++ grass/trunk/vector/v.extrude/local_proto.h 2013-05-15 13:35:12 UTC (rev 56263)
@@ -5,5 +5,6 @@
/* extrude.c */
int extrude(struct Map_info *, struct Map_info *,
const struct line_cats *, const struct line_pnts *,
- int, int, int, double, double,
+ int, int, int, double, int, double,
+ double, double,
const struct Cell_head *, int, int);
Modified: grass/trunk/vector/v.extrude/main.c
===================================================================
--- grass/trunk/vector/v.extrude/main.c 2013-05-15 13:29:38 UTC (rev 56262)
+++ grass/trunk/vector/v.extrude/main.c 2013-05-15 13:35:12 UTC (rev 56263)
@@ -37,7 +37,7 @@
struct GModule *module;
struct {
struct Option *input, *output, *zshift, *height, *elevation, *hcolumn,
- *type, *field, *cats, *where, *interp;
+ *type, *field, *cats, *where, *interp, *scale, *null;
} opt;
struct {
struct Flag *trace;
@@ -56,6 +56,7 @@
int only_type, cat;
int fdrast, interp_method, trace;
double objheight, objheight_default, voffset;
+ double scale, null_val;
struct field_info *Fi;
dbDriver *driver = NULL;
@@ -65,10 +66,13 @@
module = G_define_module();
G_add_keyword(_("vector"));
G_add_keyword(_("geometry"));
+ G_add_keyword(_("sampling"));
G_add_keyword(_("3D"));
- module->description =
- _("Extrudes flat vector features to 3D with defined height.");
-
+ module->label =
+ _("Extrudes flat vector features to 3D vector features with defined height.");
+ module->description =
+ _("Optionally the height can be derived from sampling of elevation raster map.");
+
flag.trace = G_define_flag();
flag.trace->key = 't';
flag.trace->description = _("Trace elevation");
@@ -124,6 +128,20 @@
opt.interp->answer = "nearest";
opt.interp->guisection = _("Elevation");
+ opt.scale = G_define_option();
+ opt.scale->key = "scale";
+ opt.scale->type = TYPE_DOUBLE;
+ opt.scale->description = _("Scale factor sampled raster values");
+ opt.scale->answer = "1.0";
+ opt.scale->guisection = _("Elevation");
+
+ opt.null = G_define_option();
+ opt.null->key = "null_value";
+ opt.null->type = TYPE_DOUBLE;
+ opt.null->description =
+ _("Height for sampled raster NULL values");
+ opt.null->guisection = _("Elevation");
+
G_gisinit(argv[0]);
if (G_parser(argc, argv))
@@ -145,8 +163,18 @@
objheight_default = objheight;
only_type = Vect_option_to_types(opt.type);
+
+ /* sampling method */
interp_method = Rast_option_to_interp_type(opt.interp);
+ /* used to scale sampled raster values */
+ scale = atof(opt.scale->answer);
+
+ /* is null value defined */
+ if (opt.null->answer)
+ null_val = atof(opt.null->answer);
+
+ /* trace elevation */
trace = flag.trace->answer ? TRUE : FALSE;
/* set input vector map name and mapset */
@@ -268,7 +296,8 @@
G_debug(3, "area: %d height: %f", area, objheight);
extrude(&In, &Out, Cats, Points,
- fdrast, trace, interp_method,
+ fdrast, trace, interp_method, scale,
+ opt.null->answer ? TRUE : FALSE, null_val,
objheight, voffset, &window, GV_AREA,
centroid);
} /* foreach area */
@@ -316,7 +345,8 @@
} /* if opt.hcolumn->answer */
extrude(&In, &Out, Cats, Points,
- fdrast, trace, interp_method,
+ fdrast, trace, interp_method, scale,
+ opt.null->answer ? TRUE : FALSE, null_val,
objheight, voffset, &window, type, -1);
} /* for each line */
} /* else if area */
More information about the grass-commit
mailing list