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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 29 11:54:43 PDT 2019


Author: mmetz
Date: 2019-04-29 11:54:43 -0700 (Mon, 29 Apr 2019)
New Revision: 74436

Modified:
   grass/trunk/lib/proj/do_proj.c
Log:
libproj: PROJ5: EPSG must lowercase epsg, PROJ6+: EPSG must uppercase EPSG

Modified: grass/trunk/lib/proj/do_proj.c
===================================================================
--- grass/trunk/lib/proj/do_proj.c	2019-04-28 13:49:34 UTC (rev 74435)
+++ grass/trunk/lib/proj/do_proj.c	2019-04-29 18:54:43 UTC (rev 74436)
@@ -92,16 +92,44 @@
     info_trans->pj = NULL;
     if (!info_trans->def) {
 	if (info_in->srid && info_out->pj && info_out->srid) {
+	    char *insrid, *outsrid;
+
+#if PROJ_VERSION_MAJOR >= 6
+	    /* PROJ6+: EPSG must uppercase EPSG */
+	    if (strncmp(info_in->srid, "epsg", 4) == 0)
+		insrid = G_store_upper(info_in->srid);
+	    else
+		insrid = G_store(info_in->srid);
+
+	    if (strncmp(info_out->srid, "epsg", 4) == 0)
+		outsrid = G_store_upper(info_out->srid);
+	    else
+		outsrid = G_store(info_out->srid);
+#else
+	    /* PROJ5: EPSG must lowercase epsg */
+	    if (strncmp(info_in->srid, "EPSG", 4) == 0)
+		insrid = G_store_lower(info_in->srid);
+	    else
+		insrid = G_store(info_in->srid);
+
+	    if (strncmp(info_out->srid, "EPSG", 4) == 0)
+		outsrid = G_store_lower(info_out->srid);
+	    else
+		outsrid = G_store(info_out->srid);
+
+#endif
 	    /* ask PROJ for the best pipeline */
 	    info_trans->pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX,
-	                                            info_in->srid,
-						    info_out->srid,
+	                                            insrid,
+						    outsrid,
 						    NULL);
 
 	    if (info_trans->pj == NULL) {
 		G_warning(_("proj_create_crs_to_crs() failed for '%s' and '%s'"),
-		          info_in->srid, info_out->srid);
+		          insrid, outsrid);
 	    }
+	    G_free(insrid);
+	    G_free(outsrid);
 #if PROJ_VERSION_MAJOR >= 6
 	    else {
 		const char *str = proj_as_proj_string(NULL, info_trans->pj,
@@ -221,6 +249,8 @@
     /* prepare */
     if (in_is_ll) {
 	/* convert to radians */
+	/* PROJ 6: conversion to radians is not always needed:
+	 * if proj_angular_input(info_trans->pj, dir) == 1 -> convert */
 	c.lpzt.lam = (*x) / RAD_TO_DEG;
 	c.lpzt.phi = (*y) / RAD_TO_DEG;
 	c.lpzt.z = 0;
@@ -250,6 +280,8 @@
     /* output */
     if (out_is_ll) {
 	/* convert to degrees */
+	/* PROJ 6: conversion to radians is not always needed:
+	 * if proj_angular_output(info_trans->pj, dir) == 1 -> convert */
 	*x = c.lpzt.lam * RAD_TO_DEG;
 	*y = c.lpzt.phi * RAD_TO_DEG;
 	if (z)



More information about the grass-commit mailing list