函数如何“提取"?处理不同的预测? [英] How does the function "extract" deal with different projections?
问题描述
我需要使用函数extract()使用具有相等大小正方形的网格像元从栅格中进行加权平均提取.我的多边形网格位于UTM21n中,而栅格位于GCS WGS84基准面D中.在将栅格用于extract()之前,是否需要重新投影栅格?还是该函数会正确处理?
I need to use the function extract() to do a weighted average extraction from a raster using a grid cell of equal sized squares. My polygon grid is in UTM21n and the raster is in GCS WGS84 datum D. Do I have to reproject the raster before using it into extract()? Or will the function handle it properly?
推荐答案
您可以找到SpatialPolygons
的函数extract
的源代码
You can find the source code of function extract
for SpatialPolygons
here. The code starts with the following snippet:
setMethod('extract', signature(x='Raster', y='SpatialPolygons'),
function(x, y, fun=NULL, na.rm=FALSE, weights=FALSE, cellnumbers=FALSE, small=FALSE, df=FALSE, layer, nl, factors=FALSE, sp=FALSE, ...){
px <- projection(x, asText=FALSE)
comp <- .compareCRS(px, projection(y), unknown=TRUE)
if (!comp) {
.requireRgdal()
warning('Transforming SpatialPolygons to the CRS of the Raster')
y <- spTransform(y, px)
}
...
这暗示extract
实际上确实执行投影(将SpatialPolygon的投影更改为栅格的投影),尽管事实没有在帮助页面中进行记录.
Which suggests that extract
does in fact perform the projection itself (changing the projection of the SpatialPolygon to the projection of the raster), despite the fact that it is not documented in the help page.
这篇关于函数如何“提取"?处理不同的预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!