[GRASS-user] Automatic import ?

Hi,

is there a way to get grass to import geodata without creating a location first? Grass will not start unless the location is already there or is created in the GUI.

What I mean is:
how can I write a script that will create a new location using projection and extent from an existing file with geodata and then import that file to that location? So that when starting grass the location and the data are already there.

This should be possible with no more than 2 commands (one for create and one for import) but I have no idea how to get grass to run the commands without starting it first.

TIA
stn

Hi,

2010/6/19 stn <stneumann@web.de>:

is there a way to get grass to import geodata without creating a location
first? Grass will not start unless the location is already there or is
created in the GUI.

What I mean is:
how can I write a script that will create a new location using projection
and extent from an existing file with geodata and then import that file to
that location? So that when starting grass the location and the data are
already there.

start GRASS with some location, using

r.in.gdal location=<newlocation> ...

for raster data or

v.in.ogr location=<newlocation> ...

for vector data

you can create new location based on imported data and import data
into the new location in one command.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

2010/6/19 Martin Landa <landa.martin@gmail.com>
Hi,

start GRASS with some location, using

v.in.ogr location= …

you can create new location based on imported data and import data
into the new location in one command.

Hi all, hi Martin,

thank you, that worked on Ubuntu 10.04 with GRASS GIS 6.4.0RC5+39438.

Except for something strange. As said before the idea was to import+create location by a script. So I made a linux shell-script that does this:

echo “v.in.ogr dsn=mydata.shp location=import output=‘mydata’ min_area=0.0001 snap=-1” | grass -text “$GISDATEN/tmplocation/PERMANENT”

That works in principle and automatically imports the data from the shapefile into location ‘import’. Unfortunately only partially. One third of the polygons gets imported, the rest is missing.

I also started grass with gui, selected “tmplocation” and the on the commandline entered exactly the command used above (v.in.ogr dsn=mydata.shp location=import output=‘mydata’ min_area=0.0001 snap=-1). Then all the objects get imported correctly.

What is that?

THX, stn

Hi,

2010/6/20 stn <stneumann@web.de>:

Except for something strange. As said before the idea was to import+create
location by a script. So I made a linux shell-script that does this:

echo "v.in.ogr dsn=mydata.shp location=import output='mydata'
min_area=0.0001 snap=-1" | grass -text "$GISDATEN/tmplocation/PERMANENT"

try to set up script as batch job, see [1].

Martin

[1] http://grass.osgeo.org/wiki/GRASS_and_Shell#GRASS_Batch_jobs

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

2010/6/20 Martin Landa <landa.martin@gmail.com>

Hi,

2010/6/20 stn <stneumann@web.de>:

Except for something strange. As said before the idea was to import+create
location by a script. So I made a linux shell-script that does this:

echo “v.in.ogr dsn=mydata.shp location=import output=‘mydata’
min_area=0.0001 snap=-1” | grass -text “$GISDATEN/tmplocation/PERMANENT”

try to set up script as batch job, see [1].

Hi Martin,

thanks you for the info.
Unfortunately that changed nothing.
The script was executed as expected but afterwards only part of the data has been imported.

Script looks like this now:

echo “v.in.ogr dsn=/home/user/grassdata/BRD_Kreise.shp location=import output=‘BRD_Kreise_shp’ min_area=0.0001 snap=-1” > “$HOME/x.grass”
export GRASS_BATCH_JOB=“$HOME/x.grass”
grass -text “$GISDATEN/tmplocation/PERMANENT”

THX
stn

Martin

[1] http://grass.osgeo.org/wiki/GRASS_and_Shell#GRASS_Batch_jobs


Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi,

2010/6/21 stn <stneumann@web.de>:

[...]

Script looks like this now:

echo "v.in.ogr dsn=/home/user/grassdata/BRD_Kreise.shp location=import
output='BRD_Kreise_shp' min_area=0.0001 snap=-1" > "$HOME/x.grass"

$ cat "$HOME/x.grass"
#!/bin/sh
v.in.ogr dsn=/home/user/grassdata/BRD_Kreise.shp location=import
output='BRD_Kreise_shp' min_area=0.0001 snap=-1

$ chmod +x $HOME/x.grass

Helps?

export GRASS_BATCH_JOB="$HOME/x.grass"
grass -text "$GISDATEN/tmplocation/PERMANENT"

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

2010/6/21 Martin Landa <landa.martin@gmail.com>

Hi,

2010/6/21 stn <stneumann@web.de>:

[…]

Script looks like this now:

echo “v.in.ogr dsn=/home/user/grassdata/BRD_Kreise.shp location=import
output=‘BRD_Kreise_shp’ min_area=0.0001 snap=-1” > “$HOME/x.grass”

$ cat “$HOME/x.grass”
#!/bin/sh

v.in.ogr dsn=/home/user/grassdata/BRD_Kreise.shp location=import
output=‘BRD_Kreise_shp’ min_area=0.0001 snap=-1

$ chmod +x $HOME/x.grass

Helps?

export GRASS_BATCH_JOB=“$HOME/x.grass”
grass -text “$GISDATEN/tmplocation/PERMANENT”

Hi Martin,

sorry, still same as before. Only part of the polygons are imported.

This is the newest complete shell-script:

#!/bin/bash
GISDATEN=“$HOME/grassdata”
OUTPUT=“mydata”
rm -r “$GISDATEN/import”
echo “#!/bin/sh
v.in.ogr dsn=$1 location=import output=‘$OUTPUT’ min_area=0.0001 snap=-1
" > “$HOME/x.grass”
export GRASS_BATCH_JOB=”$HOME/x.grass"
chmod +x “$HOME/x.grass”
grass -text “$GISDATEN/tmplocation/PERMANENT”

Martin

Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa