如何使用空间polygonsdataframe对象掩盖栅格?
我想使用“空间polygonsdataframe”对象中包含的所有多边形掩盖栅格。 到目前为止,我尝试了此操作:
r=raster("myraster.asc")
然后我得到了带有6个多边形列表的对象(称为“ vor_spdf”)对象,所以我运行了:
typeof(vor_spdf) # It results in [1] "S4"
r1=crop(r,extent(vor_spdf))
r2=mask(r1,vor_spdf@polygons[[1]]) #Trying to mask the raster on the geometry of the first polygon
这是错误... 错误... ):无法找到用于函数'掩码'签名'rasterlayer的函数'''rastlayer'的方法,“多边形”'
您是否有有关如何处理 这? 谢谢
I would like to mask a raster using all the polygons contained in a "SpatialPolygonsDataFrame" object.
Up until now i tried this:
r=raster("myraster.asc")
Then I got my SpatialPolygonsDataFrame (called "vor_spdf") object with a list of 6 Polygons, so I runned:
typeof(vor_spdf) # It results in [1] "S4"
r1=crop(r,extent(vor_spdf))
r2=mask(r1,vor_spdf@polygons[[1]]) #Trying to mask the raster on the geometry of the first polygon
This is the error... Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘mask’ for signature ‘"RasterLayer", "Polygons"’
Do you have any suggestion on how to handle this?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例数据
解决方案
,但您正在使用过时的软件包。您可能会使用“ Terra”更好。
Example data
Solution
But you are using outdated packages. You might be better off using "terra" instead.