[R] taking a small piece of large tiff
mdsumner at gmail.com
Wed Apr 5 17:30:20 CEST 2017
On Wed, 5 Apr 2017 at 20:13 jim holtman <jholtman at gmail.com> wrote:
> if you have 8GB of memory it should be easy to handle.
TIFF is a container format and may be compressed internally, and so could
expand out as a matrix it might be very many times larger than the file
(Follow Ben's advice and use raster, which in turn uses rgdal to read
TIFF/GeoTIFF. It's ridiculously good).
r <- raster("/path/to/myfile.tif")
print(r) ## to see the units of the extent
## enter the singleton-values for xmin/xmax/ymin/ymax that you want here:
b <- crop(r, extent(xmin, xmax, ymin, ymax))
Note that the extent values must be in the coordinate system used by the
raster itself, it might be in longitude-latitude or in some
"eastings-northings" map projection (CRS, or coordinate reference system).
The print out of print(r) will tell you, and projection(r) if you need to
use it directly.
There's no need to do your own transformations from world-space to pixel
index space. but the price of that convenience is you have to interact with
the data via the raster package's design and interfaces. You can get a
matrix out but it's well worth learning the higher level abstractions
available as well.
> Jim Holtman
> Data Munger Guru
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
> On Wed, Apr 5, 2017 at 3:23 AM, Louisa Reynolds
> <louisa_reynolds at yahoo.co.uk> wrote:
> > Ok. I have a tiff of size over 2GB. It covers a sixth of the Earth's
> surface and I'm trying to cut a UK piece out of it. The tiff I start with
> seems to be too large for R to handle.
> > Sent from my iPhone
> >> On 4 Apr 2017, at 18:37, jim holtman <jholtman at gmail.com> wrote:
> >> How big is 'large'?
> >> Jim Holtman
> >> Data Munger Guru
> >> What is the problem that you are trying to solve?
> >> Tell me what you want to do, not how you want to do it.
> >> On Tue, Apr 4, 2017 at 7:47 AM, Louisa Reynolds via R-help
> >> <r-help at r-project.org> wrote:
> >>> Dear Forum
> >>> I am trying to cut out a small section of a very large 2-dimensional
> grayscale image as a tiff in R, but it is having difficulty handling such
> large files. I have looked at bigmemory and ff packages but it is unclear
> how I can use these packages with tiffs. Can anyone please suggest
> something? I have tried tiff and rtiff libraries.
> >>> Thanks in advance.
> >>> [[alternative HTML version deleted]]
> >>> ______________________________________________
> >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide
> >>> and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia
[[alternative HTML version deleted]]
More information about the R-help