Changing Colours in OSM Map

Our Previous Work

  1. Creating our own OSM tile Server
  2. Adding one more Zoom Level
  3. Online Map Editing using ID Editor
  4. Changing Colours of roads in Map by editing file OSMBright.xml (which is wrong approach)

This is what we have done earlier. Today, we will talk about the right approach to change the colours of the roads, widths of the roads and much more. Now, we will study every concept related to OSM in details, whether it is its database ‘postgresql’ or XML files or any other technology used in this like mapnik, mod_tile, OpenLayers.osm etc. So, we will cover every topic in details and definitely with some good examples. For now, we will start with editing colours of map roads. For this, you need to know about the following-

  1. pallette.mss file
  2. roads.mss file
  3. project.mml file
  4. OSMBright.xml file
  5. Carto

All the files are stored in the folder OSMBright, address could be /usr/local/share/maps/style/OSMBright/.

So, let’s study each one by one:-

  1. pallette.mss – For style customization like colours and fonts, we can use this file. I wanted to change the colours of primary roads and residential roads, so I made changes in this file and after rendering got the colours of roads of my choice.
  2. roads.mss- This file contains line widths of roads at every zoom level. We can make changes here if we want to change the widths of roads. Also, it uses the colour ids we created in the palette.mss file.
  3. project.mml- This file contains all the information of data stored in the postgresql database. We have given dbname ‘gis’ to our database where details of every line, area and land is stored in file format .mml. This file contains the IDs we used in .mss files to define the properties of roads, buildings etc.
  4. Carto- Carto converts the .mml file into Mapnik XML file. It adds the Carto stylesheet with the every entity.
  5. OSMBright.xml- This is final output mapnik XML file generated with the following command- $ carto project.mml > OSMBright.xml. Now, this file is rendered to show maps on the browser with the attributes of our choice.

Changes I made-

I made some changes in the pallete.mss file to create a map having primary and secondary roads of green colour and all the residential roads with black colour. Also changed building colours to red. Then I recreated the OSMBright.xml file and performed rendering to see the output on the browser. You can see the changes hee in the following screenshots-


If, you want more details, feel free to ask any question and stay tuned for future posts.

Change all buildings Color to Red

To change all buildings Color to Red, open /usr/local/share/maps/style/OSMBright/OSMBright.xml file and then

1. In line 966 where style name building is defined (Style name=”buildings” filter-mode=”first”), change the fill colour to red i.e. #FF0000 at every zoom level.

2. Change it for polygonsymbolizer, buildingSymbolizer etc.

3. Then perform re-rendering, if needed remove the old tiles in <code>/var/lib/mod_tile </code>folder and re-generate all.

4. Now, check the result on the browser.


Increase zoom level in OSM

To increase one more zoom level in OSM, follow the given steps:-

1. Edit renderd.conf file located at /usr/local/etc/ and add this-


Now, save the file and close.

2. Edit the file /var/www/html/osm/slippymap.html

In line number 37 and 44 set numZoomLevels: 20;
In line number 39 add

map.setCenter (new OpenLayers.lonLat(659688.852138, 5710701.2962197), 20);

3. Re-render the tiles. The zoom level will be increased.

Map Editing

Map editing is quite an easy job to be done on Open Street Map. Map editing is of two types here:-

  1. Online
  2. Offline

In Online map editing, we use ID editor. It is easy to use. It contains Edit Feature Pannel, some tools and Map Pannel. Using ID, you can add points, draw lines and shapes as well. You set accessibility information and can also add notes, Wikimedia links etc.

In the other case, we can use JSOM which is far more configurable editor than ID.

You can learn both from the following links easily. This website provides really good beginners guide for both including their comparison.


Power of ‘cp’

cp command we regularly use and it seems the simple to us. Let’s know the power of this command:

What we already know about ‘cp’ is- copy files and directories.

Ways to use: cp [OPTION]..SOURC DEST

It means copy source to destination or multiple sources to the destination. So, this is the basic idea of cp. Noe, let’s explore more about this. cp command comes with so many additional options like -a, -b, -f, -d, -i and so on.

Question1: What’s then if you want to copy all folders/directories recursively? You can’t do this with simple cp command.

Solution: Use the option -r, -R or -recursive to copy all directories recursively.

Question: When you need to create a backup of each existing destination file?

Solution: Use –backup[=CONTROL]

Practice these 15 examples in the post (link shared below) by linoxide:

There are so many other examples. You can visit the following link for more detail:

Mutt-A Command Line Email Client

