Kaynağa Gözat

libproj (#939)

fix for PROJ6+ to get the ll equivalent of a crs
Markus Metz 4 yıl önce
ebeveyn
işleme
ee051524c9

+ 3 - 0
display/d.grid/plot.c

@@ -575,10 +575,13 @@ void init_proj(struct pj_info *info_in, struct pj_info *info_out,
         /* Check that datumparams are defined for this location (otherwise
          * the WGS84 values would be meaningless), and if they are set the 
          * input datum to WGS84 */
+#if PROJ_VERSION_MAJOR < 6
+	/* PROJ6+ has its own datum transformation parameters */
         if (G_get_datumparams_from_projinfo(in_proj_info, buff, dum) < 0)
             G_fatal_error(_("WGS84 grid output not possible as this location does not contain\n"
                            "datum transformation parameters. Try running g.setproj."));
         else
+#endif
             G_set_key_value("datum", "wgs84", out_proj_info);
 
         /* set input projection to lat/long */

+ 3 - 0
display/d.where/main.c

@@ -124,10 +124,13 @@ int main(int argc, char **argv)
 	    /* Check that datumparams are defined for this location (otherwise
 	     * the WGS84 values would be meaningless), and if they are set the 
 	     * output datum to WGS84 */
+#if PROJ_VERSION_MAJOR < 6
+	    /* PROJ6+ has its own datum transformation parameters */
 	    if (G_get_datumparams_from_projinfo(in_proj_info, buff, dum) < 0)
 		G_fatal_error(_("WGS84 output not possible as this location does not contain\n"
 			       "datum transformation parameters. Try running g.setproj."));
 	    else
+#endif
 		G_set_key_value("datum", "wgs84", out_proj_info);
 
 	    G_set_key_value("unit", "degree", out_unit_info);

+ 3 - 0
general/g.region/printwindow.c

@@ -569,10 +569,13 @@ void print_window(struct Cell_head *window, int print_flag, int flat_flag)
 
 	    G_set_key_value("proj", "ll", out_proj_info);
 
+#if PROJ_VERSION_MAJOR < 6
+	    /* PROJ6+ has its own datum transformation parameters */
 	    if (G_get_datumparams_from_projinfo(in_proj_info, buff, dum) < 0)
 		G_fatal_error(_("WGS84 output not possible as this location does not contain "
 			       "datum transformation parameters. Try running g.setproj."));
 	    else
+#endif
 		G_set_key_value("datum", "wgs84", out_proj_info);
 
 	    G_set_key_value("unit", "degree", out_unit_info);

+ 12 - 7
lib/proj/do_proj.c

@@ -378,7 +378,6 @@ int GPJ_init_transform(const struct pj_info *info_in,
     else if (info_out->pj == NULL) {
 	const char *projstr = NULL;
 	char *indef = NULL;
-	PJ *source_crs;
 	
 	/* Even Rouault:
 	 * if info_in->def contains a +towgs84/+nadgrids clause, 
@@ -391,15 +390,21 @@ int GPJ_init_transform(const struct pj_info *info_in,
 	 * and in that case, take the source CRS with proj_get_source_crs(),
 	 * and do the inverse transform on it */
 
-	source_crs = proj_get_source_crs(NULL, info_in->pj);
-	if (source_crs) {
-	    projstr = proj_as_proj_string(NULL, source_crs, PJ_PROJ_5, NULL);
-	    if (projstr)
-		indef = G_store(projstr);
-	    proj_destroy(source_crs);
+	if (proj_get_type(info_in->pj) == PJ_TYPE_BOUND_CRS) {
+	    PJ *source_crs;
+
+	    G_debug(1, "transform to ll equivalent: found bound crs");
+	    source_crs = proj_get_source_crs(NULL, info_in->pj);
+	    if (source_crs) {
+		projstr = proj_as_proj_string(NULL, source_crs, PJ_PROJ_5, NULL);
+		if (projstr)
+		    indef = G_store(projstr);
+		proj_destroy(source_crs);
+	    }
 	}
 	if (indef == NULL)
 	    indef = G_store(info_in->def);
+	G_debug(1, "ll equivalent definition: %s", indef);
 
 	/* what about axis order?
 	 * is it always enu?