/
render.cpp
93 lines (66 loc) · 2.46 KB
/
render.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <fstream>
#include <mapnik/load_map.hpp>
#include <mapnik/graphics.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/save_map.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
int main(int argc, char **argv) {
std::cout << "Using MAPNIKDIR = " << MAPNIKDIR << "\n";
namespace po = boost::program_options;
std::string mapnik_input_dir = MAPNIKDIR;
std::string input_file;
int width, height;
po::options_description desc("carto");
desc.add_options()
("help,h", "produce this usage message")
("version,V","print version string")
("xml", po::value<std::string>(&input_file), "input xml style")
("width", po::value<int>(&width), "map width")
("height", po::value<int>(&height), "map height");
std::string usage("\nusage: render map.xml [--width 800] [--height 600]");
po::positional_options_description p;
p.add("xml",1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count("version"))
{
std::cout << "version 0.0.0" << std::endl;
return 1;
}
if (vm.count("help"))
{
std::cout << desc << usage << std::endl;
return 1;
}
if (!vm.count("xml"))
{
std::cout << "Please provide an input xml file\n" << std::endl;
std::cout << desc << usage << std::endl;
return 1;
}
if (!vm.count("width")) width = 800;
if (!vm.count("height")) height = 600;
try {
std::string mapnik_dir = MAPNIKDIR;
mapnik::datasource_cache::instance()->register_datasources(mapnik_dir);
mapnik::freetype_engine::register_fonts(mapnik_dir + "/../fonts/", TRUE);
mapnik::freetype_engine::register_fonts("/usr/share/fonts/", TRUE);
mapnik::Map m(width,height);
mapnik::load_map(m, input_file, TRUE);
mapnik::image_32 buf(m.width(),m.height());
mapnik::agg_renderer<mapnik::image_32> ren(m,buf);
ren.apply();
mapnik::save_to_file(buf,"demo.png","png");
} catch (std::exception& e) {
std::cerr << "Error: " << e.what() << "\n";
} catch(...) {
std::cerr << "Error: Unknown error\n";
}
return 0;
}