Skip to content

Commit

Permalink
switch environment: also change mapset (#286)
Browse files Browse the repository at this point in the history
* switch environment: also change mapset

* r.proj: use current (target) location + mapset when calling GPJ_init_transform(), needed to get the correct region to be passed as area of interest to PROJ6+
  • Loading branch information
metzm committed Jan 16, 2020
1 parent c2e8bb4 commit 804867d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions raster/r.in.gdal/main.c
Expand Up @@ -894,6 +894,7 @@ int main(int argc, char *argv[])
G_create_alt_env();
G_setenv_nogisrc("LOCATION_NAME", parm.target->answer);
sprintf(target_mapset, "PERMANENT"); /* must exist */
G_setenv_nogisrc("MAPSET", target_mapset);

if (G_mapset_permissions(target_mapset) == -1) {
/* create target location later */
Expand Down
7 changes: 7 additions & 0 deletions raster/r.proj/main.c
Expand Up @@ -284,6 +284,7 @@ int main(int argc, char **argv)
G_create_alt_env();
G_setenv_nogisrc("GISDBASE", indbase->answer ? indbase->answer : G_gisdbase());
G_setenv_nogisrc("LOCATION_NAME", inlocation->answer);
G_setenv_nogisrc("MAPSET", setname);

permissions = G_mapset_permissions(setname);
if (permissions < 0) /* can't access mapset */
Expand Down Expand Up @@ -338,6 +339,9 @@ int main(int argc, char **argv)
tproj.def = G_store(pipeline->answer);
}
#endif

/* switch back to current location */
G_switch_env();
if (GPJ_init_transform(&iproj, &oproj, &tproj) < 0)
G_fatal_error(_("Unable to initialize coordinate transformation"));

Expand All @@ -348,6 +352,9 @@ int main(int argc, char **argv)
if (G_verbose() > G_verbose_std())
pj_print_proj_params(&iproj, &oproj);

/* switch to input location */
G_switch_env();

/* this call causes r.proj to read the entire map into memeory */
Rast_get_cellhd(inmap->answer, setname, &incellhd);

Expand Down
1 change: 1 addition & 0 deletions vector/v.proj/main.c
Expand Up @@ -192,6 +192,7 @@ int main(int argc, char *argv[])
select_target_env();
G_setenv_nogisrc("GISDBASE", gbase);
G_setenv_nogisrc("LOCATION_NAME", iloc_name);
G_setenv_nogisrc("MAPSET", iset_name);
stat = G_mapset_permissions(iset_name);

if (stat >= 0) { /* yes, we can access the mapset */
Expand Down

0 comments on commit 804867d

Please sign in to comment.