[GRASS-user] importing or reading a small part of a tiff file

Hamish hamish_b at yahoo.com
Fri Jun 15 16:09:06 PDT 2012


Ivan wrote:
> is there a simple way to import only a small part of a tiff
> file (by mean, for example, of a bbox)?
> some gdal parameter for r.in.gdal? 

There's not a way with r.in.gdal that I know of, but it is an
easy job with gdal_translate to prepare a subset:

      -srcwin xoff yoff xsize ysize:
           Selects a subwindow from the source image
           for copying based on pixel/line location.

       -projwin ulx uly lrx lry:
           Selects a subwindow from the source image
           for copying (like -srcwin) but with the
           corners given in georeferenced coordinates.


then use r.in.gdal to import the cropped version.


random tip:
going the other way, if you have a bunch of file tiles you wish
to import as a single large grass raster you can make a GDAL
virtual raster with a small text file. Combine that with
r.external and you can avoid many gigabytes of duplicated
hard disk space (at the cost of more CPU cycles). It's a very
powerful technique for large raster data sets.


which leads me to an alternate solution to your problem- you
could connect to the original large TIFF with r.external, adjust
the GRASS region to where you want it with g.region, then use
  r.mapcalc 'cropped_map = full_map'
to save just the section you want into a new raster.


Hamish


More information about the grass-user mailing list