[GRASS-SVN] r69522 - grass-addons/grass7/raster3d/r3.profile

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 18 19:09:41 PDT 2016


Author: wenzeslaus
Date: 2016-09-18 19:09:40 -0700 (Sun, 18 Sep 2016)
New Revision: 69522

Added:
   grass-addons/grass7/raster3d/r3.profile/r3.profile.html
Removed:
   grass-addons/grass7/raster3d/r3.profile/r.profile.html
Modified:
   grass-addons/grass7/raster3d/r3.profile/Makefile
   grass-addons/grass7/raster3d/r3.profile/input.c
   grass-addons/grass7/raster3d/r3.profile/local_proto.h
   grass-addons/grass7/raster3d/r3.profile/main.c
   grass-addons/grass7/raster3d/r3.profile/read_rast.c
Log:
r3.profile: write 3D raster vertical slice as 2D raster (unpolished code)

Modified: grass-addons/grass7/raster3d/r3.profile/Makefile
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/Makefile	2016-09-19 01:32:08 UTC (rev 69521)
+++ grass-addons/grass7/raster3d/r3.profile/Makefile	2016-09-19 02:09:40 UTC (rev 69522)
@@ -1,9 +1,9 @@
 MODULE_TOPDIR = ../..
 
-PGM = r.profile
+PGM = r3.profile
 
-LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
-DEPENDENCIES = $(RASTERDEP) $(GISDEP)
+LIBES = $(RASTER3DLIB) $(RASTERLIB) $(GISLIB) $(MATHLIB)
+DEPENDENCIES = $(RASTER3DDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass-addons/grass7/raster3d/r3.profile/input.c
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/input.c	2016-09-19 01:32:08 UTC (rev 69521)
+++ grass-addons/grass7/raster3d/r3.profile/input.c	2016-09-19 02:09:40 UTC (rev 69522)
@@ -1,3 +1,15 @@
+/*
+ * Declarations for the whole module
+ *
+ * Author: Bob Covill <bcovill tekmap.ns.ca>
+ *
+ * Copyright 2000 by Bob Covill, and the GRASS Development Team
+ *
+ * This program is free software licensed under the GPL (>=v2).
+ * Read the COPYING file that comes with GRASS for details.
+ *
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>

Modified: grass-addons/grass7/raster3d/r3.profile/local_proto.h
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/local_proto.h	2016-09-19 01:32:08 UTC (rev 69521)
+++ grass-addons/grass7/raster3d/r3.profile/local_proto.h	2016-09-19 02:09:40 UTC (rev 69522)
@@ -1,3 +1,17 @@
+/*
+ * Declarations for the whole module
+ *
+ * Authors:
+ *   Bob Covill <bcovill tekmap.ns.ca>
+ *   Vaclav Petras <wenzeslaus gmail com>
+ *
+ * Copyright 2000-2016 by Bob Covill, and the GRASS Development Team
+ *
+ * This program is free software licensed under the GPL (>=v2).
+ * Read the COPYING file that comes with GRASS for details.
+ *
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -4,14 +18,22 @@
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
+#include <grass/raster3d.h>
 
+#include "double_list.h"
+
 /* main.c */
-int do_profile(double, double, double, double, int, double, int, int,
-               FILE *, char *, const char *, double);
+int do_profile(double e1, double e2, double n1, double n2,
+               int coords, double res, RASTER3D_Map * fd, int data_type,
+               FILE * fp, char *null_string, const char *unit, double factor,
+               RASTER3D_Region * region, int depth,
+               struct DoubleList *values);
 
 /* read_rast.c */
-int read_rast(double, double, double, int, int, RASTER_MAP_TYPE, FILE *,
-              char *);
+int read_rast(double east, double north, double dist, RASTER3D_Map * fd,
+              int coords, RASTER_MAP_TYPE data_type, FILE * fp,
+              char *null_string, RASTER3D_Region * region, int depth,
+              struct DoubleList *values);
 
 /* input.c */
 int input(char *, char *, char *, char *, char *, FILE *);

Modified: grass-addons/grass7/raster3d/r3.profile/main.c
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/main.c	2016-09-19 01:32:08 UTC (rev 69521)
+++ grass-addons/grass7/raster3d/r3.profile/main.c	2016-09-19 02:09:40 UTC (rev 69522)
@@ -1,14 +1,23 @@
-/*
- * Copyright (C) 2000 by the GRASS Development Team
- * Author: Bob Covill <bcovill at tekmap.ns.ca>
- * 
- * This Program is free software under the GPL (>=v2)
- * Read the file COPYING coming with GRASS for details
+/****************************************************************************
  *
- */
+ * MODULE:       r3.profile (based on r.profile)
+ *
+ * AUTHOR(S):    Bob Covill <bcovill tekmap.ns.ca> (r.profile)
+ *               Vaclav Petras <wenzeslaus gmail com> (r3.profile)
+ *
+ * PURPOSE:      Profiles (slices vertically) 3D raster at 2D coordinates
+ *
+ * COPYRIGHT:    (C) 2000-2016 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the file COPYING that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
 
 #include <stdlib.h>
 #include <grass/gis.h>
+#include <grass/raster3d.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
@@ -26,7 +35,7 @@
     const char *unit;
     int unit_id;
     double factor;
-    int fd, projection;
+    int projection;
     FILE *fp, *coor_fp;
     double res;
     char *null_string;
@@ -40,8 +49,8 @@
     struct Cell_head window;
     struct
     {
-        struct Option *opt1, *profile, *res, *output, *null_str, *coord_file,
-            *units;
+        struct Option *opt1, *profile, *res, *output, *raster_output,
+            *null_str, *coord_file, *units;
         struct Flag *g, *c, *m;
     }
     parm;
@@ -56,7 +65,7 @@
     module->description =
         _("Outputs the raster map layer values lying on user-defined line(s).");
 
-    parm.opt1 = G_define_standard_option(G_OPT_R_INPUT);
+    parm.opt1 = G_define_standard_option(G_OPT_R3_INPUT);
 
     parm.output = G_define_standard_option(G_OPT_F_OUTPUT);
     parm.output->required = NO;
@@ -64,6 +73,10 @@
     parm.output->description =
         _("Name of file for output (use output=- for stdout)");
 
+    parm.raster_output = G_define_standard_option(G_OPT_R_OUTPUT);
+    parm.raster_output->key = "raster_output";
+    parm.raster_output->required = NO;
+
     parm.profile = G_define_standard_option(G_OPT_M_COORDS);
     parm.profile->required = NO;
     parm.profile->multiple = YES;
@@ -161,13 +174,22 @@
     if (parm.g->answer)
         coords = 1;
 
+    RASTER3D_Region region;
+
+    Rast3d_init_defaults();
+    Rast3d_get_window(&region);
+    G_message("region west=%f ewres=%f north=%f nsres=%f", region.west,
+              region.ew_res, region.north, region.ns_res);
+
     /* Open Raster File */
-    fd = Rast_open_old(name, "");
+    int cache = RASTER3D_USE_CACHE_DEFAULT;
+    int type = FCELL_TYPE;      /* or RASTER3D_TILE_SAME_AS_FILE */
+    /* TODO: mapset support correct? */
+    RASTER3D_Map *fd =
+        Rast3d_open_cell_old(name, "", RASTER3D_DEFAULT_WINDOW, type, cache);
+    if (!fd)
+        G_fatal_error(_("Unable to open file <%s>"), name);
 
-    /* initialize color structure */
-    if (clr)
-        Rast_read_colors(name, "", &colors);
-
     /* Open ASCII file for output or stdout */
     outfile = parm.output->answer;
 
@@ -178,7 +200,7 @@
         G_fatal_error(_("Unable to open file <%s>"), outfile);
 
     /* Get Raster Type */
-    data_type = Rast_get_map_type(fd);
+    data_type = TYPE_DOUBLE;
     /* Done with file */
 
     /* Show message giving output format */
@@ -189,88 +211,131 @@
                 unit);
     else
         sprintf(formatbuff, _("Along track dist. [%s], Elevation"), unit);
-    if (clr)
-        strcat(formatbuff, _(" RGB color"));
+
     G_message("%s", formatbuff);
 
-    /* Get Profile Start Coords */
-    if (parm.coord_file->answer) {
-        if (strcmp("-", parm.coord_file->answer) == 0)
-            coor_fp = stdin;
-        else
-            coor_fp = fopen(parm.coord_file->answer, "r");
+    struct DoubleList values;
+    int output_initialized = FALSE;
+    int outfd;
+    void *output_buff = NULL;
+    size_t cell_size = Rast_cell_size(data_type);
+    struct Cell_head output_region;
 
-        if (coor_fp == NULL)
-            G_fatal_error(_("Could not open <%s>"), parm.coord_file->answer);
+    int depth;
 
+    for (depth = region.depths - 1; depth >= 0; depth--) {
+        double_list_init(&values);
+        /* Get Profile Start Coords */
+        if (parm.coord_file->answer) {
+            if (strcmp("-", parm.coord_file->answer) == 0)
+                /* coor_fp = stdin; */
+                G_fatal_error(_("Standard input is not yet supported"));
+            else
+                coor_fp = fopen(parm.coord_file->answer, "r");
 
-        for (n = 1; input(b1, ebuf, b2, nbuf, label, coor_fp); n++) {
-            G_debug(4, "stdin line %d: ebuf=[%s]  nbuf=[%s]", n, ebuf, nbuf);
-            if (!G_scan_easting(ebuf, &e2, G_projection()) ||
-                !G_scan_northing(nbuf, &n2, G_projection()))
-                G_fatal_error(_("Invalid coordinates %s %s"), ebuf, nbuf);
+            if (coor_fp == NULL)
+                G_fatal_error(_("Could not open <%s>"),
+                              parm.coord_file->answer);
 
-            if (havefirst)
-                do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
-                           fp, null_string, unit, factor);
-            e1 = e2;
-            n1 = n2;
-            havefirst = TRUE;
-        }
 
-        if (coor_fp != stdin)
-            fclose(coor_fp);
-    }
-    else {
-        /* Coords given on the Command Line using the profile= option */
-        for (i = 0; parm.profile->answers[i]; i += 2) {
-            /* Test for number coordinate pairs */
-            k = i;
-        }
+            for (n = 1; input(b1, ebuf, b2, nbuf, label, coor_fp); n++) {
+                G_debug(4, "stdin line %d: ebuf=[%s]  nbuf=[%s]", n, ebuf,
+                        nbuf);
+                if (!G_scan_easting(ebuf, &e2, G_projection()) ||
+                    !G_scan_northing(nbuf, &n2, G_projection()))
+                    G_fatal_error(_("Invalid coordinates %s %s"), ebuf, nbuf);
 
-        if (k == 0) {
-            /* Only one coordinate pair supplied */
-            G_scan_easting(parm.profile->answers[0], &e1, G_projection());
-            G_scan_northing(parm.profile->answers[1], &n1, G_projection());
-            e2 = e1;
-            n2 = n1;
+                if (havefirst)
+                    do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
+                               fp, null_string, unit, factor, &region, depth,
+                               &values);
+                e1 = e2;
+                n1 = n2;
+                havefirst = TRUE;
+            }
 
-            /* Get profile info */
-            do_profile(e1, e2, n1, n2, coords, res, fd, data_type, fp,
-                       null_string, unit, factor);
+            /* TODO: we can't use stdin in loop like this, need to store the coords */
+            if (coor_fp != stdin)
+                fclose(coor_fp);
         }
         else {
-            for (i = 0; i <= k - 2; i += 2) {
-                G_scan_easting(parm.profile->answers[i], &e1, G_projection());
-                G_scan_northing(parm.profile->answers[i + 1], &n1,
+            /* Coords given on the Command Line using the profile= option */
+            for (i = 0; parm.profile->answers[i]; i += 2) {
+                /* Test for number coordinate pairs */
+                k = i;
+            }
+
+            if (k == 0) {
+                /* Only one coordinate pair supplied */
+                G_scan_easting(parm.profile->answers[0], &e1, G_projection());
+                G_scan_northing(parm.profile->answers[1], &n1,
                                 G_projection());
-                G_scan_easting(parm.profile->answers[i + 2], &e2,
-                               G_projection());
-                G_scan_northing(parm.profile->answers[i + 3], &n2,
-                                G_projection());
+                e2 = e1;
+                n2 = n1;
 
                 /* Get profile info */
-                do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
-                           fp, null_string, unit, factor);
+                do_profile(e1, e2, n1, n2, coords, res, fd, data_type, fp,
+                           null_string, unit, factor, &region, depth,
+                           &values);
+            }
+            else {
+                for (i = 0; i <= k - 2; i += 2) {
+                    G_scan_easting(parm.profile->answers[i], &e1,
+                                   G_projection());
+                    G_scan_northing(parm.profile->answers[i + 1], &n1,
+                                    G_projection());
+                    G_scan_easting(parm.profile->answers[i + 2], &e2,
+                                   G_projection());
+                    G_scan_northing(parm.profile->answers[i + 3], &n2,
+                                    G_projection());
 
+                    /* Get profile info */
+                    do_profile(e1, e2, n1, n2, coords, res, fd, data_type,
+                               fp, null_string, unit, factor, &region, depth,
+                               &values);
+
+                }
             }
         }
+        if (!output_initialized) {
+            Rast_get_window(&output_region);
+            output_region.south = 0;
+            output_region.north = region.depths;
+            output_region.west = 0;
+            output_region.east = values.num_items;
+            /* TODO: make the distances in the x and y directions right */
+            output_region.ew_res = 1;
+            output_region.ns_res = 1;
+
+            Rast_set_output_window(&output_region);
+            outfd = Rast_open_new(parm.raster_output->answer, data_type);
+            output_buff = Rast_allocate_output_buf(data_type);
+            output_initialized = TRUE;
+        }
+        void *ptr = output_buff;
+        int i;
+
+        for (i = 0; i < values.num_items; i++) {
+            Rast_set_d_value(ptr, values.items[i], data_type);
+            ptr = G_incr_void_ptr(ptr, cell_size);
+        }
+        Rast_put_row(outfd, output_buff, data_type);
+        double_list_free(&values);
     }
+    Rast_close(outfd);
 
-    Rast_close(fd);
+    Rast3d_close(fd);
     fclose(fp);
 
-    if (clr)
-        Rast_free_colors(&colors);
-
     exit(EXIT_SUCCESS);
 }                               /* Done with main */
 
 /* Calculate the Profile Now */
 /* Establish parameters */
 int do_profile(double e1, double e2, double n1, double n2,
-               int coords, double res, int fd, int data_type, FILE * fp,
-               char *null_string, const char *unit, double factor)
+               int coords, double res, RASTER3D_Map * fd, int data_type,
+               FILE * fp, char *null_string, const char *unit, double factor,
+               RASTER3D_Region * region, int depth, struct DoubleList *values)
 {
     double rows, cols, LEN;
     double Y, X, k;
@@ -289,8 +354,8 @@
         /* Special case for no movement */
         e = e1;
         n = n1;
-        read_rast(e, n, dist / factor, fd, coords, data_type, fp,
-                  null_string);
+        read_rast(e, n, dist / factor, fd, coords, data_type, fp, null_string,
+                  region, depth, values);
     }
 
     k = res / hypot(rows, cols);
