2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02: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,
|
2006-02-01 00:09:52 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* 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-02-01 00:09:52 +01:00
|
|
|
//$Id: mapnik_python.cc 27 2005-03-30 21:45:40Z pavlenko $
|
|
|
|
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <boost/get_pointer.hpp>
|
|
|
|
#include <boost/python/detail/api_placeholder.hpp>
|
|
|
|
|
|
|
|
void export_color();
|
|
|
|
void export_layer();
|
|
|
|
void export_parameters();
|
|
|
|
void export_envelope();
|
2006-09-11 11:48:27 +02:00
|
|
|
void export_query();
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_image();
|
|
|
|
void export_map();
|
|
|
|
void export_python();
|
|
|
|
void export_filter();
|
|
|
|
void export_rule();
|
|
|
|
void export_style();
|
|
|
|
void export_stroke();
|
|
|
|
void export_datasource_cache();
|
2006-02-25 12:03:30 +01:00
|
|
|
void export_point_symbolizer();
|
|
|
|
void export_line_symbolizer();
|
|
|
|
void export_line_pattern_symbolizer();
|
|
|
|
void export_polygon_symbolizer();
|
|
|
|
void export_polygon_pattern_symbolizer();
|
|
|
|
void export_raster_symbolizer();
|
|
|
|
void export_text_symbolizer();
|
2006-03-19 22:55:59 +01:00
|
|
|
void export_font_engine();
|
2006-02-01 00:09:52 +01:00
|
|
|
|
2006-09-11 11:48:27 +02:00
|
|
|
#include <map.hpp>
|
|
|
|
#include <agg_renderer.hpp>
|
|
|
|
#include <graphics.hpp>
|
2006-10-03 10:44:04 +02:00
|
|
|
#include <datasource_cache.hpp>
|
2006-09-11 11:48:27 +02:00
|
|
|
|
|
|
|
void render_to_file(const mapnik::Map& map,
|
|
|
|
const std::string& file,
|
|
|
|
const std::string& format)
|
2006-02-01 00:09:52 +01:00
|
|
|
{
|
2006-09-11 11:48:27 +02:00
|
|
|
mapnik::Image32 image(map.getWidth(),map.getHeight());
|
|
|
|
mapnik::agg_renderer<mapnik::Image32> ren(map,image);
|
2006-02-25 12:03:30 +01:00
|
|
|
ren.apply();
|
2006-02-01 00:09:52 +01:00
|
|
|
image.saveToFile(file,format);
|
|
|
|
}
|
|
|
|
|
2006-09-11 11:48:27 +02:00
|
|
|
void render(const mapnik::Map& map,mapnik::Image32& image)
|
2006-02-01 00:09:52 +01:00
|
|
|
{
|
2006-09-11 11:48:27 +02:00
|
|
|
mapnik::agg_renderer<mapnik::Image32> ren(map,image);
|
2006-02-25 12:03:30 +01:00
|
|
|
ren.apply();
|
2006-02-01 00:09:52 +01:00
|
|
|
}
|
|
|
|
|
2006-10-03 10:44:04 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//user-friendly wrapper that uses Python dictionary
|
|
|
|
using namespace boost::python;
|
|
|
|
boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
boost::python::list keys=d.keys();
|
|
|
|
for (int i=0; i<len(keys); ++i)
|
|
|
|
{
|
|
|
|
std::string key=extract<std::string>(keys[i]);
|
|
|
|
std::string value=extract<std::string>(d[key]);
|
|
|
|
params[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mapnik::datasource_cache::create(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
BOOST_PYTHON_MODULE(_mapnik)
|
|
|
|
{
|
|
|
|
using namespace boost::python;
|
2006-09-11 11:48:27 +02:00
|
|
|
using mapnik::Featureset;
|
|
|
|
using mapnik::featureset_ptr;
|
|
|
|
using mapnik::datasource;
|
|
|
|
using mapnik::coord;
|
|
|
|
using mapnik::filter_ptr;
|
|
|
|
|
|
|
|
export_query();
|
|
|
|
|
|
|
|
class_<Featureset,featureset_ptr,boost::noncopyable>("FeatureSet",no_init)
|
|
|
|
;
|
2006-02-01 00:09:52 +01:00
|
|
|
|
|
|
|
class_<datasource,boost::shared_ptr<datasource>,
|
2006-10-03 10:44:04 +02:00
|
|
|
boost::noncopyable>("Datasource",no_init)
|
|
|
|
.def("envelope",&datasource::envelope,
|
|
|
|
return_value_policy<reference_existing_object>())
|
|
|
|
.def("features",&datasource::features)
|
|
|
|
.def("params",&datasource::params,return_value_policy<reference_existing_object>(),
|
|
|
|
"The configuration parameters of the data source. "
|
|
|
|
"These vary depending on the type of data source.")
|
|
|
|
;
|
|
|
|
|
|
|
|
def("CreateDatasource",&create_datasource);
|
2006-09-11 11:48:27 +02:00
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
export_parameters();
|
|
|
|
export_color();
|
|
|
|
export_envelope();
|
|
|
|
export_image();
|
|
|
|
export_filter();
|
|
|
|
export_rule();
|
|
|
|
export_style();
|
|
|
|
export_layer();
|
|
|
|
export_stroke();
|
|
|
|
export_datasource_cache();
|
2006-02-25 12:03:30 +01:00
|
|
|
export_point_symbolizer();
|
|
|
|
export_line_symbolizer();
|
|
|
|
export_line_pattern_symbolizer();
|
|
|
|
export_polygon_symbolizer();
|
|
|
|
export_polygon_pattern_symbolizer();
|
|
|
|
export_raster_symbolizer();
|
|
|
|
export_text_symbolizer();
|
2006-03-19 22:55:59 +01:00
|
|
|
export_font_engine();
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2006-02-20 02:34:02 +01:00
|
|
|
class_<coord<double,2> >("Coord",init<double,double>())
|
2006-02-01 00:09:52 +01:00
|
|
|
.def_readwrite("x", &coord<double,2>::x)
|
|
|
|
.def_readwrite("y", &coord<double,2>::y)
|
|
|
|
;
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
export_map();
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
def("render_to_file",&render_to_file);
|
|
|
|
def("render",&render);
|
|
|
|
register_ptr_to_python<filter_ptr>();
|
|
|
|
}
|