Geoserver+postSQL+openlayer实现路径规划
生活随笔
收集整理的這篇文章主要介紹了
Geoserver+postSQL+openlayer实现路径规划
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Geoserver+postSQL+openlayer實現(xiàn)路徑規(guī)劃
轉(zhuǎn)載請注明出處!!!
轉(zhuǎn)載請注明出處!!!
轉(zhuǎn)載請注明出處!!!
獲取路網(wǎng)數(shù)據(jù),可以自己模擬,可以去osm網(wǎng)站下載,將路網(wǎng)數(shù)據(jù)存入postSQL數(shù)據(jù)庫
文檔:獲取貴陽市路網(wǎng)數(shù)據(jù).note
鏈接:http://note.youdao.com/noteshare?id=20acd381a39bb6bed683a33ac28331c4
將獲取的路網(wǎng)數(shù)據(jù)用arcmap打開,建立拓撲打斷點。
右側(cè)目錄點擊文件夾連接文件夾
打開arcmap,右擊圖層—添加數(shù)據(jù)
在文件夾連接里選擇shp數(shù)據(jù)導入,
原始路網(wǎng)結(jié)果展示
右鍵點擊開始編輯
打開地理----arctoolbox----數(shù)據(jù)管理工具(Data management tools)——>要素(Features)——>要素轉(zhuǎn)線(Feature to line)這樣就可以得到一條一條線段
將打斷點之后的數(shù)據(jù)導出為shp文件,導入postSQL中,
CREATE EXTENSION postgis; CREATE EXTENSION pgrouting; CREATE EXTENSION postgis_topology; CREATE EXTENSION fuzzystrmatch; CREATE EXTENSION address_standardizer;--添加起點idALTER TABLE testline ADD COLUMN source integer;--添加終點idALTER TABLE testline ADD COLUMN target integer;--添加道路權重值ALTER TABLE testline ADD COLUMN length double precision;--為sampledata表創(chuàng)建拓撲布局,即為source和target字段賦值SELECT pgr_createTopology('testline',0.0001, 'geom', 'gid');--為source和target字段創(chuàng)建索引CREATE INDEX source_idx ON testline("source");CREATE INDEX target_idx ON testline("target");--為length賦值 //或者用已有的字段長度賦值,下面shape_length為shp中已有的長度屬性 update testline set length =st_length(geom);或者 UPDATE crossroad SET length = shape_length; --將長度值賦給reverse_cost,作為路線選擇標準 ALTER TABLE crossroad ADD COLUMN reverse_cost double precision; UPDATE crossroad SET reverse_cost =length;使用pgr_dijkstra算法查詢 SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_dijkstra(' SELECT gid AS id, source::integer, target::integer, length::double precision AS cost FROM crossroad, 1, 9, false, false);4用geoserver發(fā)布圖層(路網(wǎng)圖層).用geoserver發(fā)布視圖(最短路徑) 第一個為路網(wǎng),第二個為道路交匯點發(fā)布完成后,發(fā)布視圖 SELECT seq, id1 AS node, id2 AS edge, cost,geom FROM pgr_dijkstra(' SELECT gid AS id, source::integer, target::integer, length::double precision AS cost FROM testline', %from%, %to%, false, false) as di join testline pt on di.id2 = pt.gid編寫前端頁面調(diào)用地圖圖層
<html> <head><link rel="stylesheet" href="js/ol.css" type="text/css"><style>.map {height: 90vh;width: 100%;}</style><script src="js/jquery-1.12.3.min.js"></script><script src="js/ol.js"></script><title>路徑規(guī)劃</title> </head> <body><div><input type="number" id = "fromInput"><input type="number" id = "toInput"><button type="button" id="add">路徑查詢</button></div><div id = 'map'></div><script src="js/get_rout.js"></script><script>$(document).ready(function(){initMap(); });$('#add').click(function(){var from = $("#fromInput").val();var to = $("#toInput").val();getRoutingByAjax(from,to);}); </script></body> </html>js文件內(nèi)容
var map; function initMap() {var tileLayer = new ol.layer.Tile({title: "天地圖底圖",source: new ol.source.XYZ({url: "http://t0.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=你的密鑰"})});//標注圖層var tileMark = new ol.layer.Tile({title: "天地圖文字標注",source: new ol.source.XYZ({url: "http://t0.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=你的密鑰"})});// 路網(wǎng)圖層數(shù)據(jù)var roadLayer = new ol.layer.Tile({source: new ol.source.TileWMS({url: 'http://localhost:8080/geoserver/workspace/wms',params: { 'LAYERS': 'workspace:export_output', 'TILED': true },// serverType: 'geoserver',}),})//道路交匯處打斷點var roadPoint = new ol.layer.Tile({source: new ol.source.TileWMS({url: 'http://localhost:8080/geoserver/workspace/wms',params: { 'LAYERS': 'workspace:export_output_vertices_pgr', 'TILED': true },// serverType: 'geoserver',}),})map = new ol.Map({target: 'map',view: new ol.View({center: [110.52650, 29.12068],zoom: 16,projection: "EPSG:4326"}),layers: [tileLayer,//順序不能出錯tileMark,roadLayer,roadPoint]}); }var routeSource = new ol.source.Vector(); var routeLayer = new ol.layer.Vector({source: routeSource,style: new ol.style.Style({stroke: new ol.style.Stroke({color: 'green',width: 5})}),name: 'route' });function getRoutingByAjax(fromID, toID) {clearLayer();var data = {'service': 'wfs','version': '1.0.0','request': 'GetFeature','typeName': 'workspace:testSqlView1','outputFormat': 'application/json','viewparams': 'from:' + fromID + ';to:' + toID};$.ajax({type: "POST",url: "http://localhost:8080/geoserver/workspace/wfs",data: data}).then(function (response) {var features = new ol.format.GeoJSON().readFeatures(response);routeSource.addFeatures(features);}) }function clearLayer() {map.removeLayer(routeLayer);map.addLayer(routeLayer);routeSource.clear(); }結(jié)果展示
參考:
https://blog.csdn.net/u014529917/article/details/72866436
https://blog.csdn.net/u012413551/article/details/85217105
https://blog.csdn.net/u012413551/article/details/85145966
總結(jié)
以上是生活随笔為你收集整理的Geoserver+postSQL+openlayer实现路径规划的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue 实例数据绑定 指令 事件
- 下一篇: plSQL中修改代码字体的大小