一踪央、準備工作
1.完成數(shù)據(jù)準備OSM本地發(fā)布(二)-----數(shù)據(jù)準備
2.推薦使用Navicat操作數(shù)據(jù)庫
3.下文是在《在GeoServer中為OpenStreetMap數(shù)據(jù)設置OSM樣式》基礎上的改進,可直接看該文實現(xiàn)圖層發(fā)布
二、OSM字段說明
planet_osm_line,planet_osm_point,planet_osm_polygon和planet_osm_roads四個數(shù)據(jù)表中字段官方說明文檔:https://wiki.openstreetmap.org/wiki/Zh-hans:Map_Features方妖;以下為對部分字段的整理莺琳。
1.共有字段
字段名 |
說明 |
osm_id |
主鍵 |
way |
存儲的地理數(shù)據(jù) |
name |
屬性名稱 |
tags |
標簽蚓土,屬性描述信息 |
2.道路相關字段
官方詳細說明文檔:Map Features - OpenStreetMap highway
字段名稱 |
字段取值 |
說明 |
highway |
motorway |
國家級/省級高速公路。 |
|
trunk |
國道/城市快速路丛晦。 |
|
primary |
省道/主干道尔苦。 |
|
motorway_link |
其他公路通往高速公路的連接道路涩馆,高速公路之間的連接匝道。 |
|
trunk_link |
連接國道/快速路與其他國道/快速路或更低級道路的連接路允坚。 |
|
primary_link |
連接省道/主干道與其他省道/主干道或更低級道路的連接路魂那。 |
|
proposed |
規(guī)劃道路(未建成道路)。 |
|
construction |
在建道路稠项。 |
|
motorway_junction |
指定高速公路出口涯雅,一般標記在出口匝道與主線的分流處。 |
|
services |
服務區(qū)展运。通常位于高速公路或快速公路上 |
barrier |
toll_booth |
一個收取道路使用費或費用的地點活逆。 |
3.水路相關字段
官方詳細說明文檔:Map Features - OpenStreetMap waterway
字段名稱 |
字段取值 |
說明 |
waterway |
river |
河流的線性流動,在流動的方向 |
|
riverbank |
河流的水域覆蓋區(qū)域 |
|
canal |
人工"開放式流動"水道用于輸送有用的水用于運輸拗胜、供水或灌溉蔗候。 |
|
fairway |
湖或海中的通航路線,通常以浮標或信標為標志埂软。 |
4.鐵路相關字段
官方詳細說明文檔:Map Features - OpenStreetMap railway
字段名稱 |
字段取值 |
說明 |
railway |
construction |
在建鐵路锈遥。 |
|
disused |
廢棄鐵路,路基勘畔、鐵軌還沒有被拆除所灸。 |
|
rail |
在該國標準軌距上的全尺寸旅客或貨物列車 |
|
station |
火車站 |
bridge |
yes |
橋梁 |
electrified |
contact_line/rail/yes/no |
架空電力線/第三軌供電/電氣化,但是供電方式不詳/非電氣化鐵路 |
service |
siding |
側(cè)線炫七,長度較短的軌道庆寺,并行(及連接)于主線。 |
|
spur |
專用線诉字,長度較短,連接企業(yè)知纷、廠礦壤圃。 |
|
yard |
站線,車站內(nèi)的線路琅轧。 |
usage |
main/branch/industrial/military/tourism |
鐵路主要用途(主線/支線/工業(yè)/軍事/旅游) |
public_transport |
station |
鐵路客運專站伍绳。 |
5.設施相關字段
官方詳細說明文檔:Map Features - OpenStreetMap amenity
字段名稱 |
字段取值 |
說明 |
amenity |
ferry_terminal |
渡輪站/渡輪碼頭,渡輪驼Ч穑靠站可供人和車輛上船冲杀。 |
|
townhall |
市政廳效床,鄉(xiāng),鎮(zhèn)权谁,市等地方政府的辦公大樓剩檀,或者是社區(qū)公所。 |
6.土地類型相關字段
官方詳細說明文檔:Map Features - OpenStreetMap landuse
字段名稱 |
字段取值 |
說明 |
landuse |
commercial |
商業(yè)辦公用地 |
|
construction |
建筑工地 |
|
education |
主要用于教育目的/設施的區(qū)域旺芽。 |
|
industrial |
工業(yè)用地沪猴,包括工廠、車間和倉儲用地采章。 |
|
residential |
居住區(qū)运嗜。 |
|
forest |
林業(yè)用地。 |
|
railway |
鐵路用地悯舟,一般不對公眾開放担租。 |
|
reservoir |
水庫 |
7.線路相關字段
官方詳細說明文檔:Map Features - OpenStreetMap route
字段名稱 |
字段取值 |
說明 |
route |
ferry |
渡輪從兩端來回行駛的線路。(航線) |
8.邊界相關字段
官方詳細說明文檔:Map Features - OpenStreetMap boundary
字段名稱 |
字段取值 |
說明 |
boundary |
administrative |
行政邊界抵怎。 |
|
rmaritime |
不是行政邊界的海洋邊界:基線奋救、毗連區(qū)和專屬經(jīng)濟區(qū) |
9.地區(qū)相關字段
官方詳細說明文檔:Map Features - OpenStreetMap place
字段名稱 |
字段取值 |
說明 |
place |
country |
國家高級政治/行政區(qū)域。 |
|
province |
省 |
|
county |
縣 |
|
city |
市 |
|
suburb |
城鎮(zhèn)或城市的一部分便贵,有一個眾所周知的名字 |
|
borough |
大城市的一部分被歸入行政單位菠镇。 |
|
town |
一個重要的城市中心,在村莊和城市之間 |
三承璃、執(zhí)行sql語句生成不同圖層的表
注意:默認生成圖層的坐標系:EPSG:3857
這里以生成簡易地圖為例利耍,圖層主要包括:建筑物、地名盔粹、道路隘梨、河流、水域等舷嗡。
表 1 建筑物面圖層(building)
字段名稱 |
說明 |
way |
空間信息字段 |
name |
名稱 |
building |
建筑類型 |
aeroway |
航空相關建筑物 |
DROP TABLE IF EXISTS "building";
CREATE TABLE "building" AS (
SELECT "name",way,building,aeroway
FROM planet_osm_polygon
WHERE
( "building" IS NOT NULL AND "building" != 'no' )
OR "aeroway" = 'terminal'
OR "waterway" = 'dam'
OR man_made = 'pier'
ORDER BY z_order ASC
);
CREATE INDEX "building_way_idx" ON "building" USING gist (way);
表 2 全國行政地名點圖層(placenames_medium)
字段名稱 |
說明 |
way |
空間信息字段 |
name |
名稱 |
place |
地名行政等級類型:state首都/city城市/ferry港口碼頭/small_town村莊轴猎、鄉(xiāng)/large_town街道、辦事處/town鎮(zhèn) |
capital |
城市分類:3首都/4省會城市/5二級城市/6城市各區(qū) |
amenity |
其他屬性 |
DROP TABLE IF EXISTS "placenames_medium";
CREATE TABLE "placenames_medium" AS (
SELECT
(CASE WHEN "name" = '澳門 Macau' THEN '澳門'
WHEN "name" = '香港 Hong Kong' THEN '香港'
ELSE "name" END) as "name",
way,
(CASE WHEN "amenity" = 'ferry_terminal' THEN 'ferry'
ELSE place END) as place,
(CASE WHEN capital = 'yes' and name = '北京市' THEN '3'
WHEN capital = 'yes' and name <> '北京市' THEN '4'
WHEN capital = '3' and name <> '北京市' THEN null
WHEN name in ('澳門 Macau', '香港 Hong Kong') and place = 'city' THEN '4'
ELSE capital END) as capital,
amenity
FROM planet_osm_point
WHERE place IN ('state','city','metropolis','town','large_town','small_town') AND osm_id <> '8899974086' OR amenity = 'ferry_terminal'
);
CREATE INDEX "placenames_medium_way_idx" ON "placenames_medium" USING gist (way);
表 3 道路線圖層(route_line)
字段名稱 |
說明 |
way |
空間信息字段 |
osm_id |
主鍵id |
name |
道路名稱 |
highway |
道路類型 |
oneway |
航空道路類型 |
tunnel |
是否單向道路:yes是 |
service |
是否為隧道:yes是/no不是 |
DROP TABLE IF EXISTS "route_line";
CREATE TABLE "route_line" AS (
SELECT osm_id,"name",way,
(CASE WHEN route = 'ferry' THEN 'ferry'
ELSE highway END) AS highway,
aeroway,
CASE WHEN oneway IN ('yes','true','1') THEN 'yes'::text END AS oneway,
case when tunnel IN ( 'yes', 'true', '1' ) then 'yes'::text
else 'no'::text end as tunnel,
case when service IN ( 'parking_aisle',
'drive_through','driveway' ) then 'INT_minor'::text
else service end as service
FROM planet_osm_line
WHERE highway IS NOT NULL
OR "aeroway" IN ('apron','runway','taxiway')
OR route = 'ferry'
ORDER BY z_order
);
CREATE INDEX "route_line_way_idx" ON "route_line" USING gist (way);
表 4 河流線圖層(river)
字段名稱 |
說明 |
name |
名稱 |
natural |
自然或人工河流 |
landuse |
土地利用類型 |
waterway |
水路類型:river河流 |
DROP TABLE IF EXISTS "river";
CREATE TABLE "river" AS (
SELECT
(CASE WHEN name in ('金沙江','長江','揚子江') THEN '長江'
WHEN name in ('黃河','?????? 瑪曲','黃河 濟南市—德州市界') THEN '黃河'
WHEN name in ('喀拉額爾齊斯河','喀拉額爾齊斯河;額爾齊斯河','Джалгызагат-Хэ') THEN '額爾齊斯河'
ELSE "name" END) as "name" ,
"natural", "landuse", "waterway", "way"
FROM planet_osm_line
WHERE "waterway" IN ('river','riverbank')
ORDER BY z_order asc
);
CREATE INDEX "river_idx" ON "river" USING gist (way);
表 5 水域邊界線圖層(water_outline)
字段名稱 |
說明 |
name |
名稱 |
natural |
水域類型:water水域 |
landuse |
土地利用類型:reservoir蓄水池/basin盆地/grass草地 |
waterway |
水路類型:stream自然流動水路/river河流/canal運河/riverbank河岸/fish_pass/drain下水道 |
water |
河流類型 |
DROP TABLE IF EXISTS "water_outline";
CREATE TABLE "water_outline" AS (
SELECT "name","natural", "landuse", "waterway", "water", "way"
FROM planet_osm_line
WHERE "natural" IN ('lake','water')
OR "waterway" IN ('canal','mill_pond','river','riverbank')
OR "landuse" IN ('basin','reservoir','water')
ORDER BY z_order asc
);
CREATE INDEX "water_outline_way_idx" ON "water_outline" USING gist (way);
表 6 水域面圖層(water)
字段名稱 |
說明 |
name |
名稱 |
natural |
水域類型:hot_spring溫泉/lake湖泊/shingle河濱海濱/water水域/wetland濕地 |
landuse |
土地利用類型 |
waterway |
水路類型 |
water |
系列水域名稱 |
DROP TABLE IF EXISTS "water";
CREATE TABLE "water" AS (
SELECT "name","natural", "landuse", "waterway", "water", "way"
FROM planet_osm_polygon
WHERE "natural" IN ('lake','water')
OR "waterway" IN ('canal','mill_pond','river','riverbank')
OR "landuse" IN ('basin','reservoir','water')
ORDER BY z_order asc
);
CREATE INDEX "water_way_idx" ON "water" USING gist (way);
完整SQL:
DROP TABLE IF EXISTS "building";
CREATE TABLE "building" AS (
SELECT "name",way,building,aeroway
FROM planet_osm_polygon
WHERE
( "building" IS NOT NULL AND "building" != 'no' )
OR "aeroway" = 'terminal'
OR "waterway" = 'dam'
OR man_made = 'pier'
ORDER BY z_order ASC
);
CREATE INDEX "building_way_idx" ON "building" USING gist (way);
DROP TABLE IF EXISTS "placenames_medium";
CREATE TABLE "placenames_medium" AS (
SELECT
(CASE WHEN "name" = '澳門 Macau' THEN '澳門'
WHEN "name" = '香港 Hong Kong' THEN '香港'
ELSE "name" END) as "name",
way,
(CASE WHEN "amenity" = 'ferry_terminal' THEN 'ferry'
ELSE place END) as place,
(CASE WHEN capital = 'yes' and name = '北京市' THEN '3'
WHEN capital = 'yes' and name <> '北京市' THEN '4'
WHEN capital = '3' and name <> '北京市' THEN null
WHEN name in ('澳門 Macau', '香港 Hong Kong') and place = 'city' THEN '4'
ELSE capital END) as capital,
amenity
FROM planet_osm_point
WHERE place IN ('state','city','metropolis','town','large_town','small_town') AND osm_id <> '8899974086' OR amenity = 'ferry_terminal'
);
CREATE INDEX "placenames_medium_way_idx" ON "placenames_medium" USING gist (way);
DROP TABLE IF EXISTS "route_line";
CREATE TABLE "route_line" AS (
SELECT osm_id,"name",way,
(CASE WHEN route = 'ferry' THEN 'ferry'
ELSE highway END) AS highway,
aeroway,
CASE WHEN oneway IN ('yes','true','1') THEN 'yes'::text END AS oneway,
case when tunnel IN ( 'yes', 'true', '1' ) then 'yes'::text
else 'no'::text end as tunnel,
case when service IN ( 'parking_aisle',
'drive_through','driveway' ) then 'INT_minor'::text
else service end as service
FROM planet_osm_line
WHERE highway IS NOT NULL
OR "aeroway" IN ('apron','runway','taxiway')
OR route = 'ferry'
ORDER BY z_order
);
CREATE INDEX "route_line_way_idx" ON "route_line" USING gist (way);
DROP TABLE IF EXISTS "river";
CREATE TABLE "river" AS (
SELECT
(CASE WHEN name in ('金沙江','長江','揚子江') THEN '長江'
WHEN name in ('黃河','?????? 瑪曲','黃河 濟南市—德州市界') THEN '黃河'
WHEN name in ('喀拉額爾齊斯河','喀拉額爾齊斯河;額爾齊斯河','Джалгызагат-Хэ') THEN '額爾齊斯河'
ELSE "name" END) as "name" ,
"natural", "landuse", "waterway", "way"
FROM planet_osm_line
WHERE "waterway" IN ('river','riverbank')
ORDER BY z_order asc
);
CREATE INDEX "river_idx" ON "river" USING gist (way);
DROP TABLE IF EXISTS "water_outline";
CREATE TABLE "water_outline" AS (
SELECT "name","natural", "landuse", "waterway", "water", "way"
FROM planet_osm_line
WHERE "natural" IN ('lake','water')
OR "waterway" IN ('canal','mill_pond','river','riverbank')
OR "landuse" IN ('basin','reservoir','water')
ORDER BY z_order asc
);
CREATE INDEX "water_outline_way_idx" ON "water_outline" USING gist (way);
DROP TABLE IF EXISTS "water";
CREATE TABLE "water" AS (
SELECT "name","natural", "landuse", "waterway", "water", "way"
FROM planet_osm_polygon
WHERE "natural" IN ('lake','water')
OR "waterway" IN ('canal','mill_pond','river','riverbank')
OR "landuse" IN ('basin','reservoir','water')
ORDER BY z_order asc
);
CREATE INDEX "water_way_idx" ON "water" USING gist (way);
執(zhí)行上述SQL語句生成不同圖層进萄。
四捻脖、QGIS查看圖層
到此地圖雛形基本顯現(xiàn),但直觀看上去很亂中鼠,后面將對其進行樣式調(diào)節(jié)并發(fā)布到Geoserver中可婶。