日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

学习 Cesium (五):加载离线高程数据

發布時間:2023/12/31 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 学习 Cesium (五):加载离线高程数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

  • 學習 Cesium (五):加載離線高程數據
    • 前言
      • 本文的測試環境
      • 基本的構建流程
    • 獲取高程數據
    • 高程數據處理
      • 使用 Cesiumlab 制作地形文件
      • 使用 gdal2srtmtiles.py 腳本制作heightmap-1.0 格式地形文件
        • 安裝 Python 2.7
        • 注冊 Python 2.7
        • 安裝 PIL
        • 安裝 GDAL
        • 安裝 numpy
        • 安裝 GDAL py2.7版
        • 生成 .terrain 數據
      • 使用 Cesium Terrain Builder 工具制作 Quantized-Mesh-1.0 格式地形文件
        • 源碼編譯安裝及使用
          • 準備
          • 編譯安裝GDAL
          • 編譯安裝zlib
          • 編譯CTB
          • 使用 CTB
        • Docker 安裝 CTB 及使用
    • 集成到Cesium

學習 Cesium (五):加載離線高程數據

前言

通過前面的學習,Cesium 最基本的應用已經可以了。但是,在實際項目中我們還需要加入高程數據,才能顯示真實的地形。下面我就一步一步介紹如何加載真實的高程數據。

本文的測試環境

  • OS: Window 10 家庭版
  • Cesium: v1.78.0
  • Web Browser: Chrome v88.0.4324.150

基本的構建流程

