Browse Source

r.in.gdal, r.external, r.region: add flag to auto-adjust cell header in lat/lon

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70664 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 8 years ago
parent
commit
9f73b4db85
3 changed files with 39 additions and 5 deletions
  1. 11 1
      raster/r.external/main.c
  2. 15 3
      raster/r.in.gdal/main.c
  3. 13 1
      raster/r.region/main.c

+ 11 - 1
raster/r.external/main.c

@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
 	struct Option *input, *source, *output, *band, *title;
 	struct Option *input, *source, *output, *band, *title;
     } parm;
     } parm;
     struct {
     struct {
-	struct Flag *o, *f, *e, *h, *v, *t;
+	struct Flag *o, *f, *e, *h, *v, *t, *a;
     } flag;
     } flag;
     int min_band, max_band, band;
     int min_band, max_band, band;
     struct band_info info;
     struct band_info info;
@@ -108,6 +108,11 @@ int main(int argc, char *argv[])
     flag.e->label = _("Extend region extents based on new dataset");
     flag.e->label = _("Extend region extents based on new dataset");
     flag.e->description = _("Also updates the default region if in the PERMANENT mapset");
     flag.e->description = _("Also updates the default region if in the PERMANENT mapset");
 
 
+    flag.a = G_define_flag();
+    flag.a->key = 'a';
+    flag.a->label = _("Auto-adjustment for lat/lon");
+    flag.a->description = _("Attempt to fix small precision errors in resolution and extents");
+
     flag.h = G_define_flag();
     flag.h = G_define_flag();
     flag.h->key = 'h';
     flag.h->key = 'h';
     flag.h->description = _("Flip horizontally");
     flag.h->description = _("Flip horizontally");
@@ -188,6 +193,11 @@ int main(int argc, char *argv[])
 
 
     check_projection(&cellhd, hDS, flag.o->answer);
     check_projection(&cellhd, hDS, flag.o->answer);
 
 
+    if (flag.a->answer && cellhd.proj == PROJECTION_LL) {
+	G_adjust_Cell_head(&cellhd, 1, 1);
+	G_adjust_window_ll(&cellhd);
+    }
+
     Rast_set_window(&cellhd);
     Rast_set_window(&cellhd);
 
 
     if (parm.band->answer)
     if (parm.band->answer)

+ 15 - 3
raster/r.in.gdal/main.c

@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
 	              *rat;
 	              *rat;
     } parm;
     } parm;
     struct Flag *flag_o, *flag_e, *flag_k, *flag_f, *flag_l, *flag_c, *flag_p,
     struct Flag *flag_o, *flag_e, *flag_k, *flag_f, *flag_l, *flag_c, *flag_p,
-        *flag_j;
+        *flag_j, *flag_a;
 
 
     /* -------------------------------------------------------------------- */
     /* -------------------------------------------------------------------- */
     /*      Initialize.                                                     */
     /*      Initialize.                                                     */
@@ -208,6 +208,11 @@ int main(int argc, char *argv[])
     flag_l->description =
     flag_l->description =
 	_("Force Lat/Lon maps to fit into geographic coordinates (90N,S; 180E,W)");
 	_("Force Lat/Lon maps to fit into geographic coordinates (90N,S; 180E,W)");
 
 
+    flag_a = G_define_flag();
+    flag_a->key = 'a';
+    flag_a->label = _("Auto-adjustment for lat/lon");
+    flag_a->description = _("Attempt to fix small precision errors in resolution and extents");
+
     flag_k = G_define_flag();
     flag_k = G_define_flag();
     flag_k->key = 'k';
     flag_k->key = 'k';
     flag_k->description =
     flag_k->description =
@@ -379,10 +384,12 @@ int main(int argc, char *argv[])
 	cellhd.ns_res = fabs(adfGeoTransform[5]);
 	cellhd.ns_res = fabs(adfGeoTransform[5]);
 	cellhd.ns_res3 = fabs(adfGeoTransform[5]);
 	cellhd.ns_res3 = fabs(adfGeoTransform[5]);
 	cellhd.south = cellhd.north - cellhd.ns_res * cellhd.rows;
 	cellhd.south = cellhd.north - cellhd.ns_res * cellhd.rows;
