2

I have a sh script that I want to use to process raster files. eg

#!/bin/sh
# my first script, 
# copyright, year, Author

r.mask -r

for file in A*chlor_a_4km ; do
  echo "map: $file"
    gdal_translate -a_srs "+init=epsg:4326" -a_nodata 65535 \
      -a_ullr -180 90 180 -90 -co "COMPRESS=PACKBITS" \
      $file ${file}_prep.tif
    r.in.gdal in=${file}_prep.tif out=$file --overwrite

done

I'm running from the OSGeo4W Shell, Windows 7, Grass 7.2.2, all freshly installed via OSGeo4W.

The script runs, but it produces eg 'r.in.gdal command not found' but then carries on to the next raster.

I expect this is something to do with the Path? I've just installed this so can someone please send instructions on how to set the OSGeo4W Shell up for use.

  • Your shell script seems to be a unix bash shell script. Under windows and osgeo4w you'll need msys, with grass under OSGEO4W there is also a package called msys-grass. I've never tried this, but i don't think you can execute your script without msys. – Andreas Müller Nov 2 '17 at 11:19
3

The GRASS bin does not get added to your PATH variable by default with the OSGEO4W install (that is, when you open the shell or launch CMD via the BAT shell). If you want to run 'r.in.gdal.exe' - or any similar function associated with GRASS, you'll have to either manually add the GRASS bin folder to your path or update the o4w_env.bat file in your OSGEO4W\bin folder to include it.

For my install, this is where r.in.gdal.exe was sourced: C:\OSGeo4W64\apps\grass\grass-7.2.2\bin

You can either add that to your PATH environment variable and will be all set, or add it to the .bat file in the line following "REM start with clean path", and it will work but only out of the OSGEO4W shell.

Note: you'll also need to add the following dependency with required DLLs to your path, or the exe won't run correctly: C:\OSGeo4W64\apps\grass\grass-7.2.2\lib

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.