#mermaid-svg-IZqpAUFMTnctixjH .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-IZqpAUFMTnctixjH .label text{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .node rect,#mermaid-svg-IZqpAUFMTnctixjH .node circle,#mermaid-svg-IZqpAUFMTnctixjH .node ellipse,#mermaid-svg-IZqpAUFMTnctixjH .node polygon,#mermaid-svg-IZqpAUFMTnctixjH .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-IZqpAUFMTnctixjH .node .label{text-align:center;fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .node.clickable{cursor:pointer}#mermaid-svg-IZqpAUFMTnctixjH .arrowheadPath{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-IZqpAUFMTnctixjH .flowchart-link{stroke:#333;fill:none}#mermaid-svg-IZqpAUFMTnctixjH .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-IZqpAUFMTnctixjH .edgeLabel rect{opacity:0.9}#mermaid-svg-IZqpAUFMTnctixjH .edgeLabel span{color:#333}#mermaid-svg-IZqpAUFMTnctixjH .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-IZqpAUFMTnctixjH .cluster text{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-IZqpAUFMTnctixjH .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-IZqpAUFMTnctixjH text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-IZqpAUFMTnctixjH .actor-line{stroke:grey}#mermaid-svg-IZqpAUFMTnctixjH .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-IZqpAUFMTnctixjH .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-IZqpAUFMTnctixjH #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-IZqpAUFMTnctixjH .sequenceNumber{fill:#fff}#mermaid-svg-IZqpAUFMTnctixjH #sequencenumber{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH #crosshead path{fill:#333;stroke:#333}#mermaid-svg-IZqpAUFMTnctixjH .messageText{fill:#333;stroke:#333}#mermaid-svg-IZqpAUFMTnctixjH .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-IZqpAUFMTnctixjH .labelText,#mermaid-svg-IZqpAUFMTnctixjH .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-IZqpAUFMTnctixjH .loopText,#mermaid-svg-IZqpAUFMTnctixjH .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-IZqpAUFMTnctixjH .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-IZqpAUFMTnctixjH .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-IZqpAUFMTnctixjH .noteText,#mermaid-svg-IZqpAUFMTnctixjH .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-IZqpAUFMTnctixjH .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-IZqpAUFMTnctixjH .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-IZqpAUFMTnctixjH .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-IZqpAUFMTnctixjH .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .section{stroke:none;opacity:0.2}#mermaid-svg-IZqpAUFMTnctixjH .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-IZqpAUFMTnctixjH .section2{fill:#fff400}#mermaid-svg-IZqpAUFMTnctixjH .section1,#mermaid-svg-IZqpAUFMTnctixjH .section3{fill:#fff;opacity:0.2}#mermaid-svg-IZqpAUFMTnctixjH .sectionTitle0{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .sectionTitle1{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .sectionTitle2{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .sectionTitle3{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-IZqpAUFMTnctixjH .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .grid path{stroke-width:0}#mermaid-svg-IZqpAUFMTnctixjH .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-IZqpAUFMTnctixjH .task{stroke-width:2}#mermaid-svg-IZqpAUFMTnctixjH .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .taskText:not([font-size]){font-size:11px}#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-IZqpAUFMTnctixjH .task.clickable{cursor:pointer}#mermaid-svg-IZqpAUFMTnctixjH .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-IZqpAUFMTnctixjH .taskText0,#mermaid-svg-IZqpAUFMTnctixjH .taskText1,#mermaid-svg-IZqpAUFMTnctixjH .taskText2,#mermaid-svg-IZqpAUFMTnctixjH .taskText3{fill:#fff}#mermaid-svg-IZqpAUFMTnctixjH .task0,#mermaid-svg-IZqpAUFMTnctixjH .task1,#mermaid-svg-IZqpAUFMTnctixjH .task2,#mermaid-svg-IZqpAUFMTnctixjH .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutside0,#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutside2{fill:#000}#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutside1,#mermaid-svg-IZqpAUFMTnctixjH .taskTextOutside3{fill:#000}#mermaid-svg-IZqpAUFMTnctixjH .active0,#mermaid-svg-IZqpAUFMTnctixjH .active1,#mermaid-svg-IZqpAUFMTnctixjH .active2,#mermaid-svg-IZqpAUFMTnctixjH .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-IZqpAUFMTnctixjH .activeText0,#mermaid-svg-IZqpAUFMTnctixjH .activeText1,#mermaid-svg-IZqpAUFMTnctixjH .activeText2,#mermaid-svg-IZqpAUFMTnctixjH .activeText3{fill:#000 !important}#mermaid-svg-IZqpAUFMTnctixjH .done0,#mermaid-svg-IZqpAUFMTnctixjH .done1,#mermaid-svg-IZqpAUFMTnctixjH .done2,#mermaid-svg-IZqpAUFMTnctixjH .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-IZqpAUFMTnctixjH .doneText0,#mermaid-svg-IZqpAUFMTnctixjH .doneText1,#mermaid-svg-IZqpAUFMTnctixjH .doneText2,#mermaid-svg-IZqpAUFMTnctixjH .doneText3{fill:#000 !important}#mermaid-svg-IZqpAUFMTnctixjH .crit0,#mermaid-svg-IZqpAUFMTnctixjH .crit1,#mermaid-svg-IZqpAUFMTnctixjH .crit2,#mermaid-svg-IZqpAUFMTnctixjH .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-IZqpAUFMTnctixjH .activeCrit0,#mermaid-svg-IZqpAUFMTnctixjH .activeCrit1,#mermaid-svg-IZqpAUFMTnctixjH .activeCrit2,#mermaid-svg-IZqpAUFMTnctixjH .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-IZqpAUFMTnctixjH .doneCrit0,#mermaid-svg-IZqpAUFMTnctixjH .doneCrit1,#mermaid-svg-IZqpAUFMTnctixjH .doneCrit2,#mermaid-svg-IZqpAUFMTnctixjH .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-IZqpAUFMTnctixjH .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-IZqpAUFMTnctixjH .milestoneText{font-style:italic}#mermaid-svg-IZqpAUFMTnctixjH .doneCritText0,#mermaid-svg-IZqpAUFMTnctixjH .doneCritText1,#mermaid-svg-IZqpAUFMTnctixjH .doneCritText2,#mermaid-svg-IZqpAUFMTnctixjH .doneCritText3{fill:#000 !important}#mermaid-svg-IZqpAUFMTnctixjH .activeCritText0,#mermaid-svg-IZqpAUFMTnctixjH .activeCritText1,#mermaid-svg-IZqpAUFMTnctixjH .activeCritText2,#mermaid-svg-IZqpAUFMTnctixjH .activeCritText3{fill:#000 !important}#mermaid-svg-IZqpAUFMTnctixjH .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-IZqpAUFMTnctixjH g.classGroup text .title{font-weight:bolder}#mermaid-svg-IZqpAUFMTnctixjH g.clickable{cursor:pointer}#mermaid-svg-IZqpAUFMTnctixjH g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-IZqpAUFMTnctixjH g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-IZqpAUFMTnctixjH .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-IZqpAUFMTnctixjH .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-IZqpAUFMTnctixjH .dashed-line{stroke-dasharray:3}#mermaid-svg-IZqpAUFMTnctixjH #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH .commit-id,#mermaid-svg-IZqpAUFMTnctixjH .commit-msg,#mermaid-svg-IZqpAUFMTnctixjH .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-IZqpAUFMTnctixjH g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-IZqpAUFMTnctixjH g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-IZqpAUFMTnctixjH g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-IZqpAUFMTnctixjH .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-IZqpAUFMTnctixjH .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-IZqpAUFMTnctixjH .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-IZqpAUFMTnctixjH .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-IZqpAUFMTnctixjH .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-IZqpAUFMTnctixjH .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-IZqpAUFMTnctixjH .edgeLabel text{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-IZqpAUFMTnctixjH .node circle.state-start{fill:black;stroke:black}#mermaid-svg-IZqpAUFMTnctixjH .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-IZqpAUFMTnctixjH #statediagram-barbEnd{fill:#9370db}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-state .divider{stroke:#9370db}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-IZqpAUFMTnctixjH .note-edge{stroke-dasharray:5}#mermaid-svg-IZqpAUFMTnctixjH .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-IZqpAUFMTnctixjH .error-icon{fill:#522}#mermaid-svg-IZqpAUFMTnctixjH .error-text{fill:#522;stroke:#522}#mermaid-svg-IZqpAUFMTnctixjH .edge-thickness-normal{stroke-width:2px}#mermaid-svg-IZqpAUFMTnctixjH .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-IZqpAUFMTnctixjH .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-IZqpAUFMTnctixjH .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-IZqpAUFMTnctixjH .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-IZqpAUFMTnctixjH .marker{fill:#333}#mermaid-svg-IZqpAUFMTnctixjH .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-IZqpAUFMTnctixjH {color: rgba(0, 0, 0, 0.75);font: ;}獲取源 DEM 文件如 SRTM 的 tif 文件使用 tif 文件生成地形瓦片托管靜態瓦片資源配置 Cesium TerrainProvider

獲取高程數據

高程數據從哪里來呢?現在市面上有些衛星地圖下載軟件,比如水經注、BIGEMAP等,其中一些也包含高程數據下載。我沒有試過,具體好不好用不清楚。也可以到CGIAR CSI的網站下載。

這里介紹最原始的方法,就是去 NASA 的 EarthData 網站下載。這里有很多全球地理數據,大家可以找自己想要的下載。

  • 我這里選擇了 ASTGTM v003 的數據,可以在這個網址 https://lpdaac.usgs.gov/products/astgtmv003/ 查看。

  • 點擊頁面的【ACCESS DATA】按鈕,在彈出對話框中可以看到有多種下載方式。我選擇了從 NASA Earthdata Search 下載。

  • 點擊彈出窗口 NASA Earthdata Search 的【Download Data】按鈕,進入下載流程。這里提醒需要先注冊 Earthdata 的賬戶。請注冊登錄賬戶后進行下載。建議選用腳本的方式下載,因為是國外網站,數據量大,經常會因為網絡不穩定導致下載中斷。使用腳本可以在中斷后重新執行腳本,繼續下載。

  • 高程數據處理

    高程數據一般是 .tif 文件格式,在應用到 Cesium 前,需要將其轉換成瓦片文件。cesium目前支持的格式有下面的兩種地形格式,分別是:

    • Quantized-Mesh(推薦使用)
    • HeightMap

    在heightmap 1.0 terrain format說明頁面上,官方明確指出這種格式已經廢棄了,推薦使用quantized-mesh。

    地形文件制作有三種途徑:

    • 使用 Cesium 實驗室的 Cesiumlab2 工具進行處理,開箱即用。
    • 使用 gdal2srtmtiles.py 腳本進行處理,需要安裝依賴工具庫。
    • 使用 Cesium Terrain Builder 開源工具進行處理,需要編譯安裝相關軟件。

    使用 Cesiumlab 制作地形文件

  • 下載 Cesiumlab 安裝文件,我使用的的 Cesiumlab v2.0.8 版本。
  • 注冊賬戶,登錄使用。
  • 該軟件可生產 Quantized-Mesh 和 HeightMap 兩種格式的地形文件。軟件界面友好,詳細制作過程無需說明,在此略過。

    使用 gdal2srtmtiles.py 腳本制作heightmap-1.0 格式地形文件

    請先下載工具包 https://download.csdn.net/download/LeoOthello/15911813 ,可將文件解壓到 C:\terrain 目錄下。

    安裝 Python 2.7

    雙擊安裝 T1-python-2.7.11.msi,默認即可。默認安裝到 C:\Python27,安裝完成后配
    置環境變量,在系統環境變量 path 中添加 C:\Python27 。

    注冊 Python 2.7

    在 cmd 控制臺執行

    > python C:\terrain\T2-reg.py

    執行成功后會提示

    === Python 2.7 is now registered!

    安裝 PIL

    雙擊安裝 T3-PIL-1.1.7.win32-py2.7.exe 程序,默認即可。

    安裝 GDAL

    雙擊安裝 T4-gdal-111-1800-core.msi 程序,默認即可。如果默認安裝路徑為
    C:\Program Files (x86)\GDAL\ ,增加或修改系統環境變量:

  • 增加環境變量 GDAL_DATA 值為 C:\Program Files (x86)\GDAL\gdal-data\
  • 修改環境變量 path,在 path 中增加 C:\Program Files (x86)\GDAL 。
  • 安裝 numpy

    雙擊安裝 T5-numpy-1.8.1-win32-superpack-python2.7.exe 程序,默認即可。

    安裝 GDAL py2.7版

    雙擊安裝 T6-GDAL-1.11.4.win32-py2.7.msi 程序,默認即可。

    生成 .terrain 數據

  • 拷貝 T7-gdal2srtmtiles-demo.py 文件,將克隆文件改名為 T7-gdal2srtmtiles.py 。
  • 打開 T7-gdal2srtmtiles.py 進行編輯,找到文檔最后
    面幾行(第 2592 行),修改 T7-gdal2srtmtiles.py 的位置為你機器上的位置,修改
    tif 的位置和輸出文件的位置。-z 后面可以輸入生成的級數如 0-8 或 0-15 等,級數越大越慢。修改完成后保存。
  • 在 cmd 中輸入
  • python C:\terrain\T7-gdal2srtmtiles.py

    如果不報錯,應該休息片刻就可以看生成的文件了。生成的文件每個目錄下都有.terrain,.hdr,.kml 三種文件,我們只用到.terrain 文件。
    4. 拷貝“覆蓋至生成 tiles 結果”目錄中的 layer.json 文件和 0 文件夾至生成結果目錄下,比如我當前是 terrain_tiles 目錄下。
    5. 目前這套工具只能處理單個 tif 文件,如果涉及多個 tif 文件,可將每次生成的 terrain_tiles 文件夾覆蓋添加到一個文件夾中。

    使用 Cesium Terrain Builder 工具制作 Quantized-Mesh-1.0 格式地形文件

    在 Cesium Terrain Builder 的網頁上介紹了兩種使用該工具的方式。一種是源碼編譯安裝,一種是使用 Docker 安裝 CTB 的鏡像文件。下面進行分別介紹。

    源碼編譯安裝及使用

    準備
  • 下載 CTB 工具源文件
  • 安裝 VS2015
  • 安裝 CMake
  • 下載依賴庫 GDAL 源文件 https://download.osgeo.org/gdal/2.4.4/gdal-2.4.4.tar.gz
  • 下載依賴庫 zlib 壓縮包 http://zlib.net/zlib1211.zip
  • 編譯安裝GDAL
  • 解壓gdal壓縮包
  • 進入解壓后的目錄,修改./nmake.opt文件(最好使用vs2015打開),將57行的GDAL_HOME改成解壓后的GDAL的實際路徑,將191行的#WIN64=YES改為WIN64=YES(即把#去掉)。
  • 管理員運行x64 Native Tools Command Prompt for VS 2015工具,輸入
  • nmake -f makefile.vc MSVC_VER=1900 WIN64=1

    開始編譯,喝杯咖啡,完成后,依次輸入

    nmake -f makefile.vc install nmake -f makefile.vc devinstall

    最后,配置環境變量,將./data配置為GDAL_DATA。

    編譯安裝zlib
  • 解壓zlib壓縮包
  • 使用管理員打開vs2015,然后打開./contrib/vstudio/vc14/zlibvc.sln解決方案,解決方案配置改為release,平臺改為x64,右鍵zlibvc項目,找到生成事件,把命令行的bat文件路徑改成絕對路徑,最后直接右鍵解決方案,選擇生成。
  • 創建include和lib/release/x64目錄,復制./zconf.h、./zlib.h到include目錄下;復制./contrib/vstudio/vc14/x64/ZlibDllRelease/zlibwapi.dll、./contrib/vstudio/vc14/x64/ZlibDllRelease/zlibwapi.lib到x64目錄下。
  • 編譯CTB
  • 打開 cmake gui,配置 source code 路徑到 /path/to/cesium-terrain-builder/src。
  • 在 cesium-terrain-builder 目錄下創建 build 目錄,配置 cmake 的 build 路徑到該目錄,勾選Advanced。
  • 點擊 Configure 按鈕。
  • 配置 GDAL_INCLUDE_DIR 為GDAL編譯后的 include 文件夾,GDAL_LIBRARY 為 GDAL 編譯后的.lib文件。
  • 配置 ZLIB_INCLUDE_DIR 是 zlib 動態庫所在文件夾,ZLIB_LIBRARY_DEBUG , ZLIB_LIBRARY_RELEASE 是 zlib 的 .lib 文件。
  • 選擇編譯平臺為 MSVC2015,然后點擊 Generate,即可在build路徑下生成 MSVC2015 的 sln 工程文件。
  • 點擊 Open Project ,使用 VS2015 打開項目。
  • 右鍵 ALL_BUILD 項目,點擊生成。
  • 創建 bin 文件夾,將 build/src/Release、build/tools/Release 兩個文件夾下的所有文件拷貝到 bin 文件夾里;將 gdal、zlib 等 dll 拷貝到 bin 文件夾里。將 gdal 的工具 gdalbuildvrt.exe 文件拷貝到 bin 文件夾里。
  • PS: CTB工具生成的 Quantized-Mesh 地形文件默認是 gzip 壓縮的 terrain 文件。這種文件在下面的集成中會報錯找不到文件。因此,在編譯 CTB 工具前需要對源代碼進行修改。

    使用 CTB
  • 測試 CTB
  • > tile-info.exe --version
  • 使用 gdalbuildvrt.exe 工具,將多個 tif 文件合并為 vrt 文件
  • > gdalbuildvrt.exe D:/temp/temp.vrt D:/temp/N29E106.tif
  • 使用 CTB,命令如下
  • > ctb-tile -o D:/temp/terrain_tiles -f Mesh D:/temp/temp.vrt -c 4
  • 生成 layer.json 文件,命令如下
  • > ctb-tile -o D:/temp/terrain_tiles -f Mesh D:/temp/temp.vrt -c 1 -l

    Docker 安裝 CTB 及使用

  • 安裝 Docker Desktop
  • 啟動 Docker ,拉取 CTB 鏡像
  • $ docker pull tumgis/ctb-quantized-mesh
  • 創建一個新容器,啟動 ctb 環境
  • $ docker run -v D:/temp:/data -ti -i tumgis/ctb-quantized-mesh:latest bash
  • 合并tiffs,生成.vrt文件
  • /data# gdalbuildvrt ./temp.vrt ./*.tif
  • 運行ctb-tile生成瓦片
  • /data# ctb-tile -f Mesh -C -N -v -o ./terrain_tiles ./temp.vrt
  • 最后創建Cesium layer.json描述文件
  • /data# ctb-tile -f Mesh -C -N -v -o ./terrain_tiles ./temp.vrt -l

    如前所述,這個鏡像版生成的 Quantized-Mesh 格式地形文件也是 gzip 壓縮過的。

    集成到Cesium

  • 將高程數據 terrain_tiles 文件夾放在 HelloWorld 項目目錄的 Assets 目錄下。
  • 在 Cesium 應用代碼中添加地形提供者 terrainProvider。
  • // 創建地形提供者var terrainProvider=new Cesium.CesiumTerrainProvider({url: Cesium.buildModuleUrl("Assets/terrain_tiles") // 指定地形文件的路徑});// 在觀察器中指定地形提供者let viewer = new Cesium.Viewer("cesiumContainer",{geocoder:false, // 關閉查找位置工具homeButton:false, // 禁用Home按鈕sceneModePicker:false, // 禁用視景模式拾取器baseLayerPicker:false, // 禁用數據層拾取器terrainProvider:terrainProvider, // 啟用地形提供者navigationHelpButton:false, // 禁用導航按鈕animation:false, // 禁用動畫部件timeline:false, // 禁用時間線fullscreenButton:false, // 禁用全屏按鈕// 使用自帶的離線影像作為紋理貼圖imageryProvider: new Cesium.TileMapServiceImageryProvider({url: Cesium.buildModuleUrl("Assets/TMS/tiles")}),});
  • HeightMap 格式地形的最終效果如下圖
  • Quantized-Mesh 格式地形的最終效果如下圖
  • 總結

    以上是生活随笔為你收集整理的学习 Cesium (五):加载离线高程数据的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。