00001 #include "gis.h"
00002 #include "glocale.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00064 char *G_adjust_Cell_head(struct Cell_head *cellhd,int row_flag,int col_flag)
00065 {
00066 if (!row_flag)
00067 {
00068 if (cellhd->ns_res <= 0)
00069 return (_("Illegal n-s resolution value"));
00070 }
00071 else
00072 {
00073 if (cellhd->rows <= 0)
00074 return (_("Illegal row value"));
00075 }
00076 if (!col_flag)
00077 {
00078 if (cellhd->ew_res <= 0)
00079 return (_("Illegal e-w resolution value"));
00080 }
00081 else
00082 {
00083 if (cellhd->cols <= 0)
00084 return (_("Illegal col value"));
00085 }
00086
00087
00088 if (cellhd->proj == PROJECTION_LL)
00089 {
00090 if (cellhd->north > 90.0)
00091 return (_("Illegal latitude for North"));
00092 if (cellhd->south < -90.0)
00093 return (_("Illegal latitude for South"));
00094 while (cellhd->east <= cellhd->west)
00095 cellhd->east += 360.0;
00096 }
00097
00098
00099 if (cellhd->north <= cellhd->south)
00100 {
00101 if (cellhd->proj == PROJECTION_LL)
00102 return (_("North must be north of South"));
00103 else
00104 return (_("North must be larger than South"));
00105 }
00106 if (cellhd->east <= cellhd->west)
00107 return (_("East must be larger than West"));
00108
00109
00110
00111 if (!row_flag)
00112 {
00113 cellhd->rows = (cellhd->north - cellhd->south + cellhd->ns_res/2.0) / cellhd->ns_res;
00114 if (cellhd->rows == 0)
00115 cellhd->rows = 1;
00116 }
00117 if (!col_flag)
00118 {
00119 cellhd->cols = (cellhd->east - cellhd->west + cellhd->ew_res/2.0) / cellhd->ew_res;
00120 if (cellhd->cols == 0)
00121 cellhd->cols = 1;
00122 }
00123
00124 if (cellhd->cols < 0 || cellhd->rows < 0 )
00125 {
00126 return (_("Invalid coordinates"));
00127 }
00128
00129
00130
00131 cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
00132 cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
00133
00134 return NULL;
00135 }
00136
00161 char *G_adjust_Cell_head3(struct Cell_head *cellhd,int row_flag,int col_flag, int depth_flag)
00162 {
00163 if (!row_flag)
00164 {
00165 if (cellhd->ns_res <= 0)
00166 return (_("Illegal n-s resolution value"));
00167 if (cellhd->ns_res3 <= 0)
00168 return (_("Illegal n-s3 resolution value"));
00169 }
00170 else
00171 {
00172 if (cellhd->rows <= 0)
00173 return (_("Illegal row value"));
00174 if (cellhd->rows3 <= 0)
00175 return (_("Illegal row3 value"));
00176 }
00177 if (!col_flag)
00178 {
00179 if (cellhd->ew_res <= 0)
00180 return (_("Illegal e-w resolution value"));
00181 if (cellhd->ew_res3 <= 0)
00182 return (_("Illegal e-w3 resolution value"));
00183 }
00184 else
00185 {
00186 if (cellhd->cols <= 0)
00187 return (_("Illegal col value"));
00188 if (cellhd->cols3 <= 0)
00189 return (_("Illegal col3 value"));
00190 }
00191 if (!depth_flag)
00192 {
00193 if (cellhd->tb_res <= 0)
00194 return (_("Illegal t-b3 resolution value"));
00195 }
00196 else
00197 {
00198 if (cellhd->depths <= 0)
00199 return (_("Illegal depths value"));
00200 }
00201
00202
00203 if (cellhd->proj == PROJECTION_LL)
00204 {
00205 if (cellhd->north > 90.0)
00206 return (_("Illegal latitude for North"));
00207 if (cellhd->south < -90.0)
00208 return (_("Illegal latitude for South"));
00209 while (cellhd->east <= cellhd->west)
00210 cellhd->east += 360.0;
00211 }
00212
00213
00214 if (cellhd->north <= cellhd->south)
00215 {
00216 if (cellhd->proj == PROJECTION_LL)
00217 return (_("North must be north of South"));
00218 else
00219 return (_("North must be larger than South"));
00220 }
00221 if (cellhd->east <= cellhd->west)
00222 return (_("East must be larger than West"));
00223
00224
00225
00226 if (!row_flag)
00227 {
00228 cellhd->rows = (cellhd->north - cellhd->south + cellhd->ns_res/2.0) / cellhd->ns_res;
00229 if (cellhd->rows == 0)
00230 cellhd->rows = 1;
00231
00232 cellhd->rows3 = (cellhd->north - cellhd->south + cellhd->ns_res3/2.0) / cellhd->ns_res3;
00233 if (cellhd->rows3 == 0)
00234 cellhd->rows3 = 1;
00235 }
00236 if (!col_flag)
00237 {
00238 cellhd->cols = (cellhd->east - cellhd->west + cellhd->ew_res/2.0) / cellhd->ew_res;
00239 if (cellhd->cols == 0)
00240 cellhd->cols = 1;
00241
00242 cellhd->cols3 = (cellhd->east - cellhd->west + cellhd->ew_res3/2.0) / cellhd->ew_res3;
00243 if (cellhd->cols3 == 0)
00244 cellhd->cols3 = 1;
00245 }
00246
00247 if (!depth_flag)
00248 {
00249 cellhd->depths = (cellhd->top - cellhd->bottom + cellhd->tb_res/2.0) / cellhd->tb_res;
00250 if (cellhd->depths < 0)
00251 cellhd->depths = 1;
00252
00253 }
00254
00255
00256 if (cellhd->cols < 0 || cellhd->rows < 0 || cellhd->cols3 < 0 || cellhd->rows3 < 0
00257 || cellhd->depths < 0 )
00258 {
00259 return (_("Invalid coordinates"));
00260 }
00261
00262
00263
00264 cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
00265 cellhd->ns_res3 = (cellhd->north - cellhd->south) / cellhd->rows3;
00266 cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
00267 cellhd->ew_res3 = (cellhd->east - cellhd->west) / cellhd->cols3;
00268 cellhd->tb_res = (cellhd->top - cellhd->bottom) / cellhd->depths;
00269
00270 return NULL;
00271 }
00272