【问题标题】:What is the fastest way to plot coordinates on map inline (Jupyter)?在地图内联(Jupyter)上绘制坐标的最快方法是什么?
【发布时间】:2018-01-05 09:41:49
【问题描述】:

我想知道在 OpenStreetMap 上绘制多个坐标(150 万)的最直接和最快的方法是什么。

它必须能够在 Jupyter Notebook 中内联显示。

我一直在尝试使用 Folium 模块和列表理解:

import folium
import datetime as dt
import random as rnd

t0 = dt.datetime.now()

#New York City Coordinates
NYC_COORD = [40.7128, -74.0059]

# Sample (0.33% over 1.5 million) 
sample_coords = rnd.sample(list(coords),5000)

# Build map 
map_nyc = folium.Map(location=NYC_COORD, zoom_start=12, 
tiles='cartodbpositron', width=640, height=480)

# Plot coordinates using comprehension list
[folium.CircleMarker(sample_coords[i], radius=1,
                color='#0080bb', fill_color='#0080bb').add_to(map_nyc) 
for i in range(len(sample_coords))]

# Display map in Jupyter
map_nyc

t1 = dt.datetime.now()
print('Total time: %i seconds' % (t1 - t0).seconds)

总时间:33 秒

如您所见,33 秒。如果我们真的想绘制 1.5M,那真的是很长的时间。那么,有人知道是否可以改善那个时间吗?

【问题讨论】:

    标签: python gps jupyter-notebook jupyter folium


    【解决方案1】:

    150 万个坐标对 datashader 来说是没有问题的;这是 3 秒内 1000 万的代码,包括读取文件,以及在缩放或平移时重绘的几分之一秒(来自 http://pyviz.org/tutorial/01_Workflow_Introduction.html):

    import dask.dataframe as dd, geoviews as gv, cartopy.crs as crs
    from colorcet import fire
    from holoviews.operation.datashader import datashade
    from geoviews.tile_sources import CartoLight
    gv.extension('bokeh')
    
    tiles = CartoLight.options(width=700, height=600, xaxis=None, yaxis=None, show_grid=False) 
    
    taxi  = dd.read_parquet('../data/nyc_taxi_wide.parq').persist()
    pts   = gv.Points(taxi, ['pickup_x', 'pickup_y'], crs=crs.GOOGLE_MERCATOR)
    trips = datashade(pts, cmap=fire, width=1000, height=600, x_sampling=0.5, y_sampling=0.5)
    
    tiles * trips
    

    【讨论】:

      【解决方案2】:

      我认为可以通过使用 MarkerClusters 来改进它,但不会显着。 150万是很多要绘制的点

      不是一个完美的替代品,但也许你可以看看datashadermpl-scatter-density

      编辑:我最近发现了 FastMarkerCluster,这是一个非常快速的选项,但不如 MarkerClusters 灵活。也就是说,对于 150 万人来说,这可能不是一个很好的选择。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-18
        • 1970-01-01
        相关资源
        最近更新 更多