gpt4 book ai didi

python - 在 map 内联(Jupyter)上绘制坐标的最快方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:00 25 4
gpt4 key购买 nike

我想知道在 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秒

enter image description here

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

最佳答案

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

enter image description here

关于python - 在 map 内联(Jupyter)上绘制坐标的最快方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45388412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com