So I have a map that’s plotting a .csv dataset. Everything with the static_geo map is exactly how I like. It currently uses the np.nan values for Lat and Lon, and the line plot that is displayed below is how I would like it do display for the first time, everytime. However, I would like to click the map, use the Lat and Lon from a click to get a new line plot from the data elvs. Elvs has two dimensions, time and points. I get the closest point in the data by using the two sampled points and comparing those to the elvs dataset. I expect Elvs.sel(points=test_point) to provide with an array of numbers to plot on a line plot - it does that just need it to update with a click on the map.
data = gv.Points(df, [('X_lon', 'Longitude'), ('Y_lat', 'Latitude')],
[('AvgRate_ftPerYr', 'Weighted Combo Filtered'),
('AvgRate_Implicit','Implicit Average'),
('Median_ftPerYr','Median'),
('AvgRate_First_Last_ftPerYr','Last - First'),])
data = gv.Dataset(gv.operation.project_points(data))
size_opts = dict(min_height=500, min_width=500, responsive=True)
geo_opts = dict(size_opts, cmap='RdBu', global_extent=False, logz=False, colorbar=True)
elvs = reach_array.elevations
class ShoalingRateTest(param.Parameterized):
average = param.ObjectSelector(default='AvgRate_ftPerYr', objects=['AvgRate_ftPerYr'
,'AvgRate_Implicit'
,'Median_ftPerYr'
,'AvgRate_First_Last_ftPerYr'])
limit = max(df['AvgRate_ftPerYr'])
@param.depends('average')
def view(self,**kwargs):
geo_bg = gv.tile_sources.EsriImagery.options(alpha=0.8, bgcolor='black')
geo_kw = dict(aggregator=ds.mean(self.average), x_sampling=5, y_sampling=5)
geo_map = gv.Points(data, crs=ccrs.GOOGLE_MERCATOR).redim.range(AvgRate_ftPerYr=(-self.limit, self.limit),
AvgRate_Implicit=(-self.limit,self.limit),
Median_ftPerYr=(-self.limit,self.limit),
AvgRate_First_Last_ftPerYr=(-self.limit,self.limit))
static_geo = rasterize(geo_map, **geo_kw).options(alpha=1.0, tools=['hover','box_select', 'lasso_select'], active_tools=['box_select'], **geo_opts)
tap = hv.streams.SingleTap(source=static_geo, x=np.nan, y=np.nan)
test_point = np.argmin((tap.x-lons)**2+(tap.x-lats)**2)
temp_ts = elvs.sel(points=test_point)
temp_line = temp_ts.hvplot.line(x='time',y='elevations')
return (geo_bg*static_geo + temp_line)
shoal_test = ShoalingRateTest()
stock_dmap = shoal_test.view
pn.Row(pn.Column(shoal_test.param, parameters=['average']), stock_dmap)