[GRASS-SVN] r67744 - grass/branches/releasebranch_7_0/raster/r.external
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 6 10:10:33 PST 2016
Author: martinl
Date: 2016-02-06 10:10:33 -0800 (Sat, 06 Feb 2016)
New Revision: 67744
Modified:
grass/branches/releasebranch_7_0/raster/r.external/list.c
grass/branches/releasebranch_7_0/raster/r.external/main.c
grass/branches/releasebranch_7_0/raster/r.external/proto.h
Log:
r.external: added -t flag for listing bands
(merge r67284 from trunk)
Modified: grass/branches/releasebranch_7_0/raster/r.external/list.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.external/list.c 2016-02-06 17:53:59 UTC (rev 67743)
+++ grass/branches/releasebranch_7_0/raster/r.external/list.c 2016-02-06 18:10:33 UTC (rev 67744)
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <grass/gis.h>
+#include <grass/gprojects.h>
#include <grass/glocale.h>
#include <grass/gis.h>
@@ -43,3 +44,50 @@
pszRWFlag, GDALGetDriverLongName(hDriver));
}
}
+
+void list_bands(struct Cell_head *cellhd, GDALDatasetH hDS)
+{
+ struct Cell_head loc_wind;
+ struct Key_Value *proj_info = NULL, *proj_units = NULL;
+ struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
+ int n_bands, i_band, proj_same;
+ GDALRasterBandH hBand;
+ GDALDataType gdal_type;
+
+ if (GPJ_wkt_to_grass(cellhd, &proj_info,
+ &proj_units, GDALGetProjectionRef(hDS), 0) < 0) {
+ proj_same = 0;
+ }
+ else {
+
+ G_get_default_window(&loc_wind);
+ if (loc_wind.proj != PROJECTION_XY) {
+ loc_proj_info = G_get_projinfo();
+ loc_proj_units = G_get_projunits();
+ }
+
+
+ if (loc_wind.proj != cellhd->proj ||
+ (G_compare_projections
+ (loc_proj_info, loc_proj_units, proj_info, proj_units)) < 0) {
+ proj_same = 0;
+ }
+ else {
+ proj_same = 1;
+ }
+
+ }
+
+ n_bands = GDALGetRasterCount(hDS);
+
+ for (i_band = 1; i_band <= n_bands; i_band++) {
+
+ hBand = GDALGetRasterBand(hDS, i_band);
+ gdal_type = GDALGetRasterDataType(hBand);
+
+ fprintf(stdout, "%d,%s,%d\n", i_band, GDALGetDataTypeName(gdal_type),
+ proj_same);
+
+ }
+}
+
Modified: grass/branches/releasebranch_7_0/raster/r.external/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.external/main.c 2016-02-06 17:53:59 UTC (rev 67743)
+++ grass/branches/releasebranch_7_0/raster/r.external/main.c 2016-02-06 18:10:33 UTC (rev 67744)
@@ -44,7 +44,7 @@
struct Option *input, *source, *output, *band, *title;
} parm;
struct {
- struct Flag *o, *f, *e, *h, *v;
+ struct Flag *o, *f, *e, *h, *v, *t;
} flag;
int min_band, max_band, band;
struct band_info info;
@@ -116,6 +116,14 @@
flag.v->key = 'v';
flag.v->description = _("Flip vertically");
+ flag.t = G_define_flag();
+ flag.t->key = 't';
+ flag.t->label =
+ _("List available bands including band type in dataset and exit");
+ flag.t->description = _("Format: band number,type,projection check");
+ flag.t->guisection = _("Print");
+ flag.t->suppress_required = YES;
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -171,6 +179,13 @@
setup_window(&cellhd, hDS, &flip);
+ if (flag.t->answer) {
+ list_bands(&cellhd, hDS);
+ /* close the GDALDataset to avoid segfault in libgdal */
+ GDALClose(hDS);
+ exit(EXIT_SUCCESS);
+ }
+
check_projection(&cellhd, hDS, flag.o->answer);
Rast_set_window(&cellhd);
Modified: grass/branches/releasebranch_7_0/raster/r.external/proto.h
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.external/proto.h 2016-02-06 17:53:59 UTC (rev 67743)
+++ grass/branches/releasebranch_7_0/raster/r.external/proto.h 2016-02-06 18:10:33 UTC (rev 67744)
@@ -35,6 +35,7 @@
/* list.c */
void list_layers(FILE *, const char *);
void list_formats(void);
+void list_bands(struct Cell_head *, GDALDatasetH);
/* proj.c */
void check_projection(struct Cell_head *, GDALDatasetH, int);
More information about the grass-commit
mailing list