[QGIS Commit] r12902 - trunk/qgis/src/providers/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Feb 8 18:46:37 EST 2010
Author: jef
Date: 2010-02-08 18:46:35 -0500 (Mon, 08 Feb 2010)
New Revision: 12902
Modified:
trunk/qgis/src/providers/grass/qgis.d.rast.c
trunk/qgis/src/providers/grass/qgis.g.info.c
Log:
remove glocale and package names again
Modified: trunk/qgis/src/providers/grass/qgis.d.rast.c
===================================================================
--- trunk/qgis/src/providers/grass/qgis.d.rast.c 2010-02-08 21:48:46 UTC (rev 12901)
+++ trunk/qgis/src/providers/grass/qgis.d.rast.c 2010-02-08 23:46:35 UTC (rev 12902)
@@ -1,172 +1,175 @@
/****************************************************************************
- *
+ *
* MODULE: qgis.d.rast
* AUTHOR(S): Radim Blazek <radim.blazek gmail.com>
* using d.rast from GRASS
* PURPOSE: display raster maps in active graphics display
- * COPYRIGHT: (C) 2010 by Radim Blazek
+ * COPYRIGHT: (C) 2010 by Radim Blazek
*
* This program is free software under the GNU General Public
* License (>=v2).
*
*****************************************************************************/
-#define PACKAGE "grassmods"
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/display.h>
-#include <grass/glocale.h>
-int display(char *name, char *mapset, RASTER_MAP_TYPE data_type);
+int display( char *name, char *mapset, RASTER_MAP_TYPE data_type );
-int main(int argc, char **argv)
+int main( int argc, char **argv )
{
- char *mapset;
- char *name;
- int fp;
- struct GModule *module;
- struct Option *map;
- struct Option *win;
- struct Cell_head window;
+ char *mapset;
+ char *name;
+ int fp;
+ struct GModule *module;
+ struct Option *map;
+ struct Option *win;
+ struct Cell_head window;
- /* Initialize the GIS calls */
- G_gisinit(argv[0]);
+ /* Initialize the GIS calls */
+ G_gisinit( argv[0] );
- module = G_define_module();
- module->keywords = ("display, raster");
- module->description = ("Output raster map layers in a format suitable for display in QGIS");
+ module = G_define_module();
+ module->keywords = ( "display, raster" );
+ module->description = ( "Output raster map layers in a format suitable for display in QGIS" );
- map = G_define_standard_option(G_OPT_R_MAP);
- map->description = ("Raster map to be displayed");
+ map = G_define_standard_option( G_OPT_R_MAP );
+ map->description = ( "Raster map to be displayed" );
- win = G_define_option();
- win->key = "window";
- win->type = TYPE_DOUBLE;
- win->multiple = YES;
- win->description = "xmin,ymin,xmax,ymax,ncols,nrows";
-
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
+ win = G_define_option();
+ win->key = "window";
+ win->type = TYPE_DOUBLE;
+ win->multiple = YES;
+ win->description = "xmin,ymin,xmax,ymax,ncols,nrows";
- name = map->answer;
+ if ( G_parser( argc, argv ) )
+ exit( EXIT_FAILURE );
- G_get_window(&window);
- window.west = atof(win->answers[0]);
- window.south = atof(win->answers[1]);
- window.east = atof(win->answers[2]);
- window.north = atof(win->answers[3]);
- window.cols = atoi(win->answers[4]);
- window.rows = atoi(win->answers[5]);
- G_adjust_Cell_head(&window,1,1);
- G_set_window(&window);
+ name = map->answer;
- /* Make sure map is available */
- mapset = G_find_cell2(name, "");
- if (mapset == NULL)
- G_fatal_error(("Raster map <%s> not found"), name);
+ G_get_window( &window );
+ window.west = atof( win->answers[0] );
+ window.south = atof( win->answers[1] );
+ window.east = atof( win->answers[2] );
+ window.north = atof( win->answers[3] );
+ window.cols = atoi( win->answers[4] );
+ window.rows = atoi( win->answers[5] );
+ G_adjust_Cell_head( &window, 1, 1 );
+ G_set_window( &window );
+ /* Make sure map is available */
+ mapset = G_find_cell2( name, "" );
+ if ( mapset == NULL )
+ G_fatal_error(( "Raster map <%s> not found" ), name );
- fp = G_raster_map_is_fp(name, mapset);
- /* use DCELL even if the map is FCELL */
- if (fp)
- display(name, mapset, DCELL_TYPE );
- else
- display(name, mapset, CELL_TYPE );
+ fp = G_raster_map_is_fp( name, mapset );
- exit(EXIT_SUCCESS);
+ /* use DCELL even if the map is FCELL */
+ if ( fp )
+ display( name, mapset, DCELL_TYPE );
+ else
+ display( name, mapset, CELL_TYPE );
+
+ exit( EXIT_SUCCESS );
}
-static int cell_draw(char *, char *, struct Colors *, RASTER_MAP_TYPE);
+static int cell_draw( char *, char *, struct Colors *, RASTER_MAP_TYPE );
-int display(char *name,
- char *mapset,
- RASTER_MAP_TYPE data_type)
+int display( char *name,
+ char *mapset,
+ RASTER_MAP_TYPE data_type )
{
- struct Colors colors;
+ struct Colors colors;
- if (G_read_colors(name, mapset, &colors) == -1)
- G_fatal_error(("Color file for <%s> not available"), name);
+ if ( G_read_colors( name, mapset, &colors ) == -1 )
+ G_fatal_error(( "Color file for <%s> not available" ), name );
- //G_set_null_value_color(r, g, b, &colors);
+ //G_set_null_value_color(r, g, b, &colors);
- /* Go draw the raster map */
- cell_draw(name, mapset, &colors, data_type);
+ /* Go draw the raster map */
+ cell_draw( name, mapset, &colors, data_type );
- /* release the colors now */
- G_free_colors(&colors);
+ /* release the colors now */
+ G_free_colors( &colors );
- return 0;
+ return 0;
}
-static int cell_draw(char *name,
- char *mapset,
- struct Colors *colors,
- RASTER_MAP_TYPE data_type)
+static int cell_draw( char *name,
+ char *mapset,
+ struct Colors *colors,
+ RASTER_MAP_TYPE data_type )
{
- int cellfile;
- void *xarray;
- int row;
- int ncols, nrows;
- static unsigned char *red, *grn, *blu, *set;
- int i;
- void *ptr;
- int big_endian;
- long one= 1;
- FILE *fo;
+ int cellfile;
+ void *xarray;
+ int row;
+ int ncols, nrows;
+ static unsigned char *red, *grn, *blu, *set;
+ int i;
+ void *ptr;
+ int big_endian;
+ long one = 1;
+ FILE *fo;
- big_endian = !(*((char *)(&one)));
+ big_endian = !( *(( char * )( &one ) ) );
- ncols = G_window_cols();
- nrows = G_window_rows();
+ ncols = G_window_cols();
+ nrows = G_window_rows();
- /* Make sure map is available */
- if ((cellfile = G_open_cell_old(name, mapset)) == -1)
- G_fatal_error(("Unable to open raster map <%s>"), name);
+ /* Make sure map is available */
+ if (( cellfile = G_open_cell_old( name, mapset ) ) == -1 )
+ G_fatal_error(( "Unable to open raster map <%s>" ), name );
- /* Allocate space for cell buffer */
- xarray = G_allocate_raster_buf(data_type);
- red = G_malloc(ncols);
- grn = G_malloc(ncols);
- blu = G_malloc(ncols);
- set = G_malloc(ncols);
+ /* Allocate space for cell buffer */
+ xarray = G_allocate_raster_buf( data_type );
+ red = G_malloc( ncols );
+ grn = G_malloc( ncols );
+ blu = G_malloc( ncols );
+ set = G_malloc( ncols );
- /* some buggy C libraries require BOTH setmode() and fdopen(bin) ? */
- //setmode(fileno(stdin), O_BINARY);
- fo = fdopen (fileno(stdout), "wb");
-
- /* loop for array rows */
- for ( row = 0; row < nrows; row++ ) {
- G_get_raster_row(cellfile, xarray, row, data_type);
- ptr = xarray;
+ /* some buggy C libraries require BOTH setmode() and fdopen(bin) ? */
+ //setmode(fileno(stdin), O_BINARY);
+ fo = fdopen( fileno( stdout ), "wb" );
- G_lookup_raster_colors(xarray, red, grn, blu, set, ncols, colors,
- data_type);
+ /* loop for array rows */
+ for ( row = 0; row < nrows; row++ )
+ {
+ G_get_raster_row( cellfile, xarray, row, data_type );
+ ptr = xarray;
- for (i = 0; i < ncols; i++) {
- unsigned char alpha = 255;
- if ( G_is_null_value(ptr, data_type) ) {
- alpha = 0;
- }
- ptr = G_incr_void_ptr(ptr, G_raster_size(data_type));
-
+ G_lookup_raster_colors( xarray, red, grn, blu, set, ncols, colors,
+ data_type );
- // We need data suitable for QImage 32-bpp
- // the data are stored in QImage as QRgb which is unsigned int.
- // Because it depends on byte order of the platform we have to
- // consider byte order (well, middle endian ignored)
- if ( big_endian ) {
- // I have never tested this
- fprintf(fo, "%c%c%c%c", alpha, red[i],grn[i],blu[i]);
- } else {
- fprintf(fo, "%c%c%c%c", blu[i],grn[i],red[i],alpha);
- }
- }
+ for ( i = 0; i < ncols; i++ )
+ {
+ unsigned char alpha = 255;
+ if ( G_is_null_value( ptr, data_type ) )
+ {
+ alpha = 0;
+ }
+ ptr = G_incr_void_ptr( ptr, G_raster_size( data_type ) );
+
+
+ // We need data suitable for QImage 32-bpp
+ // the data are stored in QImage as QRgb which is unsigned int.
+ // Because it depends on byte order of the platform we have to
+ // consider byte order (well, middle endian ignored)
+ if ( big_endian )
+ {
+ // I have never tested this
+ fprintf( fo, "%c%c%c%c", alpha, red[i], grn[i], blu[i] );
+ }
+ else
+ {
+ fprintf( fo, "%c%c%c%c", blu[i], grn[i], red[i], alpha );
+ }
}
+ }
- G_close_cell(cellfile);
- return (0);
+ G_close_cell( cellfile );
+ return ( 0 );
}
Modified: trunk/qgis/src/providers/grass/qgis.g.info.c
===================================================================
--- trunk/qgis/src/providers/grass/qgis.g.info.c 2010-02-08 21:48:46 UTC (rev 12901)
+++ trunk/qgis/src/providers/grass/qgis.g.info.c 2010-02-08 23:46:35 UTC (rev 12902)
@@ -1,143 +1,141 @@
/****************************************************************************
- *
+ *
* MODULE: qgis.g.info
* AUTHOR(S): Radim Blazek <radim.blazek gmail.com>
- * using various GRASS modules
+ * using various GRASS modules
* PURPOSE: get informations about locations,mapsets,maps
- * COPYRIGHT: (C) 2010 by Radim Blazek
+ * COPYRIGHT: (C) 2010 by Radim Blazek
*
* This program is free software under the GNU General Public
* License (>=v2).
*
*****************************************************************************/
-#define PACKAGE "grassmods"
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/display.h>
-#include <grass/glocale.h>
#include <grass/gprojects.h>
-int main(int argc, char **argv)
+int main( int argc, char **argv )
{
- struct GModule *module;
- struct Option *info_opt, *rast_opt, *vect_opt, *coor_opt;
- struct Cell_head window;
-
- /* Initialize the GIS calls */
- G_gisinit(argv[0]);
+ struct GModule *module;
+ struct Option *info_opt, *rast_opt, *vect_opt, *coor_opt;
+ struct Cell_head window;
- module = G_define_module();
- module->description = ("Get info about locations,mapsets,maps");
+ /* Initialize the GIS calls */
+ G_gisinit( argv[0] );
- info_opt = G_define_option();
- info_opt->key = "info";
- info_opt->type = TYPE_STRING;
- info_opt->description = "info key";
- info_opt->options = "proj,window,query";
+ module = G_define_module();
+ module->description = ( "Get info about locations,mapsets,maps" );
- rast_opt = G_define_standard_option(G_OPT_R_INPUT);
- rast_opt->key = "rast";
- rast_opt->required = NO;
+ info_opt = G_define_option();
+ info_opt->key = "info";
+ info_opt->type = TYPE_STRING;
+ info_opt->description = "info key";
+ info_opt->options = "proj,window,query";
- vect_opt = G_define_standard_option(G_OPT_V_INPUT);
- vect_opt->key = "vect";
- vect_opt->required = NO;
+ rast_opt = G_define_standard_option( G_OPT_R_INPUT );
+ rast_opt->key = "rast";
+ rast_opt->required = NO;
- coor_opt = G_define_option();
- coor_opt->key = "coor";
- coor_opt->type = TYPE_DOUBLE;
- coor_opt->multiple = YES;
-
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
+ vect_opt = G_define_standard_option( G_OPT_V_INPUT );
+ vect_opt->key = "vect";
+ vect_opt->required = NO;
+ coor_opt = G_define_option();
+ coor_opt->key = "coor";
+ coor_opt->type = TYPE_DOUBLE;
+ coor_opt->multiple = YES;
- if ( strcmp("proj",info_opt->answer) == 0 )
+ if ( G_parser( argc, argv ) )
+ exit( EXIT_FAILURE );
+
+
+ if ( strcmp( "proj", info_opt->answer ) == 0 )
+ {
+ G_get_window( &window );
+ /* code from g.proj */
+ if ( window.proj != PROJECTION_XY )
{
- G_get_window(&window);
- /* code from g.proj */
- if (window.proj != PROJECTION_XY) {
- struct Key_Value *projinfo, *projunits;
- char *wkt;
- projinfo = G_get_projinfo();
- projunits = G_get_projunits();
- wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
- fprintf (stdout, "%s", wkt);
- }
+ struct Key_Value *projinfo, *projunits;
+ char *wkt;
+ projinfo = G_get_projinfo();
+ projunits = G_get_projunits();
+ wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
+ fprintf( stdout, "%s", wkt );
}
- else if ( strcmp("window",info_opt->answer) == 0 )
+ }
+ else if ( strcmp( "window", info_opt->answer ) == 0 )
+ {
+ if ( rast_opt->answer )
{
- if ( rast_opt->answer )
- {
- G_get_cellhd( rast_opt->answer, "", &window);
- fprintf (stdout, "%f,%f,%f,%f", window.west, window.south,window.east,window.north );
- }
- else if ( vect_opt->answer )
- {
- G_fatal_error ("Not yet supported");
- }
+ G_get_cellhd( rast_opt->answer, "", &window );
+ fprintf( stdout, "%f,%f,%f,%f", window.west, window.south, window.east, window.north );
}
- else if ( strcmp("query",info_opt->answer) == 0 )
+ else if ( vect_opt->answer )
{
- double x, y;
- int row, col;
- x = atof ( coor_opt->answers[0] );
- y = atof ( coor_opt->answers[1] );
- if ( rast_opt->answer )
- {
- int fd;
- RASTER_MAP_TYPE rast_type;
- DCELL *dcell;
- CELL *cell;
- G_get_cellhd( rast_opt->answer, "", &window);
- G_set_window(&window);
- fd = G_open_cell_old( rast_opt->answer, "");
- col = (int) G_easting_to_col( x, &window);
- row = (int) G_northing_to_row( y, &window);
- if (col == window.cols) col--;
- if (row == window.rows) row--;
+ G_fatal_error( "Not yet supported" );
+ }
+ }
+ else if ( strcmp( "query", info_opt->answer ) == 0 )
+ {
+ double x, y;
+ int row, col;
+ x = atof( coor_opt->answers[0] );
+ y = atof( coor_opt->answers[1] );
+ if ( rast_opt->answer )
+ {
+ int fd;
+ RASTER_MAP_TYPE rast_type;
+ DCELL *dcell;
+ CELL *cell;
+ G_get_cellhd( rast_opt->answer, "", &window );
+ G_set_window( &window );
+ fd = G_open_cell_old( rast_opt->answer, "" );
+ col = ( int ) G_easting_to_col( x, &window );
+ row = ( int ) G_northing_to_row( y, &window );
+ if ( col == window.cols ) col--;
+ if ( row == window.rows ) row--;
- if ( col < 0 || col > window.cols || row < 0 || row > window.rows )
+ if ( col < 0 || col > window.cols || row < 0 || row > window.rows )
+ {
+ fprintf( stdout, "value:null\n" );
+ }
+ else
+ {
+ rast_type = G_get_raster_map_type( fd );
+ cell = G_allocate_c_raster_buf();
+ dcell = G_allocate_d_raster_buf();
+
+ if ( rast_type == CELL_TYPE )
+ {
+ if ( G_get_c_raster_row( fd, cell, row ) < 0 )
{
- fprintf (stdout, "value:null\n");
+ G_fatal_error(( "Unable to read raster map <%s> row %d" ),
+ rast_opt->answer, row );
}
- else
+ fprintf( stdout, "value:%d\n", cell[col] );
+ }
+ else
+ {
+ if ( G_get_d_raster_row( fd, dcell, row ) < 0 )
{
- rast_type = G_get_raster_map_type(fd);
- cell = G_allocate_c_raster_buf();
- dcell = G_allocate_d_raster_buf();
-
- if (rast_type == CELL_TYPE)
- {
- if (G_get_c_raster_row(fd, cell, row) < 0)
- {
- G_fatal_error(("Unable to read raster map <%s> row %d"),
- rast_opt->answer, row);
- }
- fprintf (stdout, "value:%d\n", cell[col] );
- }
- else
- {
- if (G_get_d_raster_row(fd, dcell, row) < 0)
- {
- G_fatal_error(("Unable to read raster map <%s> row %d"),
- rast_opt->answer, row);
- }
- fprintf (stdout, "value:%f\n", dcell[col] );
- }
+ G_fatal_error(( "Unable to read raster map <%s> row %d" ),
+ rast_opt->answer, row );
}
- G_close_cell( fd );
+ fprintf( stdout, "value:%f\n", dcell[col] );
}
- else if ( vect_opt->answer )
- {
- G_fatal_error ("Not yet supported");
- }
+ }
+ G_close_cell( fd );
}
+ else if ( vect_opt->answer )
+ {
+ G_fatal_error( "Not yet supported" );
+ }
+ }
- exit(EXIT_SUCCESS);
+ exit( EXIT_SUCCESS );
}
More information about the QGIS-commit
mailing list