簡體   English   中英

從緯度、經度、高程數據繪制 3d 表面圖

[英]Plotly 3d surface plot from latitude, longitude, elevation Data

我有以下來自 azure 海拔 API 響應的 dict 格式的海拔數據,我正在嘗試根據該數據繪制海拔剖面。

出於此查詢的目的,我已將用於樣本目的的大小減小到 4x4 緯度/長方形網格區域,實際區域是一個更大的樣本。

我正在嘗試根據此數據使用 Plotly 生成 3d 曲面圖近似值。

我的理解是

1)首先需要將緯度/經度轉換為 x,y 坐標? 這樣做的最佳方法是什么? 2) 還需要將 Z/ 高程轉換為二維數組嗎? 基於 x,y 來自 1)?

import plotly.offline as py
import plotly.graph_objs as go
import pandas as pd

elevation = {'data': [{'coordinate': {'latitude': -33.88676483475523,
    'longitude': 150.84667222543544},
   'elevationInMeter': 59.76341},
  {'coordinate': {'latitude': -33.88676483475523,
    'longitude': 150.84689611369265},
   'elevationInMeter': 58.91294},
  {'coordinate': {'latitude': -33.88676483475523,
    'longitude': 150.8471200019499},
   'elevationInMeter': 58.2653},
  {'coordinate': {'latitude': -33.88676483475523,
    'longitude': 150.8473438902071},
   'elevationInMeter': 57.80102},
  {'coordinate': {'latitude': -33.88657811224419,
    'longitude': 150.84667222543544},
   'elevationInMeter': 60.25625},
  {'coordinate': {'latitude': -33.88657811224419,
    'longitude': 150.84689611369265},
   'elevationInMeter': 59.25375},
  {'coordinate': {'latitude': -33.88657811224419,
    'longitude': 150.8471200019499},
   'elevationInMeter': 58.59771},
  {'coordinate': {'latitude': -33.88657811224419,
    'longitude': 150.8473438902071},
   'elevationInMeter': 58.17687},
  {'coordinate': {'latitude': -33.88639138973315,
    'longitude': 150.84667222543544},
   'elevationInMeter': 60.63495},
  {'coordinate': {'latitude': -33.88639138973315,
    'longitude': 150.84689611369265},
   'elevationInMeter': 59.59782},
  {'coordinate': {'latitude': -33.88639138973315,
    'longitude': 150.8471200019499},
   'elevationInMeter': 58.97992},
  {'coordinate': {'latitude': -33.88639138973315,
    'longitude': 150.8473438902071},
   'elevationInMeter': 58.59934},
  {'coordinate': {'latitude': -33.8862046672221,
    'longitude': 150.84667222543544},
   'elevationInMeter': 61.03286},
  {'coordinate': {'latitude': -33.8862046672221,
    'longitude': 150.84689611369265},
   'elevationInMeter': 60.10513},
  {'coordinate': {'latitude': -33.8862046672221,
    'longitude': 150.8471200019499},
   'elevationInMeter': 59.54065},
  {'coordinate': {'latitude': -33.8862046672221,
    'longitude': 150.8473438902071},
   'elevationInMeter': 59.13883}]}


val_x = []
val_y = []
val_z = []

for entry in elevation['data']:
    x, y, zone, ut = utm.from_latlon(entry['coordinate']['latitude'], entry['coordinate']['longitude'])
    val_x.append(x)
    val_y.append(y)
    val_z.append(entry['elevationInMeter'])

    
fig = go.Figure(data=[go.Surface(x=val_x, y=val_y, z=val_z)])
  
fig.update_traces(contours_z=dict(
    show=True, usecolormap=True,
    highlightcolor="limegreen",
    project_z=True))
  
fig.show()

  • https://plotly.com/python/reference/surface/描述表面坐標的數據設置在z z數據應該是一個二維列表。 xy坐標可以是一維列表或 {2D 數組}(例如繪制參數曲面)
  • 這很容易通過使用熊貓塑造您的數據來實現
# load data into dataframe
df = pd.json_normalize(elevation["data"])
# reshape so we have 2D matrix of elevations
df = df.set_index(["coordinate.latitude", "coordinate.longitude"]).unstack(
    "coordinate.longitude"
)
fig = go.Figure(
    go.Surface(z=df.values, y=df.index.values, x=df.columns.get_level_values(1).values)
)
fig.update_traces(
    contours_z=dict(
        show=True, usecolormap=True, highlightcolor="limegreen", project_z=True
    )
).update_layout( margin={"l":0,"r":0,"t":0,"b":0})

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM