Question on UTM to Screen Conversion
Evan Preston
preston at malibu.dst.battelle.org
Wed Aug 17 15:14:02 EDT 1994
GRASS programming gurus:
I have been trying (unsuccessfully) to solve the following problem:
I want to be able to take a UTM coordinate (within my current region), and
convert it to screen coordinates so that I may use the R_panel_save routine
to save the "chunk" of map surrounding the UTM position. Here's a section of
my code (not the entire program):
void flash (char *icon)
{
FILE *file;
int i, t, b, l, r;
char cmd[256],
*panel;
struct Cell_head region;
double y,
x,
east,
north;
/* initialize grass libraries */
G_gisinit("flash");
/* read in easting and northing */
file = fopen(icon, "r");
fscanf(file, "%lf %lf", &east, &north);
fclose(file);
R_open_driver();
D_setup(0);
/* get screen max, min */
t=R_screen_top();
b=R_screen_bot();
l=R_screen_left();
r=R_screen_rite();
/* convert E, N to screen coords, define panel size, save panel */
G_get_window(®ion);
D_get_screen_window(&t,&b,&l,&r);
D_do_conversions(®ion,t,b,l,r);
y=D_u_to_d_row(north);
x=D_u_to_d_col(east);
/* define box */
t=y+10;
b=y-10;
r=x+10;
l=x-10;
/* save map "chunk", draw a simple box, then restore map "chunk" */
panel = G_tempfile();
R_panel_save(panel,t,b,l,r);
R_standard_color(1);
R_box_abs(l,t,r,b);
R_panel_restore(panel);
R_panel_delete(panel);
R_close_driver();
}
The screen coordinates, and region parameters sent to D_do_conversions appear
"normal", as follows:
east=228947.683604
north=4412208.345485
screen window: 0 829 0 1144 (top bottom left right)
Cell_head info:
North: 4762270.000000
South: 3650770.000000
West: -103279.000000
East: 877763.000000
ew-res: 7109.000000
ns-res: 8892.000000
The results from the call to D_u_to_d_row and D_u_to_d_col are as follows:
y=1095816396.000000 x=1091302045.000000
(Shouldn't these numbers be somewhere between the original screen limits
of 0-829 and 0-1144??)
Consequently, when I add and subtract constants from these numbers to define the
size of a box, I am getting the following type of nasty X errors (right after
the call to R_panel_save).
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 73 (X_GetImage)
Serial number of failed request: 1485
Current serial number in output stream: 1485
ERROR eof from graphics driver.
Any ideas whats causing this program to blow up? Many thanks in advance!
################################################################################
# Evan B. Preston # Battelle #
# phone: 614.424.3983 # National Security Division #
# fax: 614.424.3776 # 505 King Ave. #
# internet: preston at malibu.dst.battelle.org # Columbus, Ohio 43201 #
################################################################################
More information about the grass-dev
mailing list