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

hi,

according to
http://grass.gdf-hannover.de/wiki/GRASS_6.2_Feature_Plan#RC3.2FFinal

i prepared 2 lines patch for this. it works for me, should i apply?

jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

(attachments)

r.out.gdal.patch (708 Bytes)

Hi,

I think r.out.gdal should be region sensitive, the patch looks like OK for me...

Best, Martin

2006/10/17, Jachym Cepicky <jachym.cepicky@centrum.cz>:

hi,

according to
http://grass.gdf-hannover.de/wiki/GRASS_6.2_Feature_Plan#RC3.2FFinal

i prepared 2 lines patch for this. it works for me, should i apply?

jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFFNUH4yKt0uAjU4I8RAkgDAJ9e1vU5W1YquohFZ0Z0AB8XveUmngCfU72r
yvxifRiQzZKnCyuQUNVMwGc=
=AVA3
-----END PGP SIGNATURE-----

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

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

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.

Paul

On Tue, 17 Oct 2006, Jachym Cepicky wrote:

hi,

according to
http://grass.gdf-hannover.de/wiki/GRASS_6.2_Feature_Plan#RC3.2FFinal

i prepared 2 lines patch for this. it works for me, should i apply?

jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

Jachym Cepicky wrote:

according to
http://grass.gdf-hannover.de/wiki/GRASS_6.2_Feature_Plan#RC3.2FFinal

i prepared 2 lines patch for this. it works for me, should i apply?

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.

Maciek

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@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

(attachments)

r.out.gdal.patch (1.55 KB)

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@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

(attachments)

r.out.gdal.patch (1.55 KB)

Oops, the line endings on that patch got corrupted - please look at this one instead.

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@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

(attachments)

r.out.gdal.patch (1.49 KB)

hi
On Wed, Oct 18, 2006 at 09:56:22AM +0100, Paul Kelly wrote:

[...]
What do you think?

Paul

i think, that you are much better coder :slight_smile:

thanks for the hints, i'll have a look at this

jachym

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@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@node.mendelu.cz
>URL: http://mapserver.mendelu.cz
>Tel.: +420 545 134 514
>

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

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Jachym Cepicky
e-mail: jachym.cepicky@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

hi,

i tested the patch and it works ok (also on lat/long location). since nobody complained against this new feature, i committed
the patch to cvs

many thanks to Paul, the author of this patch

jachym

On Wed, Oct 18, 2006 at 10:00:53AM +0100, Paul Kelly wrote:

Oops, the line endings on that patch got corrupted - please look at this
one instead.

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@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@node.mendelu.cz
>URL: http://mapserver.mendelu.cz
>Tel.: +420 545 134 514
>

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

--
Jachym Cepicky
e-mail: jachym.cepicky@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

Paul Kelly wrote:

+# region sensitive output
+if [ $GIS_FLAG_R -eq 1 ] ; then
+
+ TEMPRASTER=r.out.gdal_${INPUT}_$$
+ r.resample input=$INPUT output=$TEMPRASTER
+ INPUT=$TEMPRASTER

Possible addition:

+else
+ echo "WARNING: future versions will use current region by default" >&2

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

>> In order for the behaviour of r.out.gdal to be consistent with
>> other r.out.* modules,

just a check re. region bounds & grid vs. pixel conventions, does a
full cycle result in the same exact data?

r.out.gdal -r in=orig_map format=[...] out=map.ext

r.in.gdal in=map.ext out=map2

r.resample in=orig_map out=orig_map.resamp

r.mapcalc diff="orig_map.resamp - map2"

r.univar diff

?
Hamish

hi,
On Thu, Oct 19, 2006 at 12:22:14PM +1300, Hamish wrote:

> >> In order for the behaviour of r.out.gdal to be consistent with
> >> other r.out.* modules,

just a check re. region bounds & grid vs. pixel conventions, does a
full cycle result in the same exact data?

r.out.gdal -r in=orig_map format=[...] out=map.ext

r.in.gdal in=map.ext out=map2

r.resample in=orig_map out=orig_map.resamp

r.mapcalc diff="orig_map.resamp - map2"

r.univar diff

?
Hamish

if i understand this well, you are asking for result like this:
    
d.zoom
r.out.gdal -r in=soils type=Byte out=map.ext
r.in.gdal in=map.ext out=map2 --o
r.resample in=soils out=soils.resamp --o
r.mapcalc diff="soils.resamp - map2"
r.univar diff

total null and non-null cells: 29382
total null cells: 0

Of the non-null cells:
----------------------
n: 29382
minimum: 0
maximum: 0
range: 0
mean: 0
mean of absolute values: 0
standard deviation: 0
variance: 0
variation coefficient: nan %
sum: 0

i would say, this looks good(?)

jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@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@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

Jachym Cepicky wrote:

> > >> In order for the behaviour of r.out.gdal to be consistent with
> > >> other r.out.* modules,
>
> just a check re. region bounds & grid vs. pixel conventions, does a
> full cycle result in the same exact data?

..

if i understand this well, you are asking for result like this:
    
d.zoom
r.out.gdal -r in=soils type=Byte out=map.ext
r.in.gdal in=map.ext out=map2 --o
r.resample in=soils out=soils.resamp --o
r.mapcalc diff="soils.resamp - map2"

yes

r.univar diff

total null and non-null cells: 29382
total null cells: 0

Of the non-null cells:
----------------------
n: 29382
minimum: 0
maximum: 0
range: 0
mean: 0
mean of absolute values: 0
standard deviation: 0
variance: 0
variation coefficient: nan %
sum: 0

i would say, this looks good(?)

I would say this looks very good! Thanks.

Hamish