[GRASS-SVN] r72470 - grass/trunk/lib/proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 21 11:04:03 PDT 2018


Author: mmetz
Date: 2018-03-21 11:04:02 -0700 (Wed, 21 Mar 2018)
New Revision: 72470

Modified:
   grass/trunk/lib/proj/convert.c
   grass/trunk/lib/proj/do_proj.c
   grass/trunk/lib/proj/get_proj.c
Log:
liproj: add hack for internal fns in PROJ 5+, to be removed again

Modified: grass/trunk/lib/proj/convert.c
===================================================================
--- grass/trunk/lib/proj/convert.c	2018-03-21 15:53:05 UTC (rev 72469)
+++ grass/trunk/lib/proj/convert.c	2018-03-21 18:04:02 UTC (rev 72470)
@@ -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 @@
 
     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 @@
 	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);

Modified: grass/trunk/lib/proj/do_proj.c
===================================================================
--- grass/trunk/lib/proj/do_proj.c	2018-03-21 15:53:05 UTC (rev 72469)
+++ grass/trunk/lib/proj/do_proj.c	2018-03-21 18:04:02 UTC (rev 72470)
@@ -43,19 +43,14 @@
 
 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);
+char *pj_get_def(PJ *, int);
+void pj_dalloc(void *);
+void pj_free(PJ *);
 
-    pjdef = G_store(pj_proj_info.definition);
-
-    return pjdef;
-}
-
 /* 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)
@@ -62,15 +57,15 @@
 {
     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;

Modified: grass/trunk/lib/proj/get_proj.c
===================================================================
--- grass/trunk/lib/proj/get_proj.c	2018-03-21 15:53:05 UTC (rev 72469)
+++ grass/trunk/lib/proj/get_proj.c	2018-03-21 18:04:02 UTC (rev 72470)
@@ -33,21 +33,11 @@
 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 @@
     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 @@
     }
 
     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);
 	}



More information about the grass-commit mailing list