以下資料形成參考:http://blog.csdn.net/goldenhawking/article/details/7952303
GIS相關(guān)的開(kāi)源軟件和Ubuntu結(jié)合的更好狰住,很多依賴都可以直接從源安裝惧笛,在CentOS7上折騰確實(shí)是艱難的決定壶辜。
更進(jìn)一步,OSGEO這個(gè)組織對(duì)Lubuntu16.04做了進(jìn)一步的改造铛漓,直接推出安裝幾乎所有GIS相關(guān)軟件的ISO鏡像溯香,真是我這種初學(xué)者的好福利啊。詳情請(qǐng)看'http://www.osgeo.org/'
1.系統(tǒng)部署
絕大部分軟件都已經(jīng)是安裝好的狀態(tài)浓恶,少部分需要手動(dòng)安裝玫坛。
1.1 安裝系統(tǒng)依賴
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install libmapnik-dev libmapnik3.0 apache2-dev openssh-server lrzsz p7zip-full ttf-unifont
1.2 提升www-data權(quán)限
sudo vim /etc/passwd
改為/bin/bash
2.數(shù)據(jù)庫(kù)配置
參考 Centos7部署PostGIS 部分
3.配置mapnik-style
3.1 下載mapnik-style
sudo mkdir /var/lib/mod_tile
cd /var/lib/mod_tile
sudo chown www-data:www-data -R /var/lib/mod_tile
sudo su www-data
svn co http://svn.openstreetmap.org/applications/rendering/mapnik mapnik-style
注意:
vim mapnik-style/inc/fontset-settings.xml.inc.template
替換
unifont Medium 為 Unifont Medium
3.2下載世界,海岸線地圖數(shù)據(jù)
以下五個(gè)文件從mapnik-style中g(shù)et-coastlines.sh文件獲取下載地址包晰,可能有變化
http://tile.openstreetmap.org/world_boundaries-spherical.tgz
http://tile.openstreetmap.org/processed_p.tar.bz2
http://tile.openstreetmap.org/shoreline_300.tar.bz2
http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_boundary_lines_land.zip
解壓world_boundaries下載步驟中的五個(gè)文件湿镀,取出所有的文件,并放到world_boundaries中
sudo mv world_boundaries /usr/local/share/
3.3 生成OSM.XML
cd /mapnik-style
./generate_xml.py --world_boundaries=/usr/local/share/world_boundaries --host=127.0.0.1 --port=5432 --user=osmgis --password=1 --dbname=osmgis
3.4測(cè)試渲染
./generate_image.py
保存后伐憾,直接執(zhí)行勉痴,如果沒(méi)錯(cuò),就出現(xiàn)了 image.png
4.部署mod_tile
git clone https://github.com/openstreetmap/mod_tile
4.1 編譯與安裝
cd mod_tile
./autogen.sh
./configure
make
sudo make install
sudo make install-mod_tile
sudo ldconfig
4.2導(dǎo)入mod_tile
sudo vim /etc/apache2/mods-available/mod_tile.load
里面添加一行:
LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so
生效
cd /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/mod_tile.load
5.配置瓦片渲染后臺(tái)服務(wù)renderd
5.1創(chuàng)建文件夾
sudo mkdir /var/run/renderd
sudo chown www-data /var/run/renderd
5.2配置renderd
sudo vim /usr/local/etc/renderd.conf
做一下配置:
[renderd]
;把socketname設(shè)置到剛才創(chuàng)建的文件夾里
socketname=/var/run/renderd/renderd.sock
num_threads=4
tile_dir=/var/lib/mod_tile
stats_file=/var/run/renderd/renderd.stats
[mapnik]
plugins_dir=/usr/lib/mapnik/3.0/input
font_dir=/usr/share/fonts/truetype
font_dir_recurse=1
[default]
URI=/osm_tiles/
XML=/var/lib/mod_tile/mapnik-style/osm.xml
HOST=localhost
;HTCPHOST=proxy.openstreetmap.org
5.3 設(shè)置用戶訪問(wèn)網(wǎng)頁(yè)的入口點(diǎn)
sudo vim /etc/apache2/sites-available/000-default.conf
加入
LoadTileConfigFile /usr/local/etc/renderd.conf
ModTileRenderdSocketName /var/run/renderd/renderd.sock
ModTileRequestTimeout 0
ModTileMissingRequestTimeout 30
5.4測(cè)試
cd /var/lib/mod_tile
sudo su www-data
renderd -f -c /usr/local/etc/renderd.conf
網(wǎng)頁(yè)打開(kāi):
http://192.168.15.137/osm_tiles/0/0/0.png
修改時(shí)間戳:
sudo touch /var/lib/mod_tile/planet-import-complete
sudo chown www-data /var/lib/mod_tile/planet-import-complete
6.OpenLayer
wget http://www.openstreetmap.org/openlayers/OpenStreetMap.js
6.1部署
sudo mv OpenStreetMap.js /var/www/html/openlayers
sudo chmod +r -R /var/www/html/openlayers
6.2html
sudo vim /var/www/html/map.html
寫入
<html>
<head>
<title>OSM Local Tiles</title>
<link rel="stylesheet" href="/openlayers/theme/default/style.css" type="text/css" />
<!-- bring in the OpenLayers javascript library
(here we bring it from the remote site, but you could
easily serve up this javascript yourself) -->
<script src="/openlayers/OpenLayers.js"></script>
<!-- bring in the OpenStreetMap OpenLayers layers.
Using this hosted file will make sure we are kept up
to date with any necessary changes -->
<script src="/openlayers/OpenStreetMap.js"></script>
<script type="text/javascript">
// Start position for the map (hardcoded here for simplicity)
var lat=31.27386;
var lon=121.48132;
var zoom=7;
var map; //complex object of type OpenLayers.Map
//Initialise the 'map' object
function init() {
map = new OpenLayers.Map ("map", {
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
//new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine({geodesic: true}),
new OpenLayers.Control.Permalink('permalink'),
new OpenLayers.Control.KeyboardDefaults(),
new OpenLayers.Control.NavToolbar(),
new OpenLayers.Control.Attribution()],
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0339,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
} );
// This is the layer that uses the locally stored tiles
var newLayer = new OpenLayers.Layer.OSM("Local Tiles", "/osm_tiles/${z}/${x}/${y}.png", {numZoomLevels: 19, transitionEffect: "resize"});
map.addLayer(newLayer);
var switcherControl = new OpenLayers.Control.LayerSwitcher();
map.addControl(switcherControl);
var vector_layer = new OpenLayers.Layer.Vector('Editable Vectors');
map.addControl(new OpenLayers.Control.EditingToolbar(vector_layer));
map.addLayer(vector_layer);
map.addControl(new OpenLayers.Control.Graticule({visible: false}));
var mousepos = new OpenLayers.Control.MousePosition({div: document.getElementById('mousepos_div')});
map.addControl(mousepos);
//mousepos.moveTo(new OpenLayers.Pixel(64,0));
map.addControl(new OpenLayers.Control.OverviewMap());
/*
var navigationT = new OpenLayers.Control.TouchNavigation({
dragPanOptions:{
enableKinetic: true
}
});
map.addControl(navigationT);
*/
if( ! map.getCenter() ){
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter (lonLat, zoom);
}
}
</script>
</head>
<!-- body.onload is called once the page is loaded (call the 'init' function) -->
<body onload="init();">
<!-- define a DIV into which the map will appear. Make it take up the whole window -->
<div style="width: 100%; height: 93%" id="map">
</div>
<P><a href='/index.html'>start screen</a></P>
<div style="width: 100%; height: 5%" id="mousepos_div">
</div>
</body>
</html>
6.3訪問(wèn)測(cè)試
http://192.168.15.137/map.html