[GRASSLIST:1942] Re: Export Raster - followup

Glynn Clements glynn.clements at virgin.net
Tue Dec 2 16:54:16 EST 2003


Daniel Victoria wrote:

> Just to finish the topic.
> 
> I made 2 shell scripts, one that will tar/bzip2 all
> maps with a specific name to a tar.bz2 file and the
> other that will unpack it. The unpacking is not
> necessary since it can be done by simply using the
> command
> tar -jxPvf file_name
> the P is to keep the original file path
> 
> Hope it can be usefull to anyone. Feel free to change
> it as you see fit

> tar -jcPvf $outfile
> $GISDBASE/$LOCATION_NAME/$MAPSET/*/$pattern

Presumably this was meant to be a single line, but was wrapped by your
mail client?

A few points:

1. You can't rely upon $GISDBASE, $LOCATION_NAME or $MAPSET being set;
in 5.0.0 and later, these settings aren't stored in environment
variables. The script would need to do:

	eval `g.gisenv`

to set those variables.

2. One potential problem with using absolute pathnames is that you
might exceed the maximum length of a command line, particularly if
$GISDBASE is long and a map has a large number of components. If you
want complete pathnames in the tar file, a more reliable approach
would be:

	dir="$GISDBASE/$LOCATION_NAME/$MAPSET"
	cd "$dir"
	for file in */$pattern ; do
	    echo "$dir/$file"
	done | tar cjPvfT "$outfile" -

3. Personally, I wouldn't use absolute paths, but would at least make
them relative to $GISDBASE, so that they can still be extracted if
$GISDBASE moves. E.g.

	root="$GISDBASE"
	dir="$LOCATION_NAME/$MAPSET"
	( cd "$root/$dir"
	  for file in */$pattern ; do
	      echo "$dir/$file"
	  done ) | tar cjPvCfT "$root" "$outfile" -

A similar argument could be made about using paths which are relative
to either the location or mapset directory. However, the arguments for
including either the location or location+mapset directories are
somewhat stronger than for the database directory (i.e. they form part
of the database' structure).

Having said all that, the ultimate solution would be to use the code
in src/general/manage (g.copy etc) to produce a utility which lists
all of the files which actually comprise a map (via etc/element_list).
 
That would eliminate false positives, i.e. files with the same name as
a map but which aren't actually part of that map. This is particularly
relevant if you have raster/vector/sites maps with the same name.

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-user mailing list