@@ -309,7 +374,7 @@
         /* SE Quad or due east */
         for (e = e1, n = n1; e < e2 || n > n2; e += X, n -= Y) {
             read_rast(e, n, dist / factor, fd, coords, data_type, fp,
-                      null_string);
+                      null_string, region, depth, values);
             /* d+=res; */
             dist += G_distance(e - X, n + Y, e, n);
         }
@@ -319,7 +384,7 @@
         /* NE Quad  or due north */
         for (e = e1, n = n1; e < e2 || n < n2; e += X, n += Y) {
             read_rast(e, n, dist / factor, fd, coords, data_type, fp,
-                      null_string);
+                      null_string, region, depth, values);
             /* d+=res; */
             dist += G_distance(e - X, n - Y, e, n);
         }
@@ -329,7 +394,7 @@
         /* SW Quad or due south */
         for (e = e1, n = n1; e > e2 || n > n2; e -= X, n -= Y) {
             read_rast(e, n, dist / factor, fd, coords, data_type, fp,
-                      null_string);
+                      null_string, region, depth, values);
             /* d+=res; */
             dist += G_distance(e + X, n + Y, e, n);
         }
@@ -339,7 +404,7 @@
         /* NW Quad  or due west */
         for (e = e1, n = n1; e > e2 || n < n2; e -= X, n += Y) {
             read_rast(e, n, dist / factor, fd, coords, data_type, fp,
-                      null_string);
+                      null_string, region, depth, values);
             /* d+=res; */
             dist += G_distance(e + X, n - Y, e, n);
         }

