[R-sig-Geo] Clipping a large image without reading in the entire image

Tim Keitt tkeitt at gmail.com
Sat Jun 2 00:02:43 CEST 2007


The getRasterData command in rgdal will return a subset of the image
given an rgdal object handle. I believe you can now also use simple
array [] operations as well.

THK

On 6/1/07, Andrew Niccolai <andrew.niccolai at yale.edu> wrote:
> Greetings Spatial R users/developers,
>
> I was curious as to whether or not it would be possible to describe a
> bounding box for a large image so that what is read into R would be just the
> contents of the image inside the bounding box.  Conceptually, it would be
> akin to "clipping" the image but without the image read into the program.
> My issue is that I have a very large 3-band orthophoto of several hundreds
> of hectares of forest (roughly 8MB image).  I am running an analysis of
> LIDAR data that requires the user to select a smaller area of a highly
> degraded lidar image.  I would like the bounding box of this LIDAR area to
> be used to "clip" a georegistered orthophoto that complements the LIDAR
> data.  However, the complete ortho image seems to crash my WindowsXP, R
> v2.4.1 setup. When I take the bounding box coordinates into ERDAS Imagine
> and subset the orthophoto the following code works fine to bring it into R:
>
> ## Read in Tif file
> setwd(anypathway)
> tif.image <- "Pre_Subset_Image.tif"
> LIDAR.tif <- GDAL.open(tif.image)
> dim(LIDAR.tif)
> image(LIDAR.tif[,,1])
>
> ## This converts the rgdal class to an SpatialGridDataFrame class
> LIDAR.tif.1 <- LIDAR.tif[,]
> bbox(LIDAR.tif.1)
> image(LIDAR.tif.1,main="")
> mtext("Orthophoto of Preloaded Fusion Example", side=3, line = 3, font=3,
> cex=1.25)
>
>
> However, this would be impractical with the code that I am building to jump
> out of R and subset images in Imagine (plus very expensive for the end
> user).  Therefore, does anyone have any solutions for reading in an image
> that would work in theory like the following:
>
> setwd(anypathway)
> tif.image <- "VERY_LARGE_IMAGE.tif"
> Bounded.tif <- GDAL.open(tif.image, bbox=c(UpL.X, LwR.X, UpL.Y, LwR.Y))
>
> By the way, I am not set on GDAL.open as the solution but it seems to work
> well reading in Tifs & Jpegs.
>
> Again, thanks in advance
>
>
> Andrew Niccolai
> Doctoral Candidate
> Yale School of Forestry
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>


-- 
Timothy H. Keitt, University of Texas at Austin
Contact info and schedule at http://www.keittlab.org/tkeitt/
Reprints at http://www.keittlab.org/tkeitt/papers/
ODF attachment? See http://www.openoffice.org/




More information about the R-sig-Geo mailing list