” Well, if it can be thought, it can be done, a problem can be overcome”.

Ya, exactly after two weeks finally the problem is solved. You will be surprised to know there was not any error actually. It was just a silly mistake.

Now, talking about it less and should come to main point.

When I was retrieving a piece of OpenStreetMap data in PBF format from the site I have to create the bounding box of the desired location and seriously I selected the box containing Berlin 😉 in a hurry and didn’t noticed it. Ya, I know it is a funny moment.

As, my mentor suggested me to concentrate more on the fundamentals of the OSM and record the flow of things going on in order to solve your error(i.e. not getting map on browser). So, today I share with you the fruitful things I learned while searching upon this.

Here we will start ->

Rendering

The process of rendering a map generally means taking raw geospatial data and making a visual map from it.

Geo loosely means ‘the Earth’, as in geography or geochemistry. Spatial refers to ‘in space’, meaning anything that can be represented in terms of position, coordinates etc.

Geographic Information Systems (GIS)

GIS is a computer system for capturing, storing, checking, and displaying data related to positions on Earth’s surface. GIS can show many different kinds of data on one map. This enables people to more easily see, analyze, and understand patterns and relationships

The Global Positioning System (GPS) is a space-based navigation system that provides location and time information in all weather conditions, anywhere on or near the Earth where there is an unobstructed line of sight to four or more GPS satellites.

There are different layers like Standard, Cycle Map, Transport Map, Humanitarain showing different rendering styles. There are several layers created using Mapnik software including the default ‘Standard’ layer.

QGIS (previously also known as Quantum GIS) is a free (GNU GPL v2) and open source GIS application enabling the user to visualize, manage, edit, analyse data, and compose printable maps. It runs on Linux, Unix, Mac OSX, Windows and Android and can be downloaded free of charge from qgis.org.

OpenLayer.js

OpenLayers makes it easy to put a dynamic map in any web page. It can display map tiles, vector data and markers loaded from any source. OpenLayers has been developed to further the use of geographic information of all kinds. It is completely free,

OpenLayers has long been the standard choice for embedding a browsable OpenStreetMap view into a webpage. A mature and comprehensive library (over 400k of minimised JavaScript), it has a moderate learning curve but is capable of many applications beyond a simple “slippy map”: its features include full projection support, vector drawing, overview maps, and much more.

Now, to see your map on the browser, you need to add this(OpenLayer.js) javascript file. You may always choose any other alternative like Leaflet (a new and lighter library). I used OpenLayer.js

These files will help you to run your OpenLayer.js file offline. Now, configure these in slippymap.html file which display your local tiles on the browser.

sudo vim slippymap.html

You can give any name to this file according to your choice. Now add following text in this file:

<html><head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>OSMLocalTiles</title><linkrel="stylesheet"href="style.css"type="text/css"/><!--bringintheOpenLayersjavascriptlibrary--><scriptsrc="OpenLayers.js"></script><!--bringintheOpenStreetMapOpenLayerslayers.--><scriptsrc="OpenStreetMap.js"></script><scripttype="text/javascript">// Start position for the map (hardcoded here for simplicity)varlat=47.7;varlon=7.5;varzoom=10;varmap;//complex object of type OpenLayers.Map//Initialise the 'map' objectfunctioninit(){map=newOpenLayers.Map("map",{controls:[newOpenLayers.Control.Navigation(),newOpenLayers.Control.PanZoomBar(),newOpenLayers.Control.Permalink(),newOpenLayers.Control.ScaleLine({geodesic:true}),newOpenLayers.Control.Permalink('permalink'),newOpenLayers.Control.MousePosition(),newOpenLayers.Control.Attribution()],maxExtent:newOpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),maxResolution:156543.0339,numZoomLevels:19,units:'m',projection:newOpenLayers.Projection("EPSG:900913"),displayProjection:newOpenLayers.Projection("EPSG:4326")});layerMapnik=newOpenLayers.Layer.OSM.Mapnik("Mapnik");layerMapnik.setOpacity(0.4);map.addLayer(layerMapnik);layerCycleMap=newOpenLayers.Layer.OSM.CycleMap("CycleMap");layerCycleMap.setOpacity(0.4);map.addLayer(layerCycleMap);// This is the layer that uses the locally stored tilesvarnewLayer=newOpenLayers.Layer.OSM("Local Tiles","https://localhost/osm_tiles/${z}/${x}/${y}.png",{numZoomLevels:19,alpha:true,isBaseLayer:false});map.addLayer(newLayer);// This is the end of the layervarswitcherControl=newOpenLayers.Control.LayerSwitcher();map.addControl(switcherControl);switcherControl.maximizeControl();if(!map.getCenter()){varlonLat=newOpenLayers.LonLat(lon,lat).transform(newOpenLayers.Projection("EPSG:4326"),map.getProjectionObject());map.setCenter(lonLat,zoom);}}</script></head><!--body.onloadiscalledoncethepageisloaded(callthe'init'function)--><bodyonload="init();"><!--defineaDIVintowhichthemapwillappear.Makeittakeupthewholewindow--><divstyle="width:100%; height:100%"id="map"></div></body></html>

