Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(raster)
- # read in raster
- rasterSource <- 'landsat.TIF'
- r <- raster(rasterSource)
- # convert to spatial points data frame
- r.spgrd<-as(r,"SpatialPointsDataFrame")
- # elminate NA values
- r.spgrd = r.spgrd[!is.na(r.spgrd[[1]]),]
- # sample points
- selectedPoints = sample(1:length(r.spgrd[[1]]), 1000)
- r.sampled = r.spgrd[selectedPoints,]
- # try to make spgrd into a raster
- r.test <- raster(r.sampled)
- class : RasterLayer
- dimensions : 10, 10, 100 (nrow, ncol, ncell)
- resolution : 28617, 14766 (x, y)
- extent : 1838505, 2124675, 2328685, 2476345 (xmin, xmax, ymin, ymax)
- coord. ref. : +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
- values : none
- # write out as ascii file
- writeRaster(r.test, filename="test1.ASC", datatype="ascii", overwrite=TRUE)
- Error: hasValues(x) is not TRUE
- r <- raster(ncol=30,nrow=20)
- r[] <- 1:(30*20) # Raster for testing
- #plot(r) # (If you want to see it)
- r[runif(30*20) >= 0.30] <- NA # Randomly *unselect* 70% of the data
- plot(r)
- library(raster)
- r <- raster(ncol=30,nrow=20)
- r[] <- 1:(30*20)
- x <- sampleRandom(r, ncell(r)*.3, asRaster=TRUE)
Add Comment
Please, Sign In to add comment