-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyses.h
112 lines (98 loc) · 3.03 KB
/
analyses.h
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
#ifndef ANALYSES_H
#define ANALYSES_H
extern "C" {
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/vector.h>
#include <grass/spawn.h>
#include <grass/glocale.h>
}
#include <stdlib.h>
inline
int contours(const char *map, const char *output, float step)
{
char buf[1024];
const char *argv[8], *argv2[8];
int argc = 0;
int argc2 = 0;
/* first set computational region */
argv2[argc2++] = "g.region";
argv2[argc2++] = "-u";
sprintf(buf, "raster=%s", map);
argv2[argc2++] = G_store(buf);
argv2[argc2++] = "save=contours_region";
argv2[argc2++] = "--o";
argv2[argc2++] = NULL;
G_vspawn_ex(argv2[0], argv2);
setenv("WIND_OVERRIDE", "contours_region", 1);
/* then run contours */
argv[argc++] = "r.contour";
argv[argc++] = "-t";
argv[argc++] = "--o";
sprintf(buf, "input=%s", map);
argv[argc++] = G_store(buf);
sprintf(buf, "output=%s", output);
argv[argc++] = G_store(buf);
sprintf(buf, "step=%f", step);
argv[argc++] = G_store(buf);
argv[argc++] = NULL;
return G_vspawn_ex(argv[0], argv);
}
inline
void set_default_color(char* raster) {
/* colortable for elevations */
struct Colors colors;
struct FPRange range;
double zmin, zmax;
Rast_init_colors(&colors);
Rast_read_fp_range(raster, "", &range);
Rast_get_fp_range_min_max(&range, &zmin, &zmax);
double zstep = (FCELL) (zmax - zmin) / 5.;
for (int j = 1; j <= 5; j++) {
FCELL data1 = (FCELL) (zmin + (j - 1) * zstep);
FCELL data2 = (FCELL) (zmin + j * zstep);
switch (j) {
case 1:
Rast_add_f_color_rule(&data1, 50, 121, 70,
&data2, 90, 148, 80, &colors);
break;
case 2:
Rast_add_f_color_rule(&data1, 90, 148, 80,
&data2, 148, 174, 92, &colors);
break;
case 3:
Rast_add_f_color_rule(&data1, 148, 174, 92,
&data2, 224, 205, 103, &colors);
break;
case 4:
Rast_add_f_color_rule(&data1, 224, 205, 103,
&data2, 186, 151, 74, &colors);
break;
case 5:
Rast_add_f_color_rule(&data1, 186, 151, 74,
&data2, 159, 100, 44, &colors);
break;
}
}
const char *mapset = G_find_file("cell", raster, "");
Rast_write_colors(raster, mapset, &colors);
Rast_quantize_fp_map_range(raster, mapset,
(DCELL) zmin - 0.5, (DCELL) zmax + 0.5,
(CELL) (zmin - 0.5), (CELL) (zmax + 0.5));
}
inline
int equalized(const char *map)
{
char buf[1024];
const char *argv[5];
int argc = 0;
argv[argc++] = "r.colors";
argv[argc++] = "-e";
argv[argc++] = "--q";
argv[argc++] = "color=elevation";
sprintf(buf, "map=%s", map);
argv[argc++] = G_store(buf);
argv[argc++] = NULL;
return G_vspawn_ex(argv[0], argv);
}
#endif // ANALYSES_H