[GRASS-user] cutting rasters with a vector

Nikos Alexandris nik at nikosalexandris.net
Sat Nov 30 02:47:15 PST 2013

Nikos A:

> > Is it about trimming Landsat borders?

Anna Z:

> No, it's about selecting an area inside the tile, which I need to work on.

> anyway, since you mentioned it, the issue of cutting away borders is also
> interesting ...

In short

Attached a custom python script (for GRASS GIS 7 I think) which needs a 
Landsat scene to be imported based on a GRASS-Wiki Landsat import script [1] 
and the corresponding vector tile to be imported in GRASS as well.  If you get 
into this I'll try to make it more clear how I used it.

Attached as well, a slightly modified import script, based on the GRASS-Wiki 
one, to handle, hopefully all: L5, L7 and L8.

Long story

There is this question: <http://gis.stackexchange.com/q/34637/5256> and a 
GRASSy answer: <http://gis.stackexchange.com/a/45268/5256>. So there is/was 
already a grass-addon named i.landsat.trim in 
<http://grasswiki.osgeo.org/wiki/AddOns/GRASS_6#i.landsat.trim>.  However, it 
is somewhat experimental and not using the exact WRS2 tiles.

Back in May I have tried to give a generic answer to this task by writing a 
Python script called "i.landsat.wrs2trim" :-). I imagined that a script could 
simply be instructed which tile(s) and row(s) from the official WRS2 tiles [0] 
and it should trim all Landsat bands that pertain to an aquisition over the 
tile(s) in question.

I ended up, once again, with something kinda hardcoded that would require to 
have prepared and have beforehand the vector tile of interest. It is attached. 
It works only for "LE7" scenes and only if the bands are imported using the 
python script given in GRASS-Wiki [1] (thanks to Martin for this), i.e. they 
are named after B1, B2, B3, B4, B5, B61, B62, B8.

Of course (!), one needs to prepare the vector tile for the specific to-be-
trimmed Landsat bands. As far as I remember, this involves getting the WRS2 
Shapefile, selecting and saving the tile of interest (in QGIS quicker I think, 
load > select > save as...), then importing in GRASS.

The logic is to have Landsat scenes imported in independent Mapsets, that is 
all bands of a scene in one Mapset, and all bands of another scene in another 
Mapset, et.c.  Each Mapset named after the Landsat scenes' ID.

I didn't know how to have available the WRS2 tiles.  Let the user download 
them and set the path to it, and let the script do its work? Or, make the 
script do all this? Packing the WRS2 tiles along with the script somehow? 
Bah... Not a programmer here :-/

Oh, thanks to Alexander Muriy for his time at some point for checking the 
python script and giving some hints. I just have had no time to work on this 
again. Nonetheless, I consider such a tool as a must-have along the other 
landsat tools in GRASS.


[0] <http://landsat.usgs.gov/documents/wrs2_descending.zip>
[1] <http://grasswiki.osgeo.org/wiki/LANDSAT#Automated_data_import>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: import_landsat_custom.py
Type: text/x-python
Size: 5625 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20131130/cc78397f/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trim_landsat_scenes.py
Type: text/x-python
Size: 13925 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20131130/cc78397f/attachment-0001.py>

More information about the grass-user mailing list