Skip to content

Commit adf8e0e

Browse files
author
jef
committedFeb 8, 2010
remove glocale and package names again
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12902 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+242
-241
lines changed

2 files changed

+242
-241
lines changed
 

‎src/providers/grass/qgis.d.rast.c

Lines changed: 141 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,175 @@
11
/****************************************************************************
2-
*
2+
*
33
* MODULE: qgis.d.rast
44
* AUTHOR(S): Radim Blazek <radim.blazek gmail.com>
55
* using d.rast from GRASS
66
* PURPOSE: display raster maps in active graphics display
7-
* COPYRIGHT: (C) 2010 by Radim Blazek
7+
* COPYRIGHT: (C) 2010 by Radim Blazek
88
*
99
* This program is free software under the GNU General Public
1010
* License (>=v2).
1111
*
1212
*****************************************************************************/
13-
#define PACKAGE "grassmods"
14-
1513
#include <stdlib.h>
1614
#include <stdio.h>
1715
#include <string.h>
1816
#include <grass/gis.h>
1917
#include <grass/raster.h>
2018
#include <grass/display.h>
21-
#include <grass/glocale.h>
2219

23-
int display(char *name, char *mapset, RASTER_MAP_TYPE data_type);
20+
int display( char *name, char *mapset, RASTER_MAP_TYPE data_type );
2421

25-
int main(int argc, char **argv)
22+
int main( int argc, char **argv )
2623
{
27-
char *mapset;
28-
char *name;
29-
int fp;
30-
struct GModule *module;
31-
struct Option *map;
32-
struct Option *win;
33-
struct Cell_head window;
34-
35-
/* Initialize the GIS calls */
36-
G_gisinit(argv[0]);
37-
38-
module = G_define_module();
39-
module->keywords = ("display, raster");
40-
module->description = ("Output raster map layers in a format suitable for display in QGIS");
41-
42-
map = G_define_standard_option(G_OPT_R_MAP);
43-
map->description = ("Raster map to be displayed");
44-
45-
win = G_define_option();
46-
win->key = "window";
47-
win->type = TYPE_DOUBLE;
48-
win->multiple = YES;
49-
win->description = "xmin,ymin,xmax,ymax,ncols,nrows";
50-
51-
if (G_parser(argc, argv))
52-
exit(EXIT_FAILURE);
53-
54-
name = map->answer;
55-
56-
G_get_window(&window);
57-
window.west = atof(win->answers[0]);
58-
window.south = atof(win->answers[1]);
59-
window.east = atof(win->answers[2]);
60-
window.north = atof(win->answers[3]);
61-
window.cols = atoi(win->answers[4]);
62-
window.rows = atoi(win->answers[5]);
63-
G_adjust_Cell_head(&window,1,1);
64-
G_set_window(&window);
65-
66-
/* Make sure map is available */
67-
mapset = G_find_cell2(name, "");
68-
if (mapset == NULL)
69-
G_fatal_error(("Raster map <%s> not found"), name);
70-
71-
72-
fp = G_raster_map_is_fp(name, mapset);
73-
74-
/* use DCELL even if the map is FCELL */
75-
if (fp)
76-
display(name, mapset, DCELL_TYPE );
77-
else
78-
display(name, mapset, CELL_TYPE );
79-
80-
exit(EXIT_SUCCESS);
24+
char *mapset;
25+
char *name;
26+
int fp;
27+
struct GModule *module;
28+
struct Option *map;
29+
struct Option *win;
30+
struct Cell_head window;
31+
32+
/* Initialize the GIS calls */
33+
G_gisinit( argv[0] );
34+
35+
module = G_define_module();
36+
module->keywords = ( "display, raster" );
37+
module->description = ( "Output raster map layers in a format suitable for display in QGIS" );
38+
39+
map = G_define_standard_option( G_OPT_R_MAP );
40+
map->description = ( "Raster map to be displayed" );
41+
42+
win = G_define_option();
43+
win->key = "window";
44+
win->type = TYPE_DOUBLE;
45+
win->multiple = YES;
46+
win->description = "xmin,ymin,xmax,ymax,ncols,nrows";
47+
48+
if ( G_parser( argc, argv ) )
49+
exit( EXIT_FAILURE );
50+
51+
name = map->answer;
52+
53+
G_get_window( &window );
54+
window.west = atof( win->answers[0] );
55+
window.south = atof( win->answers[1] );
56+
window.east = atof( win->answers[2] );
57+
window.north = atof( win->answers[3] );
58+
window.cols = atoi( win->answers[4] );
59+
window.rows = atoi( win->answers[5] );
60+
G_adjust_Cell_head( &window, 1, 1 );
61+
G_set_window( &window );
62+
63+
/* Make sure map is available */
64+
mapset = G_find_cell2( name, "" );
65+
if ( mapset == NULL )
66+
G_fatal_error(( "Raster map <%s> not found" ), name );
67+
68+
69+
fp = G_raster_map_is_fp( name, mapset );
70+
71+
/* use DCELL even if the map is FCELL */
72+
if ( fp )
73+
display( name, mapset, DCELL_TYPE );
74+
else
75+
display( name, mapset, CELL_TYPE );
76+
77+
exit( EXIT_SUCCESS );
8178
}
8279

