I have a list of coordinates with temperatures at each coordinate. The data frame looks as follows: eg:
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 |
Is there a way in geopandas to directly find the observations within 100m distance for every row and create a new column with the mean of nearest observations
eg:
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 |
Ive tried using nearest_point:
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
but it finds the closest observation and its value.. I would like to find all the observations within 100m radius and then find the mean