Deleted: grass-addons/grass7/raster3d/r3.profile/r.profile.html
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/r.profile.html	2016-09-19 01:32:08 UTC (rev 69521)
+++ grass-addons/grass7/raster3d/r3.profile/r.profile.html	2016-09-19 02:09:40 UTC (rev 69522)
@@ -1,169 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-This program outputs two or four column (with <b>-g</b>) data to stdout or 
-an ASCII file. The default two column output consists of cumulative profile 
-length and raster value. The optional four column output consists 
-of easting, northing, cumulative profile length, and raster value. Profile
-end or "turning" points can be set manually with the <b>coordinates</b>
-argument. The profile resolution, or distance between profile
-points, is obtained from the current region resolution, or can be manually
-set with the <b>resolution</b> argument.
-
-<p>
-The <b>coordinates</b> parameter can be set to comma separated geographic
-coordinates for profile line endpoints.
-Alternatively the coordinate pairs can be piped from the text file specified
-by <b>file</b> option, or if set to "-", from <tt>stdin</tt>.
-In these cases the coordinate pairs should be given one comma separated pair
-per line.
-
-<p>
-The <b>resolution</b> parameter sets the distance between each profile point
-(resolution). The resolution must be provided in GRASS database units (i.e.
-decimal degrees for Lat Long databases and meters for UTM). By default
-<em>r.profile</em> uses the resolution of the current GRASS region.
-
-<p>
-The <b>null</b> parameter can optionally be set to change the character
-string representing null values.
-
-
-<h2>OUTPUT FORMAT</h2>
-
-The multi column output from <em>r.profile</em> is intended for easy use in
-other programs.  The output can be piped (|) directly into other programs or
-saved to a file for later use. Output with geographic coordinates (<em>-g</em>)
-is compatible with <em><a href="v.in.ascii.html">v.in.ascii</a></em> and can 
-be piped direcly into this program.
-
-<div class="code"><pre>
-r.profile -g input=elevation coordinates=... | v.in.ascii output=elevation_profile separator=space
-</pre></div>
-
-The 2 column output is compatible with most plotting programs.
-<p>
-The optional RGB output provides the associated GRASS colour value for
-each profile point.
-
-<p>Option <b>units</b> enables to set units of the profile length output.
-If the units are not specified, current location units will be used.
-In case of geographic locations (latitude/longitude), meters are used as default unit.
-
-<h2>NOTES</h2>
-
-The profile resolution is measured exactly from the supplied end or
-"turning" point along the profile. The end of a profile segment will be an
-exact multiple of the profile resolution and will therefore not always match
-the end point coordinates entered for the segmanet.
-
-<p>To extract the numbers in scripts, following parameters can be used:
-<div class="code"><pre>
-r.profile input=dgm12.5 coordinates=3570631,5763556 2>/dev/null
-</pre></div>
-
-This filters out the everything except the numbers.
-
-<h2>EXAMPLES</h2>
-
-<h3>Extraction of values along profile defined by coordinates (variant 1)</h3>
-
-Extract a profile with coordinates (wayoints) provided on the command line
-(North Carolina data set):
-
-<div class="code"><pre>
-g.region raster=elevation -p
-r.profile -g input=elevation output=profile_points.csv \
-          coordinates=641712,226095,641546,224138,641546,222048,641049,221186
-</pre></div>
-This will extract a profile along the track defined by the three coordinate
-pairs. The output file "profile_points.csv" contains
-east,north,distance,value (here: elevation).
-<p><br>
-
-
-<!-- d.where no longer there
-<b>Example 2</b><br>
-Extract a profile with coordinates provided from standard input or an external file:
-<p>First create a points file with <em><a href="d.where.html">d.where</a></em>
-
-<div class="code"><pre>
-d.where > saved.points
-</pre></div>
-
-Then pipe the points file into r.profile
-
-<div class="code"><pre>
-cat saved.points | r.profile input=elev.rast output=profile.pts file=-
-</pre></div>
-
-The advantage of this method is that the same profile points can be piped
-into different GRASS rasters by changing the input parameter.
-<p>
-With this method the coordinates must be given as space or tab separated
-easting and northing. Labels after these values are ignored.
-<p>
-Another example using d.where:
-
-<div class="code"><pre>
-d.where | r.profile elevation.dem
-</pre></div>
-<p><br>
--->
-
-<h3>Extraction of values along profile defined by coordinates (variant 2)</h3>
-
-Coordinate pairs can also being "piped" into <em>r.profile</em> (variant 2a):
-
-<div class="code"><pre>
-r.profile elevation resolution=1000 file=- << EOF
-641712,226095
-641546,224138
-641546,222048
-641049,221186
-EOF
-</pre></div>
-
-<p>
-Coordinate pairs can also being "piped" into <em>r.profile</em> (variant 2b):
-
-<div class="code"><pre>
-echo "641712,226095
-641546,224138
-641546,222048
-641049,221186" > coors.txt
-cat coors.txt | r.profile elevation resolution=1000 file=-
-</pre></div>
-
-The output is printed into the terminal (unless the <em>output</em> parameter
-is used) and looks as follows:
-
-<div class="code"><pre>
-Using resolution: 1000 [meters]
-Output columns:
-Along track dist. [meters], Elevation
-Approx. transect length: 1964.027749 [meters]
- 0.000000 84.661507
- 1000.000000 98.179062
-Approx. transect length: 2090.000000 [meters]
- 1964.027749 83.638138
- 2964.027749 89.141029
- 3964.027749 78.497757
-Approx. transect length: 995.014070 [meters]
- 4054.027749 73.988029
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="v.in.ascii.html">v.in.ascii</a>,
-<a href="r.what.html">r.what</a>,
-<a href="r.transect.html">r.transect</a>,
-<a href="wxGUI.html">wxGUI profile tool</a>
-</em>
-
-
-<h2>AUTHOR</h2>
-<a href="mailto:bcovill at tekmap.ns.ca">Bob Covill</a>
-
-<p>
-<i>Last changed: $Date$</i>

