我正在使用 topojson 地图数据。
基本上我希望根据 data_count 值看到每个区域高度的海拔。但我看到所有区域的高度相同。 get_elevation 代替 get_elevation_weight 显示 2D 地图。 如图所示,计数值不同,左:659,右:250,但海拔看起来相同
我的代码片段如下所示:
with open(topojson_file) as f:
topojson_data = json.load(f)
# Editing TopoJSON with data counts from csv data
for zone in topojson_data['features']:
division_name = zone['properties'].get('division', 'Unknown')
data_count = division_data_counts.get(division_name, 0)
zone['properties']['data_count'] = data_count
geojson_layer = pdk.Layer(
"GeoJsonLayer",
topojson_data,
opacity=0.6,
stroked=False,
filled=True,
extruded=True,
get_fill_color="[data_count * 10, 150, 200]",
get_elevation_weight="data_count * 100",
pickable=True,
auto_highlight=True,
)
view_state = pdk.ViewState(
latitude=data['latitude'].mean(),
longitude=data['longitude'].mean(),
zoom=7,
pitch=60,
)
r = pdk.Deck(
layers=[geojson_layer],
initial_view_state=view_state,
tooltip={
"html": "<b>Zone:</b> {division}<br/><b>Data Count:</b> {data_count}",
"style": {"color": "white"}
}
)`
data_count 在其他地方定义,我对此没有问题。我的数据没有问题: 这是直接在 pydeck 上加载我的 data_count ,而不需要 topo_json
我已经解决了。在zone_to_division中查找属性:zone_code。
for feature in topojson_data['features']:
division_name = feature['properties'].get('division', 'Unknown')
zone_code = next((k for k, v in zone_to_division.items() if v == division_name), None)
if zone_code and zone_code in zone_colors:
feature['properties']['color'] = zone_colors[zone_code]
feature['properties']['data_count'] = division_crime_counts.get(division_name, 0)
else:
feature['properties']['color'] = [200, 200, 200] # Default gray
feature['properties']['data_count'] = 0
# Layers
geojson_layer = pdk.Layer(
"GeoJsonLayer",
topojson_data,
opacity=0.6,
stroked=True,
filled=True,
extruded=True,
get_fill_color='properties.color',
get_elevation='properties.crime_count * 100',
...