83-
static int cell_draw(char *, char *, struct Colors *, RASTER_MAP_TYPE);
80+
static int cell_draw( char *, char *, struct Colors *, RASTER_MAP_TYPE );
8481

85-
int display(char *name,
86-
char *mapset,
87-
RASTER_MAP_TYPE data_type)
82+
int display( char *name,
83+
char *mapset,
84+
RASTER_MAP_TYPE data_type )
8885
{
89-
struct Colors colors;
86+
struct Colors colors;
9087

91-
if (G_read_colors(name, mapset, &colors) == -1)
92-
G_fatal_error(("Color file for <%s> not available"), name);
88+
if ( G_read_colors( name, mapset, &colors ) == -1 )
89+
G_fatal_error(( "Color file for <%s> not available" ), name );
9390

94-
//G_set_null_value_color(r, g, b, &colors);
91+
//G_set_null_value_color(r, g, b, &colors);
9592

96-
/* Go draw the raster map */
97-
cell_draw(name, mapset, &colors, data_type);
93+
/* Go draw the raster map */
94+
cell_draw( name, mapset, &colors, data_type );
9895

99-
/* release the colors now */
100-
G_free_colors(&colors);
96+
/* release the colors now */
97+
G_free_colors( &colors );
10198

102-
return 0;
99+
return 0;
103100
}
104101

