autocad檔案(dxf、dwg)釋出到 Geoserver作為地圖圖層
目錄
一、Geoserver服務執行
二、dwg檔案轉dxf
三、dxf轉shp
四、shp轉檔案檢視
五、shp檔案style設定
六、shp檔案匯入到Geoserver
七、open Layer 展示
準備環境
一、Geoserver服務執行
java sdk、tomcat、Geoserver
具體配置過程參見:
二、dwg檔案轉dxf
工具軟體:Autodesk AutoCAD 2016
Autodesk AutoCAD 2016外掛:Arcgis for AutoCAD
這一步主要的目的是轉化格式和座標。
1.使用AutoCAD開啟檔案、去掉多餘的圖層和資訊
2.載入ArcGIS for AutoCAD調整座標和檔案大小
(1)載入過程及操作參見
ArcGIS for AutoCAD輕鬆實現ArcGIS 與 AutoCAD互操作
(2)分配座標。這一步很關鍵,關係到與原有的shp檔案是否在同一座標系。
本部落格採用的座標系ESPG:900913(來自原有的shp檔案,open street map匯出的shp檔案和osm檔案採用的就是這一座標系)
(3)選擇座標系,ArcGIS for AutoCAD安裝目錄 D:\Program Files\ArcGIS for AutoCAD 355\Coordinate Systems\Projected Coordinate Systems\World 下的
WGS 1984 Web Mercator.prj
座標說明參見 https://www.cnblogs.com/arxive/p/6103358.html?utm_source=itdadao&utm_medium=referral
(4)選擇地圖型別,選擇world Imagery
(5)地圖匯入後的效果,如果一開始看不到地圖,就縮放地圖。此時AutoCAD的座標原點與之前選擇的地理座標原點重合。(ESPG:900913的座標原點在非洲西部的大西洋中)
(6)整體顯示
(6)平移圖形到目標位置,並縮放圖形至目標大小。
(7)儲存檔案為dxf或者dwg格式。
三、dxf或者dwg轉shp
工具:QGIS 3.4.1
(1)匯入dxf或者dwg,如果在Project中沒有看到Import/Export -> Import Layers from dwg/dxf ,那麼跳到(2)為QGIS新增外掛 “DXF Importer /DXF2Shp ”。
不記得該功能是軟體自帶,還是外掛新增的。
(2)新增外掛DXF Importer /DXF2Shp。在plugins|installed 視窗中 搜尋安裝 該外掛
(3)匯入配置填寫如圖,我的圖層取名為“EPSG:900913room”.
我匯入dwg檔案的時候報錯,丟掉了一些需要顯示的內容,匯入dxf時沒有報錯。
(4)匯入以後,軟體左下方出現圖層。選中新匯入的圖層並右擊,選擇“Zoom to Group ”或者“Zoom to Layer”。
顯示效果如圖,圖片中同時顯示了Open Street Map 的 gis_osm_roads_free_1.shp 檔案作為參照。
對比效果
(4)匯出為shp檔案 右擊圖層 選擇 Export -> Save Feature AS ... 彈出下圖對話方塊
將gruop下的各個圖層匯出到shp檔案
(4)檔案
四、shp轉檔案檢視
工具:uDig
uDig,不僅是shp檔案檢視工具跟重要的是,設計渲染樣式的工具
具體操作參見
如何用uDig美化地圖併發布到GeoServer
https://blog.csdn.net/coderwait/article/details/80453162
五、shp檔案style設定
同上
六、shp檔案匯入到Geoserver
具體操作見 如何用uDig美化地圖併發布到GeoServer
(1)圖層釋出時,座標系選擇。
釋出完成後顯示。
七、Openlayers 展示
(1)顯示結果。藍色的線條為Geoserver服務提供的資料,我在Geoserver中匯入了Open steet map的道路(OSM)資料 一併顯示出來了,藍色的小方塊是dwg的檔案內容
顯示效果較差主要是因為圖層的style檔案沒有配置
整體效果,open Street map 中 中國的資料沒有臺灣和藏南
(2)OpenLayers3 html 原始碼。
<!DOCTYPE html> <html> <head> <title>Tiled WMS</title> <link rel="stylesheet" href="https://openlayers.org/en/v3.20.1/css/ol.css" type="text/css"> <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> <script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script> </head> <body> <div id="map" class="map"></div> <script> var layers = [ //OpenSteetMap地圖來源網路 new ol.layer.Tile({ source: new ol.source.OSM() }), //OpenSteetMap 道路圖層 new ol.layer.Tile({ //extent: [-13884991, 2870341, -7455066, 6338219], source: new ol.source.TileWMS({ url: 'http://localhost:8080/geoserver/wms', params: {'LAYERS': 'china:planet_osm_roads_big', 'TILED': true}, serverType: 'geoserver' }) }), //dxf檔案的圖層 new ol.layer.Tile({ // extent: [-13884991, 2870341, -7455066, 6338219], source: new ol.source.TileWMS({ url: 'http://192.168.0.157:8080/geoserver/wms', params: {'LAYERS': 'chinaoutline:lines', 'TILED': true}, serverType: 'geoserver' }) }), new ol.layer.Tile({ // extent: [-13884991, 2870341, -7455066, 6338219], source: new ol.source.TileWMS({ url: 'http://192.168.0.157:8080/geoserver/wms', params: {'LAYERS': 'chinaoutline:polylines', 'TILED': true}, serverType: 'geoserver' }) }) ]; var map = new ol.Map({ layers: layers, target: 'map', view: new ol.View({ center: [12570580.877,3253259.398 ], zoom: 10 }) }); </script> </body> </html>