We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
您可以使用各种方法对 GRASS 执行此操作。哪一种最合适取决于您的数据和所需的输出。请注意,您也可以使用 GRASS 工具箱或 Sextante 工具箱在 QGIS 中使用 GRASS。
假设您有:
vector_zones
,其中定义了区域属性表中的
myzones
列。r.statistics
要使用 r.statistics,您首先需要将矢量图转换为栅格图层,您可以使用 v.to.rast。接下来,使用 r.statistics 计算区域统计数据。
这将为您提供一个包含所选区域统计数据的新图层,该统计数据可以是平均值、众数、中位数、方差等(请参阅上面的手册页链接)。
r.univar
univar 函数也适用于栅格图层。
输出是一个包含区域统计数据的表。
v.rast.stats
这个不需要您将矢量图层转换为栅格层(这是在内部完成的)。该函数根据栅格地图计算每个矢量类别(猫)的基本单变量统计数据。
结果上传至矢量地图属性表。
You can do this with GRASS using various methods. Which one is most suitable will depend on your data and the required output. Note that you can use GRASS also from within QGIS using the GRASS toolbox or Sextante toolbox.
Let's assume you have:
vector_zones
with the zones defined in thecolumn
myzones
in the attribute table.r.statistics
To use r.statistics, you first need to convert the vector map to a raster layer, which you can do with v.to.rast. Next, use r.statistics to calculate the zonal statistics.
This will give you a new layer with the selected zonal statistic, which could be average, mode, median, variance, etc. (see the man page link above).
r.univar
The r.univar function also works on raster layers.
The output is a table with the zonal statistics.
v.rast.stats
This does not require you to convert the vector layer to a raster layer (this is done internally). The function calculates basic univariate statistics per vector category (cat) from the raster map.
The results are uploaded to the vector map attribute table.
您可以在 R 中使用栅格包
you can use the raster package in R
如果我错了,请纠正我,RobertH,但我相信 zonal() 要求区域在某种意义上已经“栅格化”,而很多时候人们会想要落在多边形内的栅格单元的统计数据。 sp 包中的 R 中的各种覆盖方法(请参阅: ?"overlay-methods" )对此是必要的,尽管如果我错了,我会很高兴听到它。与使用 SpatialGridsDataFrames 相比,我更喜欢栅格包,但我认为必须依赖 sp 类来混合多边形和网格数据。这没什么问题,但会出现问题,因为它缺乏栅格包的强大内存管理功能,这使得在大型栅格上的 R 中很难进行多边形点样式操作。
我也相信,但没有尝试过,这可以在 GRASS 内和/或通过 QGIS 完成,下一版本的 QGIS (1.7) 将具有某种内置的区域统计功能。
Correct me if I'm wrong, RobertH, but I believe zonal() requires that the zones are already 'rasterized' in some sense, whereas many times one will want the statistics of raster cells that fall within polygons. The various overlay methods in R within the sp package (see: ?"overlay-methods" ) are necessary for this, though if I am wrong I would be glad to hear it. I quite prefer the raster package over using SpatialGridsDataFrames, but I think one must rely on sp classes to mix polygons and gridded data. Which is ok, except becomes problematic because it lacks the great memory management of the raster package, which making point-in-polygons style operations really hard to do in R on large rasters.
I am also led to believe, but have not tried, that this can be done within GRASS, and/or through QGIS, with the next release of QGIS (1.7) to have some sort of built-in zonal stats feature.
Rasterstats 包是一个很好的开源工具,对我来说效果很好:
http://blog.perrygeo.net/2013/09/24 /python-raster-stats/
我开始使用它作为解决方法,因为 arcpy 的 ZonalStatistics 方法生成了一个有问题的栅格,在尝试将栅格转换为数组时会导致奇怪的错误 (https://gis.stackexchange.com/questions/110274/save-fails-on -从 numpyarraytoraster 创建的栅格对象)。 Rasterstats 运行良好,为我的问题提供了有效的解决方案。
The Rasterstats package is a nice open source tool that worked well for me:
http://blog.perrygeo.net/2013/09/24/python-raster-stats/
I started using it as a work-around because arcpy's ZonalStatistics method was producing a problematic raster that lead to an odd error when trying to convert the raster to an array (https://gis.stackexchange.com/questions/110274/save-fails-on-raster-object-created-from-numpyarraytoraster). Rasterstats worked well and provided an efficient solution for my problem.