[GRASS-user] Re: A Script that only selects raster inside a polygon

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Fri Sep 24 15:20:38 EDT 2010


Pedro Roma:

> >I want to develop a script that crops a raster in order to only have the
> >pixels that are located inside a vector polygon.

Marcello Gorini: 

> There is probably a more elegant solution, but this will do:
 
> g.region vect=your_vector
> v.to.rast input=your_vector output=your_vector_rasterized use=val

(comment of minor importance I guess... the above needs "value=" to be fed 
with a value of course).

> r.mask input=your_vector_rasterized
> r.mapcalc "clipped_raster=original_raster"
> r.mask -r

Marcello,

honestly, it's very nice to see how you stepped up from 0 to 100 within almost 
zero time :-)

(...watch out for curves and steep slopes :-p)

All the best, Nikos

Cheers, Nikos


More information about the grass-user mailing list