/* * d.extend: set window region from displayed maps. * * Copyright (C) 2000 by the GRASS Development Team * Author: Huidae Cho * * This program is free software under the GPL (>=v2) * Read the file COPYING coming with GRASS for details. * */ #include #include #include #include #include #include #include int main (int argc, char **argv) { struct GModule *module; int i, first=1; char *mapset; char **rast, **vect, **site; int nrasts, nvects, nsites; struct Cell_head window, temp_window; G_gisinit(argv[0]) ; module = G_define_module(); module->keywords = _("display, setup"); module->description = "Set window region so that all currently displayed raster, " "vector and sites maps can be shown in a monitor."; if(argc > 1 && G_parser(argc, argv)) exit(-1); if (R_open_driver() != 0) G_fatal_error ("No graphics device selected"); if(D_get_cell_list (&rast, &nrasts) < 0) rast = NULL; if(D_get_dig_list (&vect, &nvects) < 0) vect = NULL; if(D_get_site_list (&site, &nsites) < 0) site = NULL; R_close_driver(); if (rast == NULL && vect == NULL && site == NULL) G_fatal_error("No raster, vector or sites file displayed"); G_get_window(&window); if (rast) { for(i=0; i= 0) { if(first) { first = 0; G_copy(&window, &temp_window, sizeof(window)); } else { if(window.east < temp_window.east) window.east = temp_window.east; if(window.west > temp_window.west) window.west = temp_window.west; if(window.south > temp_window.south) window.south = temp_window.south; if(window.north < temp_window.north) window.north = temp_window.north; /* if(window.ns_res < nsres) nsres = window.ns_res; if(window.ew_res < ewres) ewres = window.ew_res; */ } } } G_adjust_Cell_head3(&window, 0, 0, 0); } if (vect) { struct Map_info Map; G_copy(&temp_window, &window, sizeof(window)); Vect_set_open_level(2); for(i=0; i Map.plus.box.W) window.west = Map.plus.box.W; if(window.south > Map.plus.box.S) window.south = Map.plus.box.S; if(window.north < Map.plus.box.N) window.north = Map.plus.box.N; } Vect_close(&Map); } } if(window.north == window.south) { window.north += 0.5 * temp_window.ns_res; window.south -= 0.5 * temp_window.ns_res; } if(window.east == window.west) { window.east += 0.5 * temp_window.ew_res; window.west -= 0.5 * temp_window.ew_res; } G_align_window(&window, &temp_window); } if (site) { FILE *fp; Site *s; int rtype, ndim, nstr, ndec; G_copy(&temp_window, &window, sizeof(window)); for(i=0; ieast; window.west = s->east; window.south = s->north; window.north = s->north; } else { if(window.east < s->east) window.east = s->east; if(window.west > s->east) window.west = s->east; if(window.south > s->north) window.south = s->north; if(window.north < s->north) window.north = s->north; } } /* is 100 enough to contain one point from * boundary? east += 100; west -= 100; south -= 100; north += 100; */ G_free(s); fclose(fp); } } if(window.north == window.south) { window.north += 0.5 * temp_window.ns_res; window.south -= 0.5 * temp_window.ns_res; } if(window.east == window.west) { window.east += 0.5 * temp_window.ew_res; window.west -= 0.5 * temp_window.ew_res; } G_align_window(&window, &temp_window); } G_adjust_Cell_head3(&window, 0, 0, 0); G_put_window(&window); exit(0); }