105-
static int cell_draw(char *name,
106-
char *mapset,
107-
struct Colors *colors,
108-
RASTER_MAP_TYPE data_type)
102+
static int cell_draw( char *name,
103+
char *mapset,
104+
struct Colors *colors,
105+
RASTER_MAP_TYPE data_type )
109106
{
110-
int cellfile;
111-
void *xarray;
112-
int row;
113-
int ncols, nrows;
114-
static unsigned char *red, *grn, *blu, *set;
115-
int i;
116-
void *ptr;
117-
int big_endian;
118-
long one= 1;
119-
FILE *fo;
120-
121-
big_endian = !(*((char *)(&one)));
122-
123-
ncols = G_window_cols();
124-
nrows = G_window_rows();
125-
126-
/* Make sure map is available */
127-
if ((cellfile = G_open_cell_old(name, mapset)) == -1)
128-
G_fatal_error(("Unable to open raster map <%s>"), name);
129-
130-
/* Allocate space for cell buffer */
131-
xarray = G_allocate_raster_buf(data_type);
132-
red = G_malloc(ncols);
133-
grn = G_malloc(ncols);
134-
blu = G_malloc(ncols);
135-
set = G_malloc(ncols);
136-
137-
/* some buggy C libraries require BOTH setmode() and fdopen(bin) ? */
138-
//setmode(fileno(stdin), O_BINARY);
139-
fo = fdopen (fileno(stdout), "wb");
140-
141-
/* loop for array rows */
142-
for ( row = 0; row < nrows; row++ ) {
143-
G_get_raster_row(cellfile, xarray, row, data_type);
144-
ptr = xarray;
145-
146-
G_lookup_raster_colors(xarray, red, grn, blu, set, ncols, colors,
147-
data_type);
148-
149-
for (i = 0; i < ncols; i++) {
150-
unsigned char alpha = 255;
151-
if ( G_is_null_value(ptr, data_type) ) {
152-
alpha = 0;
153-
}
154-
ptr = G_incr_void_ptr(ptr, G_raster_size(data_type));
155-
156-
157-
// We need data suitable for QImage 32-bpp
158-
// the data are stored in QImage as QRgb which is unsigned int.
159-
// Because it depends on byte order of the platform we have to
160-
// consider byte order (well, middle endian ignored)
161-
if ( big_endian ) {
162-
// I have never tested this
163-
fprintf(fo, "%c%c%c%c", alpha, red[i],grn[i],blu[i]);
164-
} else {
165-
fprintf(fo, "%c%c%c%c", blu[i],grn[i],red[i],alpha);
166-
}
167-
}
107+
int cellfile;
108+
void *xarray;
109+
int row;
110+
int ncols, nrows;
111+
static unsigned char *red, *grn, *blu, *set;
112+
int i;
113+
void *ptr;
114+
int big_endian;
115+
long one = 1;
116+
FILE *fo;
117+
118+
big_endian = !( *(( char * )( &one ) ) );
119+
120+
ncols = G_window_cols();
121+
nrows = G_window_rows();
122+
123+
/* Make sure map is available */
124+
if (( cellfile = G_open_cell_old( name, mapset ) ) == -1 )
125+
G_fatal_error(( "Unable to open raster map <%s>" ), name );
126+
127+
/* Allocate space for cell buffer */
128+
xarray = G_allocate_raster_buf( data_type );
129+
red = G_malloc( ncols );
130+
grn = G_malloc( ncols );
131+
blu = G_malloc( ncols );
132+
set = G_malloc( ncols );
133+
134+
/* some buggy C libraries require BOTH setmode() and fdopen(bin) ? */
135+
//setmode(fileno(stdin), O_BINARY);
136+
fo = fdopen( fileno( stdout ), "wb" );
137+
138+
/* loop for array rows */
139+
for ( row = 0; row < nrows; row++ )
140+
{
141+
G_get_raster_row( cellfile, xarray, row, data_type );
142+
ptr = xarray;
143+
144+
G_lookup_raster_colors( xarray, red, grn, blu, set, ncols, colors,
145+
data_type );
146+
147+
for ( i = 0; i < ncols; i++ )
148+
{
149+
unsigned char alpha = 255;
150+
if ( G_is_null_value( ptr, data_type ) )
151+
{
152+
alpha = 0;
153+
}
154+
ptr = G_incr_void_ptr( ptr, G_raster_size( data_type ) );
155+
156+
157+
// We need data suitable for QImage 32-bpp
158+
// the data are stored in QImage as QRgb which is unsigned int.
159+
// Because it depends on byte order of the platform we have to
160+
// consider byte order (well, middle endian ignored)
161+
if ( big_endian )
162+
{
163+
// I have never tested this
164+
fprintf( fo, "%c%c%c%c", alpha, red[i], grn[i], blu[i] );
165+
}
166+
else
167+
{
168+
fprintf( fo, "%c%c%c%c", blu[i], grn[i], red[i], alpha );
169+
}
168170
}
171+
}
169172

170-
G_close_cell(cellfile);
171-
return (0);
173+
G_close_cell( cellfile );
174+
return ( 0 );
172175
}

‎src/providers/grass/qgis.g.info.c

Lines changed: 101 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,141 @@
11
/****************************************************************************
2-
*
2+
*
33
* MODULE: qgis.g.info
44
* AUTHOR(S): Radim Blazek <radim.blazek gmail.com>
5-
* using various GRASS modules
5+
* using various GRASS modules
66
* PURPOSE: get informations about locations,mapsets,maps
7-
* COPYRIGHT: (C) 2010 by Radim Blazek
7+
* COPYRIGHT: (C) 2010 by Radim Blazek
88
*
99
* This program is free software under the GNU General Public
1010
* License (>=v2).
1111
*
1212
*****************************************************************************/
13-
#define PACKAGE "grassmods"
14-
1513
#include <stdlib.h>
1614
#include <stdio.h>
1715
#include <string.h>
1816
#include <grass/gis.h>
1917
#include <grass/raster.h>
2018
#include <grass/display.h>
21-
#include <grass/glocale.h>
2219
#include <grass/gprojects.h>
2320

24-
int main(int argc, char **argv)
21+
int main( int argc, char **argv )
2522
{
26-
struct GModule *module;
27-
struct Option *info_opt, *rast_opt, *vect_opt, *coor_opt;
28-
struct Cell_head window;
29-
30-
/* Initialize the GIS calls */
31-
G_gisinit(argv[0]);
23+
struct GModule *module;
24+
struct Option *info_opt, *rast_opt, *vect_opt, *coor_opt;
25+
struct Cell_head window;
26+
27+
/* Initialize the GIS calls */
28+
G_gisinit( argv[0] );
3229

33-
module = G_define_module();
34-
module->description = ("Get info about locations,mapsets,maps");
30+
module = G_define_module();
31+
module->description = ( "Get info about locations,mapsets,maps" );
3532

36-
info_opt = G_define_option();
37-
info_opt->key = "info";
38-
info_opt->type = TYPE_STRING;
39-
info_opt->description = "info key";
40-
info_opt->options = "proj,window,query";
33+
info_opt = G_define_option();
34+
info_opt->key = "info";
35+
info_opt->type = TYPE_STRING;
36+
info_opt->description = "info key";
37+
info_opt->options = "proj,window,query";
4138

42-
rast_opt = G_define_standard_option(G_OPT_R_INPUT);
43-
rast_opt->key = "rast";
44-
rast_opt->required = NO;
39+
rast_opt = G_define_standard_option( G_OPT_R_INPUT );
40+
rast_opt->key = "rast";
41+
rast_opt->required = NO;
4542

46-
vect_opt = G_define_standard_option(G_OPT_V_INPUT);
47-
vect_opt->key = "vect";
48-
vect_opt->required = NO;
43+
vect_opt = G_define_standard_option( G_OPT_V_INPUT );
44+
vect_opt->key = "vect";
45+
vect_opt->required = NO;
4946

50-
coor_opt = G_define_option();
51-
coor_opt->key = "coor";
52-
coor_opt->type = TYPE_DOUBLE;
53-
coor_opt->multiple = YES;
54-
55-
if (G_parser(argc, argv))
56-
exit(EXIT_FAILURE);
47+
coor_opt = G_define_option();
48+
coor_opt->key = "coor";
49+
coor_opt->type = TYPE_DOUBLE;
50+
coor_opt->multiple = YES;
5751

52+
if ( G_parser( argc, argv ) )
53+
exit( EXIT_FAILURE );
5854

59-
if ( strcmp("proj",info_opt->answer) == 0 )
55+
56+
if ( strcmp( "proj", info_opt->answer ) == 0 )
57+
{
58+
G_get_window( &window );
59+
/* code from g.proj */
60+
if ( window.proj != PROJECTION_XY )
6061
{
61-
G_get_window(&window);
62-
/* code from g.proj */
63-
if (window.proj != PROJECTION_XY) {
64-
struct Key_Value *projinfo, *projunits;
65-
char *wkt;
66-
projinfo = G_get_projinfo();
67-
projunits = G_get_projunits();
68-
wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
69-
fprintf (stdout, "%s", wkt);
70-
}
62+
struct Key_Value *projinfo, *projunits;
63+
char *wkt;
64+
projinfo = G_get_projinfo();
65+
projunits = G_get_projunits();
66+
wkt = GPJ_grass_to_wkt( projinfo, projunits, 0, 0 );
67+
fprintf( stdout, "%s", wkt );
7168
}
72-
else if ( strcmp("window",info_opt->answer) == 0 )
69+
}
70+
else if ( strcmp( "window", info_opt->answer ) == 0 )
71+
{
72+
if ( rast_opt->answer )
7373
{
74-
if ( rast_opt->answer )
75-
{
76-
G_get_cellhd( rast_opt->answer, "", &window);
77-
fprintf (stdout, "%f,%f,%f,%f", window.west, window.south,window.east,window.north );
78-
}
79-
else if ( vect_opt->answer )
80-
{
81-
G_fatal_error ("Not yet supported");
82-
}
74+
G_get_cellhd( rast_opt->answer, "", &window );
75+
fprintf( stdout, "%f,%f,%f,%f", window.west, window.south, window.east, window.north );
8376
}
84-
else if ( strcmp("query",info_opt->answer) == 0 )
77+
else if ( vect_opt->answer )
8578
{
86-
double x, y;
87-
int row, col;
88-
x = atof ( coor_opt->answers[0] );
89-
y = atof ( coor_opt->answers[1] );
90-
if ( rast_opt->answer )
91-
{
92-
int fd;
93-
RASTER_MAP_TYPE rast_type;
94-
DCELL *dcell;
95-
CELL *cell;
96-
G_get_cellhd( rast_opt->answer, "", &window);
97-
G_set_window(&window);
98-
fd = G_open_cell_old( rast_opt->answer, "");
99-
col = (int) G_easting_to_col( x, &window);
100-
row = (int) G_northing_to_row( y, &window);
101-
if (col == window.cols) col--;
102-
if (row == window.rows) row--;
79+
G_fatal_error( "Not yet supported" );
80+
}
81+
}
82+
else if ( strcmp( "query", info_opt->answer ) == 0 )
83+
{
84+
double x, y;
85+
int row, col;
86+
x = atof( coor_opt->answers[0] );
87+
y = atof( coor_opt->answers[1] );
88+
if ( rast_opt->answer )
89+
{
90+
int fd;
91+
RASTER_MAP_TYPE rast_type;
92+
DCELL *dcell;
93+
CELL *cell;
94+
G_get_cellhd( rast_opt->answer, "", &window );
95+
G_set_window( &window );
96+
fd = G_open_cell_old( rast_opt->answer, "" );
97+
col = ( int ) G_easting_to_col( x, &window );
98+
row = ( int ) G_northing_to_row( y, &window );
99+
if ( col == window.cols ) col--;
100+
if ( row == window.rows ) row--;
103101

104-
if ( col < 0 || col > window.cols || row < 0 || row > window.rows )
105-
{
106-
fprintf (stdout, "value:null\n");
107-
}
108-
else
109-
{
110-
rast_type = G_get_raster_map_type(fd);
111-
cell = G_allocate_c_raster_buf();
112-
dcell = G_allocate_d_raster_buf();
102+
if ( col < 0 || col > window.cols || row < 0 || row > window.rows )
103+
{
104+
fprintf( stdout, "value:null\n" );
105+
}
106+
else
107+
{
108+
rast_type = G_get_raster_map_type( fd );
109+
cell = G_allocate_c_raster_buf();
110+
dcell = G_allocate_d_raster_buf();
113111

114-
if (rast_type == CELL_TYPE)
115-
{
116-
if (G_get_c_raster_row(fd, cell, row) < 0)
117-
{
118-
G_fatal_error(("Unable to read raster map <%s> row %d"),
119-
rast_opt->answer, row);
120-
}
121-
fprintf (stdout, "value:%d\n", cell[col] );
122-
}
123-
else
124-
{
125-
if (G_get_d_raster_row(fd, dcell, row) < 0)
126-
{
127-
G_fatal_error(("Unable to read raster map <%s> row %d"),
128-
rast_opt->answer, row);
129-
}
130-
fprintf (stdout, "value:%f\n", dcell[col] );
131-
}
112+
if ( rast_type == CELL_TYPE )
113+
{
114+
if ( G_get_c_raster_row( fd, cell, row ) < 0 )
115+
{
116+
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
117+
rast_opt->answer, row );
132118
}
133-
G_close_cell( fd );
119+
fprintf( stdout, "value:%d\n", cell[col] );
134120
}
135-
else if ( vect_opt->answer )
121+
else
136122
{
137-
G_fatal_error ("Not yet supported");
123+
if ( G_get_d_raster_row( fd, dcell, row ) < 0 )
124+
{
125+
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
126+
rast_opt->answer, row );
127+
}
128+
fprintf( stdout, "value:%f\n", dcell[col] );
138129
}
130+
}
131+
G_close_cell( fd );
132+
}
133+
else if ( vect_opt->answer )
134+
{
135+
G_fatal_error( "Not yet supported" );
139136
}
137+
}
140138

141-
exit(EXIT_SUCCESS);
139+
exit( EXIT_SUCCESS );
142140
}
143141

0 commit comments

Comments
 (0)
Please sign in to comment.