浏览代码

libproj (#252)

* libproj

fix lookup mechanism for datum grids with all versions of PROJ
Markus Metz 5 年之前
父节点
当前提交
4dc36bb86f
共有 3 个文件被更改,包括 29 次插入21 次删除
  1. 1 1
      include/defs/gprojects.h
  2. 10 11
      lib/proj/datum.c
  3. 18 9
      lib/proj/get_proj.c

+ 1 - 1
include/defs/gprojects.h

@@ -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 */

+ 10 - 11
lib/proj/datum.c

@@ -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",

+ 18 - 9
lib/proj/get_proj.c

@@ -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
 
@@ -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)
@@ -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;
 }