OSM Continued …

Stylesheet configuration

Now that all of the necessary software is installed, you will need to download and configure a stylesheet.

For these instructions we will use OSM Bright, a good all-purpose stylesheet with a style reminiscent of popular webmaps. (If you’d like a map that looks exactly the same as the one on openstreetmap.org, you’ll need to use the openstreetmap-carto project which has its own installation instructions.)

Together with most modern stylesheets, OSM Bright is written in a stylesheet language called CartoCSS which is reminiscent of the CSS used for web design. Its main advantage is easy reading/writing, leading to rapid prototyping (using utilities such as Tilemill, Kosmtik or Sputnik). However, you do typically need to adapt third-party CartoCSS stylesheets for your own server setup, and then compile them to the XML required by Mapnik; that’s what we’ll do here.

We will use /usr/local/share/maps/style as a common directory for our stylesheet files and resources.

Download OSM Bright

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.

sudo mkdir -p /usr/local/share/maps/style
sudo chown username /usr/local/share/maps/style
cd /usr/local/share/maps/style
wget https://github.com/mapbox/osm-bright/archive/master.zip
wget http://data.openstreetmapdata.com/simplified-land-polygons-complete-3857.zip
wget http://data.openstreetmapdata.com/land-polygons-split-3857.zip
mkdir ne_10m_populated_places_simple
cd ne_10m_populated_places_simple
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places_simple.zip
unzip ne_10m_populated_places_simple.zip
rm ne_10m_populated_places_simple.zip
cd ..

We then move the downloaded data into the osm-bright-master project directory:

unzip '*.zip'
mkdir osm-bright-master/shp
mv land-polygons-split-3857 osm-bright-master/shp/
mv simplified-land-polygons-complete-3857 osm-bright-master/shp/
mv ne_10m_populated_places_simple osm-bright-master/shp/

To improve performance, we create index files for the larger shapefiles:

cd osm-bright-master/shp/land-polygons-split-3857
shapeindex land_polygons.shp
cd ../simplified-land-polygons-complete-3857/
shapeindex simplified_land_polygons.shp
cd ../..

Configuring OSM Bright

The OSM Bright stylesheet now needs to be adjusted to include the location of our data files. Edit the file osm-bright/osm-bright.osm2pgsql.mml in your favourite text editor, for example:

vim osm-bright/osm-bright.osm2pgsql.mml

Be careful while editing this file, there should not be any syntax error. Find the lines with URLs pointing to shapefiles (ending .zip) and replace each one with these appropriate pairs of lines:

"file": "/usr/local/share/maps/style/osm-bright-master/shp/land-polygons-split-3857/land_polygons.shp",
"type": "shape"

"file": "/usr/local/share/maps/style/osm-bright-master/shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp",
"type": "shape",

"file": "/usr/local/share/maps/style/osm-bright-master/shp/ne_10m_populated_places_simple/ne_10m_populated_places_simple.shp",
"type": "shape"

Note that we are also adding “type”: “shape” to each one. (If you’re using nano, to save, now press ctrl-X and Y.)

Finally, in the section dealing with “ne_places”, replace the “srs” and “srs-name” lines with this one line:

"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

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
nano 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

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.

Problem I faced at this step:

When I did this on my local computer, it was working fine. But I tried this on some other system (Experimental Server) in my college, It gave the following error on running the command:

carto project.mml > OSMBright.xml

Initially, I were getting

module.js:340
throw err;
^
Error: Cannot find module ‘underscore’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/usr/lib/nodejs/carto/lib/carto/parser.js:3:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

The suggested solution on Internet was to manually install ‘underscore’ module. But this didn’t work. Dependencies were installed fine. But when I again tried to use the
command carto then got the given error-

$# carto project.mml > OSMBright.xml

/usr/lib/nodejs/carto/lib/carto/tree/reference.js:19
if (mapnik_reference.version.hasOwnProperty(version)) {
^
TypeError: Cannot call method ‘hasOwnProperty’ of undefined
at Object.ref.setVersion
(/usr/lib/nodejs/carto/lib/carto/tree/reference.js:19:34)
at /usr/lib/nodejs/carto/lib/carto/tree/reference.js:209:5
at Object.<anonymous>
(/usr/lib/nodejs/carto/lib/carto/tree/reference.js:213:3)
    at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at exports.(anonymous function)
(/usr/lib/nodejs/carto/lib/carto/index.js:73:5)

Then Dr. Rai issued following command on Exp:

dpkg -i –force-overwrite nodejs-legacy_0.10.25~dfsg2-2ubuntu1_all.deb
apt-get -f install
apt-get purge nodejs-legacy nodejs
apt-get install nodejs
npm install millstone carto

and now:

carto project.mml > OSMBright.xml

Give following error:

-su: /usr/bin/carto: No such file or directory

After this, I simply did npm install -g carto

This worked fine for a while. OSMBright.xml generated with complete details. After sometime it stopped working again. May be carto was creating a conflict between the old carto files. Someone has already did the same work before, so there were some files inside.

Vigas simply did this:

$ sudo mv carto cartoold

$ sudo npm install -g carto

Now, again it was working fine. Proceeding with further steps.

 

Advertisements

Published by

kaurdavinder

I am the one who discover myself daily through reading, writing, interacting with people and expressing my thoughts to inspire them if I would be able to bring a little change to the society through my work. I write blogs, participate in various social activities and want to be a Professional Speaker. Currently, I am pursuing my post graduation in Computer Applications from Guru Nanak Dev Engineering College, Ludhiana and I’m very much active in many technical & social communities.

2 thoughts on “OSM Continued …”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s