2006-10-03 10:06:38 +00:00
|
|
|
/*****************************************************************************
|
2011-11-14 03:54:32 +00:00
|
|
|
*
|
2006-10-03 10:06:38 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 13:04:25 +00:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2006-10-03 10:06:38 +00:00
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2006-05-08 20:29:13 +00:00
|
|
|
|
2006-10-04 11:22:18 +00:00
|
|
|
#include <mapnik/map.hpp>
|
2012-07-25 01:35:41 +00:00
|
|
|
#include <mapnik/layer.hpp>
|
|
|
|
#include <mapnik/rule.hpp>
|
2013-01-04 02:58:44 +00:00
|
|
|
#include <mapnik/line_symbolizer.hpp>
|
|
|
|
#include <mapnik/polygon_symbolizer.hpp>
|
|
|
|
#include <mapnik/text_symbolizer.hpp>
|
2012-07-25 01:35:41 +00:00
|
|
|
#include <mapnik/feature_type_style.hpp>
|
2012-05-09 11:39:23 +00:00
|
|
|
#include <mapnik/graphics.hpp>
|
2006-10-04 11:22:18 +00:00
|
|
|
#include <mapnik/datasource_cache.hpp>
|
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
|
|
|
#include <mapnik/agg_renderer.hpp>
|
2012-02-12 11:46:07 +00:00
|
|
|
#include <mapnik/expression.hpp>
|
2006-10-04 11:22:18 +00:00
|
|
|
#include <mapnik/color_factory.hpp>
|
|
|
|
#include <mapnik/image_util.hpp>
|
2006-10-03 08:44:04 +00:00
|
|
|
|
2009-03-03 19:28:26 +00:00
|
|
|
#if defined(HAVE_CAIRO)
|
2009-01-15 22:53:29 +00:00
|
|
|
#include <mapnik/cairo_renderer.hpp>
|
2013-01-09 20:48:05 +00:00
|
|
|
#include <mapnik/cairo_context.hpp>
|
2009-03-03 19:28:26 +00:00
|
|
|
#endif
|
2009-01-15 22:53:29 +00:00
|
|
|
|
2006-05-08 20:29:13 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2008-01-09 11:48:39 +00:00
|
|
|
|
2006-05-08 20:29:13 +00:00
|
|
|
int main ( int argc , char** argv)
|
2011-11-14 03:54:32 +00:00
|
|
|
{
|
2006-09-17 19:45:01 +00:00
|
|
|
if (argc != 2)
|
|
|
|
{
|
2013-01-10 20:48:56 +00:00
|
|
|
std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local\n";
|
2009-03-03 19:28:26 +00:00
|
|
|
std::cout << "Warning: ./rundemo looks for data in ../data/,\nTherefore must be run from within the demo/c++ folder.\n";
|
2006-09-17 19:45:01 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2007-03-13 22:46:01 +00:00
|
|
|
using namespace mapnik;
|
2013-01-11 14:50:49 +00:00
|
|
|
const std::string srs_lcc="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 \
|
|
|
|
+datum=NAD83 +units=m +no_defs";
|
2013-01-28 18:48:13 +00:00
|
|
|
const std::string srs_merc="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 \
|
|
|
|
+y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over";
|
2013-01-11 14:50:49 +00:00
|
|
|
|
2008-01-08 21:09:16 +00:00
|
|
|
try {
|
|
|
|
std::cout << " running demo ... \n";
|
2008-01-09 11:48:39 +00:00
|
|
|
std::string mapnik_dir(argv[1]);
|
2013-01-10 20:48:56 +00:00
|
|
|
std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/lib/mapnik/input/" << "\n";
|
|
|
|
datasource_cache::instance().register_datasources(mapnik_dir + "/lib/mapnik/input/");
|
|
|
|
std::cout << " looking for DejaVuSans font in... " << mapnik_dir << "/lib/mapnik/fonts/DejaVuSans.ttf" << "\n";
|
|
|
|
freetype_engine::register_font(mapnik_dir + "/lib/mapnik/fonts/DejaVuSans.ttf");
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-01-08 21:09:16 +00:00
|
|
|
Map m(800,600);
|
2012-08-29 17:44:04 +00:00
|
|
|
m.set_background(parse_color("white"));
|
2013-01-11 14:50:49 +00:00
|
|
|
m.set_srs(srs_merc);
|
2008-06-29 10:58:29 +00:00
|
|
|
// create styles
|
|
|
|
|
|
|
|
// Provinces (polygon)
|
|
|
|
feature_type_style provpoly_style;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-01-13 21:35:01 +00:00
|
|
|
rule provpoly_rule_on;
|
2009-12-16 20:02:06 +00:00
|
|
|
provpoly_rule_on.set_filter(parse_expression("[NAME_EN] = 'Ontario'"));
|
2009-01-14 12:43:26 +00:00
|
|
|
provpoly_rule_on.append(polygon_symbolizer(color(250, 190, 183)));
|
2008-06-29 10:58:29 +00:00
|
|
|
provpoly_style.add_rule(provpoly_rule_on);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-01-13 21:35:01 +00:00
|
|
|
rule provpoly_rule_qc;
|
2012-04-04 22:17:37 +00:00
|
|
|
provpoly_rule_qc.set_filter(parse_expression("[NOM_FR] = 'Québec'"));
|
2009-01-14 12:43:26 +00:00
|
|
|
provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203)));
|
2008-06-29 10:58:29 +00:00
|
|
|
provpoly_style.add_rule(provpoly_rule_qc);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("provinces",provpoly_style);
|
|
|
|
|
|
|
|
// Provinces (polyline)
|
|
|
|
feature_type_style provlines_style;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2009-01-14 12:43:26 +00:00
|
|
|
stroke provlines_stk (color(0,0,0),1.0);
|
2008-06-29 10:58:29 +00:00
|
|
|
provlines_stk.add_dash(8, 4);
|
|
|
|
provlines_stk.add_dash(2, 2);
|
|
|
|
provlines_stk.add_dash(2, 2);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-01-13 21:35:01 +00:00
|
|
|
rule provlines_rule;
|
2008-06-29 10:58:29 +00:00
|
|
|
provlines_rule.append(line_symbolizer(provlines_stk));
|
|
|
|
provlines_style.add_rule(provlines_rule);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("provlines",provlines_style);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
|
|
|
// Drainage
|
2008-06-29 10:58:29 +00:00
|
|
|
feature_type_style qcdrain_style;
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2011-01-13 21:35:01 +00:00
|
|
|
rule qcdrain_rule;
|
2009-12-16 20:02:06 +00:00
|
|
|
qcdrain_rule.set_filter(parse_expression("[HYC] = 8"));
|
2009-01-14 12:43:26 +00:00
|
|
|
qcdrain_rule.append(polygon_symbolizer(color(153, 204, 255)));
|
2008-06-29 10:58:29 +00:00
|
|
|
qcdrain_style.add_rule(qcdrain_rule);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("drainage",qcdrain_style);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Roads 3 and 4 (The "grey" roads)
|
2011-11-14 03:54:32 +00:00
|
|
|
feature_type_style roads34_style;
|
2011-01-13 21:35:01 +00:00
|
|
|
rule roads34_rule;
|
2009-12-16 20:02:06 +00:00
|
|
|
roads34_rule.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
|
2009-01-14 12:43:26 +00:00
|
|
|
stroke roads34_rule_stk(color(171,158,137),2.0);
|
2008-06-29 10:58:29 +00:00
|
|
|
roads34_rule_stk.set_line_cap(ROUND_CAP);
|
|
|
|
roads34_rule_stk.set_line_join(ROUND_JOIN);
|
|
|
|
roads34_rule.append(line_symbolizer(roads34_rule_stk));
|
|
|
|
roads34_style.add_rule(roads34_rule);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("smallroads",roads34_style);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2006-05-08 20:29:13 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Roads 2 (The thin yellow ones)
|
|
|
|
feature_type_style roads2_style_1;
|
2011-01-13 21:35:01 +00:00
|
|
|
rule roads2_rule_1;
|
2009-12-16 20:02:06 +00:00
|
|
|
roads2_rule_1.set_filter(parse_expression("[CLASS] = 2"));
|
2009-01-14 12:43:26 +00:00
|
|
|
stroke roads2_rule_stk_1(color(171,158,137),4.0);
|
2008-06-29 10:58:29 +00:00
|
|
|
roads2_rule_stk_1.set_line_cap(ROUND_CAP);
|
|
|
|
roads2_rule_stk_1.set_line_join(ROUND_JOIN);
|
|
|
|
roads2_rule_1.append(line_symbolizer(roads2_rule_stk_1));
|
|
|
|
roads2_style_1.add_rule(roads2_rule_1);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("road-border", roads2_style_1);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
feature_type_style roads2_style_2;
|
2011-01-13 21:35:01 +00:00
|
|
|
rule roads2_rule_2;
|
2009-12-16 20:02:06 +00:00
|
|
|
roads2_rule_2.set_filter(parse_expression("[CLASS] = 2"));
|
2009-01-14 12:43:26 +00:00
|
|
|
stroke roads2_rule_stk_2(color(255,250,115),2.0);
|
2008-06-29 10:58:29 +00:00
|
|
|
roads2_rule_stk_2.set_line_cap(ROUND_CAP);
|
|
|
|
roads2_rule_stk_2.set_line_join(ROUND_JOIN);
|
|
|
|
roads2_rule_2.append(line_symbolizer(roads2_rule_stk_2));
|
|
|
|
roads2_style_2.add_rule(roads2_rule_2);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("road-fill", roads2_style_2);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Roads 1 (The big orange ones, the highways)
|
|
|
|
feature_type_style roads1_style_1;
|
2011-01-13 21:35:01 +00:00
|
|
|
rule roads1_rule_1;
|
2009-12-16 20:02:06 +00:00
|
|
|
roads1_rule_1.set_filter(parse_expression("[CLASS] = 1"));
|
2009-01-14 12:43:26 +00:00
|
|
|
stroke roads1_rule_stk_1(color(188,149,28),7.0);
|
2008-06-29 10:58:29 +00:00
|
|
|
roads1_rule_stk_1.set_line_cap(ROUND_CAP);
|
|
|
|
roads1_rule_stk_1.set_line_join(ROUND_JOIN);
|
|
|
|
roads1_rule_1.append(line_symbolizer(roads1_rule_stk_1));
|
|
|
|
roads1_style_1.add_rule(roads1_rule_1);
|
|
|
|
m.insert_style("highway-border", roads1_style_1);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
feature_type_style roads1_style_2;
|
2011-01-13 21:35:01 +00:00
|
|
|
rule roads1_rule_2;
|
2009-12-16 20:02:06 +00:00
|
|
|
roads1_rule_2.set_filter(parse_expression("[CLASS] = 1"));
|
2009-01-14 12:43:26 +00:00
|
|
|
stroke roads1_rule_stk_2(color(242,191,36),5.0);
|
2008-06-29 10:58:29 +00:00
|
|
|
roads1_rule_stk_2.set_line_cap(ROUND_CAP);
|
|
|
|
roads1_rule_stk_2.set_line_join(ROUND_JOIN);
|
|
|
|
roads1_rule_2.append(line_symbolizer(roads1_rule_stk_2));
|
|
|
|
roads1_style_2.add_rule(roads1_rule_2);
|
|
|
|
m.insert_style("highway-fill", roads1_style_2);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Populated Places
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
feature_type_style popplaces_style;
|
2011-01-13 21:35:01 +00:00
|
|
|
rule popplaces_rule;
|
2011-08-22 20:26:45 +00:00
|
|
|
text_symbolizer popplaces_text_symbolizer(parse_expression("[GEONAME]"),"DejaVu Sans Book",10,color(0,0,0));
|
2009-01-14 12:43:26 +00:00
|
|
|
popplaces_text_symbolizer.set_halo_fill(color(255,255,200));
|
2008-06-29 10:58:29 +00:00
|
|
|
popplaces_text_symbolizer.set_halo_radius(1);
|
|
|
|
popplaces_rule.append(popplaces_text_symbolizer);
|
|
|
|
popplaces_style.add_rule(popplaces_rule);
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
m.insert_style("popplaces",popplaces_style );
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2009-12-16 20:02:06 +00:00
|
|
|
// layers
|
2008-06-29 10:58:29 +00:00
|
|
|
// Provincial polygons
|
|
|
|
{
|
|
|
|
parameters p;
|
|
|
|
p["type"]="shape";
|
|
|
|
p["file"]="../data/boundaries";
|
2012-04-04 22:17:37 +00:00
|
|
|
p["encoding"]="latin1";
|
2011-11-14 03:54:32 +00:00
|
|
|
|
|
|
|
layer lyr("Provinces");
|
2012-09-07 15:23:03 +00:00
|
|
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
2011-11-14 03:54:32 +00:00
|
|
|
lyr.add_style("provinces");
|
2013-01-11 14:50:49 +00:00
|
|
|
lyr.set_srs(srs_lcc);
|
2008-06-29 10:58:29 +00:00
|
|
|
m.addLayer(lyr);
|
|
|
|
}
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Drainage
|
|
|
|
{
|
|
|
|
parameters p;
|
|
|
|
p["type"]="shape";
|
|
|
|
p["file"]="../data/qcdrainage";
|
2009-12-16 20:02:06 +00:00
|
|
|
layer lyr("Quebec Hydrography");
|
2012-09-07 15:23:03 +00:00
|
|
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
2013-01-11 14:50:49 +00:00
|
|
|
lyr.set_srs(srs_lcc);
|
2011-11-14 03:54:32 +00:00
|
|
|
lyr.add_style("drainage");
|
2008-06-29 10:58:29 +00:00
|
|
|
m.addLayer(lyr);
|
|
|
|
}
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
{
|
|
|
|
parameters p;
|
|
|
|
p["type"]="shape";
|
|
|
|
p["file"]="../data/ontdrainage";
|
2011-11-14 03:54:32 +00:00
|
|
|
layer lyr("Ontario Hydrography");
|
2012-09-07 15:23:03 +00:00
|
|
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
2013-01-11 14:50:49 +00:00
|
|
|
lyr.set_srs(srs_lcc);
|
2011-11-14 03:54:32 +00:00
|
|
|
lyr.add_style("drainage");
|
2008-06-29 10:58:29 +00:00
|
|
|
m.addLayer(lyr);
|
|
|
|
}
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Provincial boundaries
|
|
|
|
{
|
|
|
|
parameters p;
|
|
|
|
p["type"]="shape";
|
|
|
|
p["file"]="../data/boundaries_l";
|
2011-11-14 03:54:32 +00:00
|
|
|
layer lyr("Provincial borders");
|
2013-01-11 14:50:49 +00:00
|
|
|
lyr.set_srs(srs_lcc);
|
2012-09-07 15:23:03 +00:00
|
|
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
2011-11-14 03:54:32 +00:00
|
|
|
lyr.add_style("provlines");
|
2008-06-29 10:58:29 +00:00
|
|
|
m.addLayer(lyr);
|
|
|
|
}
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2008-06-29 10:58:29 +00:00
|
|
|
// Roads
|
|
|
|
{
|
|
|
|
parameters p;
|
|
|
|
p["type"]="shape";
|
2011-11-14 03:54:32 +00:00
|
|
|
p["file"]="../data/roads";
|
|
|
|
layer lyr("Roads");
|
2013-01-11 14:50:49 +00:00
|
|
|
lyr.set_srs(srs_lcc);
|
2012-09-07 15:23:03 +00:00
|
|
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
2008-06-29 10:58:29 +00:00
|
|
|
lyr.add_style("smallroads");
|
|
|
|
lyr.add_style("road-border");
|
|
|
|
lyr.add_style("road-fill");
|
|
|
|
lyr.add_style("highway-border");
|
|
|
|
lyr.add_style("highway-fill");
|
2008-01-08 21:09:16 +00:00
|
|
|
|
2011-11-14 03:54:32 +00:00
|
|
|
m.addLayer(lyr);
|
2008-06-29 10:58:29 +00:00
|
|
|
}
|
|
|
|
// popplaces
|
|
|
|
{
|
|
|
|
parameters p;
|
|
|
|
p["type"]="shape";
|
|
|
|
p["file"]="../data/popplaces";
|
|
|
|
p["encoding"] = "latin1";
|
2009-12-16 20:02:06 +00:00
|
|
|
layer lyr("Populated Places");
|
2013-01-11 14:50:49 +00:00
|
|
|
lyr.set_srs(srs_lcc);
|
2012-09-07 15:23:03 +00:00
|
|
|
lyr.set_datasource(datasource_cache::instance().create(p));
|
2011-11-14 03:54:32 +00:00
|
|
|
lyr.add_style("popplaces");
|
2008-06-29 10:58:29 +00:00
|
|
|
m.addLayer(lyr);
|
|
|
|
}
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2013-01-11 14:50:49 +00:00
|
|
|
m.zoom_to_box(box2d<double>(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855));
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2010-06-25 15:23:35 +00:00
|
|
|
image_32 buf(m.width(),m.height());
|
2009-12-16 20:02:06 +00:00
|
|
|
agg_renderer<image_32> ren(m,buf);
|
2008-06-29 10:58:29 +00:00
|
|
|
ren.apply();
|
2011-11-14 03:54:32 +00:00
|
|
|
|
2012-05-09 11:39:23 +00:00
|
|
|
save_to_file(buf,"demo.jpg","jpeg");
|
|
|
|
save_to_file(buf,"demo.png","png");
|
2013-01-09 20:48:05 +00:00
|
|
|
save_to_file(buf,"demo256.png","png8");
|
2012-05-09 11:39:23 +00:00
|
|
|
save_to_file(buf,"demo.tif","tiff");
|
2012-09-07 15:23:03 +00:00
|
|
|
|
2009-01-15 22:53:29 +00:00
|
|
|
std::cout << "Three maps have been rendered using AGG in the current directory:\n"
|
2011-11-14 03:54:32 +00:00
|
|
|
"- demo.jpg\n"
|
|
|
|
"- demo.png\n"
|
|
|
|
"- demo256.png\n"
|
2011-11-29 11:13:27 +00:00
|
|
|
"- demo.tif\n"
|
2011-11-14 03:54:32 +00:00
|
|
|
"Have a look!\n";
|
2012-02-02 01:38:18 +00:00
|
|
|
|
2011-11-14 03:54:32 +00:00
|
|
|
#if defined(HAVE_CAIRO)
|
2013-01-09 20:48:05 +00:00
|
|
|
// save to pdf/svg files
|
|
|
|
save_to_cairo_file(m,"cairo-demo.pdf");
|
|
|
|
save_to_cairo_file(m,"cairo-demo.svg");
|
2009-01-15 22:53:29 +00:00
|
|
|
|
2013-01-09 20:48:05 +00:00
|
|
|
/* we could also do:
|
2009-01-15 22:53:29 +00:00
|
|
|
|
2013-01-11 14:50:49 +00:00
|
|
|
save_to_cairo_file(m,"cairo-demo.png");
|
2009-01-15 22:53:29 +00:00
|
|
|
|
2013-01-11 14:50:49 +00:00
|
|
|
but instead let's build up a surface for more flexibility
|
2013-01-09 20:48:05 +00:00
|
|
|
*/
|
2009-01-15 22:53:29 +00:00
|
|
|
|
2013-01-09 20:48:05 +00:00
|
|
|
cairo_surface_ptr image_surface(
|
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
|
|
|
|
cairo_surface_closer());
|
|
|
|
double scale_factor = 1.0;
|
|
|
|
cairo_ptr image_context = (create_context(image_surface));
|
|
|
|
mapnik::cairo_renderer<cairo_ptr> png_render(m,image_context,scale_factor);
|
|
|
|
png_render.apply();
|
|
|
|
// we can now write to png with cairo functionality
|
|
|
|
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
|
|
|
// but we can also benefit from quantization by converting
|
|
|
|
// to a mapnik image object and then saving that
|
|
|
|
image_32 im(image_surface);
|
|
|
|
save_to_file(im, "cairo-demo256.png","png8");
|
|
|
|
cairo_surface_finish(&*image_surface);
|
2009-01-15 22:53:29 +00:00
|
|
|
|
|
|
|
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
2011-11-14 03:54:32 +00:00
|
|
|
"- cairo-demo.png\n"
|
|
|
|
"- cairo-demo256.png\n"
|
|
|
|
"- cairo-demo.pdf\n"
|
|
|
|
"- cairo-demo.svg\n"
|
|
|
|
"Have a look!\n";
|
|
|
|
#endif
|
2009-01-15 22:53:29 +00:00
|
|
|
|
2006-05-08 20:29:13 +00:00
|
|
|
}
|
2008-01-08 21:09:16 +00:00
|
|
|
catch ( const std::exception & ex )
|
2006-05-08 20:29:13 +00:00
|
|
|
{
|
2009-03-03 19:28:26 +00:00
|
|
|
std::cerr << "### std::exception: " << ex.what() << std::endl;
|
2008-01-08 21:09:16 +00:00
|
|
|
return EXIT_FAILURE;
|
2006-05-08 20:29:13 +00:00
|
|
|
}
|
2008-01-08 21:09:16 +00:00
|
|
|
catch ( ... )
|
2006-05-08 20:29:13 +00:00
|
|
|
{
|
2008-01-08 21:09:16 +00:00
|
|
|
std::cerr << "### Unknown exception." << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
2006-05-08 20:29:13 +00:00
|
|
|
}
|
2006-09-17 19:45:01 +00:00
|
|
|
return EXIT_SUCCESS;
|
2006-05-08 20:29:13 +00:00
|
|
|
}
|