[R-sig-Geo] selection of data subsets in spatial classes
Edzer J. Pebesma
e.pebesma at geo.uu.nl
Wed Jun 7 11:41:55 CEST 2006
Thanks for this. For the record:
sp has a subset function for SpatialPixelsDataFrame,
but it is not exported (nor documented, I believe).
In addition, it seems not to work:
SP27GTIF_c <- sp:::subset.SpatialPixelsDataFrame(SP27GTIF_a, band1 < 100)
Error in sp:::subset.SpatialPixelsDataFrame(SP27GTIF_a, band1 < 100) :
object "band1" not found
Roger Bivand wrote:
> 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):
> SP27GTIF <- readGDAL(system.file("pictures/SP27GTIF.TIF", package =
> image(SP27GTIF, col=grey(1:9/10))
> SP27GTIF_a <- as(SP27GTIF, "SpatialPixelsDataFrame")
> SP27GTIF_b <- SP27GTIF_a[SP27GTIF_a$band1 < 100,]
> because SpatialPixelsDataFrame objects have their coordinates recorded
> explicitly, and "know where they are" on a full grid.
> fullgrid(SP27GTIF_b) <- TRUE
> 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.
>> 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?
>> 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
More information about the R-sig-Geo