[GRASS-user] g.region (was v.to.rast conversion)

Sorry for the change of the topic.

Hi Achim,
First of all, thanks for your reply.
To clarify my problem, i want to specify that the main problem is that all command that involves the g.region always returns the reported error (ERROR: default region is not set.) also the "help".

I found a similar discussion here:
http://lists.osgeo.org/pipermail/grass-user/2009-November/052988.html

Where the solution was to use of the SVN version of the grass.
I already tried to use that version, bunt nothing changed.
Any me any suggestions?
Thank you.

Achim Kisseler wrote:

Hi,

it says: "default" region is not set. Try
g.region -s
to save as fefault region

eventually use
v.in.ogr -e
to extend the location extends

Achim

Giacomo Piva schrieb:
  

Hi all,
I have already read and tested how to integrate the GRASS modules on a
BASH script as Markus suggested.
I'm running GRASS 6.4RC5 version.

I should convert a shapefile given in the Italian projection system
(Gauss-Boaga) into a raster file (GeoTIFF format) at a given resolution.
I have tried to use the v.to.rast module, but it first requires the
import module v.in.ogr.
So, I found some troubles in the region defining.

I've tried to set it manually with the command:
g.region s=... n=... e=.. w=..

But the command returns the following error:
ERROR: default region is not set.

I've tried also other solutions, as the command: g.region
vect="path/to/file.shp"
But it returns the same error.

Could anyone give me any suggestions?
Thank you.

--
Giacomo

On Thu, 10 Dec 2009, Giacomo Piva wrote:

To clarify my problem, i want to specify that the main problem is that all
command that involves the g.region always returns the reported error
(ERROR: default region is not set.) also the "help".

Giacomo,

   If you did not set the region/boundary when defining the location and
mapset you'll see this error. Have you tried 'g.region vect=<mapname>'? That
sets the region to that of the imported vector map. You can also use the
rast= option to set the region based on a raster map.

Rich

Giacomo Piva:

First of all, thanks for your reply.
To clarify my problem, i want to specify that the main
problem is that
all command that involves the g.region always returns the
reported error
(ERROR: default region is not set.) also the "help".

I found a similar discussion here:
http://lists.osgeo.org/pipermail/grass-user/2009-November/052988.html

Where the solution was to use of the SVN version of the
grass.
I already tried to use that version, bunt nothing changed.
Any me any suggestions?

maybe the rc5 bug is now gone, but the corrupted WIND file still
remains in your mapset. try 'g.region -d' to reset it.

does it work from a newly created mapset?

Hamish

Hamish wrote:

Giacomo Piva:
  

First of all, thanks for your reply.
To clarify my problem, i want to specify that the main
problem is that all command that involves the g.region always returns the
reported error (ERROR: default region is not set.) also the "help".

I found a similar discussion here:
http://lists.osgeo.org/pipermail/grass-user/2009-November/052988.html

Where the solution was to use of the SVN version of the
grass.
I already tried to use that version, bunt nothing changed.
Any me any suggestions?
    
maybe the rc5 bug is now gone, but the corrupted WIND file still
remains in your mapset. try 'g.region -d' to reset it.

does it work from a newly created mapset?

Hamish

Hi Hamish,
Maybe it could be usefull to do a backward step.

I should convert a shapefile into a raster file (GeoTIFF format) at a given resolution and I want to use the GRASS modules as a command line tools.
I followed the instructions in the chapter "Automated usage of grass" in the Markus's book and I created a bash script in order to prepare the grass enviroment:

#!/bin/bash
LOCATION=test

GISBASE=/usr/local/grass-6.5.svn
GISDBASE=/usr/local/share/grassdata

rm $HOME/.grassrc6
rm -rf "$GISDBASE/$LOCATION" #cleaning LOCATION

TMPDIR=$$.tmp
mkdir -p $GISDBASE/$TMPDIR/temp

echo "LOCATION_NAME: $TMPDIR" > $HOME/.grassrc6
echo "MAPSET: temp" >> $HOME/.grassrc6
echo "DIGITIZER: none" >> $HOME/.grassrc6
echo "GISDBASE: $GISDBASE" >> $HOME/.grassrc6

