Skip to content

Commit

Permalink
libproj (#939)
Browse files Browse the repository at this point in the history
fix for PROJ6+ to get the ll equivalent of a crs
  • Loading branch information
metzm committed Aug 27, 2020
1 parent 128b343 commit ee05152
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions display/d.grid/plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions display/d.where/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions general/g.region/printwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 12 additions & 7 deletions lib/proj/do_proj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?
Expand Down

0 comments on commit ee05152

Please sign in to comment.