Details Ticket 4145


Comment | Reply | Take | Open


Serial Number 4145
Subject r.patch -z eats holes in data
Area grass6
Queue grass
Requestors cedricgrass@shockfamily.net
Owner none
Status resolved
Last User Contact Tue Mar 7 16:42:37 2006 (2 yr ago)
Current Priority 30
Final Priority 70
Due No date assigned
Last Action Sat Mar 11 02:47:33 2006 (2 yr ago)
Created Tue Mar 7 05:35:08 2006 (2 yr ago)

Transaction History Ticket 4145


Tue, Mar 7 2006 05:35:08    Request created by guest  
Subject: r.patch -z eats holes in data

Platform: GNU/Linux/x86
grass obtained from: Other (CDROM etc)
grass binary for platform: Downloaded precompiled Binaries
GRASS Version: 6.0.1

r.patch with the -z option does not patch null data in the first input with 0
data in later inputs.

r.patch with the -z option is frequently used to patch together data of somewhat
poor quality in which 0 is used both for no data in the boundaries of patches
and as a legitimite piece of data in the interior of tiles. It is my belief,
therfore, that the correct behaviour for r.patch is to not only attempt to replace
nulls and zeros with data points, but also to replace nulls with zeros. Changing
this behaviour would make the results of r.patch much less dependent upon the
order in which input maps are presented. As it is the first input map's zeros
are preserved when there is no other data, but the zeros in the other input maps
are removed and replaced with nulls (because when no replacement is found it
defaults to the value of the first input by the act of not changing anything).
You can see an example of these holes (magenta dots near bright curves at bottom
and elsewhere) here: http://www.shockfamily.net/cedric/grass/spearfish1.png
Here is the segment of code in do_patch.c as it currently stands:

    if (ZEROFLAG)  /* use 0 for transparency instead of NULL */
    {
	if (G_is_zero_value(result, out_type) ||
	    G_is_null_value(result, out_type))
	{
	    if(G_is_zero_value(patch, out_type) ||
	       G_is_null_value(patch, out_type))
		more = 1;
            else
	    {
	        G_raster_cpy(result, patch, 1, out_type);
		if(out_type==CELL_TYPE)
	            G_update_cell_stats ((CELL *) result, 1, statf);
	    }
	} /* ZERO support */
    }


And here is a suggested, and untested, replacement to fix this problem:

    if (ZEROFLAG)  /* use 0 for transparency instead of NULL */
    {
	if (G_is_zero_value(result, out_type) ||
	    G_is_null_value(result, out_type))
	{
	    if(G_is_null_value(patch, out_type))
		more = 1;
            else
	    {
	        if (G_is_zero_value(patch, out_type))
	            more = 1;
	        G_raster_cpy(result, patch, 1, out_type);
		if(out_type==CELL_TYPE)
	            G_update_cell_stats ((CELL *) result, 1, statf);
	    }
	} /* ZERO support */
    }

If the replacment data is null we mark the row as having more replacements to
be done and skip replacing the cell, as before. However if the patch is zero
we go ahead and apply it (replacing either a zero or null value), but still mark
the row as candidate for further replacement.

--Cedric Shock
Tue, Mar 7 2006 16:42:37    Mail sent by guest  
Workaround:

Patch the output map again using the inputs to fill the remaining nulls with
zeros. Example:

r.patch -z input=i1,i2,i3... output=outputmap
r.patch input=outputmap,i1,i2,i3,.... output=outputmap

Note that, allthough I included it, the first input doesn't need to be used
since its zeros make it into the output but no others do.

