瀏覽代碼

liproj: add hack for internal fns in PROJ 5+, to be removed again

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@72470 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 7 年之前
父節點
當前提交
374c6f70be
共有 3 個文件被更改,包括 24 次插入68 次删除
  1. 11 24
      lib/proj/convert.c
  2. 9 14
      lib/proj/do_proj.c
  3. 4 30
      lib/proj/get_proj.c

+ 11 - 24
lib/proj/convert.c

@@ -33,21 +33,11 @@
 static void DatumNameMassage(char **);
 #endif
 
+/* TODO: remove hack for PROJ 5+ */
 #ifdef HAVE_PROJ_H
-char *gpj_get_def(PJ *P)
-{
-    char *pjdef;
-    PJ_PROJ_INFO pjinfo;
-
-    if (P == NULL)
-	G_fatal_error("Invalid PJ pointer");
-
-    pjinfo = proj_pj_info(P);
-
-    pjdef = G_store(pjinfo.definition);
-
-    return pjdef;
-}
+char *pj_get_def(PJ *, int);
+void pj_dalloc(void *);
+void pj_free(PJ *);
 #endif
 
 
@@ -207,22 +197,21 @@ OGRSpatialReferenceH GPJ_grass_to_osr(const struct Key_Value * proj_info,
 
     hSRS = OSRNewSpatialReference(NULL);
 
+    /* create PROJ structure from GRASS key/value pairs */
     if (pj_get_kv(&pjinfo, proj_info, proj_units) < 0) {
 	G_warning(_("Unable parse GRASS PROJ_INFO file"));
 	return NULL;
     }
 
-#ifdef HAVE_PROJ_H
-    if ((proj4 = gpj_get_def(pjinfo.pj)) == NULL) {
+    /* fetch the PROJ definition */
+    /* TODO: get the PROJ definition as used by pj_get_kv() */
+    if ((proj4 = pj_get_def(pjinfo.pj, 0)) == NULL) {
 	G_warning(_("Unable get PROJ.4-style parameter string"));
 	return NULL;
     }
+#ifdef HAVE_PROJ_H
     proj_destroy(pjinfo.pj);
 #else
-    if ((proj4 = pj_get_def(pjinfo.pj, 0)) == NULL) {
-	G_warning(_("Unable get PROJ.4-style parameter string"));
-	return NULL;
-    }
     pj_free(pjinfo.pj);
 #endif
 
@@ -232,11 +221,9 @@ OGRSpatialReferenceH GPJ_grass_to_osr(const struct Key_Value * proj_info,
 	G_asprintf(&proj4mod, "%s +to_meter=%s", proj4, unfact);
     else
 	proj4mod = G_store(proj4);
-#ifdef HAVE_PROJ_H
-    G_free(proj4);
-#else
     pj_dalloc(proj4);
-#endif
+
+    /* create GDAL OSR from proj string */
     if ((errcode = OSRImportFromProj4(hSRS, proj4mod)) != OGRERR_NONE) {
 	G_warning(_("OGR can't parse PROJ.4-style parameter string: "
 		    "%s (OGR Error code was %d)"), proj4mod, errcode);

+ 9 - 14
lib/proj/do_proj.c

@@ -43,34 +43,29 @@ do {\
 
 static double METERS_in = 1.0, METERS_out = 1.0;
 
+/* TODO: remove hack for PROJ 5+ */
 #ifdef HAVE_PROJ_H
-static char *gpj_get_def(PJ *P)
-{
-    char *pjdef;
-    PJ_PROJ_INFO pj_proj_info = proj_pj_info(P);
-
-    pjdef = G_store(pj_proj_info.definition);
-
-    return pjdef;
-}
+char *pj_get_def(PJ *, int);
+void pj_dalloc(void *);
+void pj_free(PJ *);
 
 /* TODO: add to gprojects.h */
-/* Create a transformation object */
+/* Create a PROJ transformation object */
 int GPJ_prepare_pjinfo(const struct pj_info *info_in,
                        const struct pj_info *info_out,
 		       struct pj_info *info_new)
 {
     char *projdef, *projdefin, *projdefout;
 
-    projdefin = gpj_get_def(info_in->pj);
-    projdefout = gpj_get_def(info_out->pj);
+    projdefin = pj_get_def(info_in->pj, 1);
+    projdefout = pj_get_def(info_out->pj, 1);
     projdef = NULL;
     G_asprintf(&projdef, "+proj=pipeline +step %s +inv +step %s", projdefin, projdefout);
     info_new->pj = proj_create(PJ_DEFAULT_CTX, projdef);
     if (info_new->pj == NULL)
 	G_fatal_error(_("proj_create() failed"));
-    G_free(projdefin);
-    G_free(projdefout);
+    pj_dalloc(projdefin);
+    pj_dalloc(projdefout);
     G_free(projdef);
 
     return 1;

+ 4 - 30
lib/proj/get_proj.c

@@ -33,21 +33,11 @@ static void alloc_options(char *);
 static char *opt_in[MAX_PARGS];
 static int nopt;
 
+/* TODO: remove hack for PROJ 5+ */
 #ifdef HAVE_PROJ_H
-static char *gpj_get_def(PJ *P)
-{
-    char *pjdef;
-    PJ_PROJ_INFO pjinfo;
-
-    if (P == NULL)
-	G_fatal_error("Invalid PJ pointer");
-
-    pjinfo = proj_pj_info(P);
-
-    pjdef = G_store(pjinfo.definition);
-
-    return pjdef;
-}
+char *pj_get_def(PJ *, int);
+void pj_dalloc(void *);
+void pj_free(PJ *);
 #endif
 
 /* TODO: rename pj_ to GPJ_ to avoid symbol clash with PROJ lib */
@@ -455,19 +445,11 @@ int pj_print_proj_params(const struct pj_info *iproj, const struct pj_info *opro
     char *str;
 
     if (iproj) {
-#ifdef HAVE_PROJ_H
-	str = gpj_get_def(iproj->pj);
-#else
 	str = pj_get_def(iproj->pj, 1);
-#endif
 	if (str != NULL) {
 	    fprintf(stderr, "%s: %s\n", _("Input Projection Parameters"),
 		    str);
-#ifdef HAVE_PROJ_H
-	    G_free(str);
-#else
 	    pj_dalloc(str);
-#endif
 	    fprintf(stderr, "%s: %.16g\n", _("Input Unit Factor"),
 		    iproj->meters);
 	}
@@ -476,19 +458,11 @@ int pj_print_proj_params(const struct pj_info *iproj, const struct pj_info *opro
     }
 
     if (oproj) {
-#ifdef HAVE_PROJ_H
-	str = gpj_get_def(oproj->pj);
-#else
 	str = pj_get_def(oproj->pj, 1);
-#endif
 	if (str != NULL) {
 	    fprintf(stderr, "%s: %s\n", _("Output Projection Parameters"),
 		    str);
-#ifdef HAVE_PROJ_H
-	    G_free(str);
-#else
 	    pj_dalloc(str);
-#endif
 	    fprintf(stderr, "%s: %.16g\n", _("Output Unit Factor"),
 		    oproj->meters);
 	}