Skip to content

Commit

Permalink
Add a SCons build script for the c++ rundemo sample program, and touc…
Browse files Browse the repository at this point in the history
…hup code and readme, closes #197
  • Loading branch information
Dane Springmeyer committed Mar 3, 2009
1 parent ea2e39b commit a79714f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
52 changes: 52 additions & 0 deletions demo/c++/SConscript
@@ -0,0 +1,52 @@
#
# This file is part of Mapnik (c++ mapping toolkit)
#
# Copyright (C) 2009 Artem Pavlenko, Dane Springmeyer
#
# Mapnik is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# $Id$

Import ('env')

prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix

source = Split(
"""
rundemo.cpp
"""
)

headers = env['CPPPATH']

boost_thread = 'boost_thread%s' % env['BOOST_APPEND']

libraries = [boost_thread]

if env['CAIRO']:
libraries.append('cairo')

if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik')
libraries.append('icuuc')
libraries.append('icudata')

rundemo = env.Program('rundemo', source, CPPPATH=headers, LIBS=libraries)

# we don't install this app because the datasource paths are relative
# and we're not going to install the sample data.
#env.Install(install_prefix + '/bin', rundemo)
#env.Alias('install', install_prefix + '/bin')
15 changes: 10 additions & 5 deletions demo/c++/readme.txt
@@ -1,13 +1,18 @@
This directory contains a simple c++ program demonstrating Mapnik API. It mimics python example with couple exceptions. This directory contains a simple c++ program demonstrating the Mapnik C++ API. It mimics the python 'rundemo.py' example with a couple exceptions.


To build (using GCC/G++ toolkit): To build it re-configure SCons with DEMO=True then rebuild::


g++ -O3 -I/usr/local/include/mapnik -I/opt/boost/include/boost-1_33_1 -I/usr/include/freetype2 -I../../agg/include -L/usr/local/lib -lmapnik rundemo.cpp -o rundemo $ python scons/scons.py configure DEMO=True
$ python scons/scons.py




To run: The sample program will be compiled (but not installed).


./rundemo
To run::

$ cd demo/c++
$ ./rundemo /usr/local/lib/mapnik


For more detailed comments have a look in demo/python/rundemo.py For more detailed comments have a look in demo/python/rundemo.py


Expand Down
23 changes: 13 additions & 10 deletions demo/c++/rundemo.cpp
Expand Up @@ -21,9 +21,6 @@
*****************************************************************************/ *****************************************************************************/
// $Id$ // $Id$


// define before any includes
#define BOOST_SPIRIT_THREADSAFE

#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp> #include <mapnik/font_engine_freetype.hpp>
Expand All @@ -33,9 +30,11 @@
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/config_error.hpp> #include <mapnik/config_error.hpp>


#if defined(HAVE_CAIRO)
// cairo // cairo
#include <mapnik/cairo_renderer.hpp> #include <mapnik/cairo_renderer.hpp>
#include <cairomm/surface.h> #include <cairomm/surface.h>
#endif


#include <iostream> #include <iostream>


Expand All @@ -44,16 +43,19 @@ int main ( int argc , char** argv)
{ {
if (argc != 2) if (argc != 2)
{ {
std::cout << "usage: ./rundemo <mapnik_install_dir>\n"; std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local/lib/mapnik\n";
std::cout << "Warning: ./rundemo looks for data in ../data/,\nTherefore must be run from within the demo/c++ folder.\n";
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }


using namespace mapnik; using namespace mapnik;
try { try {
std::cout << " running demo ... \n"; std::cout << " running demo ... \n";
std::string mapnik_dir(argv[1]); std::string mapnik_dir(argv[1]);
datasource_cache::instance()->register_datasources(mapnik_dir + "/plugins/input/shape"); std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/input/" << "\n";
freetype_engine::register_font(mapnik_dir + "/fonts/dejavu-ttf-2.14/DejaVuSans.ttf"); datasource_cache::instance()->register_datasources(mapnik_dir + "/input/");
std::cout << " looking for DejaVuSans font in... " << mapnik_dir << "/fonts/DejaVuSans.ttf" << "\n";
freetype_engine::register_font(mapnik_dir + "/fonts/DejaVuSans.ttf");


Map m(800,600); Map m(800,600);
m.set_background(color_factory::from_string("white")); m.set_background(color_factory::from_string("white"));
Expand All @@ -69,7 +71,7 @@ int main ( int argc , char** argv)
provpoly_style.add_rule(provpoly_rule_on); provpoly_style.add_rule(provpoly_rule_on);


rule_type provpoly_rule_qc; rule_type provpoly_rule_qc;
provpoly_rule_qc.set_filter(create_filter("[NAME_EN] = 'Quebec'")); provpoly_rule_qc.set_filter(create_filter("[NOM_FR] = 'Québec'"));
provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203))); provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203)));
provpoly_style.add_rule(provpoly_rule_qc); provpoly_style.add_rule(provpoly_rule_qc);


Expand Down Expand Up @@ -257,7 +259,7 @@ int main ( int argc , char** argv)
"- demo256.png\n" "- demo256.png\n"
"Have a look!\n"; "Have a look!\n";



#if defined(HAVE_CAIRO)
Cairo::RefPtr<Cairo::ImageSurface> image_surface; Cairo::RefPtr<Cairo::ImageSurface> image_surface;


image_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, m.getWidth(),m.getHeight()); image_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, m.getWidth(),m.getHeight());
Expand All @@ -283,16 +285,17 @@ int main ( int argc , char** argv)
"- cairo-demo.pdf\n" "- cairo-demo.pdf\n"
"- cairo-demo.svg\n" "- cairo-demo.svg\n"
"Have a look!\n"; "Have a look!\n";
#endif


} }
catch ( const mapnik::config_error & ex ) catch ( const mapnik::config_error & ex )
{ {
std::cerr << "### Configuration error: " << ex.what(); std::cerr << "### Configuration error: " << ex.what() << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
catch ( const std::exception & ex ) catch ( const std::exception & ex )
{ {
std::cerr << "### std::exception: " << ex.what(); std::cerr << "### std::exception: " << ex.what() << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
catch ( ... ) catch ( ... )
Expand Down

0 comments on commit a79714f

Please sign in to comment.