[GRASS-SVN] r72426 - grass/trunk/general/g.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 20 11:46:45 PDT 2018


Author: mmetz
Date: 2018-03-20 11:46:45 -0700 (Tue, 20 Mar 2018)
New Revision: 72426

Modified:
   grass/trunk/general/g.proj/output.c
Log:
g.proj: use new PROJ 5+ API if available

Modified: grass/trunk/general/g.proj/output.c
===================================================================
--- grass/trunk/general/g.proj/output.c	2018-03-20 18:45:43 UTC (rev 72425)
+++ grass/trunk/general/g.proj/output.c	2018-03-20 18:46:45 UTC (rev 72426)
@@ -17,7 +17,6 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
-#include <proj_api.h>
 
 #include <grass/gis.h>
 #include <grass/gprojects.h>
@@ -122,6 +121,21 @@
     return;
 }
 
+#ifdef HAVE_PROJ_H
+static char *gpj_get_def(PJ *P)
+{
+    char *pjdef;
+    PJ_PROJ_INFO pjinfo = proj_pj_info(P);
+
+    if (P == NULL)
+	G_fatal_error("Invalid PJ pointer");
+
+    pjdef = G_store(pjinfo.definition);
+
+    return pjdef;
+}
+#endif
+
 void print_proj4(int dontprettify)
 {
     struct pj_info pjinfo;
@@ -133,9 +147,13 @@
 
     if (pj_get_kv(&pjinfo, projinfo, projunits) == -1)
         G_fatal_error(_("Unable to convert projection information to PROJ.4 format"));
+#ifdef HAVE_PROJ_H
+    proj4 = gpj_get_def(pjinfo.pj);
+    proj_destroy(pjinfo.pj);
+#else
     proj4 = pj_get_def(pjinfo.pj, 0);
     pj_free(pjinfo.pj);
-
+#endif
     /* GRASS-style PROJ.4 strings don't include a unit factor as this is
      * handled separately in GRASS - must include it here though */
     unfact = G_find_key_value("meters", projunits);
@@ -143,7 +161,11 @@
 	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
 
     for (i = proj4mod; *i; i++) {
 	/* Don't print the first space */



More information about the grass-commit mailing list