[GRASS-user] Original location: Hot to create from the command line ?

Hi,

is there an (easy) recipe to create a completely new location from scratch without using a GUI ?

To be precise:
If GRASS is started for the first time in "-text" mode (=no GUI) ** without having a sample location like Spearfish or North Carolina around**, how can location parameters (projection, extent, EPSG...) be handed over to set up a very first location ?

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

On 19/01/09 10:47, peter.loewe@gmx.de wrote:

Hi,

is there an (easy) recipe to create a completely new location from
scratch without using a GUI ?

To be precise: If GRASS is started for the first time in "-text" mode
(=no GUI) ** without having a sample location like Spearfish or North
Carolina around**, how can location parameters (projection, extent,
EPSG...) be handed over to set up a very first location ?

Just type in the name of the location you want to create and GRASS will prompt you for the parameters.

Moritz

> is there an (easy) recipe to create a completely new location from
> scratch without using a GUI ?
>
> To be precise: If GRASS is started for the first time in "-text" mode
> (=no GUI) ** without having a sample location like Spearfish or North
> Carolina around**, how can location parameters (projection, extent,
> EPSG...) be handed over to set up a very first location ?

Just type in the name of the location you want to create and GRASS will
prompt you for the parameters.

Moritz

That's true. But is there also a way to provide the parameters _without_ interaction with the user (-> GRASS scripting & automation) ?

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

peter.loewe@gmx.de wrote:

is there an (easy) recipe to create a completely new location from
scratch without using a GUI ?

To be precise:
If GRASS is started for the first time in "-text" mode (=no GUI) **
without having a sample location like Spearfish or North Carolina
around**, how can location parameters (projection, extent, EPSG...)
be handed over to set up a very first location ?

You can create a new location via the curses dialog, and specify
projection information interactively, but you can't use an EPSG code
here.

However, you can just provide bogus projection information at that
point, then correct it with "g.proj -c ..." once the startup is
complete.

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

"Peter Löwe" wrote:

> > is there an (easy) recipe to create a completely new location from
> > scratch without using a GUI ?
> >
> > To be precise: If GRASS is started for the first time in "-text" mode
> > (=no GUI) ** without having a sample location like Spearfish or North
> > Carolina around**, how can location parameters (projection, extent,
> > EPSG...) be handed over to set up a very first location ?
>
> Just type in the name of the location you want to create and GRASS will
> prompt you for the parameters.

That's true. But is there also a way to provide the parameters
_without_ interaction with the user (-> GRASS scripting & automation)

You can create a new location and mapset with "g.proj -c ...", then
make it current with g.mapset. But those are GRASS commands, and only
work within GRASS.

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

On 19/01/09 17:16, Glynn Clements wrote:

"Peter Löwe" wrote:

is there an (easy) recipe to create a completely new location from
scratch without using a GUI ?

To be precise: If GRASS is started for the first time in "-text" mode
(=no GUI) ** without having a sample location like Spearfish or North
Carolina around**, how can location parameters (projection, extent,
EPSG...) be handed over to set up a very first location ?

Just type in the name of the location you want to create and GRASS will prompt you for the parameters.

That's true. But is there also a way to provide the parameters
_without_ interaction with the user (-> GRASS scripting & automation)

You can create a new location and mapset with "g.proj -c ...", then
make it current with g.mapset. But those are GRASS commands, and only
work within GRASS.

I imagine that you can create your own location by having a script create the location directory, the PERMANENT mapset directory and the PROJ_INFO, DEFAULT_WIND and PROJ_UNITS files, or ?

Moritz

Peter wrote:

is there an (easy) recipe to create a completely new location from
scratch without using a GUI ?

To be precise: If GRASS is started for the first time in "-text" mode
(=no GUI) ** without having a sample location like Spearfish or
North >>>> Carolina around**, how can location parameters
(projection, extent, EPSG...) be handed over to set up a very first
location ?

is there also a way to provide the parameters _without_ interaction
with the user (-> GRASS scripting & automation)

Glynn:

> You can create a new location and mapset with "g.proj -c ...", then
> make it current with g.mapset. But those are GRASS commands, and only
> work within GRASS.

Moritz:

I imagine that you can create your own location by having a
script create the location directory, the PERMANENT mapset
directory and the PROJ_INFO, DEFAULT_WIND and PROJ_UNITS
files, or ?