Copied: grass-addons/grass7/raster3d/r3.profile/r3.profile.html (from rev 69520, grass-addons/grass7/raster3d/r3.profile/r.profile.html)
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/r3.profile.html	                        (rev 0)
+++ grass-addons/grass7/raster3d/r3.profile/r3.profile.html	2016-09-19 02:09:40 UTC (rev 69522)
@@ -0,0 +1,169 @@
+<h2>DESCRIPTION</h2>
+
+This program outputs two or four column (with <b>-g</b>) data to stdout or 
+an ASCII file. The default two column output consists of cumulative profile 
+length and raster value. The optional four column output consists 
+of easting, northing, cumulative profile length, and raster value. Profile
+end or "turning" points can be set manually with the <b>coordinates</b>
+argument. The profile resolution, or distance between profile
+points, is obtained from the current region resolution, or can be manually
+set with the <b>resolution</b> argument.
+
+<p>
+The <b>coordinates</b> parameter can be set to comma separated geographic
+coordinates for profile line endpoints.
+Alternatively the coordinate pairs can be piped from the text file specified
+by <b>file</b> option, or if set to "-", from <tt>stdin</tt>.
+In these cases the coordinate pairs should be given one comma separated pair
+per line.
+
+<p>
+The <b>resolution</b> parameter sets the distance between each profile point
+(resolution). The resolution must be provided in GRASS database units (i.e.
+decimal degrees for Lat Long databases and meters for UTM). By default
+<em>r.profile</em> uses the resolution of the current GRASS region.
+
+<p>
+The <b>null</b> parameter can optionally be set to change the character
+string representing null values.
+
+
+<h2>OUTPUT FORMAT</h2>
+
+The multi column output from <em>r.profile</em> is intended for easy use in
+other programs.  The output can be piped (|) directly into other programs or
+saved to a file for later use. Output with geographic coordinates (<em>-g</em>)
+is compatible with <em><a href="v.in.ascii.html">v.in.ascii</a></em> and can 
+be piped direcly into this program.
+
+<div class="code"><pre>
+r.profile -g input=elevation coordinates=... | v.in.ascii output=elevation_profile separator=space
+</pre></div>
+
+The 2 column output is compatible with most plotting programs.
+<p>
+The optional RGB output provides the associated GRASS colour value for
+each profile point.
+
+<p>Option <b>units</b> enables to set units of the profile length output.
+If the units are not specified, current location units will be used.
+In case of geographic locations (latitude/longitude), meters are used as default unit.
+
+<h2>NOTES</h2>
+
+The profile resolution is measured exactly from the supplied end or
+"turning" point along the profile. The end of a profile segment will be an
+exact multiple of the profile resolution and will therefore not always match
+the end point coordinates entered for the segmanet.
+
+<p>To extract the numbers in scripts, following parameters can be used:
+<div class="code"><pre>
+r.profile input=dgm12.5 coordinates=3570631,5763556 2>/dev/null
+</pre></div>
+
+This filters out the everything except the numbers.
+
+<h2>EXAMPLES</h2>
+
+<h3>Extraction of values along profile defined by coordinates (variant 1)</h3>
+
+Extract a profile with coordinates (wayoints) provided on the command line
+(North Carolina data set):
+
+<div class="code"><pre>
+g.region raster=elevation -p
+r.profile -g input=elevation output=profile_points.csv \
+          coordinates=641712,226095,641546,224138,641546,222048,641049,221186
+</pre></div>
+This will extract a profile along the track defined by the three coordinate
+pairs. The output file "profile_points.csv" contains
+east,north,distance,value (here: elevation).
+<p><br>
+
+
+<!-- d.where no longer there
+<b>Example 2</b><br>
+Extract a profile with coordinates provided from standard input or an external file:
+<p>First create a points file with <em><a href="d.where.html">d.where</a></em>
+
+<div class="code"><pre>
+d.where > saved.points
+</pre></div>
+
+Then pipe the points file into r.profile
+
+<div class="code"><pre>
+cat saved.points | r.profile input=elev.rast output=profile.pts file=-
+</pre></div>
+
+The advantage of this method is that the same profile points can be piped
+into different GRASS rasters by changing the input parameter.
+<p>
+With this method the coordinates must be given as space or tab separated
+easting and northing. Labels after these values are ignored.
+<p>
+Another example using d.where:
+
+<div class="code"><pre>
+d.where | r.profile elevation.dem
+</pre></div>
+<p><br>
+-->
+
+<h3>Extraction of values along profile defined by coordinates (variant 2)</h3>
+
+Coordinate pairs can also being "piped" into <em>r.profile</em> (variant 2a):
+
+<div class="code"><pre>
+r.profile elevation resolution=1000 file=- << EOF
+641712,226095
+641546,224138
+641546,222048
+641049,221186
+EOF
+</pre></div>
+
+<p>
+Coordinate pairs can also being "piped" into <em>r.profile</em> (variant 2b):
+
+<div class="code"><pre>
+echo "641712,226095
+641546,224138
+641546,222048
+641049,221186" > coors.txt
+cat coors.txt | r.profile elevation resolution=1000 file=-
+</pre></div>
+
+The output is printed into the terminal (unless the <em>output</em> parameter
+is used) and looks as follows:
+
+<div class="code"><pre>
+Using resolution: 1000 [meters]
+Output columns:
+Along track dist. [meters], Elevation
+Approx. transect length: 1964.027749 [meters]
+ 0.000000 84.661507
+ 1000.000000 98.179062
+Approx. transect length: 2090.000000 [meters]
+ 1964.027749 83.638138
+ 2964.027749 89.141029
+ 3964.027749 78.497757
+Approx. transect length: 995.014070 [meters]
+ 4054.027749 73.988029
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.in.ascii.html">v.in.ascii</a>,
+<a href="r.what.html">r.what</a>,
+<a href="r.transect.html">r.transect</a>,
+<a href="wxGUI.html">wxGUI profile tool</a>
+</em>
+
+
+<h2>AUTHOR</h2>
+<a href="mailto:bcovill at tekmap.ns.ca">Bob Covill</a>
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster3d/r3.profile/read_rast.c
===================================================================
--- grass-addons/grass7/raster3d/r3.profile/read_rast.c	2016-09-19 01:32:08 UTC (rev 69521)
+++ grass-addons/grass7/raster3d/r3.profile/read_rast.c	2016-09-19 02:09:40 UTC (rev 69522)
@@ -1,22 +1,28 @@
 /*
- * Copyright (C) 2000 by the GRASS Development Team
- * Author: Bob Covill <bcovill at tekmap.ns.ca>
- * 
- * This Program is free software under the GPL (>=v2)
- * Read the file COPYING coming with GRASS for details
+ * Reading raster and writing output during profiling
  *
+ * Authors:
+ *   Bob Covill <bcovill tekmap.ns.ca>
+ *   Vaclav Petras <wenzeslaus gmail com>
+ *
+ * Copyright 2000-2016 by Bob Covill, and the GRASS Development Team
+ *
+ * This program is free software licensed under the GPL (>=v2).
+ * Read the COPYING file that comes with GRASS for details.
+ *
  */
 
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
 #include "local_proto.h"
