[GRASS-SVN] r62046 - in grass/trunk/raster/r.profile: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Sep 20 20:37:22 PDT 2014
Author: annakrat
Date: 2014-09-20 20:37:22 -0700 (Sat, 20 Sep 2014)
New Revision: 62046
Modified:
grass/trunk/raster/r.profile/main.c
grass/trunk/raster/r.profile/r.profile.html
grass/trunk/raster/r.profile/testsuite/test_profile_ncspm.py
Log:
r.profile: enable to use more units
Modified: grass/trunk/raster/r.profile/main.c
===================================================================
--- grass/trunk/raster/r.profile/main.c 2014-09-20 14:46:53 UTC (rev 62045)
+++ grass/trunk/raster/r.profile/main.c 2014-09-21 03:37:22 UTC (rev 62046)
@@ -24,6 +24,7 @@
{
char *name, *outfile;
const char *unit;
+ int unit_id;
double factor;
int fd, projection;
FILE *fp, *coor_fp;
@@ -39,7 +40,7 @@
struct Cell_head window;
struct
{
- struct Option *opt1, *profile, *res, *output, *null_str, *coord_file;
+ struct Option *opt1, *profile, *res, *output, *null_str, *coord_file, *units;
struct Flag *g, *c, *m;
}
parm;
@@ -100,16 +101,15 @@
parm.c->description =
_("Output RRR:GGG:BBB color values for each profile point");
- parm.m = G_define_flag();
- parm.m->key = 'm';
- parm.m->label = _("Use meters instead of current location units");
- parm.m->description =
- _("Meters are used always in latlon locations");
+ parm.units = G_define_standard_option(G_OPT_M_UNITS);
+ parm.units->options = "meters,kilometers,feet,miles";
+ parm.units->label = parm.units->description;
+ parm.units->description = _("If units are not specified, current location units are used. "
+ "Meters are used by default in geographic (latlon) locations.");
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
-
clr = 0;
if (parm.c->answer)
clr = 1; /* color output */
@@ -124,14 +124,21 @@
G_get_window(&window);
projection = G_projection();
- /* get conversion factor to current units */
- unit = G_database_unit_name(1);
- factor = G_database_units_to_meters_factor();
+ /* get conversion factor and units name */
+ if (parm.units->answer) {
+ unit_id = G_units(parm.units->answer);
+ factor = 1. / G_meters_to_units_factor(unit_id);
+ unit = G_get_units_name(unit_id, 1, 0);
+ }
/* keep meters in case of latlon */
- if (parm.m->answer || projection == 3)
- {
+ else if (projection == PROJECTION_LL) {
factor = 1;
unit = "meters";
+ }
+ else {
+ /* get conversion factor to current units */
+ unit = G_database_unit_name(1);
+ factor = G_database_units_to_meters_factor();
}
if (parm.res->answer) {
Modified: grass/trunk/raster/r.profile/r.profile.html
===================================================================
--- grass/trunk/raster/r.profile/r.profile.html 2014-09-20 14:46:53 UTC (rev 62045)
+++ grass/trunk/raster/r.profile/r.profile.html 2014-09-21 03:37:22 UTC (rev 62046)
@@ -45,9 +45,9 @@
The optional RGB output provides the associated GRASS colour value for
each profile point.
-<p>Profile distance units correspond to the location units.
-Flag <b>-m</b> can be used to force output values in meters.
-In case of latlon locations and locations using meters, this flag does nothing.
+<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>EXAMPLES</h2>
Modified: grass/trunk/raster/r.profile/testsuite/test_profile_ncspm.py
===================================================================
--- grass/trunk/raster/r.profile/testsuite/test_profile_ncspm.py 2014-09-20 14:46:53 UTC (rev 62045)
+++ grass/trunk/raster/r.profile/testsuite/test_profile_ncspm.py 2014-09-21 03:37:22 UTC (rev 62046)
@@ -93,7 +93,7 @@
self.assertIn('10 [meters]', rprofile.outputs.stderr) # resolution
def test_profile_m(self):
- rprofile = SimpleModule('r.profile', input='elevation', flags='m',
+ rprofile = SimpleModule('r.profile', input='elevation', units='meters',
coordinates=[637656, 224222, 637766, 224289])
self.assertModule(rprofile)
self.assertIn('128.798294 [meters]', rprofile.outputs.stderr) # distance
More information about the grass-commit
mailing list