Ver código fonte

switch environment: also change mapset (#286)

* 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+
Markus Metz 5 anos atrás
pai
commit
382e860357
3 arquivos alterados com 9 adições e 0 exclusões
  1. 1 0
      raster/r.in.gdal/main.c
  2. 7 0
      raster/r.proj/main.c
  3. 1 0
      vector/v.proj/main.c

+ 1 - 0
raster/r.in.gdal/main.c

@@ -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 */

+ 7 - 0
raster/r.proj/main.c

@@ -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       */
@@ -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"));
 
@@ -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);
 

+ 1 - 0
vector/v.proj/main.c

@@ -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 */