[R-sig-Geo] Help on extracting min/max from raster object

Lyndon Estes lestes at princeton.edu
Tue Mar 1 15:02:38 CET 2011


If there is not some sort of rounding issue going on with cellStats, I
wonder if perhaps your no data areas are 0 for some reason (although
your raster details suggest not).

Perhaps you could try the following:

r2 <- (r > 0) / (r > 0) * r  # Sets areas of 0 values to NA

Then try cellstats again
cellStats(r2, min)

And see if you have the correct min value.

Cheers, Lyndon








On Tue, Mar 1, 2011 at 7:22 AM, Rahul Raj <rahulosho at gmail.com> wrote:
>
> Dear All
>
> I have imported .img file in R using raster package as
>
>  r <- raster(inputfile)
>
> Summary:
>
> > r
> class       : RasterLayer
> dimensions  : 1131, 1739, 1  (nrow, ncol, nlayers)
> resolution  : 1000, 1000  (x, y)
> extent      : 535515, 2274515, 2003813, 3134813  (xmin, xmax, ymin, ymax)
> projection  : +proj=aea +lat_1=28 +lat_2=12 +lat_0=20 +lon_0=78 +x_0=2000000
> +y_0=2000000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0
> values      : H:\filename.img
> min value   :* 0.001407638 *
> max value   : 0.7978822
>
> I wanted to extract the min value and max value from the object. How can I
> do this?
> I have used the following function for this purpose
> > cellStats(r,'min')
> [1] 0
>
> But it is returning 0, not "0.001407638"
>
> Kindly help me.
>
> With regards
> Rahul Raj
> Indian Institute of Remote Sensing, India
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Lyndon Estes
Research Associate
Woodrow Wilson School
Princeton University
+1-609-258-2392 (o)
+1-609-258-6082 (f)
+1-202-431-0496 (m)
lestes at princeton.edu



More information about the R-sig-Geo mailing list