17 #include <grass/gis.h>
18 #include <grass/glocale.h>
46 if (cellhd->ns_res <= 0)
47 return (_(
"Illegal n-s resolution value"));
50 if (cellhd->rows <= 0)
51 return (_(
"Illegal row value"));
54 if (cellhd->ew_res <= 0)
55 return (_(
"Illegal e-w resolution value"));
58 if (cellhd->cols <= 0)
59 return (_(
"Illegal col value"));
63 if (cellhd->proj == PROJECTION_LL) {
64 double epsilon_ns, epsilon_ew;
67 epsilon_ns = 1. / cellhd->rows * 0.001;
70 G_debug(3,
"G_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
71 epsilon_ns, epsilon_ew);
76 if (cellhd->north > 90.0) {
77 if (((cellhd->north - 90.0) < epsilon_ns) &&
78 ((cellhd->north - 90.0) > GRASS_EPSILON)) {
79 G_warning(_(
"Fixing subtle input data rounding error of north boundary (%g>%g)"),
80 cellhd->north - 90.0, epsilon_ns);
84 return (_(
"Illegal latitude for North"));
87 if (cellhd->south < -90.0) {
88 if (((cellhd->south + 90.0) < epsilon_ns) &&
89 ((cellhd->south + 90.0) < GRASS_EPSILON)) {
90 G_warning(_(
"Fixing subtle input data rounding error of south boundary (%g>%g)"),
91 cellhd->south + 90.0, epsilon_ns);
92 cellhd->south = -90.0;
95 return (_(
"Illegal latitude for South"));
102 "G_adjust_Cell_head() cellhd->west: %f, devi: %g, eps: %g",
103 cellhd->west, cellhd->west + 180.0, epsilon_ew);
105 if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
106 && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
107 G_warning(_(
"Fixing subtle input data rounding error of west boundary (%g>%g)"),
108 cellhd->west + 180.0, epsilon_ew);
109 cellhd->west = -180.0;
113 "G_adjust_Cell_head() cellhd->east: %f, devi: %g, eps: %g",
114 cellhd->east, cellhd->east - 180.0, epsilon_ew);
116 if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
117 && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
118 G_warning(_(
"Fixing subtle input data rounding error of east boundary (%g>%g)"),
119 cellhd->east - 180.0, epsilon_ew);
120 cellhd->east = 180.0;
124 while (cellhd->east <= cellhd->west)
125 cellhd->east += 360.0;
129 if (cellhd->north <= cellhd->south) {
130 if (cellhd->proj == PROJECTION_LL)
131 return (_(
"North must be north of South"));
133 return (_(
"North must be larger than South"));
135 if (cellhd->east <= cellhd->west)
136 return (_(
"East must be larger than West"));
141 (cellhd->north - cellhd->south +
142 cellhd->ns_res / 2.0) / cellhd->ns_res;
143 if (cellhd->rows == 0)
148 (cellhd->east - cellhd->west +
149 cellhd->ew_res / 2.0) / cellhd->ew_res;
150 if (cellhd->cols == 0)
154 if (cellhd->cols < 0 || cellhd->rows < 0) {
155 return (_(
"Invalid coordinates"));
160 cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
161 cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
195 int col_flag,
int depth_flag)
198 if (cellhd->ns_res <= 0)
199 return (_(
"Illegal n-s resolution value"));
200 if (cellhd->ns_res3 <= 0)
201 return (_(
"Illegal n-s3 resolution value"));
204 if (cellhd->rows <= 0)
205 return (_(
"Illegal row value"));
206 if (cellhd->rows3 <= 0)
207 return (_(
"Illegal row3 value"));
210 if (cellhd->ew_res <= 0)
211 return (_(
"Illegal e-w resolution value"));
212 if (cellhd->ew_res3 <= 0)
213 return (_(
"Illegal e-w3 resolution value"));
216 if (cellhd->cols <= 0)
217 return (_(
"Illegal col value"));
218 if (cellhd->cols3 <= 0)
219 return (_(
"Illegal col3 value"));
222 if (cellhd->tb_res <= 0)
223 return (_(
"Illegal t-b3 resolution value"));
226 if (cellhd->depths <= 0)
227 return (_(
"Illegal depths value"));
231 if (cellhd->proj == PROJECTION_LL) {
232 double epsilon_ns, epsilon_ew;
235 epsilon_ns = 1. / cellhd->rows * 0.001;
236 epsilon_ew = .000001;
238 G_debug(3,
"G_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
239 epsilon_ns, epsilon_ew);
244 if (cellhd->north > 90.0) {
245 if (((cellhd->north - 90.0) < epsilon_ns) &&
246 ((cellhd->north - 90.0) > GRASS_EPSILON)) {
247 G_warning(_(
"Fixing subtle input data rounding error of north boundary (%g>%g)"),
248 cellhd->north - 90.0, epsilon_ns);
249 cellhd->north = 90.0;
252 return (_(
"Illegal latitude for North"));
255 if (cellhd->south < -90.0) {
256 if (((cellhd->south + 90.0) < epsilon_ns) &&
257 ((cellhd->south + 90.0) < GRASS_EPSILON)) {
258 G_warning(_(
"Fixing subtle input data rounding error of south boundary (%g>%g)"),
259 cellhd->south + 90.0, epsilon_ns);
260 cellhd->south = -90.0;
263 return (_(
"Illegal latitude for South"));
270 "G_adjust_Cell_head3() cellhd->west: %f, devi: %g, eps: %g",
271 cellhd->west, cellhd->west + 180.0, epsilon_ew);
273 if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
274 && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
275 G_warning(_(
"Fixing subtle input data rounding error of west boundary (%g>%g)"),
276 cellhd->west + 180.0, epsilon_ew);
277 cellhd->west = -180.0;
281 "G_adjust_Cell_head3() cellhd->east: %f, devi: %g, eps: %g",
282 cellhd->east, cellhd->east - 180.0, epsilon_ew);
284 if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
285 && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
286 G_warning(_(
"Fixing subtle input data rounding error of east boundary (%g>%g)"),
287 cellhd->east - 180.0, epsilon_ew);
288 cellhd->east = 180.0;
292 while (cellhd->east <= cellhd->west)
293 cellhd->east += 360.0;
297 if (cellhd->north <= cellhd->south) {
298 if (cellhd->proj == PROJECTION_LL)
299 return (_(
"North must be north of South"));
301 return (_(
"North must be larger than South"));
303 if (cellhd->east <= cellhd->west)
304 return (_(
"East must be larger than West"));
305 if (cellhd->top <= cellhd->bottom)
306 return (_(
"Top must be larger than Bottom"));
312 (cellhd->north - cellhd->south +
313 cellhd->ns_res / 2.0) / cellhd->ns_res;
314 if (cellhd->rows == 0)
318 (cellhd->north - cellhd->south +
319 cellhd->ns_res3 / 2.0) / cellhd->ns_res3;
320 if (cellhd->rows3 == 0)
325 (cellhd->east - cellhd->west +
326 cellhd->ew_res / 2.0) / cellhd->ew_res;
327 if (cellhd->cols == 0)
331 (cellhd->east - cellhd->west +
332 cellhd->ew_res3 / 2.0) / cellhd->ew_res3;
333 if (cellhd->cols3 == 0)
339 (cellhd->top - cellhd->bottom +
340 cellhd->tb_res / 2.0) / cellhd->tb_res;
341 if (cellhd->depths == 0)
346 if (cellhd->cols < 0 || cellhd->rows < 0 || cellhd->cols3 < 0 ||
347 cellhd->rows3 < 0 || cellhd->depths < 0) {
348 return (_(
"Invalid coordinates"));
352 cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
353 cellhd->ns_res3 = (cellhd->north - cellhd->south) / cellhd->rows3;
354 cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
355 cellhd->ew_res3 = (cellhd->east - cellhd->west) / cellhd->cols3;
356 cellhd->tb_res = (cellhd->top - cellhd->bottom) / cellhd->depths;
char * G_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag, int col_flag, int depth_flag)
Adjust cell header for 3D values.
char * G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.