postgres与osm初步使用
layout: post
title: postgres與osm初步使用
date: 2016-9-20
categories: blog
tags: [地圖開發(fā)]
description:地圖開發(fā)
本文主要包括以下內(nèi)容
- postgreSQL數(shù)據(jù)庫,用來存放地圖原始數(shù)據(jù)
- osm2pgsql 用來將osm地圖數(shù)據(jù)導入到postgreSQL
?
OSM數(shù)據(jù)
OpenStreetMap(簡稱OSM)是一個網(wǎng)上地圖眾籌(crowd sourcing)項目,目標是創(chuàng)造一個內(nèi)容自由且能讓所有人編輯的世界地圖
osm數(shù)據(jù)特點
- 數(shù)據(jù)來源多樣,海量數(shù)據(jù)但數(shù)據(jù)質(zhì)量參差不齊(錯誤、不一致),需要大量的后續(xù)數(shù)據(jù)處理
- 按照數(shù)據(jù)的類別,用不同的標簽標示數(shù)據(jù)類別
- 將數(shù)據(jù)進行匯編,按進行全球(Planet OSM, OSM)或區(qū)域發(fā)布
- 文件大:XML variant over 600+GB uncompressed, 50+ GB bz2 compressed and 30+GB for PBF
OpenStreetMap包括空間數(shù)據(jù)以及屬性數(shù)據(jù)。其中空間數(shù)據(jù)主要包括三種:點(Nodes)、路(Ways)和關(guān)系(Relations),這三種原始構(gòu)成了整個地圖畫面。其中,Nodes定義了空間中點的位置;Ways定義了線或區(qū)域;Relations(可選的)定義了元素間的關(guān)系, 屬性數(shù)據(jù)Tags用于描述上述矢量數(shù)據(jù)基元
node通過經(jīng)緯度定義了一個地理坐標點。同時,還可以height=標示物體所海拔;通過layer= 和 level=,可以標示物體所在的地圖層面與所在建筑物內(nèi)的層數(shù);通過place= and name=*來表示對象的名稱。同時,way也是通過多個點(node)連接成線(面)來構(gòu)成的。
通過2-2000個點(nodes)構(gòu)成了way。way可表示如下3種圖形事物(非閉合線(Open polyline )、閉合線(Closed polyline)、區(qū)域(Area ))。對于超過2000 nodes的way,可以通過分割來處理。
OSM分類Features和標簽(Tag)
各feature都通過tag來記錄數(shù)據(jù)信息,通過‘key’ and a ‘value’來對數(shù)據(jù)進行記錄。例如,可以通過highway=residential來定義居住區(qū)道路;同時,可以使用附加的命名空間來添加附加信息,例如:maxspeed:winter=*就表示冬天的最高限速
postgressql數(shù)據(jù)庫安裝
開源免費數(shù)據(jù)庫:PostgreSQL下載安裝教程_百度經(jīng)驗
OSM數(shù)據(jù)提取
下載osm:http://dev.openstreetmap.org/~bretth/osmosis-build/osmosis-latest.zip
?
下載中國地圖數(shù)據(jù)
http://download.geofabrik.de/asia/china.html
數(shù)據(jù)裁剪
區(qū)域裁減,把中國地圖裁剪成武漢地圖:
osmosis --read-pbf file="china-latest.osm.pbf" --used-node --bounding-box left=113.9502 right=114.4762 top=30.7643 bottom=30.4291 clipIncompleteEntities="true" --write-pbf Wuhan.pbf提取武漢地圖的高速公路數(shù)據(jù)
osmosis --read-pbf file="wuhan.pbf" --tf accept-ways highway=* clipIncompleteEntities="true" --write-pbf Wuhan_highway.pbf將數(shù)據(jù)導入postgres數(shù)據(jù)庫
- create extension hstore;
- create extension postgis;
- create extension pgrouting;
- 運行數(shù)據(jù)庫ddl: pgsnapshot_schema_0.6.sql
導入數(shù)據(jù):osmosis –read-pbf file=”wuhan_highway.pbf” –wp host=localhost database=osm user=postgres password=postgres
- 首先在postgres中添加3個擴展
- 再運行osmosis-latest\script文件夾下的 pgsnapshot_schema_0.6.sql腳本
- 運行導入指令即可
安裝QGIS并連接postgres可以在地圖上看到導入的數(shù)據(jù)
總結(jié)
以上是生活随笔為你收集整理的postgres与osm初步使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: map的详解及常见面试题
- 下一篇: FragmentPagerAdapter