-
-int read_rast(double east, double north, double dist, int fd, int coords,
-              RASTER_MAP_TYPE data_type, FILE * fp, char *null_string)
+#include "double_list.h"
+int read_rast(double east, double north, double dist, RASTER3D_Map * fd,
+              int coords, RASTER_MAP_TYPE data_type, FILE * fp,
+              char *null_string, RASTER3D_Region * region, int depth,
+              struct DoubleList *values)
 {
     static DCELL *dcell;
-    static int cur_row = -1;
     static CELL nullcell;
     static int nrows, ncols;
     static struct Cell_head window;
@@ -31,44 +37,46 @@
         ncols = window.cols;
     }
 
-    row = (window.north - north) / window.ns_res;
-    col = (east - window.west) / window.ew_res;
+    int unused;
+
+    Rast3d_location2coord(region, north, east, 0, &col, &row, &unused);
     G_debug(4, "row=%d:%d  col=%d:%d", row, nrows, col, ncols);
 
+    /* TODO: use 3D region */
     if ((row < 0) || (row >= nrows) || (col < 0) || (col >= ncols))
         outofbounds = TRUE;
 
+    double val;
+
     if (!outofbounds) {
-        if (row != cur_row)
-            Rast_get_d_row(fd, dcell, row);
-        cur_row = row;
+        Rast3d_get_value(fd, col, row, depth, &val, DCELL_TYPE);
     }
 