So what we need is a wrapper script that will create a dummy location/
mapset in /tmp/ and run 'grass64 + g.proj -c' via a GRASS_BATCH_JOB (be
it .sh or .py). Any hints on how the man page parts of the build process
accomplish this?

To give access to g.parser, could the enviro vars be set up at the start
of the script so the thing could bootstrap itself? ie can we somehow
find a way to use the GRASS parser from the non-GRASS command line? I'm
guessing this is not easy due to the 2-pass way g.parser works, but a
smart devel might be able to make it happen somehow.

Writing a custom shell script parser as a wrapper for g.proj -c and all
its options seems rather non-ideal, but access to 'g.proj -c' from the
command line outside GRASS seems like a very nice tool.

how do the Tcl/wx GUIs manage the bootstrapping?

Hamish

On Mon, Jan 19, 2009 at 10:00 PM, Hamish <hamish_b@yahoo.com> wrote:

So what we need is a wrapper script that will create a dummy location/
mapset in /tmp/ and run 'grass64 + g.proj -c' via a GRASS_BATCH_JOB (be
it .sh or .py). Any hints on how the man page parts of the build process
accomplish this?

See
include/Make/Html.make
The relevant variables are set, that's all.

Markus

On Mon, Jan 19, 2009 at 12:06 PM, "Peter Löwe" <peter.loewe@gmx.de> wrote:

> is there an (easy) recipe to create a completely new location from
> scratch without using a GUI ?
>
> To be precise: If GRASS is started for the first time in "-text" mode
> (=no GUI) ** without having a sample location like Spearfish or North
> Carolina around**, how can location parameters (projection, extent,
> EPSG...) be handed over to set up a very first location ?

Just type in the name of the location you want to create and GRASS will
prompt you for the parameters.

Moritz

That's true. But is there also a way to provide the parameters _without_ interaction
with the user (-> GRASS scripting & automation) ?

Sure.
An older version of a shell script is here:
http://www.grassbook.org/examples_menu2nd.php
-> create_location.sh

Keeping in mind
http://grass.osgeo.org/wiki/GRASS_and_Shell#GRASS_Batch_jobs
it should be even easier to write it.

Markus

Hamish wrote:

> So what we need is a wrapper script that will create a dummy location/
> mapset in /tmp/ and run 'grass64 + g.proj -c' via a GRASS_BATCH_JOB
> (be it .sh or .py). Any hints on how the man page parts of the build
> process accomplish this?

Markus wrote:

See
include/Make/Html.make
The relevant variables are set, that's all.

does $GISBASE/demolocation/ get installed with 'make install' so you can
use it at runtime?

Hamish

Hi Markus,

