22 #include <grass/gis.h>
23 #include <grass/gprojects.h>
24 #include <grass/glocale.h>
29 #define FINDERFUNC set_proj_lib
30 #define PERMANENT "PERMANENT"
33 static void alloc_options(
char *);
62 struct Key_Value *in_units_keys)
68 char buffa[300], factbuff[50];
69 char proj_in[50], *datum, *params;
79 strcpy(factbuff, str);
80 if (strlen(factbuff) > 0)
81 sscanf(factbuff,
"%lf", &(info->meters));
91 if (strlen(info->proj) <= 0)
95 for (i = 0; i < in_proj_keys->nitems; i++) {
97 if (strcmp(in_proj_keys->key[i],
"name") == 0) {
102 else if (strcmp(in_proj_keys->key[i],
"zone") == 0) {
109 else if (strcmp(in_proj_keys->key[i],
"datum") == 0
110 || strcmp(in_proj_keys->key[i],
"dx") == 0
111 || strcmp(in_proj_keys->key[i],
"dy") == 0
112 || strcmp(in_proj_keys->key[i],
"dz") == 0
113 || strcmp(in_proj_keys->key[i],
"datumparams") == 0
114 || strcmp(in_proj_keys->key[i],
"nadgrids") == 0
115 || strcmp(in_proj_keys->key[i],
"towgs84") == 0
116 || strcmp(in_proj_keys->key[i],
"ellps") == 0
117 || strcmp(in_proj_keys->key[i],
"a") == 0
118 || strcmp(in_proj_keys->key[i],
"b") == 0
119 || strcmp(in_proj_keys->key[i],
"es") == 0
120 || strcmp(in_proj_keys->key[i],
"f") == 0
121 || strcmp(in_proj_keys->key[i],
"rf") == 0) {
127 else if (strcmp(in_proj_keys->key[i],
"proj") == 0) {
128 if (strcmp(in_proj_keys->value[i],
"ll") == 0)
129 sprintf(buffa,
"proj=longlat");
131 sprintf(buffa,
"proj=%s", in_proj_keys->value[i]);
137 else if (strcmp(in_proj_keys->value[i],
"defined") == 0)
138 sprintf(buffa,
"%s", in_proj_keys->key[i]);
142 in_proj_keys->key[i], in_proj_keys->value[i]);
144 alloc_options(buffa);
149 if (sscanf(str,
"%d", &(info->zone)) != 1) {
152 if (info->zone < 0) {
155 info->zone = -info->zone;
159 alloc_options(buffa);
162 sprintf(buffa,
"zone=%d", info->zone);
163 alloc_options(buffa);
171 sprintf(buffa,
"ellps=%s", str);
172 alloc_options(buffa);
176 alloc_options(buffa);
182 sprintf(buffa,
"rf=%.16g", rf);
183 alloc_options(buffa);
190 alloc_options(buffa);
196 alloc_options(buffa);
202 else if (datum !=
NULL) {
206 alloc_options(buffa);
214 sprintf(buffa,
"datum=%s", datum);
215 alloc_options(buffa);
228 if (!(pj = pj_init(nopt1, opt_in))) {
230 _(
"Unable to initialise PROJ.4 with the following parameter list:"));
231 for (i = 0; i < nopt1; i++) {
234 sprintf(err,
" +%s", opt_in[i]);
238 G_warning(_(
"The error message: %s"), pj_strerrno(pj_errno));
246 static void alloc_options(
char *buffa)
250 nsize = strlen(buffa);
251 opt_in[nopt1++] = (
char *)G_malloc(nsize + 1);
252 sprintf(opt_in[nopt1 - 1],
"%s", buffa);
262 char zonebuff[50], buffa[300];
266 info->proj[0] =
'\0';
269 if ((str ==
NULL) || (str[0] ==
'\0')) {
274 sprintf(buffa,
"proj=latlong ellps=WGS84");
275 nsize = strlen(buffa);
276 opt_in[nopt] = (
char *)G_malloc(nsize + 1);
277 sprintf(opt_in[nopt++],
"%s", buffa);
285 while (s = strtok(s,
" \t\n"), s) {
286 if (strncmp(s,
"+unfact=", 8) == 0) {
288 info->meters = atof(s);
291 if (strncmp(s,
"+", 1) == 0)
293 if (nsize = strlen(s), nsize) {
295 fprintf(stderr,
"nopt = %d, s=%s\n", nopt, str);
299 if (strncmp(
"zone=", s, 5) == 0) {
300 sprintf(zonebuff,
"%s", s + 5);
301 sscanf(zonebuff,
"%d", &(info->zone));
304 if (strncmp(
"proj=", s, 5) == 0) {
305 sprintf(info->proj,
"%s", s + 5);
306 if (strcmp(info->proj,
"ll") == 0)
307 sprintf(buffa,
"proj=latlong");
314 nsize = strlen(buffa);
315 opt_in[nopt] = (
char *)G_malloc(nsize + 1);
316 sprintf(opt_in[nopt++],
"%s", buffa);
326 if (!(pj = pj_init(nopt, opt_in))) {
327 G_warning(_(
"Unable to initialize pj cause: %s"),
328 pj_strerrno(pj_errno));
357 if ((pjnew->pj = pj_latlong_from_proj(pjold->pj)) ==
NULL)
370 static size_t buf_len;
371 size_t len = strlen(gisbase) +
sizeof(GRIDDIR) + strlen(name) + 1;
377 buf = G_malloc(buf_len);
380 sprintf(buf,
"%s%s/%s", gisbase, GRIDDIR, name);
401 str = pj_get_def(iproj->pj, 1);
403 fprintf(stderr,
"%s: %s\n", _(
"Input Projection Parameters"),
406 fprintf(stderr,
"%s: %.16g\n", _(
"Input Unit Factor"),
414 str = pj_get_def(oproj->pj, 1);
416 fprintf(stderr,
"%s: %s\n", _(
"Output Projection Parameters"),
419 fprintf(stderr,
"%s: %.16g\n", _(
"Output Unit Factor"),
def info
Display an informational message using g.message -i
char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key.
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
int pj_get_kv(struct pj_info *info, struct Key_Value *in_proj_keys, struct Key_Value *in_units_keys)
Create a pj_info struct Co-ordinate System definition from a set of PROJ_INFO / PROJ_UNITS-style key-...
int GPJ_get_equivalent_latlong(struct pj_info *pjnew, struct pj_info *pjold)
Define a latitude / longitude co-ordinate system with the same ellipsoid and datum parameters as an e...
int pj_print_proj_params(struct pj_info *iproj, struct pj_info *oproj)
Print projection parameters as used by PROJ.4 for input and output co-ordinate systems.
const char * set_proj_lib(const char *name)
int GPJ__get_ellipsoid_params(struct Key_Value *proj_keys, double *a, double *e2, double *rf)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int GPJ__get_datum_params(struct Key_Value *projinfo, char **datumname, char **params)
Extract the datum transformation-related parameters from a set of general PROJ_INFO parameters...
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int GPJ_get_default_datum_params_by_name(const char *name, char **params)
"Last resort" function to retrieve a "default" set of datum parameters for a datum (N...
char * G_gisbase(void)
top level module directory
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int pj_get_string(struct pj_info *info, char *str)