--Cedric Shock
Fri, Mar 10 2006 16:52:07    Mail sent by cedricgrass@shockfamily.net  
Return-Path <cedricgrass@shockfamily.net>
Delivered-To grass-bugs@lists.intevation.de
From Cedric Shock <cedricgrass@shockfamily.net>
To Request Tracker <grass-bugs@intevation.de>
Subject Re: [GRASS5] [bug #4145] Patch for: (grass) r.patch -z eats holes in data
Date Fri, 10 Mar 2006 07:51:28 -0800
User-Agent KMail/1.8.3
References <20060307043508.90784100164@lists.intevation.de>
In-Reply-To <20060307043508.90784100164@lists.intevation.de>
Cc grass5@grass.itc.it
MIME-Version 1.0
Content-Type Multipart/Mixed; boundary="Boundary-00=_BCaEEMftNBnxifV"
Message-Id <200603100751.30016.cedricgrass@shockfamily.net>
X-Spam-Status No, hits=-4.8 tagged_above=-999.0 required=3.0 tests=BAYES_00, HTML_MESSAGE
X-Spam-Level
--Boundary-00=_BCaEEMftNBnxifV
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Interested parties,

I have fixed this bug. The attached patch contains both tested code changes 
for this bug and rewording of description.html to make it obvious that the 
current region heavily influences the output of r.patch

Description:
r.patch: Closes bug 4145 by replacing zero and null values with data and null
values with zeros when using -z flag. Description.html partly rewritten to 
describe the effect the current region has on r.patch.

--Cedric Shock

--Boundary-00=_BCaEEMftNBnxifV
Content-Type: text/x-diff;
  charset="utf-8";
  name="grass_bug_4145_patch_noOBJ"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="grass_bug_4145_patch_noOBJ"

Index: raster/r.patch/description.html
===================================================================
RCS file: /home/grass/grassrepository/grass6/raster/r.patch/description.html,v
retrieving revision 1.1
diff -u -p -r1.1 description.html
--- raster/r.patch/description.html	6 May 2003 14:44:48 -0000	1.1
+++ raster/r.patch/description.html	10 Mar 2006 15:15:42 -0000
@@ -1,8 +1,14 @@
 <H2>DESCRIPTION</H2>
 
-The GRASS program <EM>r.patch</EM> allows the user to assign known data
-values from other raster map layers to the <EM>"no data"</EM> areas (those
-assigned category value NULL/0) in another raster map layer.  This program
+The GRASS program <EM>r.patch</EM> allows the user to build a new
+raster map the size and resolution of the current region by assigning
+known data values from input raster maps to the cells in this region.
+This is done by filling in "no data" cells, those that do not yet
+contain data, contain NULL data, or, optionally contain 0 data,
+with the data from the first input map.
+Once this is done the remaining holes are filled in by the next input map,
+and so on.
+This program
 is useful for making a composite raster map layer from two or more adjacent
map layers, for filling in "holes" in a raster map layer's data (e.g., in
 digital elevation data), or for updating an older map layer with more recent
@@ -11,12 +17,10 @@ respected.
 <P>
 The first <EM>name</EM> listed in the string
 <B>input=</B><EM>name</EM>,<EM>name</EM>,<EM>name</EM>, ... is the name of
-the base map whose zero data values will be attempted to be filled by
-non-zero data values in the second through tenth input <EM>name</EM> maps
-listed.  The second through 200 (max) input <EM>name</EM> maps will be used
to
-supply remaining missing (zero) data values for the first input map
-<EM>name</EM>, based on the order in which they are listed in the string
-<B>input=</B><EM>name</EM>,<EM>name</EM>,<EM>name</EM>, ...
+the first map whose data values will be used to fill in "no data" cells
+in the current region. The second through 200 (max) input <EM>name</EM>
+maps will be used, in order, to supply data values for for the remaining
+"no data" cells.
 
 <H2>EXAMPLE</H2>
 
@@ -56,7 +60,8 @@ maps align neatly.
 <P>
 The user should check the current geographic region settings before running
<EM>r.patch</EM>, to ensure that the region boundaries encompass all 
-of the data desired to be included in the composite map. 
+of the data desired to be included in the composite map and to ensure that the
+region resolution is the resolution of the desired data.
 
 <P>
 
Index: raster/r.patch/do_patch.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/raster/r.patch/do_patch.c,v
retrieving revision 2.1
diff -u -p -r2.1 do_patch.c
--- raster/r.patch/do_patch.c	9 Feb 2006 03:09:02 -0000	2.1
+++ raster/r.patch/do_patch.c	10 Mar 2006 15:15:42 -0000
@@ -36,11 +36,14 @@ int do_patch (
 	if (G_is_zero_value(result, out_type) ||
 	    G_is_null_value(result, out_type))
 	{
-	    if(G_is_zero_value(patch, out_type) ||
-	       G_is_null_value(patch, out_type))
+	    /* Don't patch hole with a null, just mark as more */
+	    if(G_is_null_value(patch, out_type))
 		more = 1;
             else
 	    {
+	        /* Mark that there is more to be done if we patch with 0 */
+	        if(G_is_zero_value(patch, out_type))
+	            more = 1;
 	        G_raster_cpy(result, patch, 1, out_type);
 		if(out_type==CELL_TYPE)
 	            G_update_cell_stats ((CELL *) result, 1, statf);

--Boundary-00=_BCaEEMftNBnxifV--


Sat, Mar 11 2006 02:47:33    Status changed to resolved by sgebert  
Comment | Reply | Take | Open

You are currently authenticated as guest.
[Show Configuration] [Login as another user]

Users Guide - Mail Commands - Homepage of RequestTracker 1.0.7 - list any request