如何使用最近的邻居使用地球界的平均值?
我有一个GeodataFrame(“ GDF”),其中一个列为“值”,另一列为“几何”(实际上是实际的地理区域),因此每行代表一个区域。
“值”列在许多行中为零,在某些行中为大数字。
我需要使用最近的邻居进行“移动平均值”或平均值,直到某个“ max_distance”(我们可以假设GDF具有本地投射的CRS,因此MAX_DISTANCE具有实际含义)。 因此,在大多数区域中,平均值既不为零或大值,而是平均值。
一种方法是
for region in GDF:
averaged_values=sjoin_nearest(GDF,GDF,maxdistance=1000).values.mean()
,但实际上我不知道该如何进行。
预期的输出将是带有3列的GeodataFrame: “值”,“平均_VALUES”和“几何”。
有什么想法吗?
I have a geodataframe ("GDF") with one column as "values", and another column as "geometry" (that in fact are actual geographical regions), so each row represents a region.
The "values" column is zero in many rows, and a large number in some rows.
I need to make a "moving average" or rolling average, using the nearest neighbors up to a certain "max_distance" (we can assume that the GDF has a locally projected CRS, so the max_distance has real meaning).
Thus, the averaged_values would have neither zero or large values in most of the regions, but an average value.
One way to do it would be
for region in GDF:
averaged_values=sjoin_nearest(GDF,GDF,maxdistance=1000).values.mean()
But really I don't know how to proceed.
The expected output would be a geodataframe with 3 columns:
"values", "averaged_values", and "geometry".
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要做的也称为A空间滞后。最好的方法是使用
libpysal
库来创建基于设定距离的空间权重矩阵,这是Geopandas生态系统的一部分。What you are trying to do is also called a spatial lag. The best way is to create spatial weights matrix based on a set distance and compute the lag, both using
libpysal
library, which is a part of the geopandas ecosystem.