I have a bash script that does the following:

export PATH=$PATH:/usr/local/grass/bin
GRASSDATA=/output/grassdata && \
MAP=outputAmtrakMap && \
rm -rf $GRASSDATA && \
(grass -c /input/kx-amtrak-stations-SHP/amtrak-stations.shp -e $GRASSDATA && \
grass $GRASSDATA/$MAPSET/ --exec v.in.ogr --verbose --overwrite input=/input/kx-amtrak-stations-SHP/amtrak-stations.shp output=$MAP snap=0.0001) 2>&1 | tee /output/logfile && \
MAP=outputInstitutions && \
grass $GRASSDATA/$MAPSET/ --exec v.in.ogr --verbose --overwrite input=/input/Colleges_and_Universities/CollegesUniversities.shp output=$MAP snap=0.0001 2>&1 | tee /output/logfile
MAP=outputAirports && \
grass $GRASSDATA/$MAPSET/ --exec v.in.ogr --verbose --overwrite input=/input/World_Airports/world_airports.shp output=$MAP snap=0.0001 2>&1 | tee /output/logfile

I've verified that the import of the first two shapefiles works well. The problem is that the import of the third shapefile results in this error:

   ERROR: Projection of dataset does not appear to match current location.

   Location PROJ_INFO is:
   name: WGS 84 / Pseudo-Mercator
   a: 6378137
   es: 0
   proj: merc
   lat_ts: 0
   lon_0: 0
   x_0: 0
   y_0: 0
   k: 1
   nadgrids: @null
   wktext: defined
   no_defs: defined

   Dataset PROJ_INFO is:
   name: WGS 84
   datum: wgs84
   ellps: wgs84
   proj: ll
   no_defs: defined

   Difference in: proj

   In case of no significant differences in the projection definitions,
   use the -o flag to ignore them and use current location definition.
   Consider generating a new location from the input dataset using the
   'location' parameter.

Is there a way I can have my script convert the WGS 84 world_airports.shp layer to WGS 84 / Pseudo-Mercator without risking corrupted data?

1 Answer 1


If you use v.import instead of v.in.ogr then GRASS will reproject the input ogr datasource to match the MAPSET.

I would, however, suggest to review your workflow. It seems that you are

  1. Deleting and recreating a MAPSET. Why is this necessary?
  2. Opening three sessions of GRASS in the same MAPSET. That's not recommended.

Usually you would create a MAPSET once. Then start GRASS in that MAPSET, and run a script at the GRASS prompt that: imports your data, and runs whatever analysis you need. HTH

Responding to the comment:

No, that won't work. When you start GRASS it spawns a totally new shell. So you can't just chain together GRASS commands with the call to start a GRASS session. What is definitely possible, tho' is to start a GRASS session, and have it run a script of commands that you prepare in advance. So you could setup a short script (let's call it my_script.sh) that contains:

v.import --verbose --overwrite input=/input/kx-amtrak-stations-SHP/amtrak-stations.shp output=${MAP}_1 snap=0.0001
v.import --verbose --overwrite input=/input/Colleges_and_Universities/CollegesUniversities.shp output=${MAP}_2 snap=0.0001
v.import --verbose --overwrite input=/input/World_Airports/world_airports.shp output=${MAP}_3 snap=0.0001

Make that script executable. Now you can get GRASS to run this script in one of two ways: Either, as you showed, using the --exec option. i.e.

grass $GRASSDATA/$MAPSET/ --exec my_script.sh

or, you can set the GRASS_BATCH_JOB environment variable, then call GRASS. It will run the commands in the script, then exit. i.e.:

export GRASS_BATCH_JOB="$HOME/my_script.sh"
# DOn't forget to unset the env variable

More detail are on the wiki

  • Thank you! Yes, I am quite new to GRASS. So I would do something like grass $GRASSDATA/$MAPSET/ --exec v.import --verbose --overwrite input=/input/kx-amtrak-stations-SHP/amtrak-stations.shp output=$MAP snap=0.0001) 2>&1 && v.import <second-set-of-arguments .&& v.import <third-set-of-arguments>, right? Nov 7, 2022 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.