[GRASS-SVN] r33842 - in grass/trunk: gui/tcltk/gis.m gui/wxpython/gui_modules imagery imagery/i.latlong

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 12 04:59:03 EDT 2008


Author: ychemin
Date: 2008-10-12 04:59:02 -0400 (Sun, 12 Oct 2008)
New Revision: 33842

Added:
   grass/trunk/imagery/i.latlong/
   grass/trunk/imagery/i.latlong/Makefile
   grass/trunk/imagery/i.latlong/i.latlong.html
   grass/trunk/imagery/i.latlong/main.c
Modified:
   grass/trunk/gui/tcltk/gis.m/gmmenu.tcl
   grass/trunk/gui/wxpython/gui_modules/menudata.py
   grass/trunk/imagery/Makefile
Log:
added i.latlong with GUIs menus

Modified: grass/trunk/gui/tcltk/gis.m/gmmenu.tcl
===================================================================
--- grass/trunk/gui/tcltk/gis.m/gmmenu.tcl	2008-10-12 08:50:48 UTC (rev 33841)
+++ grass/trunk/gui/tcltk/gis.m/gmmenu.tcl	2008-10-12 08:59:02 UTC (rev 33842)
@@ -549,6 +549,7 @@
 	{separator}
 	{cascad {[G_msg "Basic RS processing"]} {} "" $tmenu {			
 				{command {[G_msg "MODIS Quality flags"]} {} "i.modis.qc: Extracts Modis Quality flags as raster values." {} -command {execute i.modis.qc }}
+				{command {[G_msg "Latitude/longitude maps"]} {} "i.latlong: Latitude or Longitude maps." {} -command {execute i.latlong }}
 				{separator}
 				{command {[G_msg "Albedo"]} {} "i.albedo: Calculates Albedo from Modis, Aster, Landsat or AVHRR" {} -command {execute i.albedo }}
 				{separator}

Modified: grass/trunk/gui/wxpython/gui_modules/menudata.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menudata.py	2008-10-12 08:50:48 UTC (rev 33841)
+++ grass/trunk/gui/wxpython/gui_modules/menudata.py	2008-10-12 08:59:02 UTC (rev 33842)
@@ -1630,6 +1630,11 @@
                                  _("Extract Modis Quality flags as raster values."),
                                  "self.OnMenuCmd",
                                  "i.modis.qc"),
+
+                                (_("Latitude/longitude maps"),
+                                 _("Creates Latitude or Longitude map."),
+                                 "self.OnMenuCmd",
+                                 "i.latlong"),
 	                        ("","","", ""),
 
                                 (_("Albedo"),

Modified: grass/trunk/imagery/Makefile
===================================================================
--- grass/trunk/imagery/Makefile	2008-10-12 08:50:48 UTC (rev 33841)
+++ grass/trunk/imagery/Makefile	2008-10-12 08:59:02 UTC (rev 33842)
@@ -12,6 +12,7 @@
 	i.gensigset \
 	i.group \
 	i.his.rgb \
+	i.latlong \
 	i.maxlik \
 	i.modis.qc \
 	i.rectify \

Added: grass/trunk/imagery/i.latlong/Makefile
===================================================================
--- grass/trunk/imagery/i.latlong/Makefile	                        (rev 0)
+++ grass/trunk/imagery/i.latlong/Makefile	2008-10-12 08:59:02 UTC (rev 33842)
@@ -0,0 +1,15 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.latlong
+
+LIBES =  $(GPROJLIB) $(GISLIB)
+DEPENDENCIES = $(GPROJDEP) $(GISDEP)
+EXTRA_INC = $(PROJINC)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+ifneq ($(USE_LARGEFILES),)
+	EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
+endif
+
+default: cmd

Added: grass/trunk/imagery/i.latlong/i.latlong.html
===================================================================
--- grass/trunk/imagery/i.latlong/i.latlong.html	                        (rev 0)
+++ grass/trunk/imagery/i.latlong/i.latlong.html	2008-10-12 08:59:02 UTC (rev 33842)
@@ -0,0 +1,26 @@
+<H2>DESCRIPTION</H2>
+
+<EM>i.latlong</EM> creates a latitude (degree decimal) map, or longitude if the -l flag is used, from any map in any projection using PROJ.4 library. 
+This is an input to r.sun and i.evapo.potrad.
+<H2>NOTES</H2>
+
+The proj <A HREF="http://www.remotesensing.org/proj/">website</A>.
+
+<H2>TODO</H2>
+Datum transform is not implemented, the same datum is taken as output.
+
+<H2>SEE ALSO</H2>
+
+<em>
+<A HREF="i.evapo.potrad.html">i.evapo.potrad</A><br>
+<A HREF="r.sun.html">r.sun</A><br>
+</em>
+
+
+<H2>AUTHORS</H2>
+
+Yann Chemin, International Rice Research Institute, The Philippines.<br>
+
+
+<p>
+<i>Last changed: $Date: 2008/10/12 12:25:55 $</i>

Added: grass/trunk/imagery/i.latlong/main.c
===================================================================
--- grass/trunk/imagery/i.latlong/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.latlong/main.c	2008-10-12 08:59:02 UTC (rev 33842)
@@ -0,0 +1,156 @@
+/****************************************************************************
+ *
+ * MODULE:       i.latlong
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE:      Calculates the longitude of the pixels in the map. 
+ *
+ * COPYRIGHT:    (C) 2002-2008 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	 License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	 for details.
+ *
+ *****************************************************************************/
+    
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/gprojects.h>
+#include <grass/glocale.h>
+
+int main(int argc, char *argv[]) 
+{
+    struct Cell_head cellhd;	/*region+header info */
+    int nrows, ncols;
+    int row, col;
+    int not_ll = 0;		/*if proj is not lat/long, it will be 1. */
+
+    struct GModule *module;
+    struct Option *input1, *output1;
+    struct Flag *flag1;
+    struct History history;	/*metadata */
+    struct pj_info iproj;
+    struct pj_info oproj;
+    struct Key_Value *in_proj_info, *in_unit_info;
+
+    /************************************/ 
+    char *result1;		/*output raster name */
+    
+    int infd;
+    int outfd1;
+    char *in;
+    double xmin, ymin;
+    double xmax, ymax;
+    double stepx, stepy;
+    double latitude, longitude;
+    void *inrast;
+    DCELL * outrast1;
+    DCELL d;
+
+    /************************************/ 
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("imagery, latitude, longitude, projection");
+    module->description = _("creates a latitude/longitude map");
+    
+    /* Define the different options */ 
+    input1 = G_define_standard_option(G_OPT_R_INPUT);
+    input1->description = _("Name of the input map");
+
+    output1 = G_define_standard_option(G_OPT_R_OUTPUT);
+    output1->description = _("Name of the output longitude layer");
+    
+    flag1 = G_define_flag();
+    flag1->key = 'l';
+    flag1->description = _("Longitude output");
+
+    /********************/ 
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    in = input1->answer;
+    result1 = output1->answer;
+
+    /***************************************************/ 
+    if ((infd = G_open_cell_old(in, "")) < 0)
+	G_fatal_error(_("Cannot open cell file [%s]"), in);
+    if (G_get_cellhd(in, "", &cellhd) < 0)
+	G_fatal_error(_("Cannot read file header of [%s])"), in);
+    inrast = G_allocate_d_raster_buf();
+    
+    /***************************************************/ 
+    stepx = cellhd.ew_res;
+    stepy = cellhd.ns_res;
+    xmin = cellhd.west;
+    xmax = cellhd.east;
+    ymin = cellhd.south;
+    ymax = cellhd.north;
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+    
+    /*Stolen from r.sun */ 
+    /* Set up parameters for projection to lat/long if necessary */ 
+    if ((G_projection() != PROJECTION_LL)) 
+    {
+	not_ll = 1;
+
+	if ((in_proj_info = G_get_projinfo()) == NULL)
+	    G_fatal_error(_("Can't get projection info of current location"));
+	if ((in_unit_info = G_get_projunits()) == NULL)
+	    G_fatal_error(_("Can't get projection units of current location"));
+	if (pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0)
+	    G_fatal_error(_("Can't get projection key values of current location"));
+	G_free_key_value(in_proj_info);
+	G_free_key_value(in_unit_info);
+	
+        /* Set output projection to latlong w/ same ellipsoid */ 
+	oproj.zone = 0;
+	oproj.meters = 1.;
+	sprintf(oproj.proj, "ll");
+	if ((oproj.pj = pj_latlong_from_proj(iproj.pj)) == NULL)
+	    G_fatal_error(_("Unable to set up lat/long projection parameters"));
+    }	/* End of stolen from r.sun */
+
+    outrast1 = G_allocate_d_raster_buf();
+
+    if ((outfd1 = G_open_raster_new(result1,DCELL_TYPE)) < 0)
+	G_fatal_error(_("Could not open <%s>"), result1);
+
+    for (row = 0; row < nrows; row++)
+    {
+	G_percent(row, nrows, 2);
+
+	if (G_get_d_raster_row(infd, inrast, row) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), in);
+
+	for (col = 0; col < ncols; col++)
+        {
+	    latitude = ymax - (row * stepy);
+	    longitude = xmin + (col * stepx);
+	    if (not_ll) 
+		if (pj_do_proj(&longitude, &latitude, &iproj, &oproj) < 0) 
+		    G_fatal_error(_("Error in pj_do_proj"));
+            if(flag1->answer)
+	        d = longitude;
+            else
+	        d = latitude;
+	    outrast1[col] = d;
+	}
+	if (G_put_d_raster_row(outfd1, outrast1) < 0)
+	    G_fatal_error(_("Cannot write to output raster file"));
+    }
+    G_free(inrast);
+    G_close_cell(infd);
+    G_free(outrast1);
+    G_close_cell(outfd1);
+
+    G_short_history(result1, "raster", &history);
+    G_command_history(&history);
+    G_write_history(result1, &history);
+
+    exit(EXIT_SUCCESS);
+}
+
+



More information about the grass-commit mailing list