我最近发现folium是一个非常令人印象深刻的地理数据可视化库,并将其用作我的地理数据标准库。感谢所有致力于该软件包的人们!
在我当前的项目之一中,我编写了一个服装类,该类接收(纬度,经度)元组的列表,并创建热图和聚类标记图。
为了算法上分析数据,我想应用Cluster Marker方法并为每个元组接收一个簇标签,这与DBSCAN或HDBSCAN等最新的簇算法相似。在当前的实现中有可能吗?
非常感谢您。
我的代码如下:
lat, lot = 'Latitude', 'Longitude'
class GeoData_Mapper(GeoData_Reader):
'''
class which is used to plot geo data on a map. Inherits from GeoData_Reader. Covers severals functions:
- HeatMap: draws a heatmap over a real-world map
- MapCluster: draws a map and indicates different cluster on the map itself
'''
def __init__(self,df):
super().__init__(df)
self._style_list = ["OpenStreetMap", "Mapbox Bright","Mapbox Control Room" ,
"Stamen Terrain","Stamen Toner", "Stamen Watercolor",
"CartoDB positron", "CartoDB dark_matter"]
self._grad_list = {0.2: 'blue', 0.4: 'lime', 0.6: 'orange', 1: 'red'}
self.__init_lat = df.loc[0,lat]
self.__init_lon = df.loc[0,lon]
def __generate_BaseMap(self,style, zoom_start):
self.map = folium.Map(location=[self.__init_lat,self.__init_lon], control_scale=True, zoom_start=zoom_start, tiles=self._style_list[style])
return self
def generate_HeatMap(self,style=6,zoom_start=12):
self.__generate_BaseMap(style,zoom_start)
HeatMap(data=self.df[[lat,lon]].groupby([lat,lon]).sum().reset_index().values.tolist(), radius=8, max_zoom=13).add_to(self.map)
def generate_MapCluster(self,style=6,zoom_start=12,include_Heat=True):
if include_Heat:
self.generate_HeatMap(style=style,zoom_start=zoom_start)
self.map.add_child(MarkerCluster(locations=list(zip(self.df[lat], self.df[lon]))))
else:
self.__generate_BaseMap(style,zoom_start)
self.map.add_child(MarkerCluster(locations=list(zip(self.df[lat], self.df[lon]))))