geo-visualizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGeo Visualizer
Geo Visualizer
Create interactive HTML maps from geographic data using Folium.
使用Folium从地理数据创建交互式HTML地图。
Features
功能特性
- Markers: Plot points with custom icons, popups, and tooltips
- Heatmaps: Visualize density/intensity data
- Choropleth: Color regions by data values
- Routes/Lines: Draw paths between points
- Circles/Areas: Show radius-based coverage
- Layer Control: Toggle multiple layers
- Clustering: Auto-cluster dense markers
- 标记点:使用自定义图标、弹出窗口和提示框标注点位
- 热力图:可视化密度/强度数据
- 分级着色图:根据数据值为区域着色
- 路线/线条:绘制点位间的路径
- 圆形/区域:展示基于半径的覆盖范围
- 图层控制:切换多个图层
- 聚类功能:对密集标记点自动聚类
Quick Start
快速开始
python
from geo_visualizer import GeoVisualizerpython
from geo_visualizer import GeoVisualizerSimple marker map
Simple marker map
viz = GeoVisualizer()
viz.add_markers([
{"lat": 40.7128, "lon": -74.0060, "name": "New York"},
{"lat": 34.0522, "lon": -118.2437, "name": "Los Angeles"}
])
viz.save("cities.html")
viz = GeoVisualizer()
viz.add_markers([
{"lat": 40.7128, "lon": -74.0060, "name": "New York"},
{"lat": 34.0522, "lon": -118.2437, "name": "Los Angeles"}
])
viz.save("cities.html")
From CSV
From CSV
viz = GeoVisualizer()
viz.from_csv("locations.csv", lat_col="latitude", lon_col="longitude")
viz.save("map.html")
undefinedviz = GeoVisualizer()
viz.from_csv("locations.csv", lat_col="latitude", lon_col="longitude")
viz.save("map.html")
undefinedCLI Usage
CLI 使用方法
bash
undefinedbash
undefinedPlot markers from CSV
Plot markers from CSV
python geo_visualizer.py --input locations.csv --lat latitude --lon longitude --output map.html
python geo_visualizer.py --input locations.csv --lat latitude --lon longitude --output map.html
Add heatmap
Add heatmap
python geo_visualizer.py --input data.csv --lat lat --lon lng --heatmap --output heat.html
python geo_visualizer.py --input data.csv --lat lat --lon lng --heatmap --output heat.html
With clustering
With clustering
python geo_visualizer.py --input stores.csv --lat lat --lon lon --cluster --output stores.html
python geo_visualizer.py --input stores.csv --lat lat --lon lon --cluster --output stores.html
Choropleth map
Choropleth map
python geo_visualizer.py --geojson states.geojson --data stats.csv --key state --value population --output choropleth.html
undefinedpython geo_visualizer.py --geojson states.geojson --data stats.csv --key state --value population --output choropleth.html
undefinedAPI Reference
API 参考
GeoVisualizer Class
GeoVisualizer 类
python
class GeoVisualizer:
def __init__(self, center=None, zoom=10, tiles="OpenStreetMap")
# Data loading
def from_csv(self, filepath, lat_col, lon_col, **kwargs) -> 'GeoVisualizer'
def from_dataframe(self, df, lat_col, lon_col, **kwargs) -> 'GeoVisualizer'
def from_geojson(self, filepath) -> 'GeoVisualizer'
# Markers
def add_marker(self, lat, lon, popup=None, tooltip=None, icon=None, color="blue")
def add_markers(self, locations: list, name_col=None, popup_cols=None)
def cluster_markers(self, enabled=True) -> 'GeoVisualizer'
# Layers
def add_heatmap(self, points=None, weight_col=None, radius=15) -> 'GeoVisualizer'
def add_choropleth(self, geojson, data, key_on, value_col, **kwargs) -> 'GeoVisualizer'
def add_route(self, points, color="blue", weight=3) -> 'GeoVisualizer'
def add_circle(self, lat, lon, radius_m, color="blue", fill=True)
# Output
def save(self, filepath) -> str
def get_html(self) -> str
def fit_bounds(self) -> 'GeoVisualizer'python
class GeoVisualizer:
def __init__(self, center=None, zoom=10, tiles="OpenStreetMap")
# Data loading
def from_csv(self, filepath, lat_col, lon_col, **kwargs) -> 'GeoVisualizer'
def from_dataframe(self, df, lat_col, lon_col, **kwargs) -> 'GeoVisualizer'
def from_geojson(self, filepath) -> 'GeoVisualizer'
# Markers
def add_marker(self, lat, lon, popup=None, tooltip=None, icon=None, color="blue")
def add_markers(self, locations: list, name_col=None, popup_cols=None)
def cluster_markers(self, enabled=True) -> 'GeoVisualizer'
# Layers
def add_heatmap(self, points=None, weight_col=None, radius=15) -> 'GeoVisualizer'
def add_choropleth(self, geojson, data, key_on, value_col, **kwargs) -> 'GeoVisualizer'
def add_route(self, points, color="blue", weight=3) -> 'GeoVisualizer'
def add_circle(self, lat, lon, radius_m, color="blue", fill=True)
# Output
def save(self, filepath) -> str
def get_html(self) -> str
def fit_bounds(self) -> 'GeoVisualizer'Marker Options
标记点选项
python
undefinedpython
undefinedCustom icons
Custom icons
viz.add_marker(lat, lon, icon="fa-coffee", color="red")
viz.add_marker(lat, lon, icon="fa-coffee", color="red")
With popup content
With popup content
viz.add_marker(lat, lon, popup="<b>Store #123</b><br>Open 9-5")
viz.add_marker(lat, lon, popup="<b>Store #123</b><br>Open 9-5")
From CSV with popup columns
From CSV with popup columns
viz.from_csv("stores.csv", lat_col="lat", lon_col="lon")
viz.add_markers(viz.data, popup_cols=["name", "address", "phone"])
undefinedviz.from_csv("stores.csv", lat_col="lat", lon_col="lon")
viz.add_markers(viz.data, popup_cols=["name", "address", "phone"])
undefinedHeatmap Options
热力图选项
python
undefinedpython
undefinedBasic heatmap
Basic heatmap
viz.add_heatmap()
viz.add_heatmap()
Weighted heatmap (e.g., by sales volume)
Weighted heatmap (e.g., by sales volume)
viz.add_heatmap(weight_col="sales", radius=20, blur=15, max_zoom=12)
undefinedviz.add_heatmap(weight_col="sales", radius=20, blur=15, max_zoom=12)
undefinedChoropleth Maps
分级着色图
python
undefinedpython
undefinedColor regions by data
Color regions by data
viz.add_choropleth(
geojson="us-states.geojson",
data=state_data,
key_on="feature.properties.name", # GeoJSON property
value_col="population",
fill_color="YlOrRd", # Color scale
legend_name="Population"
)
undefinedviz.add_choropleth(
geojson="us-states.geojson",
data=state_data,
key_on="feature.properties.name", # GeoJSON property
value_col="population",
fill_color="YlOrRd", # Color scale
legend_name="Population"
)
undefinedTile Layers
瓦片图层
Available base maps:
- (default)
OpenStreetMap - (light, minimal)
CartoDB positron - (dark theme)
CartoDB dark_matter - (terrain features)
Stamen Terrain - (high contrast B&W)
Stamen Toner
python
viz = GeoVisualizer(tiles="CartoDB positron")可用的基础地图:
- (默认)
OpenStreetMap - (浅色极简风格)
CartoDB positron - (深色主题)
CartoDB dark_matter - (地形特征)
Stamen Terrain - (高对比度黑白风格)
Stamen Toner
python
viz = GeoVisualizer(tiles="CartoDB positron")Example Workflows
示例工作流
Store Locator Map
门店定位地图
python
viz = GeoVisualizer()
viz.from_csv("stores.csv", lat_col="lat", lon_col="lon")
viz.add_markers(viz.data, popup_cols=["name", "address", "hours"])
viz.cluster_markers(True)
viz.fit_bounds()
viz.save("store_locator.html")python
viz = GeoVisualizer()
viz.from_csv("stores.csv", lat_col="lat", lon_col="lon")
viz.add_markers(viz.data, popup_cols=["name", "address", "hours"])
viz.cluster_markers(True)
viz.fit_bounds()
viz.save("store_locator.html")Sales Heatmap
销售热力图
python
viz = GeoVisualizer(tiles="CartoDB dark_matter")
viz.from_csv("sales.csv", lat_col="lat", lon_col="lon")
viz.add_heatmap(weight_col="revenue", radius=25)
viz.save("sales_heat.html")python
viz = GeoVisualizer(tiles="CartoDB dark_matter")
viz.from_csv("sales.csv", lat_col="lat", lon_col="lon")
viz.add_heatmap(weight_col="revenue", radius=25)
viz.save("sales_heat.html")Delivery Route
配送路线
python
viz = GeoVisualizer()
stops = [(40.7, -74.0), (40.8, -73.9), (40.75, -73.95)]
viz.add_route(stops, color="blue", weight=4)
for i, (lat, lon) in enumerate(stops):
viz.add_marker(lat, lon, popup=f"Stop {i+1}")
viz.save("route.html")python
viz = GeoVisualizer()
stops = [(40.7, -74.0), (40.8, -73.9), (40.75, -73.95)]
viz.add_route(stops, color="blue", weight=4)
for i, (lat, lon) in enumerate(stops):
viz.add_marker(lat, lon, popup=f"Stop {i+1}")
viz.save("route.html")Output
输出结果
- HTML: Interactive map viewable in any browser
- Auto-fit: Automatically zooms to show all data
- Responsive: Works on mobile devices
- HTML:可在任意浏览器中查看的交互式地图
- 自动适配:自动缩放以展示所有数据
- 响应式设计:支持移动设备
Dependencies
依赖项
- folium>=0.14.0
- pandas>=2.0.0
- branca>=0.6.0
- folium>=0.14.0
- pandas>=2.0.0
- branca>=0.6.0