[R-sig-Geo] selection of data subsets in spatial classes

Roger Bivand Roger.Bivand at nhh.no
Wed Jun 7 11:17:48 CEST 2006


On Wed, 7 Jun 2006 karl.sommer at dpi.vic.gov.au wrote:

> Hello list
> 
> I have been trying to figure out if it is possible to select a subset of
> data in a SpatialGridDataFrame without prior conversion to a data.frame
> using the method as.data.frame().
> 
> I have imported an ESRI " *. bil " file containing different spectral bands
> using rgdal.  The file imported as a SpatialGridDataFrame.  The data
> originates from an aerial photograph of a row crop and I would like to
> select pixels from within a row as opposed to those from the inter-row
> space for further interpolation.   Inter-row pixels have a different
> signature and therefore may be potentially screened out.  However, I have
> been unable to access the SpatialGridDataFrame directly with, for example,
> a  subset(x, band5 < lowerLimit, select c(a, b) ) call for selecting values
> according to given criteria.

This is what the SpatialPixelsDataFrame class is for (unless you want to 
change resolution too):

library(rgdal)
SP27GTIF <- readGDAL(system.file("pictures/SP27GTIF.TIF", package = 
  "rgdal")[1])
summary(SP27GTIF)
image(SP27GTIF, col=grey(1:9/10))
SP27GTIF_a <- as(SP27GTIF, "SpatialPixelsDataFrame")
summary(SP27GTIF_a)
SP27GTIF_b <- SP27GTIF_a[SP27GTIF_a$band1 < 100,]
summary(SP27GTIF_b)
image(SP27GTIF_b)

because SpatialPixelsDataFrame objects have their coordinates recorded 
explicitly, and "know where they are" on a full grid. 

fullgrid(SP27GTIF_b) <- TRUE
summary(SP27GTIF_b)

will drop them again, inserting NAs where band1 >= 100.

This class is borrowed from the Terralib "CELL" data structure, part 
raster, part DB record, only recording cells with data.

Roger

> 
> Am I using the wrong strategy, should I just demote the spatial class using
> method as.data.frame(), do the manipulation and then promote the screened
> values back to a spatial class?
> 
> Regards
> 
> Karl
> _________________________________
> Karl J Sommer,
> Department of Primary Industries,
> PO Box 905
> Mildura, VIC, Australia 3502
> 
> Tel: +61 (0)3 5051 4390
> Fax +61 (0)3 5051 4534
> 
> Email:     karl.sommer at dpi.vic.gov.au
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list