export GISBASE=$GISBASE
export GISRC=$HOME/.grassrc6
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts

After these lines I run the v.in.ogr module to import the vector:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map

And the following is the error i get.
ERROR: region for current mapset is not set
run "g.region"

I tried to get the g.region help message, also I tried to reset the region (with g.region -d) and to set a default region (with g.region -s) but I get always the same error.

I'm very new with GRASS and I cannot understand if there is a problem in the installation, or it is a bug (as it seemed), or I'm not working in the proper way.

Thanks (also for the patience)

--
Giacomo

Giacomo Piva wrote:

Hamish wrote:

Giacomo Piva:

First of all, thanks for your reply.
To clarify my problem, i want to specify that the main
problem is that all command that involves the g.region always returns the
reported error (ERROR: default region is not set.) also the "help".

I found a similar discussion here:
http://lists.osgeo.org/pipermail/grass-user/2009-November/052988.html

Where the solution was to use of the SVN version of the
grass.
I already tried to use that version, bunt nothing changed.
Any me any suggestions?

maybe the rc5 bug is now gone, but the corrupted WIND file still
remains in your mapset. try 'g.region -d' to reset it.

does it work from a newly created mapset?

Hamish

Hi Hamish,
Maybe it could be usefull to do a backward step.

I should convert a shapefile into a raster file (GeoTIFF format) at a given resolution and I want to use the GRASS modules as a command line tools.
I followed the instructions in the chapter "Automated usage of grass" in the Markus's book and I created a bash script in order to prepare the grass enviroment:

#!/bin/bash
LOCATION=test

GISBASE=/usr/local/grass-6.5.svn
GISDBASE=/usr/local/share/grassdata

rm $HOME/.grassrc6
rm -rf "$GISDBASE/$LOCATION" #cleaning LOCATION

TMPDIR=$$.tmp
mkdir -p $GISDBASE/$TMPDIR/temp

echo "LOCATION_NAME: $TMPDIR" > $HOME/.grassrc6
echo "MAPSET: temp" >> $HOME/.grassrc6
echo "DIGITIZER: none" >> $HOME/.grassrc6
echo "GISDBASE: $GISDBASE" >> $HOME/.grassrc6

export GISBASE=$GISBASE
export GISRC=$HOME/.grassrc6
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts

After these lines I run the v.in.ogr module to import the vector:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map

And the following is the error i get.
ERROR: region for current mapset is not set
run "g.region"

I tried to get the g.region help message, also I tried to reset the region (with g.region -d) and to set a default region (with g.region -s) but I get always the same error.

I'm very new with GRASS and I cannot understand if there is a problem in the installation, or it is a bug (as it seemed), or I'm not working in the proper way.

Thanks (also for the patience)

No suggestions?

--
Giacomo Piva

MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it

========================================
"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."

"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."

> I should convert a shapefile into a raster file
(GeoTIFF format) at a given resolution and I want to use the
GRASS modules as a command line tools.
> I followed the instructions in the chapter "Automated
usage of grass" in the Markus's book and I created a bash
script in order to prepare the grass enviroment:
>
> #!/bin/bash
> LOCATION=test
>
> GISBASE=/usr/local/grass-6.5.svn
> GISDBASE=/usr/local/share/grassdata
>
> rm $HOME/.grassrc6
> rm -rf "$GISDBASE/$LOCATION" #cleaning LOCATION
>
> TMPDIR=$$.tmp
> mkdir -p $GISDBASE/$TMPDIR/temp
>
> echo "LOCATION_NAME: $TMPDIR" > $HOME/.grassrc6
> echo "MAPSET: temp" >> $HOME/.grassrc6
> echo "DIGITIZER: none" >> $HOME/.grassrc6
> echo "GISDBASE: $GISDBASE" >> $HOME/.grassrc6
>
> export GISBASE=$GISBASE
> export GISRC=$HOME/.grassrc6
> export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
>
> After these lines I run the v.in.ogr module to import
the vector:
> v.in.ogr -o -e dsn=./test_data/test_data.shp
output=grass_map
>
> And the following is the error i get.
> ERROR: region for current mapset is not set
> run "g.region"
>
> I tried to get the g.region help message, also I tried
to reset the region (with g.region -d) and to set a default
region (with g.region -s) but I get always the same error.
>
> I'm very new with GRASS and I cannot understand if
there is a problem in the installation, or it is a bug (as
it seemed), or I'm not working in the proper way.
>
> Thanks (also for the patience)
>

