Create customize map with data OpenStreetMap
Recently my company is developing smart parking application and is very important path is map. Google map is great system with a lots of function but when use for particular application, there are quite a few limitations as
- Ability to customize low
- Slow update if you want to add new data
- Access restriction and charge requests
- Not self-control
So many companies choose to build their own system with high customization and fully independent. I began to learn how to build map system and search for answer for a few questions
- What is OpenStressMap ?
- How to load a small area map data ?
- What database management for saving map data ?
- How to import map ?
- How to render map ?
- How to preview map on web platform ?
Find out related issues, i obtained the following result
Openstressmap (OSM) : the map database open worldwide and you can download and use it. PostgresSQL : database management be used to store map data for OpenStressMap . PostGIS : extend of PostgresSQL to support query and search with geographic data. Osm2pgsql : tool support import data to PostGIS-PostgresSQL from file .osm Mapnik : open source C/C++ support geographic data modeling and render tiles Apache HTTP : webserver open source to serve request map tiles GEOS : C/C++ library support process geographic data Carto : CSS map-styling
Ok Let’s get started on creating on your own map system
Step 1 : Check python current version and upgrade to 2.7.6 version
-) Download python source, compile and build
$ wget –no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz $ tar xf Python-2.7.6.tar.xz $ cd Python-2.7.6 $ ./configure –prefix=/usr/local $ make && make altinstall
-) Backup current pythond version
$ mv /usr/bin/python /usr/bin/python2.6.6
-) Apply the python new version to default system
$ ln -sf /usr/local/bin/python2.7 /usr/bin/python $ head -1 /usr/bin/yum $ sed -i -e ‘s|python|python2.6.6|’ /usr/bin/yum $ head -1 /usr/bin/yum
Step 2 : Install development tools
$ yum update $ yum groupinstall ‘Development Tools’ $ yum install libpng libtiff libjpeg freetype gdal cairo pycairo sqlite geos boost curl libcurl libicu bzip2-devel libpng-devel libtiff-devel zlib-devel libjpeg-devel libxml2-devel python-setuptools proj-devel proj proj-epsg proj-nad freetype-devel libicu-devel gdal-devel sqlite-devel libcurl-devel cairo-devel pycairo-devel geos-devel protobuf-devel protobuf-c-devel lua-devel cmake proj boost-thread proj-devel autoconf automake libtool pkgconfig ragel gtk-doc glib2 glib2-devel libpng libpng-devel libwebp libtool-ltdl-devel python-devel harfbuzz harfbuzz-devel harfbuzz-icu boost-devel cabextract xorg-x11-font-utils fontconfig perl-DBD-Pg mesa-libGLU-devel postgresql-devel
Step 3 : Upgrade GCC version
$ wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo $ yum install devtoolset-2-gcc devtoolset-2-binutils $ yum install devtoolset-2-gcc-c++ devtoolset-2-gcc-gfortran $ /opt/rh/devtoolset-2/root/usr/bin/gcc –version $ scl enable devtoolset-2 bash $ source /opt/rh/devtoolset-2/enable
Step 4 : Install PostgresSQL
Step 5 : Build Boot library
Step 6 : Build and install Mapnik
$ ./configure –prefix=/opt/mapnik $ make $ make install $ sudo ldconfig
Step 7 : Build GEOS
Step 8 : Build Osm2pgsql
$ sudo yum install cmake make gcc-c++ boost-devel expat-devel zlib-devel \ bzip2-devel postgresql-devel proj-devel proj-epsg lua-devel $ git clone git://github.com/openstreetmap/osm2pgsql.git $ cd osm2pgsql $ mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH=/usr/pgsql-9.4/ $ make && make install
Step 9 : Install Apache HTTP
$ yum install httpd $ yum install httpd-devel
Step 10 : Install tile mod
$ git clone git://github.com/openstreetmap/mod_tile.git $ cd mod_tile $ ./autogen.sh $ ./configure -with-apxs=/usr/sbin/apxs
$ cp -rf mapnik/include/mapnik/* /usr/include/mapnik $ cp mapnik/include/mapnik/geometry/box2d.hpp /usr/include/mapnik $ make $ sudo make install $ sudo make install-mod_tile $ sudo ldconfig
Step 11 : Install Casto use node package manage
$ npm install -g carto
Step 12 : Config render tile mod
$ vi /usr/local/etc/renderd.conf
append the below content
[renderd] ;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/local/lib/mapnik/input font_dir=/usr/local/lib/mapnik/fonts font_dir_recurse=1
[default] URI=/osm_tiles/ TILEDIR=/var/lib/mod_tile XML=/root/openstreetmap-carto/mapnik.xml HOST=map.azstack.com TILESIZE=256
Step 13 : Config mod tile
$ vi /etc/httpd/conf.d/mod_tile.conf
LoadModule tile_module /etc/httpd/modules/mod_tile.so
ServerName map.azstack.com ServerAlias map.azstack.com DocumentRoot /var/www/html
ModTileTileDir /var/lib/mod_tile LoadTileConfigFile /usr/local/etc/renderd.conf ModTileEnableStats On ModTileBulkMode Off ModTileRequestTimeout 3 ModTileMissingRequestTimeout 10 ModTileMaxLoadOld 16 ModTileMaxLoadMissing 50 ModTileVeryOldThreshold 31536000000000 ModTileRenderdSocketName /var/run/renderd/renderd.sock ModTileCacheDurationMax 604800 ModTileCacheDurationDirty 900 ModTileCacheDurationMinimum 10800 ModTileCacheDurationMediumZoom 13 86400 ModTileCacheDurationLowZoom 9 518400 ModTileCacheLastModifiedFactor 0.20 ModTileEnableTileThrottling Off ModTileEnableTileThrottlingXForward 0 ModTileThrottlingTiles 10000 1 ModTileThrottlingRenders 128 0.2 LogLevel debug
Step 14 : Setup PostGiS
$ su -i postgres $ createuser root $ psql -d template1 -c “ALTER USER root WITH PASSWORD ‘password’;” $ psql postgres $ CREATE DATABASE gis; $ psql gis $ CREATE EXTENSION postgis; $ CREATE EXTENSION postgis_topology;
Step 15 : Import data .osm (download from OpenStressMap)
$ osm2pgsql –slim -d gis_az -C 1600 –number-process 1 -S /usr/local/share/osm2pgsql/default.style map-hieu.osm
Step 16 : Install Casto
$ git clone git://github.com/gravitystorm/openstreetmap-carto.git $ cd openstreetmap-carto $ git checkout `git rev-list -n 1 –before=”2016-12-04 00:00″ master`
# Compile and download shape files $ carto project.mml > mapnik.xml $ scripts/get-shapefiles.py
Step 17 : Start Apache HTTP with render mode
$ systemctl start httpd $ mkdir /var/run/renderd $ mkdir /var/lib/mod_tile $ renderd -f -c /usr/local/etc/renderd.conf & $ render_list -m default -a -z 0 -Z 17 -s /var/run/renderd/renderd.sock
Advertisements