提问人:Curious 提问时间:4/20/2023 更新时间:4/20/2023 访问量:61
工作散景地图图块和点投影示例需要抛光帮助
Working Bokeh Map Tiles and Points projected example help needed with polish
问:
这是单击散景贴图并进行回调的工作示例。目前,这些点尚未进行地理配准,并且似乎已按比例缩小并显示在地图的干扰中。理想情况下,我不仅会显示文本,还可以添加 hvplot 作为弹出窗口或至少在地图的一侧。任何人都可以帮助添加投影,如果他们可以帮助我点击显示 hvplot(任何数据都可以),那就太好了!!!!!
import pandas as pd
import holoviews as hv
from holoviews import opts
from holoviews.streams import Tap
import geoviews.tile_sources as gts
import geoviews as gv
import cartopy.crs as ccrs
import numpy as np
# Suppress warnings related to non-parameter attributes
hv.config.warn_options_call = False
hv.extension('bokeh')
# Create a sample DataFrame with latitude and longitude columns
data = pd.DataFrame({'lat': [51.5074, 48.8566, 40.7128],
'lon': [-0.1278, 2.3522, -74.0060],
'city': ['London', 'Paris', 'New York']})
# Function to handle the marker click event
def marker_info(x, y):
if np.isnan(x) or np.isnan(y):
return hv.Text(0,0,f'Click on a station', halign='left', valign='bottom')
else:
data['distance'] = ((data['lat'] - y) ** 2 + (data['lon'] - x) ** 2) ** 0.5
selected_point = data.loc[data['distance'].idxmin()]
info = f"Latitude: {selected_point['lat']}, Longitude: {selected_point['lon']}, City: {selected_point['city']}"
return hv.Text(x,y,info, halign='left', valign='bottom')
# Create a DynamicMap that responds to the click event on the markers
tap_stream = Tap(transient=True, x=np.nan, y=np.nan)
marker_dmap = hv.DynamicMap(marker_info, streams=[tap_stream])
# Create a map with markers from the DataFrame and add the DynamicMap with the marker information
markers = hv.Points(data, kdims=['lat', 'lon'], vdims=['city'], crs=ccrs.PlateCarree()).opts(
size=10,
color='red',
tools=['tap']
)
# Set the CRS for the tile source to Plate Carrée projection
tile_source = gv.tile_sources.OSM().clone(crs=ccrs.PlateCarree())
map_with_markers = (tile_source * markers * marker_dmap).opts(
opts.Points(active_tools=['tap']),
opts.WMTS(width=800, height=800, xlim=(-180, 180), ylim=(-90, 90))
)
# Display the map
map_with_markers
答: 暂无答案
评论