[R-sig-Geo] Why does focal() reduce the rows and columns of my raster?
Jonathan Greenberg
jgrn at illinois.edu
Fri Jan 10 17:14:12 CET 2014
Hi Eddie:
focal windows, because they are centered around a cell, have to know
how to deal with edge pixels. In the case of a 3x3 window, both the
first/last row and first/last column are "special cases" because the
3x3 window surrounding those pixels runs off of the image. Focal
analyses have to know how to treat these locations. Take a look at
the "pad" parameter to understand what focal is doing in these special
cases.
--j
On Fri, Jan 10, 2014 at 4:00 AM, Eddie Smith <eddieatr at gmail.com> wrote:
> Hi guys,
>
> This is my first attemp using focal() in raster package.
>
> Looking at the raster dimension after running focal(), it seems that
> everything is OK until I plot the raster and found out that the first and
> last column/row has been change to NA.
>
> Any help guys?
>
> Thanks in advance.
>
> r <- raster(ncols=5, nrows=5, xmn=0)
> r[] <- runif(ncell(r))
> r
>> r
> class : RasterLayer
> dimensions : 10, 10, 100 (nrow, ncol, ncell)
> resolution : 18, 18 (x, y)
> extent : 0, 180, -90, 90 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names : layer
> values : 0.01734865, 0.9977548 (min, max)
>
> # 3x3 mean filter
> r3 <- focal(r, w=matrix(1/9,nrow=3,ncol=3))
> r3
>> r3
> class : RasterLayer
> dimensions : 10, 10, 100 (nrow, ncol, ncell)
> resolution : 18, 18 (x, y)
> extent : 0, 180, -90, 90 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names : layer
> values : 0.346758, 0.6850644 (min, max)
>
> #plot 2 rasters
> par(mfrow=c(1,2))
> plot(r)
> plot(r3)
>
> [[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
--
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL 61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
More information about the R-sig-Geo
mailing list