[GRASSLIST:2574] v.to.rast aggressiveness

Hamish hamish_nospam at yahoo.com
Thu Feb 12 07:51:56 EST 2004


Hi,

I'm noticing v.to.rast is rather aggressive -- (all versions 5.0,5.3,5.7)

It will change many raster cells with only a little bit of vector line in
it to a hit, rather than checking which side of the cell's centroid the
area is on..?

This has bad implications if you want to create masks covering areas
both one side or the other, as it will always bias towards the side of
the area vs. the negative. (say in/out of a lake's shoreline)


Totally convoluted workaround that produces nice results:

Double the target resolution, run v.to.rast, take the negative, run
r.grow2 to expand the negative by one (ie 1/2) cell, reset to the 
original resolution, and resample. That gives us a slightly too big
negative. We only keep the ones that lie on the top left of the 
positive area.

It's nuts, I know, but the end result looks good.

(I'm sure someone can reduce this to a single r.mapcalc command.. 
I was just adding commands until it looked right)



G> g.region -p
...
nsres=50
ewres=50
...
G> g.region res=25
G> v.to.rast in=vect_map out=expansionistic_vect_mask
G> r.mapcalc negative_mask="if(isnull(expansionistic_vect_mask),1,null())"
G> r.grow2 in=negative_mask out=grown_neg_mask_25
G> g.region res=50
G> r.mapcalc "grown_neg_mask_50 = grown_neg_mask_25"

  (r.grow2 radius=0.51 metric=any doesn't do it.)

G> r.null map=grown_neg_mask_50 null=0
G> r.mapcalc better_neg_mask="if(negative_mask,negative_mask,\
        if(grown_neg_mask_50[0,-1],1 ) )"
G> r.mapcalc best_neg_mask="if(grown_neg_mask_50,better_neg_mask)"
G> r.mapcalc land_above="if(expansionistic_vect_mask[-1,0] && \
        isnull(negative_mask),1,0)"
G> r.mapcalc uber_neg_mask="if(land_above,null(),best_neg_mask)"
G> r.mapcalc vect_mask="if(isnull(uber_neg_mask),1,null())"


The v.to.rast raster seems to be slightly shifted to the left and up 
from the original vector map. I guess it could be a bug in v.to.rast,
coordinate at the top-left corner of cell vs. the center of cell sort 
of thing..... ideal is the little + and - corners balance on average.


yikes.
Hamish
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2rast_1.png
Type: image/png
Size: 5349 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20040213/1983016c/v2rast_1.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2rast_2.png
Type: image/png
Size: 11245 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20040213/1983016c/v2rast_2.png


More information about the grass-user mailing list