Skip to content

Commit

Permalink
libproj (#252)
Browse files Browse the repository at this point in the history
* libproj

fix lookup mechanism for datum grids with all versions of PROJ
  • Loading branch information
metzm committed Dec 9, 2019
1 parent 2de2a0c commit 5d486a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/defs/gprojects.h
Expand Up @@ -22,7 +22,7 @@ int pj_get_string(struct pj_info *, char *);
#ifndef HAVE_PROJ_H
int GPJ_get_equivalent_latlong(struct pj_info *, struct pj_info *);
#endif
const char *set_proj_lib(const char *);
const char *set_proj_share(const char *);
int pj_print_proj_params(const struct pj_info *, const struct pj_info *);

/* convert.c */
Expand Down
21 changes: 10 additions & 11 deletions lib/proj/datum.c
Expand Up @@ -189,17 +189,16 @@ int GPJ__get_datum_params(const struct Key_Value *projinfo,
returnval = 2;
}
else if (G_find_key_value("nadgrids", projinfo) != NULL) {
const char *projshare = getenv("GRASS_PROJSHARE");

if (!projshare) {
G_warning(_("Failed to detect nadgrids path, GRASS_PROJSHARE not defined"));
returnval = -1;
}
else {
G_asprintf(params, "nadgrids=%s%c%s", projshare, HOST_DIRSEP,
G_find_key_value("nadgrids", projinfo));
returnval = 2;
}
/* 1. beware of '@', do not create something like
* /usr/share/proj/@null, correct is @null or
* @/usr/share/proj/null
* 2. do not add path to the grid, there might already be a
* path, and it is safer to use pj_set_finder with PROJ.4 in
* datum.c */

G_asprintf(params, "nadgrids=%s", G_find_key_value("nadgrids", projinfo));

returnval = 2;
}
else if (G_find_key_value("towgs84", projinfo) != NULL) {
G_asprintf(params, "towgs84=%s",
Expand Down
27 changes: 18 additions & 9 deletions lib/proj/get_proj.c
Expand Up @@ -23,8 +23,8 @@
#include <grass/gprojects.h>
#include <grass/glocale.h>

/* Finder function for datum conversion lookup tables */
#define FINDERFUNC set_proj_lib
/* Finder function for datum transformation grids */
#define FINDERFUNC set_proj_share
#define PERMANENT "PERMANENT"
#define MAX_PARGS 100

Expand Down Expand Up @@ -486,15 +486,24 @@ int GPJ_get_equivalent_latlong(struct pj_info *pjnew, struct pj_info *pjold)
}
#endif

/* set_proj_lib()
* 'finder function' for use with PROJ.4 pj_set_finder() function */
/* set_proj_share()
* 'finder function' for use with PROJ.4 pj_set_finder() function
* this is used to find grids, usually in /usr/share/proj
* GRASS no longer provides copies of proj grids in GRIDDIR
* -> do not use gisbase/GRIDDIR */

const char *set_proj_lib(const char *name)
const char *set_proj_share(const char *name)
{
const char *gisbase = G_gisbase();
static char *buf = NULL;
static size_t buf_len;
size_t len = strlen(gisbase) + sizeof(GRIDDIR) + strlen(name) + 1;
const char *projshare;
static size_t buf_len = 0;
size_t len;

projshare = getenv("GRASS_PROJSHARE");
if (!projshare)
return NULL;

len = strlen(projshare) + strlen(name) + 2;

if (buf_len < len) {
if (buf != NULL)
Expand All @@ -503,7 +512,7 @@ const char *set_proj_lib(const char *name)
buf = G_malloc(buf_len);
}

sprintf(buf, "%s%s/%s", gisbase, GRIDDIR, name);
sprintf(buf, "%s/%s", projshare, name);

return buf;
}
Expand Down

0 comments on commit 5d486a7

Please sign in to comment.