by the way. These links on the GRASS Tutor example page
(http://www.grassbook.org/examples_menu2nd.php) seem to be broken:
http://grass.itc.it/statsgrass/index.html#grassgstat
http://grass.itc.it/statsgrass/index.html#grassR

Marco

Markus Neteler schrieb:

On Mon, Jan 19, 2009 at 12:06 PM, "Peter Löwe" <peter.loewe@gmx.de> wrote:
  

is there an (easy) recipe to create a completely new location from
scratch without using a GUI ?

To be precise: If GRASS is started for the first time in "-text" mode
(=no GUI) ** without having a sample location like Spearfish or North
Carolina around**, how can location parameters (projection, extent,
EPSG...) be handed over to set up a very first location ?
        

Just type in the name of the location you want to create and GRASS will
prompt you for the parameters.

Moritz
      

That's true. But is there also a way to provide the parameters _without_ interaction
with the user (-> GRASS scripting & automation) ?
    
Sure.
An older version of a shell script is here:
http://www.grassbook.org/examples_menu2nd.php
-> create_location.sh

Keeping in mind
http://grass.osgeo.org/wiki/GRASS_and_Shell#GRASS_Batch_jobs
it should be even easier to write it.

Markus
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
  

On Tue, Jan 20, 2009 at 6:10 AM, Marco Lechner - FOSSGIS e.V.
<marco.lechner@fossgis.de> wrote:

Hi Markus,

by the way. These links on the GRASS Tutor example page
(http://www.grassbook.org/examples_menu2nd.php) seem to be broken:
http://grass.itc.it/statsgrass/index.html#grassgstat
http://grass.itc.it/statsgrass/index.html#grassR

Thanks, fixed to:
http://grass.itc.it/statsgrass/index.php#grassgstat
http://grass.itc.it/statsgrass/index.php#grassR

Markus

>> > To be precise: If GRASS is started for the first time in "-text" mode
>> > (=no GUI) ** without having a sample location like Spearfish or North
>> > Carolina around**, how can location parameters (projection, extent,
>> > EPSG...) be handed over to set up a very first location ?
>>
>> Just type in the name of the location you want to create and GRASS will
>> prompt you for the parameters.
>>
>> Moritz
>
> That's true. But is there also a way to provide the parameters _without_
interaction
> with the user (-> GRASS scripting & automation) ?

Sure.
An older version of a shell script is here:
http://www.grassbook.org/examples_menu2nd.php
-> create_location.sh

Keeping in mind
http://grass.osgeo.org/wiki/GRASS_and_Shell#GRASS_Batch_jobs
it should be even easier to write it.

Markus

Well, there seem still to be some issues to be dealt with:

I am defining all basic requirements for a location and GRASS session:

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

  #Set up a temporary grassrc-File:
  echo "GISDBASE: $CURRENT_DIR
  LOCATION_NAME: $THE_LOCATION
  MAPSET: $THE_MAPSET
  " > $TMPDIR/$THE_GRASSRC

# Lets export the variables:
  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=$$

The steps described so far (should) be sufficient to define a GRASS session, with newly created directories for the location and mapset.

Until this point, no information has been provided about the projection parameters.

This should be handled by the following commands:
g.proj -p [to see what the (default ?) project is]
g.proj -c epsg=4326 [to override the projection information]
g.region -s n=90 s=-90 w=-180 e=180 res=1 [to define the default (-> -s flag) region]
g.region -p [to check the results]

Unfortunately this results in:
ERROR: default region is not set
ERROR: default region is not set
ERROR: default region is not set
ERROR: default region is not set

What's missing ?

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

Hamish wrote:

Moritz:
> I imagine that you can create your own location by having a
> script create the location directory, the PERMANENT mapset
> directory and the PROJ_INFO, DEFAULT_WIND and PROJ_UNITS
> files, or ?

You can. It would be easier to use an existing location, although this
gets problematic for concurrent use. OTOH, a script could just make
the top-level directory then extract the files from a tar/zip/etc
file.

So what we need is a wrapper script that will create a dummy location/
mapset in /tmp/ and run 'grass64 + g.proj -c' via a GRASS_BATCH_JOB (be
it .sh or .py).

Not really. The grass64 script should be reserved for interactive
startup. Scripts should set up their environment themselves; it isn't
rocket science.

Any hints on how the man page parts of the build process
accomplish this?

It points GISRC at the dist.<arch>/demolocation/.grassrc64 file, which
uses dist.<arch>/demolocation/PERMANENT as the mapset.

To give access to g.parser, could the enviro vars be set up at the start
of the script so the thing could bootstrap itself? ie can we somehow
find a way to use the GRASS parser from the non-GRASS command line? I'm
guessing this is not easy due to the 2-pass way g.parser works, but a
smart devel might be able to make it happen somehow.

Just set the environment variables.

Personally, I suggest packaging GRASS so that the environment
variables are set system wide from e.g. /etc/env.d/90grass (or
whatever mechanism a particular distribution uses for package-specific
environment settings). Users would only need to run the grass64 script
if they wanted to start a second session.

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

"Peter Löwe" wrote:

This should be handled by the following commands:
g.proj -p [to see what the (default ?) project is]
g.proj -c epsg=4326 [to override the projection information]
g.region -s n=90 s=-90 w=-180 e=180 res=1 [to define the default (-> -s flag) region]
g.region -p [to check the results]

Unfortunately this results in:
ERROR: default region is not set
ERROR: default region is not set
ERROR: default region is not set
ERROR: default region is not set

What's missing ?

  <database>/<location>/PERMANENT/DEFAULT_WIND

You may (or may not) also need MYNAME, VAR and WIND files in the
PERMANENT directory. See the demolocation directory (this is used when
GRASS commands are run during the build process, e.g. for generating
the HTML files).

You might be better off using "g.proj -c location=..." to create the
location directory. This should work without needing a current
location (this is how the GUI to create a new location for a given
EPSG code operates). I suspect that $GISBASE and $GISRC still need to
be set, but it shouldn't care about the contents of the $GISRC file.

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