Dear listers, Can anybody help me with this ? How can I mask a 1km UTM grid raster with a list of coordinates which represent the center of 10km UTM grid squares ? Ultimately I want the 1km grid raster with only the pixels that fall inside the 10km UTM grid squares. Also, how can I build a SpatialPolygonsDataFrame representing 10km UTM grid squares from a list of coordinates which represent their grid center. I will appreciate if you can give me some hints on how to do this. Arnald Marcer CREAF
how to mask a raster with a coarser resolution selected grid squares ?
3 messages · Arnald Marcer, Edzer Pebesma
On 09/17/2010 09:47 AM, Arnald Marcer wrote:
Dear listers, Can anybody help me with this ? How can I mask a 1km UTM grid raster with a list of coordinates which represent the center of 10km UTM grid squares ? Ultimately I want the 1km grid raster with only the pixels that fall inside the 10km UTM grid squares.
convert the first to SpatialPointsDataFrame, and create a SpatialPixels object from the second, then use overlay() to get the indexes of the points that lie within the 10km grid cells.
Also, how can I build a SpatialPolygonsDataFrame representing 10km UTM grid squares from a list of coordinates which represent their grid center.
first create a SpatialPixelsDataFrame, say sx, then use as(sx, "SpatialPolygonsDataFrame")
I will appreciate if you can give me some hints on how to do this. Arnald Marcer CREAF
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
Dear listers,
Thanks to Robert and Edzer I finally found a way to do this. This is the
final solution I got to, in case anybody wants to use it:
##############################################
# This function returns a masks all zones of a 1km raster which
# do not fall inside 10km grid cells defined by a list of selected
# 10km-resolution cell centers. cell.centers must be a
SpatialPointsDataFrame
##############################################
maskFromCoarserResolution <- function(r.1km, cell.centers.10k){
fr1k <- paste(dirRefCarto,"catalonia_utm1k.asc",sep="")
r1k <- raster(fr1k)
r10k <- aggregate(raster(r1k), 10)
cells <- cellFromXY(r10k, cell.centers.10k)
r10k[] <- NA
r10k[cells] <- 1
r10kto1k <- disaggregate(r10k, 10)
extent.r1k <- extent(r1k)
#in order to make sure both bounding boxes are equal
r10kto1k <- crop(r10kto1k, extent.r1k)
r1k.masked <- mask(r1k, r10kto1k)
}
Arnald Marcer
CREAF
On 09/17/2010 09:47 AM, Arnald Marcer wrote:
Dear listers, Can anybody help me with this ? How can I mask a 1km UTM grid raster with a list of coordinates which represent the center of 10km UTM grid squares ? Ultimately I want the 1km grid raster with only the pixels that fall inside the 10km UTM grid squares. Also, how can I build a SpatialPolygonsDataFrame representing 10km UTM grid squares from a list of coordinates which represent their grid center. I will appreciate if you can give me some hints on how to do this. Arnald Marcer CREAF
----------------------------------------------------------------- Arnald Marcer Investigador Centre de Recerca Ecol?gica i Aplicacions Forestals (CREAF) Universitat Aut?noma de Barcelona 08193 Barcelona Tel: 93 5811312 Fax: 93 5814151 ----------------------------------------------------------------- Arnald Marcer Researcher Centre for Ecological Research and Forestry Applications (CREAF) Autonomous University of Barcelona 08193 Barcelona Phone: +34 93 5811312 Fax: +34 93 5814151