add simple, c++ version of nik2img
This commit is contained in:
parent
7b75a24111
commit
0a26485d28
4 changed files with 156 additions and 1 deletions
|
@ -400,6 +400,7 @@ opts.AddVariables(
|
||||||
BoolVariable('PGSQL2SQLITE', 'Compile and install a utility to convert postgres tables to sqlite', 'False'),
|
BoolVariable('PGSQL2SQLITE', 'Compile and install a utility to convert postgres tables to sqlite', 'False'),
|
||||||
BoolVariable('SHAPEINDEX', 'Compile and install a utility to generate shapefile indexes in the custom format (.index) Mapnik supports', 'True'),
|
BoolVariable('SHAPEINDEX', 'Compile and install a utility to generate shapefile indexes in the custom format (.index) Mapnik supports', 'True'),
|
||||||
BoolVariable('SVG2PNG', 'Compile and install a utility to generate render an svg file to a png on the command line', 'False'),
|
BoolVariable('SVG2PNG', 'Compile and install a utility to generate render an svg file to a png on the command line', 'False'),
|
||||||
|
BoolVariable('NIK2IMG', 'Compile and install a utility to generate render a map to an image', 'True'),
|
||||||
BoolVariable('COLOR_PRINT', 'Print build status information in color', 'True'),
|
BoolVariable('COLOR_PRINT', 'Print build status information in color', 'True'),
|
||||||
BoolVariable('SAMPLE_INPUT_PLUGINS', 'Compile and install sample plugins', 'False'),
|
BoolVariable('SAMPLE_INPUT_PLUGINS', 'Compile and install sample plugins', 'False'),
|
||||||
BoolVariable('BIGINT', 'Compile support for 64-bit integers in mapnik::value', 'True'),
|
BoolVariable('BIGINT', 'Compile support for 64-bit integers in mapnik::value', 'True'),
|
||||||
|
@ -1979,6 +1980,8 @@ if not HELP_REQUESTED:
|
||||||
SConscript('utils/pgsql2sqlite/build.py')
|
SConscript('utils/pgsql2sqlite/build.py')
|
||||||
if env['SVG2PNG']:
|
if env['SVG2PNG']:
|
||||||
SConscript('utils/svg2png/build.py')
|
SConscript('utils/svg2png/build.py')
|
||||||
|
if env['NIK2IMG']:
|
||||||
|
SConscript('utils/nik2img/build.py')
|
||||||
# devtools not ready for public
|
# devtools not ready for public
|
||||||
#SConscript('utils/ogrindex/build.py')
|
#SConscript('utils/ogrindex/build.py')
|
||||||
env['LIBS'].remove('boost_program_options%s' % env['BOOST_APPEND'])
|
env['LIBS'].remove('boost_program_options%s' % env['BOOST_APPEND'])
|
||||||
|
|
|
@ -10,4 +10,5 @@ fi
|
||||||
export PYTHONPATH="${CURRENT_DIR}/bindings/python/":${PYTHONPATH}
|
export PYTHONPATH="${CURRENT_DIR}/bindings/python/":${PYTHONPATH}
|
||||||
export MAPNIK_FONT_DIRECTORY="${CURRENT_DIR}/fonts/dejavu-fonts-ttf-2.33/ttf/"
|
export MAPNIK_FONT_DIRECTORY="${CURRENT_DIR}/fonts/dejavu-fonts-ttf-2.33/ttf/"
|
||||||
export MAPNIK_INPUT_PLUGINS_DIRECTORY="${CURRENT_DIR}/plugins/input/"
|
export MAPNIK_INPUT_PLUGINS_DIRECTORY="${CURRENT_DIR}/plugins/input/"
|
||||||
export PATH="${CURRENT_DIR}/bin/":${PATH}
|
export PATH="${CURRENT_DIR}/bin/":${PATH}
|
||||||
|
export PATH="${CURRENT_DIR}/utils/nik2img":${PATH}
|
34
utils/nik2img/build.py
Normal file
34
utils/nik2img/build.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
|
Import ('env')
|
||||||
|
program_env = env.Clone()
|
||||||
|
|
||||||
|
source = Split(
|
||||||
|
"""
|
||||||
|
nik2img.cpp
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
program_env['CXXFLAGS'] = copy(env['LIBMAPNIK_CXXFLAGS'])
|
||||||
|
program_env.Append(CPPDEFINES = env['LIBMAPNIK_DEFINES'])
|
||||||
|
|
||||||
|
if env['HAS_CAIRO']:
|
||||||
|
program_env.PrependUnique(CPPPATH=env['CAIRO_CPPPATHS'])
|
||||||
|
program_env.Append(CPPDEFINES = '-DHAVE_CAIRO')
|
||||||
|
|
||||||
|
boost_program_options = 'boost_program_options%s' % env['BOOST_APPEND']
|
||||||
|
libraries = ['mapnik',boost_program_options]
|
||||||
|
libraries.extend(copy(env['LIBMAPNIK_LIBS']))
|
||||||
|
if env['RUNTIME_LINK'] == 'static' and env['PLATFORM'] == 'Linux':
|
||||||
|
libraries.append('dl')
|
||||||
|
|
||||||
|
nik2img = program_env.Program('nik2img', source, LIBS=libraries)
|
||||||
|
Depends(nik2img, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
|
||||||
|
|
||||||
|
if 'uninstall' not in COMMAND_LINE_TARGETS:
|
||||||
|
env.Install(os.path.join(env['INSTALL_PREFIX'],'bin'), nik2img)
|
||||||
|
env.Alias('install', os.path.join(env['INSTALL_PREFIX'],'bin'))
|
||||||
|
|
||||||
|
env['create_uninstall_target'](env, os.path.join(env['INSTALL_PREFIX'],'bin','nik2img'))
|
117
utils/nik2img/nik2img.cpp
Normal file
117
utils/nik2img/nik2img.cpp
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
#include <mapnik/map.hpp>
|
||||||
|
#include <mapnik/load_map.hpp>
|
||||||
|
#include <mapnik/agg_renderer.hpp>
|
||||||
|
#include <mapnik/version.hpp>
|
||||||
|
#include <mapnik/debug.hpp>
|
||||||
|
#include <mapnik/image_util.hpp>
|
||||||
|
#include <mapnik/graphics.hpp>
|
||||||
|
#include <mapnik/datasource_cache.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main (int argc,char** argv)
|
||||||
|
{
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
bool verbose = false;
|
||||||
|
bool auto_open = true;
|
||||||
|
int return_value = 0;
|
||||||
|
std::string xml_file;
|
||||||
|
std::string img_file;
|
||||||
|
mapnik::logger logger;
|
||||||
|
logger.set_severity(mapnik::logger::error);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
po::options_description desc("nik2img utility");
|
||||||
|
desc.add_options()
|
||||||
|
("help,h", "produce usage message")
|
||||||
|
("version,V","print version string")
|
||||||
|
("verbose,v","verbose output")
|
||||||
|
("open","automatically open the file after rendering (os x only)")
|
||||||
|
("xml",po::value<std::string>(),"xml map to read")
|
||||||
|
("img",po::value<std::string>(),"image to render")
|
||||||
|
;
|
||||||
|
|
||||||
|
po::positional_options_description p;
|
||||||
|
p.add("xml",1);
|
||||||
|
p.add("img",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::clog <<"version " << MAPNIK_VERSION_STRING << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.count("help"))
|
||||||
|
{
|
||||||
|
std::clog << desc << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.count("verbose"))
|
||||||
|
{
|
||||||
|
verbose = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.count("open"))
|
||||||
|
{
|
||||||
|
auto_open = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.count("xml"))
|
||||||
|
{
|
||||||
|
xml_file=vm["xml"].as<std::string>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::clog << "please provide an xml map as first argument!" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.count("img"))
|
||||||
|
{
|
||||||
|
img_file=vm["img"].as<std::string>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::clog << "please provide an img as second argument!" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
|
||||||
|
mapnik::Map map(600,400);
|
||||||
|
mapnik::load_map(map,xml_file);
|
||||||
|
map.zoom_all();
|
||||||
|
mapnik::image_32 im(map.width(),map.height());
|
||||||
|
mapnik::agg_renderer<mapnik::image_32> ren(map,im);
|
||||||
|
ren.apply();
|
||||||
|
mapnik::save_to_file(im,img_file);
|
||||||
|
if (auto_open)
|
||||||
|
{
|
||||||
|
std::ostringstream s;
|
||||||
|
#ifdef DARWIN
|
||||||
|
s << "open " << img_file;
|
||||||
|
#else
|
||||||
|
s << "xdg-open " << img_file;
|
||||||
|
#endif
|
||||||
|
int ret = system(s.str().c_str());
|
||||||
|
if (ret != 0)
|
||||||
|
return_value = ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::clog << "rendered to: " << img_file << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception const& ex)
|
||||||
|
{
|
||||||
|
std::clog << "Error " << ex.what() << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return return_value;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue