File: map_setup.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (119 lines) | stat: -rw-r--r-- 3,716 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* Function: map_setup
 **
 ** Author: Paul W. Carlson     3/92
 */

#include <grass/gis.h>
#include <grass/glocale.h>
#include "local_proto.h"
#include "distance.h"

int map_setup(void)
{
    double w, h;

    /* set top of map */
    if (PS.set_y < PS.min_y)
        PS.min_y = PS.set_y;
    PS.map_y_orig = PS.min_y / 72.0;

    if (!PS.do_raster && !grp.do_group) {
        /* if scale has been set... */
        if (PS.scaletext[0]) {
            /* if scaled map will fit in map limits... */
            w = scale(PS.scaletext);
            h = w * (PS.w.north - PS.w.south) / (PS.w.east - PS.w.west);
            if (w <= PS.map_width && h <= PS.map_height) {
                PS.map_width = w;
                PS.map_height = h;
                PS.map_pix_wide = 72.0 * PS.map_width;
                PS.map_pix_high = 72.0 * PS.map_height;
            }
            else /* kill the scale */
                PS.scaletext[0] = 0;
        }

        /* fit map to bounding box */
        fit_map_to_box();
    }

    else {
        if (PS.scaletext[0]) {
            /* if scaled map will fit in map limits... */
            w = scale(PS.scaletext);
            h = w * PS.w.ns_res * (double)PS.w.rows /
                (PS.w.ew_res * (double)PS.w.cols);
            if (w <= PS.map_width && h <= PS.map_height) {
                PS.map_width = w;
                PS.map_height = h;
                PS.map_pix_wide = 72.0 * PS.map_width;
                PS.map_pix_high = 72.0 * PS.map_height;
            }
            else /* kill the scale */
                PS.scaletext[0] = 0;
        }

        /* fit map to bounding box */
        fit_map_to_box();

        PS.cells_high = PS.w.rows;
        PS.cells_wide = PS.w.cols;
        PS.ew_res = PS.w.ew_res;
        PS.ns_res = PS.w.ns_res;

        PS.row_delta = 1;
        PS.col_delta = 1;

        /* compute conversion factors */
        PS.ew_to_x = PS.map_pix_wide / (PS.w.east - PS.w.west);
        PS.ns_to_y = PS.map_pix_high / (PS.w.north - PS.w.south);
    }

    /* set the scale */
    /*   work from height not width to minimize lat/lon curvature problems?? */
    if (!PS.scaletext[0]) {
        sprintf(PS.scaletext, "1 : %.0f",
                METERS_TO_INCHES * distance(PS.w.east, PS.w.west) * 72.0 /
                    PS.map_pix_wide);
    }

    G_message(_("Scale set to %s"), PS.scaletext);

    /* compute map edges */
    PS.map_left = 72.0 * PS.map_x_orig;
    PS.map_top = 72.0 * PS.map_y_orig;
    PS.map_bot = PS.map_top - PS.map_pix_high;
    PS.map_right = PS.map_left + PS.map_pix_wide;
    PS.min_y = PS.map_bot;

    /* we want the size to be 10 times biger, because G_plot_where_xy()
       returns integer values (pixels) for x and y, and we want doubles
       until the first decimal point. Then in move() and cont() we will
       divide x and y by 10. to get double coordinates */
    G_setup_plot(PS.map_top * 10., PS.map_bot * 10., PS.map_left * 10.,
                 PS.map_right * 10., move_local, cont_local);

    /* debug fprintf (stdout,"t %.1f b %.1f l %.1f r %.1f\n", PS.map_top,
       PS.map_bot, PS.map_left, PS.map_right);
     */

    /* no need to go on if we're just here for a look-see. (-b flag) */
    if (!PS.fp)
        return 0;

    /* save original graphics state */
    fprintf(PS.fp, "gsave ");

    /* compute conversion factor from meters to PostScript window coordinates */
    /*
       G_begin_distance_calculations();
       meters_to_PS = (PS.map_top - PS.map_bot) / G_distance(0., PS.w.south, 0.,
       PS.w.north);
     */

    /* clip to edge of border */
    box_clip(PS.map_top - 1.0, PS.map_bot + 1.0, PS.map_left + 1.0,
             PS.map_right - 1.0);

    return 0;
}