Mutt is a command line based Email client. It’s a very useful and powerful tool to send and read mails from command line in Unix based systems. Mutt also supports POP and IMAP protocols for receiving mails. It opens with a coloured interface to send Email which makes it user-friendly to send emails from command line.

To install mutt, run the following command:

sudo apt-get install mutt

To learn mutt, you may refer any of the following tutorials:

  1. Mutt by Mandeep Singh
  2. Mutt by Tarunika Shrivastava

PstgreSQL database connectivity with C++


Libpqxx library is required for database connectivity with C++.

C/C++ Interface APIs

Some of the important interface routines required to work with PostgreSQL database along with C++ code are explained below:

  1. pqxx::connection C( const std::string & dbstring ): This is a typedef which is used to connect to the database. Here, dbstring provides required parameters to connect to the database, for example dbname=testdb user=postgres password=hello hostaddr= port=5432.If the connection is setup successfully then it creates C with connection object which provides various useful functions public function.
  2. C.is_open(): The method is_open() is a public method of connection object and returns a boolean value. If the connection is active, then this method returns true otherwise, it returns false.
  3. C.disconnect(): This method is used to disconnect an opened database connection.
  4. pqxx::work W(C): This is a typedef which is used to create a transactional object using connection C, which ultimately will be used to execute SQL statements in transactional mode. If transaction object gets created successfully, then it is assigned to variable W which will be used to access public methods related to a transactional object.
  5. W.exec(const std::string & sql): This public method from transactional object is used to execute SQL statement.
  6. W.commit(): This is used to commit the transaction.
  7. W.abort(): This is used to rollback the transaction.
  8. pqxx::nontransaction N(C): This is a typedef which is used to create a non-transactional object using connection C, which ultimately will be used to execute SQL statements in non-transactional mode.If transaction object gets created successfully, then it is assigned to variable N which will be used to access public methods related to a non-transactional object.
  9. N.exec(const std::string & sql): This public method from a non-transactional object is used to execute SQL statement and returns a result object which is actually an interator holding all the returned records.

Create Database in PostgreSQL:

sudo -u postgres -i
createuser $USER # answer yes for superuser (although this isn't strictly) necessary)
createdb -E UTF8 -O $USER simran # simran is a name of database

Connectivity to Database:
Here, I’m sharing a simple program of database connectivity in C++ on local machine at port 5432. Here, I used backslash \ for line continuation.

#include <iostream>
#include <pqxx/pqxx> 

using namespace std;
using namespace pqxx;

int main(int argc, char* argv[])
      connection C("dbname=simran user=simran password=cohondob \
      hostaddr= port=5432");
      if (C.is_open()) {
         cout << "Opened database successfully: " << C.dbname() << endl;
      } else {
         cout << "Can't open database" << endl;
         return 1;
      C.disconnect ();
   }catch (const std::exception &e){
      cerr << e.what() << std::endl;
      return 1;

Now, let’s compile and run above program to connect to our database simran(or any you created), which is already available in your schema and can be accessed using user postgres and password sim. You can use user ID and password based on your database setting. Remember to keep the -lpqxx and -lpq in the given order! Otherwise, the linker will complain bitterly about missing functions with names starting with “PQ.”

$g++ check.cpp -lpqxx -lpq
Opened database successfully: simran

Similarly, you can create table, insert, delete or update the values and more. You can practice some basic programs, I shared on my Github account. To check what’s happening in the database, you may use the following:

sudo -u postgres psql
\c simran
# You may check everything you want, Refere to the following examples.

Check Examples:
postgresql: \d
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

postgresql: \l
postgresql: SELECT datname FROM pg_database;

postgresql: \d table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

postgresql: \d+ table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

I hope, you get the initial idea about working with PostgreSQL Database.

PostgreSQL – C/C++ Interface

Amarjeet wants to use PostgreSQL database for his project SIM. PostgreSQL is an Object Relational Database Management System with an emphasis on extensibility and standards-compliance. libpqxx library is used for its connection to C++. It is the official C++ client API for PostgreSQL database. It is available under BSD licence, so free to use. One can download the latest version from here and then follow the given steps:

tar xvfz libpqxx-4.0.tar.gz
cd libpqxx-4.0
make install

Now, find pg_hba.conf file in your PostgreSQL installation directory and add the following line:

# IPv4 local connections:
host    all         all          md5

We can start/restart postgres server in case it is not running using the following command:

[root@host]# service postgresql restart
Stopping postgresql service:                [  OK  ]
Starting postgresql service:                [  OK  ]