Ver código fonte

r.profile: enable to use more units

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62046 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 10 anos atrás
pai
commit
7e336e241b

+ 19 - 12
raster/r.profile/main.c

@@ -24,6 +24,7 @@ int main(int argc, char *argv[])
 {
 {
     char *name, *outfile;
     char *name, *outfile;
     const char *unit;
     const char *unit;
+    int unit_id;
     double factor;
     double factor;
     int fd, projection;
     int fd, projection;
     FILE *fp, *coor_fp;
     FILE *fp, *coor_fp;
@@ -39,7 +40,7 @@ int main(int argc, char *argv[])
     struct Cell_head window;
     struct Cell_head window;
     struct
     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;
 	struct Flag *g, *c, *m;
     }
     }
     parm;
     parm;
@@ -100,16 +101,15 @@ int main(int argc, char *argv[])
     parm.c->description =
     parm.c->description =
 	_("Output RRR:GGG:BBB color values for each profile point");
 	_("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))
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 	exit(EXIT_FAILURE);
 
 
-
     clr = 0;
     clr = 0;
     if (parm.c->answer)
     if (parm.c->answer)
 	clr = 1;		/* color output */
 	clr = 1;		/* color output */
@@ -124,14 +124,21 @@ int main(int argc, char *argv[])
     G_get_window(&window);
     G_get_window(&window);
     projection = G_projection();
     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 */
     /* keep meters in case of latlon */
-    if (parm.m->answer || projection == 3)
-    {
+    else if (projection == PROJECTION_LL) {
         factor = 1;
         factor = 1;
         unit = "meters";
         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) {
     if (parm.res->answer) {

+ 3 - 3
raster/r.profile/r.profile.html

@@ -45,9 +45,9 @@ The 2 column output is compatible with most plotting programs.
 The optional RGB output provides the associated GRASS colour value for
 The optional RGB output provides the associated GRASS colour value for
 each profile point.
 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>
 <h2>EXAMPLES</h2>
 
 

+ 1 - 1
raster/r.profile/testsuite/test_profile_ncspm.py

@@ -93,7 +93,7 @@ class TestProfileNCSPM(TestCase):
         self.assertIn('10 [meters]', rprofile.outputs.stderr)  # resolution
         self.assertIn('10 [meters]', rprofile.outputs.stderr)  # resolution
 
 
     def test_profile_m(self):
     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])
                                 coordinates=[637656, 224222, 637766, 224289])
         self.assertModule(rprofile)
         self.assertModule(rprofile)
         self.assertIn('128.798294 [meters]', rprofile.outputs.stderr)  # distance
         self.assertIn('128.798294 [meters]', rprofile.outputs.stderr)  # distance