1

I would like to have a GRASS script that creates a new location of its own, instead of using an existing location. This facilitates the usage of the script by other users.

Going through the guide on Working with GRASS without starting it explicitly and the notes on creating locations form the command line, I arrived at the following script:

#!/bin/sh
# path to GRASS binaries and libraries:
export GISBASE=/usr/lib/grass74
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
# GRASS session variables
GRASSDB="/tmp/grassdata"
GRASSLOC="tmp_location"
mkdir -p "$GRASSDB/$GRASSLOC/PERMANENT"
# Create a new GRASS location
#grass74 -c $PATH_IN"ORCDRC_M_sl1_250m_clip.tif" "$GRASSDB$GRASSLOC"
grass74 -c /path/to/some/file.tif "$GRASSDB$GRASSLOC"
echo "Creation done"
# path to GRASS settings file
export GISRC=/tmp/grass7-${USER}-$GIS_LOCK/gisrc
# remove any leftover files/folder
rm -fr /tmp/grass7-${USER}-$GIS_LOCK
mkdir /tmp/grass7-${USER}-$GIS_LOCK
# set GISDBASE, LOCATION_NAME, and/or MAPSET
echo "GISDBASE: $GRASSDB" >>$GISRC
echo "LOCATION_NAME: $GRASSLOC" >>$GISRC
echo "MAPSET: PERMANENT" >>$GISRC
# start in text mode
echo "GRASS_GUI: text" >>$GISRC
# Test it
g.version

This kind of works, however, the grass74 -c command not only creates a new location, it also starts a new GRASS session and launches the GUI.

Is there another way of creating a location without launching the GUI (and creating a session)?

asked Jun 20, 2018 at 9:10

1 Answer 1

3

Use grass -c -e -text ...

from the Help:

 -e exit after creation of location or mapset. Only with -c flag
 -text use text based interface (skip welcome screen)
answered Jun 20, 2018 at 9:25
1
  • --text should be typed with "--" Commented Jan 23, 2023 at 10:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.