R/dataframe.R

Defines functions dfRegular

dfRegular <- function(data, maxpixels)
{
    if (is(data, "Raster"))
    {
        dataSample <- sampleRegular(data,
                                    size = maxpixels,
                                    asRaster = TRUE)
        df <- raster::as.data.frame(dataSample, xy = TRUE)
        
    } else
    {
        idx <- spatSample(data,
                          size = maxpixels,
                          method = "regular",
                          cells = TRUE)
        vals <- data[idx]
        xy <- terra::xyFromCell(data, idx)
        df <- cbind(xy, vals)
    }

    df
}

Try the rasterVis package in your browser

Any scripts or data that you put into this service are public.

rasterVis documentation built on Nov. 2, 2023, 5:25 p.m.