OsgGIS 項目解析

來源:互聯網
上載者:User

        OsgGIS的project其實就是一個指令集.執行該指令集就可以從要素和柵格資料中編譯出OSG的3D幾何體.(對於開發人員而言,意味著使用osgGISProjects::Project類).可以通過xml檔案定義整個project 然後使用osggis_build命令列工具來編譯.

 

      本文對project所使用的xml定義檔案做基本的解釋.

專案檔:

      有兩種方式都可以建立一個項目:通過編程或者通過xml檔案.我們選擇使用xml檔案作為project檔案的架構是因為:1)xml便於人們閱讀和理解2)很多人都很熟悉xml檔案的文法格式3)已經存在大量的工具來讀寫和裝換xml資料.

     project檔案類似於Makefile,它定義了一些列的構建目標和規則.下面是一個基本的project檔案:

   

view plaincopy
to clipboardprint?
  1. <?xml version="1.0" ?>  
  2. <project name="sample">  
  3.   
  4.     <!-- A layer is a primary build target: -->  
  5.     <layer name="roads" source="roads" target="out/roads.ive">  
  6.         <slice min_range="0" max_range="1e6" graph="roads"/>  
  7.     </layer>  
  8.   
  9.     <!-- A source references a vector GIS source layer: -->  
  10.     <source name="roads">  
  11.         <uri>source/roads.shp</uri>  
  12.     </source>  
  13.   
  14.     <!-- A filter graph defines the assembly pipeline for turning features into 3D geometry: -->  
  15.     <graph name="roads">  
  16.         <filter type="Transform">  
  17.             <property name="localize" value="true"/>  
  18.         </filter>  
  19.         <filter type="BuildGeom">  
  20.             <property name="color" value="vec4(1,.6,.4,1)"/>  
  21.         </filter>  
  22.         <filter type="Collect"/>  
  23.         <filter type="BuildNodes"/>  
  24.     </graph>  
  25.   
  26. </project>  

<?xml version="1.0" ?><br /><project name="sample"></p><p> <!-- A layer is a primary build target: --><br /> <layer name="roads" source="roads" target="out/roads.ive"><br /> <slice min_range="0" max_range="1e6" graph="roads"/><br /> </layer></p><p> <!-- A source references a vector GIS source layer: --><br /> <source name="roads"><br /> <uri>source/roads.shp</uri><br /> </source></p><p> <!-- A filter graph defines the assembly pipeline for turning features into 3D geometry: --><br /> <graph name="roads"><br /> <filter type="Transform"><br /> <property name="localize" value="true"/><br /> </filter><br /> <filter type="BuildGeom"><br /> <property name="color" value="vec4(1,.6,.4,1)"/><br /> </filter><br /> <filter type="Collect"/><br /> <filter type="BuildNodes"/><br /> </graph></p><p></project><br />

所有的元素都定義在<project>下.其中<layer> <source>和<graph>分別定義了project中的不同的組件.下面我們來一一說明.

 

 文法規則

  下面是project檔案中的一些文法規則:

   1.次序性:元素在xml檔案中出現的次序是不重要的。有更多元素通過name來引用其他元素.被引用的元素在xml檔案中的位置是不重要的.

   2.獨特性:元素的name只要求在相同元素類型的所有元素中唯一.例如:每一個source元素的名字應該是所有的source中是唯一的.一個source和一個layer同名是可以的。

   3.路徑分割符:在所有平台上,路徑分隔字元都是前斜線("/").

   4.屬性名稱:在屬性名稱中連字號(-)和底線(_)是被認為是同一個字元.也就是說,use-terrain-srs和user_terrain_srs是同一個名稱.

 

包含檔案(include file)

   project檔案有可能會很巨大而且很複雜,比如:

   1.需要編譯好幾十個圖層

   2.同一組資料來源(datasource)需要在不同的項目中共用

   3.同一組資源檔需要在不同的項目中共用

   可以通過include元素來合并project檔案.被include的檔案自己本身也需要有project元素.

   下面是範例代碼:

  

view plaincopy
to clipboardprint?
  1. <project name="sample">  
  2.   
  3.     <include>data/source.xml</include>  
  4.     <include>resources.xml</include>  
  5.   
  6.     ...  
  7. </project>  

<project name="sample"></p><p> <include>data/source.xml</include><br /> <include>resources.xml</include></p><p> ...<br /></project><br />

include元素可以在文檔中的任何位置出現,和其它元素一樣,其位置不構成任何影響.

 

路徑和URI(Paths and URIs)

 

  許多元素都會引用外部檔案,例如資料檔案或者其他需要include的專案檔.檔案的路徑可以是絕對路徑也可以是相對路徑。如果是相對路徑,那麼相對是指相對於包含此引用的專案檔自身的路徑.(應該是指直接包含) 下面是範例代碼:

view plaincopy
to clipboardprint?
  1. ...  
  2.     <source name="trees">  
  3.         <uri>c:/data/trees.shp</uri>  
  4.     </source>     
  5.   
  6.     <source name="roads">  
  7.         <uri>source_data/roads.shp</uri>  
  8.     </source>  
  9.     ...  

...<br /> <source name="trees"><br /> <uri>c:/data/trees.shp</uri><br /> </source> </p><p> <source name="roads"><br /> <uri>source_data/roads.shp</uri><br /> </source><br /> ...<br />

在樹元素(name="trees")中uri引用了一個絕對路徑.而在道路元素(name="roads")中,uri引用了一個相對路徑。這個相對路徑是相對於包含此source介面的專案檔的位置的.

 

Project Elements下面是project檔案中的主要元素
  • <project> - 頂級元素
  • <layer> - 編譯一個圖層的起點
  • <graph> -將圖層組合為情境圖的管道
  • <source> - 引用向量資料來源
  • <terrain> - 引用地形資料來源
  • <resource> - 引用外部的紋理、模型或者其他資源
  • <include>? - 引用外部檔案
  • <script>? - 嵌入式的Lua代碼
  • <map> - 運行時地圖定義

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.