00001
00002
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 #include <grass/gis.h>
00031
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <unistd.h>
00035 #include <sys/stat.h>
00036 #include <math.h>
00037
00038
00039
00040
00041
00042
00043
00044 int G__make_location(const char *location_name,
00045 struct Cell_head *wind,
00046 struct Key_Value *proj_info,
00047 struct Key_Value *proj_units, FILE * report_file)
00048 {
00049 char path[GPATH_MAX];
00050 int out_stat;
00051
00052
00053 sprintf(path, "%s/%s", G_gisdbase(), location_name);
00054 if (G_mkdir(path) != 0)
00055 return -1;
00056
00057
00058 sprintf(path, "%s/%s/%s", G_gisdbase(), location_name, "PERMANENT");
00059 if (G_mkdir(path) != 0)
00060 return -1;
00061
00062
00063 G__setenv("LOCATION_NAME", location_name);
00064 G__setenv("MAPSET", "PERMANENT");
00065
00066
00067 G__put_window(wind, "", "DEFAULT_WIND");
00068 G__put_window(wind, "", "WIND");
00069
00070
00071 if (proj_info != NULL) {
00072 G__file_name(path, "", "PROJ_INFO", "PERMANENT");
00073 G_write_key_value_file(path, proj_info, &out_stat);
00074 if (out_stat != 0)
00075 return -2;
00076 }
00077
00078 if (proj_units != NULL) {
00079 G__file_name(path, "", "PROJ_UNITS", "PERMANENT");
00080 G_write_key_value_file(path, proj_units, &out_stat);
00081 if (out_stat != 0)
00082 return -2;
00083 }
00084
00085 return 0;
00086 }
00087
00088
00123 int G_make_location(const char *location_name,
00124 struct Cell_head *wind,
00125 struct Key_Value *proj_info,
00126 struct Key_Value *proj_units, FILE * report_file)
00127 {
00128 int err;
00129
00130 err = G__make_location(location_name, wind, proj_info, proj_units,
00131 report_file);
00132
00133 if (err == 0)
00134 return 0;
00135
00136 if (err == -1) {
00137 perror("G_make_location");
00138 }
00139
00140 G_fatal_error("G_make_location failed.");
00141
00142 return 1;
00143 }
00144
00145
00146
00147
00148
00149
00150
00164 int
00165 G_compare_projections(const struct Key_Value *proj_info1,
00166 const struct Key_Value *proj_units1,
00167 const struct Key_Value *proj_info2,
00168 const struct Key_Value *proj_units2)
00169 {
00170 const char *proj1, *proj2;
00171
00172 if (proj_info1 == NULL && proj_info2 == NULL)
00173 return TRUE;
00174
00175
00176
00177
00178
00179 if (proj_info1 == NULL || proj_info2 == NULL)
00180 return -1;
00181
00182 proj1 = G_find_key_value("proj", proj_info1);
00183 proj2 = G_find_key_value("proj", proj_info2);
00184
00185 if (proj1 == NULL || proj2 == NULL || strcmp(proj1, proj2))
00186 return -1;
00187
00188
00189
00190
00191
00192 if (proj_units1 == NULL && proj_units2 == NULL)
00193 return TRUE;
00194
00195 if (proj_units1 == NULL || proj_units2 == NULL)
00196 return -2;
00197
00198 {
00199 double a1 = 0, a2 = 0;
00200
00201 if (G_find_key_value("meters", proj_units1) != NULL)
00202 a1 = atof(G_find_key_value("meters", proj_units1));
00203 if (G_find_key_value("meters", proj_units2) != NULL)
00204 a2 = atof(G_find_key_value("meters", proj_units2));
00205
00206 if (a1 && a2 && (fabs(a2 - a1) > 0.000001))
00207 return -2;
00208 }
00209
00210
00211
00212
00213
00214
00215 {
00216 double a1 = 0, a2 = 0;
00217
00218 if (G_find_key_value("a", proj_info1) != NULL)
00219 a1 = atof(G_find_key_value("a", proj_info1));
00220 if (G_find_key_value("a", proj_info2) != NULL)
00221 a2 = atof(G_find_key_value("a", proj_info2));
00222
00223 if (a1 && a2 && (fabs(a2 - a1) > 0.000001))
00224 return -4;
00225 }
00226
00227
00228
00229
00230 if (!strcmp(proj1, "utm") && !strcmp(proj2, "utm")
00231 && atof(G_find_key_value("zone", proj_info1))
00232 != atof(G_find_key_value("zone", proj_info2)))
00233 return -5;
00234
00235
00236
00237
00238
00239 {
00240 char *x_0_1 = NULL, *x_0_2 = NULL;
00241
00242 x_0_1 = G_find_key_value("x_0", proj_info1);
00243 x_0_2 = G_find_key_value("x_0", proj_info2);
00244
00245 if (x_0_1 && x_0_2 && (fabs(atof(x_0_1) - atof(x_0_2)) > 0.000001))
00246 return -6;
00247 }
00248
00249
00250
00251
00252
00253 {
00254 char *y_0_1 = NULL, *y_0_2 = NULL;
00255
00256 y_0_1 = G_find_key_value("y_0", proj_info1);
00257 y_0_2 = G_find_key_value("y_0", proj_info2);
00258
00259 if (y_0_1 && y_0_2 && (fabs(atof(y_0_1) - atof(y_0_2)) > 0.000001))
00260 return -7;
00261 }
00262
00263
00264
00265
00266
00267 return TRUE;
00268 }