[GRASS-SVN] r54898 - grass/trunk/imagery/i.landsat.toar

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 4 07:22:41 PST 2013


Author: ychemin
Date: 2013-02-04 07:22:41 -0800 (Mon, 04 Feb 2013)
New Revision: 54898

Modified:
   grass/trunk/imagery/i.landsat.toar/landsat.h
   grass/trunk/imagery/i.landsat.toar/landsat_met.c
   grass/trunk/imagery/i.landsat.toar/main.c
Log:
New function to call metadata file values one by one for external use

Modified: grass/trunk/imagery/i.landsat.toar/landsat.h
===================================================================
--- grass/trunk/imagery/i.landsat.toar/landsat.h	2013-02-04 15:06:44 UTC (rev 54897)
+++ grass/trunk/imagery/i.landsat.toar/landsat.h	2013-02-04 15:22:41 UTC (rev 54898)
@@ -50,6 +50,8 @@
     char date[11];		/* Image acquisition date        */
     double dist_es;		/* Distance Earth-Sun            */
     double sun_elev;		/* Solar elevation               */
+    double sunza;		/* Solar Zenith Angle            */
+    double time;		/* Image Acquisition Time        */
 
     char sensor[10];		/* Type of sensor: MSS, TM, ETM+, OLI/TIRS */
     int bands;			/* Total number of bands         */

Modified: grass/trunk/imagery/i.landsat.toar/landsat_met.c
===================================================================
--- grass/trunk/imagery/i.landsat.toar/landsat_met.c	2013-02-04 15:06:44 UTC (rev 54897)
+++ grass/trunk/imagery/i.landsat.toar/landsat_met.c	2013-02-04 15:22:41 UTC (rev 54898)
@@ -110,6 +110,11 @@
     }
     chrncpy(lsat->creation, value, 10);
 
+    get_mtldata(mtldata, "SUN_AZIMUTH", value);
+    lsat->sunza = atof(value);
+    if( lsat->sunza == 0. )
+        G_warning("Sun azimuth is %f", lsat->sunza);
+
     get_mtldata(mtldata, "SUN_ELEVATION", value);
     if( value[0] == '\0' )
     {
@@ -119,6 +124,19 @@
     if( lsat->sun_elev == 0. )
         G_warning("Sun elevation is %f", lsat->sun_elev);
 
+    get_mtldata(mtldata, "SCENE_CENTER_TIME", value);
+    if( value[0] == '\0' )
+    {
+        get_mtldata(mtldata, "SCENE_CENTER_SCAN_TIME", value);
+    }
+    //Thanks Markus Metz !
+    //Remove trailing 'z'
+    value[strlen(value) - 1]='\0';
+    // Cast from hh:mm:ss into hh.hhh
+    G_llres_scan(value, &lsat->time);
+    if( lsat->time == 0. )
+        G_warning("Time is %f", lsat->time);
+
     /* Fill data with the basic sensor parameters */
     switch(lsat->number)
     {

Modified: grass/trunk/imagery/i.landsat.toar/main.c
===================================================================
--- grass/trunk/imagery/i.landsat.toar/main.c	2013-02-04 15:06:44 UTC (rev 54897)
+++ grass/trunk/imagery/i.landsat.toar/main.c	2013-02-04 15:22:41 UTC (rev 54898)
@@ -43,9 +43,9 @@
     RASTER_MAP_TYPE in_data_type;
 
     struct Option *input_prefix, *output_prefix, *metfn, *sensor, *adate, *pdate, *elev,
-	*bgain, *metho, *perc, *dark, *atmo;
+	*bgain, *metho, *perc, *dark, *atmo, *lsatmet;
     char *inputname, *met, *outputname, *sensorname;
-    struct Flag *frad;
+    struct Flag *frad, *print_meta;
 
     lsat_data lsat;
     char band_in[GNAME_MAX], band_out[GNAME_MAX];
@@ -183,11 +183,37 @@
     atmo->answer = "0.0";
     atmo->guisection = _("Settings");
 
+    lsatmet = G_define_option();
+    lsatmet->key = "lsatmet";
+    lsatmet->type = TYPE_STRING;
+    lsatmet->required = NO;
+    lsatmet->label = 	_("return value stored for a given metadata");
+    lsatmet->description = _("Required only if 'metfile' and -p given");
+    lsatmet->options = "number,creation,date,sun_elev,sensor,bands,sunza,time";
+    desc = NULL;
+    G_asprintf(&desc,
+	        "number;%s;creation;%s;date;%s;sun_elev;%s;sensor;%s;bands;%s;sunza;%s;time;%s",
+	        _("Landsat Number"),
+	        _("Creation timestamp"),
+	        _("Date"),
+	        _("Sun Elevation"),
+	        _("Sensor"),
+	        _("Bands count"),
+	        _("Sun Zenith Angle"),
+		_("Time"));
+    lsatmet->descriptions = desc;
+    lsatmet->guisection = _("Settings");
+
     /* define the different flags */
     frad = G_define_flag();
     frad->key = 'r';
     frad->description = _("Output at-sensor radiance for all bands");
 
+    /* define the different flags */
+    print_meta = G_define_flag();
+    print_meta->key = 'p';
+    print_meta->description = _("Print output metadata info");
+
     /* options and afters parser */
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -234,6 +260,36 @@
     {
         lsat.flag = METADATAFILE;
         lsat_metadata( met, &lsat );
+	if(print_meta) {
+		if (strcmp(lsatmet->answer, "number") == 0) {
+			fprintf(stdout,"%d\n",lsat.number);
+		}
+		else if (strcmp(lsatmet->answer, "creation") == 0) {
+			fprintf(stdout,"%s\n",lsat.creation);
+		}
+		else if (strcmp(lsatmet->answer, "date") == 0) {
+			fprintf(stdout,"%s\n",lsat.date);
+		}
+		else if (strcmp(lsatmet->answer, "sun_elev") == 0) {
+			fprintf(stdout,"%f\n",lsat.sun_elev);
+		}
+		else if (strcmp(lsatmet->answer, "sensor") == 0) {
+			fprintf(stdout,"%s\n",lsat.sensor);
+		}
+		else if (strcmp(lsatmet->answer, "bands") == 0) {
+			fprintf(stdout,"%d\n",lsat.bands);
+		}
+		else if (strcmp(lsatmet->answer, "sunza") == 0) {
+			fprintf(stdout,"%f\n",lsat.sunza);
+		}
+		else if (strcmp(lsatmet->answer, "time") == 0) {
+			fprintf(stdout,"%f\n",lsat.time);
+		}
+		else {
+			G_fatal_error(_("Please use a metadata keyword with -p"));
+		}
+    		exit(EXIT_SUCCESS);
+	}
         G_debug(1, "lsat.number = %d, lsat.sensor = [%s]", lsat.number, lsat.sensor);
         
         if (!lsat.sensor || lsat.number > 7 || lsat.number < 1)



More information about the grass-commit mailing list