日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Open Street Map维基世界地图初探--概念、开发

發布時間:2025/7/25 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Open Street Map维基世界地图初探--概念、开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

from: http://blog.csdn.net/viewcode/article/details/8179289

1. 什么是open street map(osm)?

2. 開發者應該知道哪些概念?包括地圖的內容、格式等

3. OSM開發有哪些環境?

4. libosmscout環境的搭建

5. libosmscout的使用示例、配置文件


1. 什么是OSM?

Open Street Map 維基世界地圖,一個開源的在線地圖項目,包括軟件和地圖數據。

官網介紹

http://wiki.openstreetmap.org/wiki/Zh-hans:Main_Page

中文網頁

http://wiki.openstreetmap.org/wiki/Main_Page

OSM與其他地圖 如google地圖的區別在哪里?

正如官網所說,它提供了一種方式,讓任何人能編輯地圖,能為OSM增加地圖數據(當然如果是錯誤的,別人是有權修改的)。而且,其他地圖大部分都不是免費的,或者需要授權使用, google地圖是免費的,但它也是被別人授權的,無法隨意編輯或在自己的軟件中使用的。

所以,人們也可以免費地使用OSM數據,包括開發等。


對OSM的常見問題,可以瀏覽

http://wiki.openstreetmap.org/wiki/FAQ


對于大部分人而言,為OSM繪圖是比較有趣的事。

有關為地圖增加數據(繪圖)的詳細介紹如下:

http://wiki.openstreetmap.org/wiki/Zh-hans:Map_Making_Overview


而對于開發者而言,更關心如何使用OSM數據,用于開發,一個必要的開發介紹和資源入口:

http://wiki.openstreetmap.org/wiki/Develop

里面介紹了 OSM的API, 如何下載map data,map data的數據格式和數據結構,常用的開發工具(已經開發好的小工具),地圖要素(有哪些數據),與OSM相關的支持的框架(庫和組件)。


OSM自身的框架描述:

http://wiki.openstreetmap.org/wiki/Component_overview


下面先介紹一些與開發相關的概念和環境。

2. OSM相關的一些概念

地圖數據的存儲方式是xml結構,后綴名可以是xml或osm。


地圖的數據結構,即地圖要素包括1?Node,?2?Way,?3?Relation4?Tag5?Common attributes

這些地圖要素,與普通的地圖或導航要素概念相同

Node是空間點,包括經緯坐標,或高度信息。其他一些可選信息,如name等,在tag子數據中表示。類似于shape point 或attribution point

way表示線或區域,能包含2-2000個node點信息。它道路與區域描述的主要形式。類似于link、edge的概念

relation表示不同的元素間的關系,將不同元素間的關系描述出來。類似于connection的概念

tag表示一個元素中包含的一個特征,或者說是包含的一小塊數據,如highway=residential,住宅區內的道路。類似于attribution的概念,不過tag的作用遠不止attribution的描述。

Common attributes就是node、way、relation的共同屬性,包括id, usr, version, timestamp等meta的信息。

更詳細的描述參見:

http://wiki.openstreetmap.org/wiki/Data_Primitives

及每個元素的子鏈接。


有關tag類型的詳細介紹和分類在這里有介紹:

http://wiki.openstreetmap.org/wiki/Map_Features


3. 開發框架

OSM目前提供了API 0.6版本的開發接口,xapi是extended api擴展的接口。而這些接口是用于web或Java應用開發的。如下介紹

http://wiki.openstreetmap.org/wiki/Databases_and_data_access_APIs

如果是使用其他語言開發,就必須使用其他的庫或組件,這里列舉了各種語言支持的庫和組件。

http://wiki.openstreetmap.org/wiki/Develop/Frameworks


對于我而言,我采用的c++開發語言,目的是讀取OSM數據,并解析,選取一些數據,我就選用libosmscout庫。

所以,下面我就介紹libosmscout的開發環境設置。


4. libosmscout環境的搭建

我使用JOSM用于查看和下載地圖數據,JOSM只能查看較小的地圖數據,其內存支持400多MB,對于更大的數據不支持。OSMOSIS用于數據轉換或分割等。

地圖數據下載,以下鏈接里包括各個地區或整個地圖的下載路徑:

http://wiki.openstreetmap.org/wiki/Planet.osm


libosmscout各個模塊的介紹:?

http://wiki.openstreetmap.org/wiki/Libosmscout

閑話少說,環境搭建(非qt版部分):

a. 使用Git從sourceforge上把源碼都下載下來