Mapnik option is working fine but the option “local tiles” is not showing GNE map. Mine is looking like this.

During Saturday presentation, Mandeep helped me to found an error and I am trying to find the solution.

If you know the solution please let me know.

The error character encoding is solved by adding two lines in the file slippymap.html after head tag.

Loading data into your server

Get the latest OpenStreetMap data

If you need the entire planet file, you can do it by issuing the following command (again substitute your user for username below):

sudo mkdir /usr/local/share/maps/planet
sudo chown username /usr/local/share/maps/planet
cd /usr/local/share/maps/planet
wget http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf
It nearly take 7 to 8 hours to download the map of the world.
So better to extract the small area of the map.

** Here you can download the data from http://extract.bbbike.org/ . By selecting the bound box and do select the format as pbf or any other according to your choice. You will get the email with the link having the data of the region you want and then download it .

Note : 1.Data is only Available for 48 hours to download from link you got in mail .

Importing data into the database

With the conversion tool compiled and the database prepared, the following command will insert the OpenStreetMap data you downloaded earlier into the database. This step is very disk I/O intensive; the full planet will take anywhere from 10 hours on a fast server with SSDs to several days depending on the speed of the computer performing the import. For smaller extracts the import time is much faster accordingly, and you may need to experiment with different -C values to fit within your machine’s available memory.

Intially, I was getting an error because I was working in another user. So, first check, if you have made new user as said in my previous blog, then move to that user.

The number of nodes, ways and relations processed will obviously differ by the size of the data extract you are using and the date of the data dump. The numbers shown here are not reflective of the full planet import, which is substantially larger.

Congratulations, if everything is working fine.

Testing your tileserver

Now that everything is installed, set-up and loaded, you can start up your tile server and hopefully everything is working. We’ll run it interactively first, just to make sure that everything’s working properly. Remember to substitute your username again:

Compiling the stylesheet

We now have a fully working CartoCSS stylesheet. Before Mapnik can use it, we need to compile it into XML using the command-line carto compiler. First of all, we use OSM Bright’s own preprocessor, which we need to edit for our setup:

cp configure.py.sample configure.py
gedit configure.py

Change the config line pointing to ~/Documents/Mapbox/project to /usr/local/share/maps/style instead, and change dbname from osm to gis. Save and exit.

Run the pre-processor and then carto:

./make.py
cd ../OSMBright/
carto project.mml > OSMBright.xml

Run make.py

./make.py

This will create a new folder called “build” with your new project, customized with the variables you set in configure.py and install a copy of this build to your MapBox project folder. If you open up TileMill you should see your new map in the project listing.

Click on the map to view it in the editing interface.

You now have a Mapnik XML stylesheet at /usr/local/share/maps/style/OSMBright/OSMBright.xml .

Setting up your webserver

Next we need to plug renderd and mod_tile into the Apache webserver, ready to receive tile requests.

Configure renderd

Change the the renderd settings by editing the /usr/local/etc/renderd.conf (you’ll need to do it as root via “sudo”) and change the following five lines, uncommenting (removing the ‘;’) when required. They are found in the [renderd], [mapnik] and [default] sections.

Configure mod_tile

Next, we need to tell the Apache web server about our new mod_tile installation.

Using your favourite text editor, create the file /etc/apache2/conf-available/mod_tile.conf and add one line:

LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so

Apache’s default website configuration file needs to be modified to include mod_tile settings. Modify the file /etc/apache2/sites-available/000-default.conf to include the following lines immediately after the admin e-mail address line:

LoadTileConfigFile /usr/local/etc/renderd.conf
ModTileRenderdSocketName /var/run/renderd/renderd.sock
# Timeout before giving up for a tile to be rendered
ModTileRequestTimeout 0
# Timeout before giving up for a tile to be rendered that is otherwise missing
ModTileMissingRequestTimeout 30

Tell Apache that you have added the new module, and restart it:

sudo a2enconf mod_tile
sudo service apache2 reload

Tuning your system

A tile server can put a lot of load on hardware and software. The default settings may therefore not be appropriate and a significant improvement can potentially be achieved through tuning various parameters.

Tuning postgresql

The default configuration for PostgreSQL 9.4 needs to be tuned for the amount of data you are about to add to it. Edit the file /etc/postgresql/9.4/main/postgresql.conf and make the following changes:

These changes require a kernel configuration change, which needs to be applied every time that the computer is rebooted. As root via “sudo”, edit /etc/sysctl.conf and add these lines near the top after the other “kernel” definitions:

Mapnik is an open source mapping toolkit for desktop- and server-based map rendering, written in C++.