No suggestions?

(I have like 5000 emails in my mailing list inbox, sorry if I missed yours)

If you are new to grass I would recommend using GRASS_BATCH_JOB instead
of setting the enviro vars by hand. Then the grass startup script takes
care of all of that for you.

see the wiki page for more.
  http://grass.osgeo.org/wiki/GRASS_and_Shell#GRASS_Batch_jobs

Hamish

Hi,

Giacomo Piva wrote:

Giacomo Piva wrote:

[...]

I should convert a shapefile into a raster file (GeoTIFF format) at a given resolution and I want to use the GRASS modules as a command line tools.
I followed the instructions in the chapter "Automated usage of grass" in the Markus's book and I created a bash script in order to prepare the grass enviroment:

#!/bin/bash
LOCATION=test

GISBASE=/usr/local/grass-6.5.svn
GISDBASE=/usr/local/share/grassdata

rm $HOME/.grassrc6
rm -rf "$GISDBASE/$LOCATION" #cleaning LOCATION

TMPDIR=$$.tmp
mkdir -p $GISDBASE/$TMPDIR/temp

echo "LOCATION_NAME: $TMPDIR" > $HOME/.grassrc6
echo "MAPSET: temp" >> $HOME/.grassrc6
echo "DIGITIZER: none" >> $HOME/.grassrc6
echo "GISDBASE: $GISDBASE" >> $HOME/.grassrc6

export GISBASE=$GISBASE
export GISRC=$HOME/.grassrc6
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts

After these lines I run the v.in.ogr module to import the vector:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map

According to the grass book, the v.in.ogr command should include the location option:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map location=$LOCATION

then go to the newly created location (set the environment variables accordingly and update .grassrc6), set the region extends and resolution to your demands, run v.to.rast, then r.out.gdal.

IMHO, it is easier to use the GUI.

Hope that helps,

Markus M

Giacomo Piva wrote:

Hamish wrote:
I followed the instructions in the chapter "Automated usage of grass" in
the Markus's book and I created a bash script in order to prepare the
grass enviroment:

#!/bin/bash
LOCATION=test

GISBASE=/usr/local/grass-6.5.svn
GISDBASE=/usr/local/share/grassdata

rm $HOME/.grassrc6
rm -rf "$GISDBASE/$LOCATION" #cleaning LOCATION

TMPDIR=$$.tmp
mkdir -p $GISDBASE/$TMPDIR/temp

echo "LOCATION_NAME: $TMPDIR" > $HOME/.grassrc6
echo "MAPSET: temp" >> $HOME/.grassrc6
echo "DIGITIZER: none" >> $HOME/.grassrc6
echo "GISDBASE: $GISDBASE" >> $HOME/.grassrc6

export GISBASE=$GISBASE
export GISRC=$HOME/.grassrc6
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts

After these lines I run the v.in.ogr module to import the vector:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map

And the following is the error i get.
ERROR: region for current mapset is not set
run "g.region"

I tried to get the g.region help message, also I tried to reset the
region (with g.region -d) and to set a default region (with g.region -s)
but I get always the same error.

You have to create a valid location and mapset. It isn't enough that
the directories exist; they have to contain certain files. At an
absolute minimum, you need the $GISDBASE/$LOCATION_NAME/$MAPSET/WIND
file. You may also need the $GISDBASE/$LOCATION_NAME/PERMANENT
directory and some or all of the files:

  $GISDBASE/$LOCATION_NAME/PERMANENT/DEFAULT_WIND
  $GISDBASE/$LOCATION_NAME/PERMANENT/MYNAME
  $GISDBASE/$LOCATION_NAME/PERMANENT/PROJ_INFO
  $GISDBASE/$LOCATION_NAME/PERMANENT/PROJ_UNITS

  $GISDBASE/$LOCATION_NAME/$MAPSET/VAR

