[GRASS-user] Re: how to get raster region corresponding to vector polygon region?

Marcello Gorini gorini at gmail.com
Thu Jun 17 19:17:52 EDT 2010



Kwas wrote:
> 
> 
> Hello, 
> I have a raster map (dem) and I want to select a region of the raster
> corresponding to a polygon that is in a vector map.  What is the best
> way to do this?  It looks like r.in.poly might be along the lines of
> what I need but in that case I think I would need to generate the ascii
> poly file first but I'm wondering if there is a better way?  Seems
> like
> there should be a single command to do this. 
> 
> My vector map has 45 polygons with cat values 1..45,  so I would like
> to get a section from my raster map corresponding to one of the
> polygons specified by cat value. 
> 
> appreciate any help! 
> thanks, 
> ken 
> 
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
> 
> 

Hello Ken,

I am also new to GRASS, but I have been doing what you want quite a lot
these days. There is probably a better way to do that (and I would like to
"hear" it very much, specially if there is a single command to do this), but
for now, I think the code below does the job:

g.region vect=your_vector
v.extract input=your_vector output=selected_polygon type=area
where="cat=desired_cat"
v.to.rast input=selected_polygon output=polygon_rasterized use=val type=area
r.mask input=polygon_rasterized

Now, any processing that you do will be applied only in the region
corresponding to the selected polygon. 
If you want to create a raster corresponding to the selected polygon, just
do:

r.mapcalc "new_raster=any_old_raster"

To take out the mask, just type:
r.mask -r

Hope this helps,

Marcello.







-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/how-to-get-raster-region-corresponding-to-vector-polygon-region-tp5192862p5193386.html
Sent from the Grass - Users mailing list archive at Nabble.com.


More information about the grass-user mailing list