+
 	cellhd.west = adfGeoTransform[0];
 	cellhd.west = adfGeoTransform[0];
 	cellhd.ew_res = fabs(adfGeoTransform[1]);
 	cellhd.ew_res = fabs(adfGeoTransform[1]);
 	cellhd.ew_res3 = fabs(adfGeoTransform[1]);
 	cellhd.ew_res3 = fabs(adfGeoTransform[1]);
 	cellhd.east = cellhd.west + cellhd.cols * cellhd.ew_res;
 	cellhd.east = cellhd.west + cellhd.cols * cellhd.ew_res;
+
 	cellhd.top = 1.;
 	cellhd.top = 1.;
 	cellhd.bottom = 0.;
 	cellhd.bottom = 0.;
 	cellhd.tb_res = 1.;
 	cellhd.tb_res = 1.;
@@ -581,12 +588,17 @@ int main(int argc, char *argv[])
 	}
 	}
     }
     }
 
 
-    G_message(_("Proceeding with import of %d raster bands..."),
-              GDALGetRasterCount(hDS));
+    if (GDALGetRasterCount(hDS) > 1)
+	G_message(_("Importing %d raster bands..."),
+		  GDALGetRasterCount(hDS));
 
 
     /* -------------------------------------------------------------------- */
     /* -------------------------------------------------------------------- */
     /*      Set the active window to match the available data.              */
     /*      Set the active window to match the available data.              */
     /* -------------------------------------------------------------------- */
     /* -------------------------------------------------------------------- */
+    if (flag_a->answer && cellhd.proj == PROJECTION_LL) {
+	G_adjust_Cell_head(&cellhd, 1, 1);
+	G_adjust_window_ll(&cellhd);
+    }
     Rast_set_window(&cellhd);
     Rast_set_window(&cellhd);
 
 
     /* -------------------------------------------------------------------- */
     /* -------------------------------------------------------------------- */

+ 13 - 1
raster/r.region/main.c

@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
     struct GModule *module;
     struct GModule *module;
     struct
     struct
     {
     {
-	struct Flag *dflt, *cur;
+	struct Flag *dflt, *cur, *llauto;
     } flag;
     } flag;
     struct
     struct
     {
     {
@@ -65,6 +65,12 @@ int main(int argc, char *argv[])
     flag.dflt->description = _("Set from default region");
     flag.dflt->description = _("Set from default region");
     flag.dflt->guisection = _("Existing");
     flag.dflt->guisection = _("Existing");
 
 
+    flag.llauto = G_define_flag();
+    flag.llauto->key = 'a';
+    flag.llauto->label = _("Auto-adjustment for lat/lon");
+    flag.llauto->description = _("Attempt to fix small precision errors in resolution and extents");
+    flag.llauto->guisection = _("Existing");
+
     /* parameters */
     /* parameters */
 
 
     parm.map = G_define_standard_option(G_OPT_R_MAP);
     parm.map = G_define_standard_option(G_OPT_R_MAP);
@@ -281,10 +287,16 @@ int main(int argc, char *argv[])
 
 
     G_adjust_Cell_head(&window, 1, 1);
     G_adjust_Cell_head(&window, 1, 1);
 
 
+    if (flag.llauto->answer && cellhd.proj == PROJECTION_LL) {
+	G_adjust_window_ll(&window);
+    }
+
     cellhd.north = window.north;
     cellhd.north = window.north;
     cellhd.south = window.south;
     cellhd.south = window.south;
     cellhd.east = window.east;
     cellhd.east = window.east;
     cellhd.west = window.west;
     cellhd.west = window.west;
+    cellhd.ns_res = window.ns_res;
+    cellhd.ew_res = window.ew_res;
 
 
     Rast_put_cellhd(parm.map->answer, &cellhd);
     Rast_put_cellhd(parm.map->answer, &cellhd);