[GRASS-user] GRASS Location from scratch: Solved

Hi,

here is a working (bash-)scripting approach on how to conjure up a minimalistic xy-location out of thin air and to transmogrify the projection (f.e. EPSG:4326):

###################################################################################
## LOCATION SETUP PREPARATION (FILESYSTEM)

#generate folders for temporal LOCATION and MAPSET
mkdir -p $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET
mkdir -p $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET/dbf
touch $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET/MYNAME

echo "proj: 0
zone: 0
north: 1
south: 0
east: 1
west: 0
cols: 1
rows: 1
e-w resol: 1
n-s resol: 1
top: 1
bottom: 0
cols3: 1
rows3: 1
depths: 1
e-w resol3: 1
n-s resol3: 1
t-b resol: 1
" > $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET/WIND

cp $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET/WIND $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET/DEFAULT_WIND

echo "DBF_DRIVER: dbf
DB_DATABASE : $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/
" > $CURRENT_DIR/$THE_LOCATION/$THE_MAPSET/VAR

##################################################################################
#Set up a temporary grassrc-File:

echo "GISDBASE: $CURRENT_DIR
LOCATION_NAME: $THE_LOCATION
MAPSET: $THE_MAPSET
" > $TMPDIR/$THE_GRASSRC

#################################################################################
# Export paths to GRASS binaries and libraries:

export GISBASE=/opt/grass
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib

# use process ID (PID) as lock file number:
export GIS_LOCK=$$

# settings for graphical output to PNG file
export GRASS_PNGFILE=$TMPDIR/grass6output.png
export GRASS_TRUECOLOR=TRUE
export GRASS_WIDTH=400
export GRASS_PNG_COMPRESSION=1

# path to GRASS settings file:
export GISRC=$TMPDIR/$THE_GRASSRC

g.proj -c epsg=4326
g.region -s n=90 s=-90 w=-180 e=180 res=1
g.region -p

Peter
--
Dr. Peter Löwe
<peter.loewe@gmx.de>

Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

Peter,

just out of curiosity: what's the *real* purpose of having this way to
create a location?

Kind regards, Nikos

-------- Original-Nachricht --------

Datum: Tue, 20 Jan 2009 15:04:58 +0100
Von: Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>
An: "\\"Peter" Löwe" <peter.loewe@gmx.de>
CC: grass-user@lists.osgeo.org
Betreff: Re: [GRASS-user] GRASS Location from scratch: Solved

Peter,

just out of curiosity: what's the *real* purpose of having this way to
create a location?

Kind regards, Nikos

2 1/2 reasons:

1) It builds character => 1 1/2) It's good for you (just like compiling GRASS from the sources!)

2) This approach allows to embed GRASS-driven computation in other applications: All GRASS ressources are only provided during the (outer) scripts execution. I tried to minimize on "carry-on luggage" for this task - there is no more to need to drag a tarzipped "primary" location along. Real boiled users might even go so far to wget & build GRASS from the sources before applying it in such a fashion :slight_smile:

Peter

--
Dr. Peter Löwe
<peter.loewe@gmx.de>

Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a

On Tue, 2009-01-20 at 15:25 +0100, "Peter Löwe" wrote:

> Betreff: Re: [GRASS-user] GRASS Location from scratch: Solved
> Peter, just out of curiosity: what's the *real* purpose of having this way to
> create a location? Kind regards, Nikos

2 1/2 reasons:

1) It builds character => 1 1/2) It's good for you (just like compiling GRASS from the sources!)
2) This approach allows to embed GRASS-driven computation in other
applications: All GRASS ressources are only provided during the
(outer) scripts execution. I tried to minimize on "carry-on luggage"
for this task - there is no more to need to drag a tarzipped "primary"
location along. Real boiled users might even go so far to wget &
build GRASS from the sources before applying it in such a fashion :slight_smile:

Peter

Indeed, good reasons. +1 for reason #1

On Tue, 20 Jan 2009, "Peter Löwe" wrote:

Hi,

here is a working (bash-)scripting approach on how to conjure up a minimalistic xy-location out of thin air and to transmogrify the projection (f.e. EPSG:4326):

It doesn't really need to be so long though - in recent versions of GRASS g.proj doesn't require a dummy location in order to run. This should do it almost as well:

###################################################################################
## LOCATION SETUP PREPARATION (FILESYSTEM)

##################################################################################
#Set up a temporary grassrc-File:

echo "GISDBASE: $CURRENT_DIR
" > $TMPDIR/$THE_GRASSRC

#################################################################################
# Export paths to GRASS binaries and libraries:

  export GISBASE=/opt/grass
  export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib

  # path to GRASS settings file:
  export GISRC=$TMPDIR/$THE_GRASSRC

g.proj -c epsg=4326 location=$THE_LOCATION

##################################################################################
#Delete temporary grassrc-File:

rm $TMPDIR/$THE_GRASSRC

The only difference is the default region will have an extent of 1 in all directions. If you want to run a g.region command to set it at the end you need to update the GISRC file with the name of the newly-created location and PERMANENT mapset.

Paul

On Jan 20, 2009, at 9:00 AM, Paul Kelly wrote:

On Tue, 20 Jan 2009, "Peter Löwe" wrote:

Hi,

here is a working (bash-)scripting approach on how to conjure up a minimalistic xy-location out of thin air and to transmogrify the projection (f.e. EPSG:4326):

It doesn't really need to be so long though - in recent versions of GRASS g.proj doesn't require a dummy location in order to run. This should do it almost as well:

###################################################################################
## LOCATION SETUP PREPARATION (FILESYSTEM)

##################################################################################
#Set up a temporary grassrc-File:

echo "GISDBASE: $CURRENT_DIR
" > $TMPDIR/$THE_GRASSRC

#################################################################################
# Export paths to GRASS binaries and libraries:

export GISBASE=/opt/grass

Maybe pick it up from an exported GISBASE in the shell? - to accomodate different install locations.

export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib

Also note that this should be DYLD_LIBRARY_PATH for OSX. Maybe something could be used from init.sh:

SYSTEM=`uname -s`
case $SYSTEM in
Darwin*)
  MACOSX=1
  ;;
esac

if [ "$MACOSX" ] ; then
if [ ! "$DYLD_LIBRARY_PATH" ] ; then
   DYLD_LIBRARY_PATH="$GISBASE/lib"
else
   DYLD_LIBRARY_PATH="$GISBASE/lib:$DYLD_LIBRARY_PATH"
fi
else
if [ ! "$LD_LIBRARY_PATH" ] ; then
   LD_LIBRARY_PATH="$GISBASE/lib"
else
   LD_LIBRARY_PATH="$GISBASE/lib:$LD_LIBRARY_PATH"
fi

g.proj -c epsg=4326 location=$THE_LOCATION

Another idea: take the projection option as a script argument. It could be any of the valid g.proj options, something like (say the script is "createloc"):

createloc epsg=4326

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

Theory of the Universe

There is a theory which states that if ever anyone discovers exactly what the universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarrely inexplicable. There is another theory which states that this has already happened.

-Hitchhiker's Guide to the Galaxy 2nd season intro

William Kyngesburye wrote:

> export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
>
Also note that this should be DYLD_LIBRARY_PATH for OSX.

And PATH for Windows, LIBPATH for AIX, and SHLIB_PATH for HP-UX.

FWIW, the variable name can be obtained from the setting of
LD_LIBRARY_PATH_VAR in include/Make/Platform.make (Makefile syntax).

--
Glynn Clements <glynn@gclements.plus.com>