【问题标题】:Animating TripsLayer in deck.gl with python使用python在deck.gl中为TripsLayer设置动画
【发布时间】:2021-01-23 22:31:46
【问题描述】:

我在 deck.gl 网站 (this one) 中看到了 TripsLayer 示例,它看起来非常酷。我想完成同样的事情,但使用 pydeck,deck.gl 的 python 绑定。 pydeck 网页 (this one) 中的示例没有动画,我不知道我应该如何做才能获得平滑的动画,如 javascript 示例中所示。我尝试了多种方法(传递列表、函数、具有变化值的变量等),但没有一种方法有效,我找不到任何 pydeck 示例。

谢谢!

【问题讨论】:

    标签: python gis deck.gl


    【解决方案1】:

    确实,该示例应该包含更多行程。下面介绍如何在jupyter notebook中实现多次行程的动画。

    import time
    import pandas as pd
    import pydeck as pdk
    
    data = '[{"agent_id":0,"path":[[-0.63968,50.83091,0.0],[-0.78175,50.83205,0.0]],"time":[65100,65520],"color":[228,87,86]},{"agent_id":1,"path":[[-0.63968,50.83091,0.0],[-0.78175,50.83205,0.0]],"time":[65940,66420],"color":[178,121,162]},{"agent_id":2,"path":[[-0.63968,50.83091,0.0],[-0.37617,50.8185,0.0]],"time":[65340,66360],"color":[157,117,93]},{"agent_id":3,"path":[[-0.63968,50.83091,0.0],[-0.78175,50.83205,0.0]],"time":[65940,66420],"color":[238,202,59]},{"agent_id":4,"path":[[-0.63968,50.83091,0.0],[-0.78175,50.83205,0.0]],"time":[67740,68160],"color":[157,117,93]}]'
    
    df = pd.read_json(data)
    view = {"bearing": 0, "latitude": 50.85, "longitude": -0.16, "pitch": 0, "zoom": 9}
    
    time_min = 65_000
    time_max = 80_000
    
    layer = pdk.Layer(
        "TripsLayer",
        df,
        get_path='path',
        get_timestamps='time',
        get_color='color',
        opacity=0.8,
        width_min_pixels=3,
        rounded=True,
        trail_length=900,
        current_time=0
    )
    
    # Render
    r = pdk.Deck(layers=[layer], initial_view_state=view, map_style='dark_no_labels')
    
    r.show()
    
    # Animate
    for ct in range(time_min, time_max, 100):
        layer.current_time = ct
        r.update()
        time.sleep(0.1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-09
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-27
      相关资源
      最近更新 更多