http://sourceforge.net/projects/libosmscout/

b. libosmscout支持windows版本,我使用的是vs2008,所以首先查看README.VisualStudio.txt,里面包含了詳細的build windows版本的步驟。

c. 依據readme,將zlib、libxml2、google protocol buffers、protoc.exe下載下來,并配置好。其中zlib、libxml2的版本要匹配,否則會有很因為版本不匹配的鏈接錯誤。

d. 依據readme,設置環境變量EXTRALIBS_HEADERS、EXTRALIBS_DEBUGLIBS。

e. 然后編譯,這時,若有與DECLARE_COEFFS(SINECOEFF_SSE)相關的編譯錯誤,就查看SSEMath.cpp中,有關math的一系列代碼是否是有效的,若無效,加入#define?OSMSCOUT_HAVE_SSE2。這個是我遇到的其vs工程中自帶的問題,可能是個小bug吧。

f. 此時libosmscout工程、libosmscout-import工程、import工程、demo_AddressLookup工程都能編譯通過。有關qt部分的工程我沒編譯,這里就不寫了。


訂閱郵件列表,用于知曉它的修改變換,及咨詢問題:

https://lists.sourceforge.net/lists/listinfo/libosmscout-development


5. libosmscout使用示例與配置

在使用demo_AddressLookup之前,要獲取OSM地圖數據及將osm地圖數據轉換為libosmscout需要的binary數據。

如果手上拿的的有xml格式的數據,可以使用osmosis工具將xml格式的數據轉換為osm格式。轉換命令示例:

osmosis --read-xml file="planetin.xml" --write-xml file="planetout.osm" 更豐富的,強大的示例在

http://wiki.openstreetmap.org/wiki/Osmosis#Example_Usage

或使用JOSM工具從服務器上下載地圖數據,并保存為osm格式,這種方法能直接打開地圖數據并查看。


然后,使用編譯好的import.exe,將osm格式的數據轉換為binary數據。在運行程序之前,將libosmscout\map.ost復制到程序當前目錄下,因為import需要默認的map.ost參數文件。建立一個用于輸出結果的文件夾(libosmscout的binary地圖作為輸入或輸出都是文件夾的形式),如轉換planet.xml,運行命令Import.exe planetout.osm --destinationDirectory planet

更詳盡的命令參數,請參看源碼或import的命令提示。

import的輸出會包含很多dat和idx文件,dat是數據文件,idx是dat的索引文件,更詳細的說明在libosmscout\libosmscout\ProcessResult.txt中,libosmscout\libosmscout\Resource.txt是一些算法和程序所占資源的說明。

并且map.ost是可以編輯的,可以增加或刪除一些選項,如以下一些必要類型保留,其他我都刪除,并添加了highway_crossing類型。這樣能減少自己不需要的生成的binary數據,當然就會提高效率。

