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

2010-06-20 Thread Ken Kwasnicki




Hi Hamish,
I like your r.reclass solution. Just wondering, you say it is a
"virtual" map, and easy to remove. How is it virtual? When I use it I
get a new map in my raster list that doesn't seem to go away so it
seems permanent to me. Although I don't understand the underlying
storage structure so maybe it is still virtual in that sense?

Thanks,
Ken


On 06/17/2010 07:52 PM, Hamish wrote:

  Marcello wrote:
  
  
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

  
  

another way (probably there are many),

v.to.rast
then a loop using r.reclass to make a temporary MASK map of each
category, then 
g.region rast=rasterized_vect
g.region zoom=rasterized_vect


r.reclass are tiny virtual maps (ie very quick to create+remove),
g.region zoom= starts at the current region and shrinks inward
until it hits a non-NULL cell. 



Hamish



  
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

  



___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


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

2010-06-18 Thread Ken Kwasnicki




Hi Marcello,
Thanks for this response! After my post I also figured out exactly
this method for doing it as well, although as you say would be great to
have a one-liner.
I will probably just write a little script that performs all these
steps and takes in the relevant vector, cat, and raster values. 

thanks!
ken

On 06/17/2010 04:17 PM, Marcello Gorini wrote:

  

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.nbsp; What is the best
way to do this?nbsp; 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?nbsp; Seems
like
there should be a single command to do this. 

My vector map has 45 polygons with cat values 1..45,nbsp; 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@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.







  



___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


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

2010-06-17 Thread Marcello Gorini


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.nbsp; What is the best
 way to do this?nbsp; 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?nbsp; Seems
 like
 there should be a single command to do this. 
 
 My vector map has 45 polygons with cat values 1..45,nbsp; 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@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.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


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

2010-06-17 Thread Hamish
Marcello wrote:
 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


another way (probably there are many),

v.to.rast
then a loop using r.reclass to make a temporary MASK map of each
category, then 
g.region rast=rasterized_vect
g.region zoom=rasterized_vect


r.reclass are tiny virtual maps (ie very quick to create+remove),
g.region zoom= starts at the current region and shrinks inward
until it hits a non-NULL cell. 



Hamish



  
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user