If your automated sessions all use the same projection, you can use an
existing location, and only generate a new mapset for each automated
session. Then you only need to create the mapset directory and the
WIND file (which can be copied from ../PERMANENT/DEFAULT_WIND).

Alternatively, you can create a "skeleton" database, and make a copy
of that for each session.

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

Hi Markus,
I'm not using the GUI because I need to use GRASS as automated tool to convert a shape file to a raster in GTIFF.
I tried to do what you have explained in many ways but without success.

I know that I have to execute something like:
v.in.ogr ...
v.to.rast ...
r.out.gdal ...

But the v.in.ogr returns the g.region error also with the location= option.

I tried to do another operation (maybe simpler), like reading a raster image and get information on the region, diong:

r.in.gdal -o -e input=$HOME/raster.tif output=grass_rast location=$LOCATION

Then setting the new location (as you suggested) and running the g.region

g.region -p

and this is the output:

Location <test> created
100%
r.in.gdal complete. Raster map <grass_rast.1> created.
Copying 144 GCPS in points file for <grass_rast>
GCPs have the following OpenGIS WKT Coordinate System::
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS
84",6378137,298.2572235629972,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]
projection: 0 (x,y)
zone: 0
north: 2030
south: 0
west: 0
east: 1354
nsres: 1
ewres: 1
rows: 2030
cols: 1354
cells: 2748620

It seems to work properly...

Why I can't run the v.in.ogr?

Thank you for help.

Markus Metz wrote:

Hi,

According to the grass book, the v.in.ogr command should include the location option:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map location=$LOCATION

then go to the newly created location (set the environment variables accordingly and update .grassrc6), set the region extends and resolution to your demands, run v.to.rast, then r.out.gdal.

IMHO, it is easier to use the GUI.

Hope that helps,

Markus M

--
Giacomo

Hi,

Giacomo Piva wrote:

Hi Markus,
I'm not using the GUI because I need to use GRASS as automated tool to convert a shape file to a raster in GTIFF.

The GUI is good to develop and debug the script before you create an automated tool that may produce bogus results.

I tried to do what you have explained in many ways but without success.

I know that I have to execute something like:
v.in.ogr ...
v.to.rast ...
r.out.gdal ...

But the v.in.ogr returns the g.region error also with the location= option.

Then try a valid location to start with, as explained by Glynn. I think you can use any valid location, also one of the sample datasets. When using an existing valid location, it should be enough to give the location name and mapset name as in your script. Then do v.in.ogr -oe location=$LOCATION
That obviously only works properly if there is a *.prj file accompanying the *.shp file, otherwise you end up with a xy location. In the absence of a *.prj file you must either ask the authors of the shapefile or guess and manually create the location with the correct projection info.

Markus M

I tried to do another operation (maybe simpler), like reading a raster image and get information on the region, diong:

r.in.gdal -o -e input=$HOME/raster.tif output=grass_rast location=$LOCATION

Then setting the new location (as you suggested) and running the g.region

g.region -p

and this is the output:

Location <test> created
100%
r.in.gdal complete. Raster map <grass_rast.1> created.
Copying 144 GCPS in points file for <grass_rast>
GCPs have the following OpenGIS WKT Coordinate System::
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS
84",6378137,298.2572235629972,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]

projection: 0 (x,y)
zone: 0
north: 2030
south: 0
west: 0
east: 1354
nsres: 1
ewres: 1
rows: 2030
cols: 1354
cells: 2748620

It seems to work properly...

Why I can't run the v.in.ogr?

Thank you for help.

Markus Metz wrote:

Hi,

According to the grass book, the v.in.ogr command should include the location option:
v.in.ogr -o -e dsn=./test_data/test_data.shp output=grass_map location=$LOCATION

then go to the newly created location (set the environment variables accordingly and update .grassrc6), set the region extends and resolution to your demands, run v.to.rast, then r.out.gdal.

IMHO, it is easier to use the GUI.

Hope that helps,

Markus M

Hi all.
Finally I get it work.
Thanks to Gynn and Markus.

--
Giacomo