One of its many users is the OpenStreetMap project (OSM), which uses it in combination with an Apache Web Server module (mod_tile) to render tiles that make up the OSM ‘Slippy Map’ Layer.

For handling common software tasks such as memory management, file system access, regular expressions, and XML parsing, Mapnik utilizes the Boost C++ libraries.

Mapnik runs on Linux, OS X, Windows, and BSD systems.

There is also an osm2pgsql utility,[4] that converts OpenStreetMap data into a format that can be loaded into PostgreSQL. Mapnik can then be used to render the OSM data into maps with the appearance the user wants.

Install Mapnik library

Wait! Wait! Don’t insert the following commands blindly in the terminal.

Next, we need to install the Mapnik library. Mapnik is used to render the OpenStreetMap data into the tiles used for an OpenLayers web map.

What is SCons?

SCons is a software construction tool—that is, a superior alternative to the classic “Make” build tool that we all know and love.

SCons is implemented as a Python script and set of modules, and SCons “configuration files” are actually executed as Python scripts. This gives SCons many powerful capabilities not found in other software build tools.

After

Verify that Mapnik has been installed correctly:

python
>>> import mapnik
>>>

If python replies with the second chevron prompt >>> and without errors, then Mapnik library was found by Python. Congratulations! You can leave Python with this command:

Download OSM Bright

OSM Bright is a sensible starting point for quickly making beautiful maps based on an OpenStreetMap database. It is written in the Carto styling language and can be opened as a project in TileMill.

The style is still a work in progress and you are encouraged to use the issue tracker to note missing features or problems with the current implementation.

OSM Bright depends on two large shapefiles. You will need to download and extract them before continuing.

Download them to the shp directory in the osm-bright folder. You can do this with wget like:

To begin with, we need to download both the OSM Bright stylesheet, and also the additional data resources it uses (for coastlines and the like). Again, substitute your username for username in the “chown” command below.

OpenStreetMap (OSM)

It is a collaborative project to create a free editable map of the world.

Now ,before beginning to make your own tile server, let me explain you some termonologies.

Web browser

Data provided by the OpenStreetMap project can be viewed in a web browser with JavaScript support via Hypertext Transfer Protocol (HTTP) on its official website.

OsmAnd

OsmAnd is free software for Android and iOS mobile devices that can use offline vector data from OSM. It also supports layering OSM vector data with prerendered raster map tiles from OpenStreetMap and other sources.

OpenCycleMap

It is a wonderful example of what you can do with the tools and data of OpenStreetMap catalyzed by an idea.

Tiled web map/ slippy map/ raster tile map

It is a map displayed in a browser by seamlessly joining dozens of individually requested image files over the internet.

It is currently the most popular way to display and navigate maps, replacing other methods such as WMS which typically display a single large image, with arrow buttons to navigate to nearby areas.

Google Maps was one of the first major mapping sites to use this technique. Tiled web maps may in turn be replaced by vector tiles as the standard.

Benifit of Having your own tile server

Maybe you need to have access to you map even when your internet provider is down. Or when the power is off. Or both. It won’t take much for you to see the benefit of having your own piece of OpenStreetMap infrastructure

Now it’s turn to install, setup and configure all the necessary software to operate your own tile server.

These instructions build what OpenStreetMap calls a tile server. That is, a computer that uses the OSM data set to create map images that are suitable for a web site. Not every OpenStreetMap function is supported, but you will be able to create a local map, keep it up to date and customize it for your own purposes.

Software installation

The OSM tile server stack is a collection of programs and libraries that work together to create a tile server. As so often with OpenStreetMap, there are many ways to achieve this goal and nearly all of the components have alternatives that have various specific advantages and disadvantages. This tutorial describes the most standard version that is also used on the main OpenStreetMap.org tile server.

It consists of 5 main components: Mod_tile, renderd, mapnik, osm2pgsql and a postgresql/postgis database. Mod_tile is an apache module, that serves cached tiles and decides which tiles need re-rendering – either because they are not yet cached or because they are outdated. Renderd provides a priority queueing system for rendering requests to manage and smooth out the load from rendering requests. Mapnik is the software library that does the actual rendering and is used by renderd.

In order to build these components, a variety of dependencies need to be installed first:

I am installing this OSM on Ubuntu 15.10.

If you are installing it on Ubuntu 14.04, then you have to edit the below command little bit.

Now you need to create a postgis database. The defaults of various programs assume the database is called gis and we will use the same convention in this tutorial, although this is not necessary. Substitute your username for username in the two places below. This should be the username that will render maps with Mapnik.

The default superuser for PostgreSQL is called postgres. You may need to login as this user first.

sudo -u postgres -i

Now, you will get username postgres@yourpcname

createuser username

createdb -E UTF8 -O username gis

exit

Create a Unix user for this user, too, choosing a password when prompted:

sudo useradd -m username
sudo passwd username

Set up PostGIS on the PostgreSQL database (again, substitute your username for username below):