#2368: Python version of r.grow does not support shrinking
-------------------------+-------------------------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
Type: | Status: new
enhancement |
Priority: minor | Milestone: 7.2.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.grow, r.grow.distance, r.buffer,
CPU: | r.buffer.lowmem
Unspecified | Platform: Unspecified
-------------------------+-------------------------------------------------
Comment (by mmetz):
Replying to [comment:9 neteler]:
> Replying to [comment:7 neteler]:
> > Replying to [comment:6 mmetz]:
> > > Replying to [comment:3 glynn]:
> > > > The easiest change would be to have an "invert" flag which caused
the distance= map to contain the distance from the nearest null cell
(currently, it's the distance from the nearest non-null cell, so the non-
null cells themselves have a distance of 0).
> > >
> > > Attached is a minimally invasive patch to add a new flag to
r.grow.distance, calculating the distance to the nearest null cell.
> >
> > Patch applied to trunk in r67620.
>
> Can I backport this to 7.2.0? Again I need a negative buffer...
This is a new feature and as such does not qualify for backport.
If you want to shrink you can use
{{{
r.mapcalc "input_inv = if(isnull(input), 1, null())"
r.grow input=input_inv
}}}
Replying to [comment:10 neteler]:
> Just tested r.grow with a negative radius and the following error
occurs:
> {{{
> # NC sample dataset
> v.in.region box
> v.to.rast input=box output=box use=val val=1
>
> r.grow input=box output=box_shrink radius=-20.01
> }}}
The example is wrong because there are no NULL cells in the current region
for the input raster. When growing, for each NULL cell the distance to the
nearest non-NULL cell is calculated. When shrinking, for each non-NULL
cell the distance to the nearest NULL cell is calculated. That means there
must be both NULL and non-NULL cells in the input raster for the current
region, otherwise nothing can be grown or shrunk.
The example can not work because r.grow does not support negative
distances. A test needs to be added to the script to call r.grow.distance
with the new flag if the radius is negative, and a different r.mapcalc
expression must be used to create the final output:
{{{
"$output = if($dist < $radius,null(),$old)"
}}}
> {{{
> Reading raster map <box>...
> 100%
> Writing output raster maps...
> 100%
> ERROR 1: PredictorSetup:Horizontal differencing "Predictor" not
supported with 64-bit samples
> ERROR 1: PredictorSetup:Horizontal differencing "Predictor" not
supported with 64-bit samples
> ERROR 1: PredictorSetup:Horizontal differencing "Predictor" not
supported with 64-bit samples
> ERROR 1: PredictorSetup:Horizontal differencing "Predictor" not
supported with 64-bit samples
> 100%
> ERROR 1: PredictorSetup:Horizontal differencing "Predictor" not
supported with 64-bit samples
> ERROR 1: PredictorSetup:Horizontal differencing "Predictor" not
supported with 64-bit samples
> Color table for raster map <box_shrink> set to 'box'
> }}}
These look like GDAL errors, they are definitively not GRASS errors.
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2368#comment:12>
GRASS GIS <https://grass.osgeo.org>