[GRASS-SVN] r29414 - in grass-addons/gipe: . i.longitude
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Dec 11 22:22:08 EST 2007
Author: ychemin
Date: 2007-12-11 22:22:08 -0500 (Tue, 11 Dec 2007)
New Revision: 29414
Added:
grass-addons/gipe/i.longitude/
grass-addons/gipe/i.longitude/Makefile
grass-addons/gipe/i.longitude/description.html
grass-addons/gipe/i.longitude/i.longitude.tmp.html
grass-addons/gipe/i.longitude/main.c
Log:
Added i.longitude
Added: grass-addons/gipe/i.longitude/Makefile
===================================================================
--- grass-addons/gipe/i.longitude/Makefile (rev 0)
+++ grass-addons/gipe/i.longitude/Makefile 2007-12-12 03:22:08 UTC (rev 29414)
@@ -0,0 +1,15 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.longitude
+
+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-addons/gipe/i.longitude/description.html
===================================================================
--- grass-addons/gipe/i.longitude/description.html (rev 0)
+++ grass-addons/gipe/i.longitude/description.html 2007-12-12 03:22:08 UTC (rev 29414)
@@ -0,0 +1,26 @@
+<H2>DESCRIPTION</H2>
+
+<EM>i.latitude</EM> creates a latitude (degree decimal) map 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>
+
+
+<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<BR>
+
+
+<p>
+<i>Last changed: $Date: 2007/06/09 22:19:55 $</i>
Added: grass-addons/gipe/i.longitude/i.longitude.tmp.html
===================================================================
--- grass-addons/gipe/i.longitude/i.longitude.tmp.html (rev 0)
+++ grass-addons/gipe/i.longitude/i.longitude.tmp.html 2007-12-12 03:22:08 UTC (rev 29414)
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS: i.longitude</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+</head>
+<body bgcolor="white">
+
+<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
+
+<h2>NAME</h2>
+<em><b>i.longitude</b></em> - creates a longitude map
+<h2>KEYWORDS</h2>
+longitude, projection
+<h2>SYNOPSIS</h2>
+<b>i.longitude</b><br>
+<b>i.longitude help</b><br>
+<b>i.longitude</b> [-<b>q</b>] <b>input</b>=<em>string</em> <b>longitude</b>=<em>string</em> [--<b>overwrite</b>] [--<b>verbose</b>] [--<b>quiet</b>]
+
+<h3>Flags:</h3>
+<DL>
+<DT><b>-q</b></DT>
+<DD>Quiet</DD>
+
+<DT><b>--overwrite</b></DT>
+<DD>Allow output files to overwrite existing files</DD>
+<DT><b>--verbose</b></DT>
+<DD>Verbose module output</DD>
+<DT><b>--quiet</b></DT>
+<DD>Quiet module output</DD>
+</DL>
+
+<h3>Parameters:</h3>
+<DL>
+<DT><b>input</b>=<em>string</em></DT>
+<DD>Name of the input map</DD>
+<DD>Default: <em>input</em></DD>
+
+<DT><b>longitude</b>=<em>string</em></DT>
+<DD>Name of the output longitude layer</DD>
+<DD>Default: <em>longitude</em></DD>
+
+</DL>
+<H2>DESCRIPTION</H2>
+
+<EM>i.latitude</EM> creates a latitude (degree decimal) map 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>
+
+
+<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<BR>
+
+
+<p>
+<i>Last changed: $Date: 2007/06/09 22:19:55 $</i>
+<HR>
+<P><a href="index.html">Main index</a> - <a href="imagery.html">imagery index</a> - <a href="full_index.html">Full index</a></P>
+© 2003-2007 <a href="http://grass.osgeo.org">GRASS Development Team</a></p>
+</body>
+</html>
Added: grass-addons/gipe/i.longitude/main.c
===================================================================
--- grass-addons/gipe/i.longitude/main.c (rev 0)
+++ grass-addons/gipe/i.longitude/main.c 2007-12-12 03:22:08 UTC (rev 29414)
@@ -0,0 +1,185 @@
+/****************************************************************************
+ *
+ * MODULE: i.longitude
+ * AUTHOR(S): Yann Chemin - ychemin at gmail.com
+ * PURPOSE: Calculates the longitude of the pixels in the map.
+ *
+ * COPYRIGHT: (C) 2002-2006 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
+ char *mapset; // mapset name
+ int nrows, ncols;
+ int row,col;
+
+ int verbose=1;
+ 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;
+ /************************************/
+ /* FMEO Declarations*****************/
+ char *name; // input raster name
+ char *result1; //output raster name
+ //File Descriptors
+ int infd;
+ int outfd1;
+
+ char *in;
+ int i=0,j=0;
+ double xp, yp;
+ double xmin, ymin;
+ double xmax, ymax;
+ double stepx,stepy;
+ double latitude, longitude;
+
+ void *inrast;
+ unsigned char *outrast1;
+ RASTER_MAP_TYPE data_type_output=DCELL_TYPE;
+ RASTER_MAP_TYPE data_type_inrast;
+ /************************************/
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ module->keywords = _("longitude, projection");
+ module->description = _("creates a longitude map");
+
+ /* Define the different options */
+ input1 = G_define_option() ;
+ input1->key = _("input");
+ input1->type = TYPE_STRING;
+ input1->required = YES;
+ input1->gisprompt =_("old,cell,raster") ;
+ input1->description=_("Name of the input map");
+ input1->answer =_("input");
+
+ output1 = G_define_option() ;
+ output1->key =_("longitude");
+ output1->type = TYPE_STRING;
+ output1->required = YES;
+ output1->gisprompt =_("new,cell,raster");
+ output1->description=_("Name of the output longitude layer");
+ output1->answer =_("longitude");
+
+
+ flag1 = G_define_flag();
+ flag1->key = 'q';
+ flag1->description = _("Quiet");
+
+ /********************/
+ if (G_parser(argc, argv))
+ exit (EXIT_FAILURE);
+
+ in = input1->answer;
+
+ result1 = output1->answer;
+ verbose = (!flag1->answer);
+ /***************************************************/
+ mapset = G_find_cell2(in, "");
+ if (mapset == NULL) {
+ G_fatal_error(_("cell file [%s] not found"), in);
+ }
+ data_type_inrast = G_raster_map_type(in,mapset);
+ if ( (infd = G_open_cell_old (in,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), in);
+ if (G_get_cellhd (in, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), in);
+ inrast = G_allocate_raster_buf(data_type_inrast);
+ /***************************************************/
+ G_debug(3, "number of rows %d",cellhd.rows);
+
+ 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();
+
+ //Shamelessly stolen from r.sun !!!!
+ /* Set up parameters for projection to lat/long if necessary */
+ if ((G_projection() != PROJECTION_LL)) {
+ not_ll=1;
+ struct Key_Value *in_proj_info, *in_unit_info;
+ 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 :P
+
+ outrast1 = G_allocate_raster_buf(data_type_output);
+ if ( (outfd1 = G_open_raster_new (result1,data_type_output)) < 0)
+ G_fatal_error(_("Could not open <%s>"),result1);
+ for (row = 0; row < nrows; row++)
+ {
+ DCELL d;
+ DCELL d_lon;
+ if(verbose)
+ G_percent(row,nrows,2);
+ if(G_get_raster_row(infd,inrast,row,data_type_inrast)<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"));
+ }
+ }else{
+ //Do nothing
+ }
+ d_lon = longitude;
+ ((DCELL *) outrast1)[col] = d_lon;
+ }
+ if (G_put_raster_row (outfd1, outrast1, data_type_output) < 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