+    if (values)
+        double_list_add_item(values, val);
+
+    /* TODO: handle textual outputs systematically */
+    /* TODO: enable colors */
+    /* TODO: enable xyz coordinates output */
+    /*
+       if (coords)
+       fprintf(fp, "%f %f", east, north);
+     */
+
     if (coords)
-        fprintf(fp, "%f %f", east, north);
+        fprintf(fp, "%f %d", dist, depth);
 
-    fprintf(fp, " %f", dist);
+    /*fprintf(fp, " %f", dist); */
 
-    if (outofbounds || Rast_is_d_null_value(&dcell[col]))
+    if (outofbounds || Rast_is_d_null_value(&val))
         fprintf(fp, " %s", null_string);
     else {
         if (data_type == CELL_TYPE)
-            fprintf(fp, " %d", (int)dcell[col]);
+            fprintf(fp, " %d", (int)val);
         else
-            fprintf(fp, " %f", dcell[col]);
+            fprintf(fp, " %f", val);
     }
 
-    if (clr) {
-        int red, green, blue;
-
-        if (outofbounds)
-            Rast_get_c_color(&nullcell, &red, &green, &blue, &colors);
-        else
-            Rast_get_d_color(&dcell[col], &red, &green, &blue, &colors);
-
-        fprintf(fp, " %03d:%03d:%03d", red, green, blue);
-    }
-
     fprintf(fp, "\n");
 
     return 0;



More information about the grass-commit mailing list