【发布时间】:2021-10-07 13:23:10
【问题描述】:
我有一个坐标列表,每个坐标都有温度。数据框如下所示: 例如:
| Lat | Lon | Temperature |
|---|---|---|
| 51.23 | 4.234 | 23.3 |
| 51.29 | 4.211 | 26.4 |
| 51.25 | 4.238 | 24.3 |
| 51.26 | 4.221 | 28.4 |
| 51.30 | 4.244 | 19.3 |
| 51.40 | 4.231 | 20.4 |
geopandas 有没有办法直接找到每行 100m 距离内的观测值,并用最近观测值的平均值创建一个新列
例如:
| Lat | Lon | Temperature | Mean Temp |
|---|---|---|---|
| 51.23 | 4.234 | 23.3 | Mean temperature within 100m distance |
| 51.29 | 4.211 | 26.4 | Mean temperature within 100m distance |
| 51.25 | 4.238 | 24.3 | Mean temperature within 100m distance |
| 51.26 | 4.221 | 28.4 | Mean temperature within 100m distance |
| 51.30 | 4.244 | 19.3 | Mean temperature within 100m distance |
| 51.40 | 4.231 | 20.4 | Mean temperature within 100m distance |
我尝试过使用最近点:
def get_nearest_values(row, other_gdf, point_column='geometry',
value_column="predictions_precipitation_type"):
# Create an union of the other GeoDataFrame's geometries:
other_points = other_gdf["geometry"].unary_union
# Find the nearest points
nearest_geoms = nearest_points(row[point_column], other_points)
# Get corresponding values from the other df
nearest_data = other_gdf.loc[other_gdf["geometry"] ==
nearest_geoms[1]]
nearest_value = nearest_data[value_column].values[0]
return nearest_value
但它会找到最接近的观察值及其值.. 我想找到 100m 半径内的所有观测值,然后找到平均值
【问题讨论】:
-
@moooeeeep 它确实部分回答了我的问题.. 因为它为每个坐标提供了最近的位置.. 但我的问题是.. 如果一个坐标的半径中有 10 个点......如何用这 10 个点的平均值创建一列,而不是只有一个附近的值