[GRASS-dev] making r.out.gdal region sensitive

Paul Kelly paul-grass at stjohnspoint.co.uk
Wed Oct 18 04:56:22 EDT 2006


Hello Jachym,
That looks OK, but I made some (untested) changes to your patch (see 
attached). First of all the re-sampled map will automatically cover the 
current region only so you do not need the extra -projwin bit on the 
gdal command line. Also I didn't understand what the '' was in the 
temporary filename: temporary_$INPUT''_$$ - why not r.out.gdal_${INPUT}_$$ 
? I put r.out.gdal in the name so it is more obvious where it came from if 
for some reason it doesn't get deleted (e.g. the script is interrupted). 
Also changed the g.remove bit to remove the temporary filename variable. 
This won't be set if the -r flag isn't used so there's no chance of the 
real input map being accidentally deleted in some unlikely circumstances. 
In fact you don't really need the test for the -r flag at the end - you 
could just forcibly remove that file and if it didn't exist (i.e. -r flag 
wasn't used) it would be OK. But having the check for the flag in makes it 
tidier I think.

What do you think?

Paul

On Wed, 18 Oct 2006, Jachym Cepicky wrote:

> hallo,
>
> On Tue, Oct 17, 2006 at 10:56:58PM +0100, Paul Kelly wrote:
>> Hello Jachym
>> In order for the behaviour of r.out.gdal to be consistent with other
>> r.out.* modules, I think it would be more appropriate for it to first
>> use
>> r.resample to resample the map according to the current region (this
>> is
>> what the other modules do) into a temporary raster map and then export
>> that.
>
> could you point me to some example? how to create temporary raster file?
> i tryed something, see this patch
>
> On Wed, Oct 18, 2006 at 09:03:54AM +0200, Maciej Sieczka wrote:
>> Please, but only as an option. We can't remove any current behavior
>> unless it's a bug.
>>
>> In GRASS 7 region-sensitiveness in r.out.gdal should become the
>> default
>> however - for consistency with other r.out.* modules.
>>
>
> i added -r flag for "region sensitive"
>
> jachym
>
>
> -- 
> Jachym Cepicky
> e-mail: jachym.cepicky at centrum.cz
> URL: http://les-ejk.cz
> GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
> -----------------------------------------
> OFFICE:
> Department of Geoinformation Technologies
> Zemedelska 3
> 613 00, Brno
> Czech Republick
> e-mail: xcepicky at node.mendelu.cz
> URL:    http://mapserver.mendelu.cz
> Tel.:   +420 545 134 514
>
-------------- next part --------------
Index: r.out.gdal

===================================================================

RCS file: /grassrepository/grass6/scripts/r.out.gdal/r.out.gdal,v

retrieving revision 1.24

diff -u -r1.24 r.out.gdal

--- r.out.gdal	19 Aug 2006 12:52:24 -0000	1.24

+++ r.out.gdal	18 Oct 2006 08:07:59 -0000

@@ -22,6 +22,10 @@

 #%  key: l

 #%  description: list supported output formats

 #%END

+#%flag

+#%  key: r

+#%  description: region sensitive output

+#%END

 #%option

 #% key: input

 #% type: string

@@ -89,6 +93,7 @@

 OUTPUT="$GIS_OPT_OUTPUT"

 CREATEKEY="`echo "$GIS_OPT_CREATEOPT" | sed 's+,+ -co +g' | sed 's+^+-co +g'`"

 METAKEY="`echo "$GIS_OPT_METAOPT" | sed 's+,+ -mo +g' | sed 's+^+-mo +g'`"

+REGION=""

 

 if [ $GIS_FLAG_L -eq 1 ] ; then

   gdal_translate | grep ':' | grep -v 'Usage' | grep -v 'The following'

@@ -99,6 +104,15 @@

 #echo $INPUT $FORMAT $OUTPUT

 #echo $GDAL_INPUT_FORMATS

 

+# region sensitive output

+if [ $GIS_FLAG_R -eq 1 ] ; then

+

+    TEMPRASTER=r.out.gdal_${INPUT}_$$

+    r.resample input=$INPUT output=$TEMPRASTER

+    INPUT=$TEMPRASTER

+fi

+

+

 #fetch the input raster map

 eval `g.findfile element=cell file=$INPUT` 

 if [ ! "$file" ] ; then

@@ -129,9 +143,14 @@

   unset METAKEY

 fi

 

+

 #do it

 CELLHD=`echo $file | sed 's+/cell/+/cellhd/+g'`

 echo "Writing format: $FORMAT"

 echo "Writing type:   $TYPE"

 gdal_translate -of $FORMAT -ot $TYPE $CREATEKEY $METAKEY $CELLHD $OUTPUT 

 

+if [ $GIS_FLAG_R -eq 1 ] ; then

+    g.remove $TEMPRASTER

+fi



More information about the grass-dev mailing list