[cpp] view plaincopy
  • OST??
  • ??
  • TYPES??
  • ??TYPE?"highway_crossing"?=?NODE?("highway"=="crossing")???
  • ??
  • ??//?Do?not?delete?the?following?type,?they?are?required?by?the?GenCityStreet?import?step??
  • ??TYPE?"boundary_administrative"?=?WAY?AREA?("boundary"=="administrative")?OR??
  • ???????????????????????????????????RELATION?("type"=="boundary"?AND?"boundary"=="administrative")?OPTIONS?MULTIPOLYGON?IGNORESEALAND??
  • ??
  • ??//?Do?not?delete?the?following?types,?they?are?required?by?the?GenCityStreet?import?step??
  • ??TYPE?"place_city"?=?NODE?AREA?("place"=="city")??
  • ??TYPE?"place_town"?=?NODE?AREA?("place"=="town")??
  • ??TYPE?"place_village"?=?NODE?AREA?("place"=="village")??
  • ??TYPE?"place_hamlet"?=?NODE?AREA?("place"=="hamlet")??
  • ??TYPE?"place_suburb"?=?NODE?AREA?("place"=="suburb")??
  • ??
  • END??

  • 自己的一個小的demo,打印地圖中highway_crossing的node(前提:自己生成的輸入地圖中有highway_crossing的數據)。 [cpp] view plaincopy
  • #include?<iostream>??
  • #include?<iomanip>??
  • #include?<vector>??
  • ??
  • #include?<osmscout/Database.h>??
  • #include?<osmscout/TypeConfigLoader.h>??
  • ??
  • using?namespace?std;??
  • const?static?size_t?RESULT_SET_MAX_SIZE?=?1000;??
  • ??
  • int?main(int?argc,?char*?argv[])??
  • {??
  • ??std::string??????????????????????map;??
  • ??map=argv[1];??
  • ??
  • ??osmscout::DatabaseParameter?databaseParameter;??
  • ??//databaseParameter.SetDebugPerformance(true);??
  • ??osmscout::Database??????????database(databaseParameter);??
  • ??
  • ??if?(!database.Open(map.c_str()))?{??
  • ????std::cerr?<<?"Cannot?open?database"?<<?std::endl;??
  • ??
  • ????return?1;??
  • ??}??
  • ??
  • ??double?minlat?=?0.f;??
  • ??double?minlon?=?0.f;??
  • ??double?maxlat?=?0.f;??
  • ??double?maxlon?=?0.f;??
  • ??database.GetBoundingBox(minlat,?minlon,?maxlat,?maxlon);??
  • ??
  • ??std::cout?<<?"?"?<<?minlat?<<?"?"?<<?minlon?<<?"?"?<<?maxlat?<<?"?"?<<?maxlon?<<?std::endl;??
  • ??
  • ??std::vector<osmscout::NodeRef>?nodes;??
  • ??std::vector<osmscout::WayRef>?ways;??
  • ??std::vector<osmscout::WayRef>?areas;??
  • ??std::vector<osmscout::RelationRef>?relationWays;??
  • ??std::vector<osmscout::RelationRef>?relationAreas;??
  • ??
  • ??osmscout::TypeConfig?typeConfig;??
  • ??
  • ??clock_t?startTime?=?clock();??
  • ??
  • ??if?(!osmscout::LoadTypeData(map,typeConfig))?{??
  • ??????std::cerr?<<?"Cannot?load?'types.dat'!"?<<?std::endl;??
  • ??????return?false;??
  • ????}??
  • ????std::cout?<<?"typeID:"?<<?typeConfig.GetTypeId("highway_crossing")?<<?endl;??
  • ??
  • ??osmscout::TypeSet?types;??
  • ??types.SetType(typeConfig.GetTypeId("highway_crossing"));??
  • ??std::cout?<<?types.HasTypes()?<<?std::endl;??
  • ??
  • ??database.GetObjects(minlon,?minlat,?maxlon,?maxlat,types,?nodes,?ways,?areas,?relationWays,?relationAreas);??
  • ??clock_t?endTime?=?clock();??
  • ??
  • ??std::cout?<<?"Time:"?<<?(endTime?-?startTime)?<<?std::endl;??
  • ??
  • ??std::cout?<<?"nodes:?"?<<?nodes.size()?<<?"?ways:"?<<?ways.size()?<<?"?areas:"?<<?areas.size()?<<?std::endl????
  • ??????<<?"relationWays:"?<<?relationWays.size()?<<?"?relationAreas:"?<<?relationAreas.size()?<<?std::endl;??
  • ??
  • ??for?(unsigned?int?i=0;?i<nodes.size();?++i)??
  • ??{??
  • ??????std::cout?<<?i?<<?"GetLat:"?<<?nodes[i].Get()->GetLat()?<<?std::endl;??
  • ??????std::cout?<<?i?<<?"GetLon:"?<<?nodes[i].Get()->GetLon()?<<?std::endl;??
  • ??????std::cout?<<?i?<<?"GetId:?????????"?<<?nodes[i].Get()->GetId()?<<?std::endl;??
  • ??????if?(nodes[i].Get()->GetTagCount()?>?0)??
  • ??????{??
  • ??????????std::cout?<<?i?<<?"GetTagCount:"?<<?nodes[i].Get()->GetTagCount()?<<?std::endl;??
  • ??????????std::cout?<<?i?<<?"GetTagKey:"?<<?nodes[i].Get()->GetTagKey(0)?<<?std::endl;??
  • ??????????std::cout?<<?i?<<?"GetTagValue:"?<<?nodes[i].Get()->GetTagValue(0)?<<?std::endl;??
  • ??????}??
  • ??????std::cout?<<?i?<<?"GetType:"?<<?nodes[i].Get()->GetType()?<<?std::endl;??
  • ??}??
  • ??
  • ??database.Close();??
  • ??
  • ??std::cout?<<?"database?close?..."?<<?std::endl;??
  • ??
  • ??return?0;??
  • }??

  • 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的Open Street Map维基世界地图初探--概念、开发的全部內容,希望文章能夠幫你解決所遇到的問題。

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