code formatting

This commit is contained in:
Dane Springmeyer 2011-11-13 19:54:32 -08:00
parent 01bd36623c
commit 4654312d00
55 changed files with 1072 additions and 1072 deletions

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -40,7 +40,7 @@ struct color_pickle_suite : boost::python::pickle_suite
} }
}; };
void export_color () void export_color ()
{ {
using namespace boost::python; using namespace boost::python;
class_<color>("Color", init<int,int,int,int>( class_<color>("Color", init<int,int,int,int>(

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -42,7 +42,7 @@ struct coord_pickle_suite : boost::python::pickle_suite
void export_coord() void export_coord()
{ {
using namespace boost::python; using namespace boost::python;
class_<coord<double,2> >("Coord",init<double, double>( class_<coord<double,2> >("Coord",init<double, double>(
// class docstring is in mapnik/__init__.py, class _Coord // class docstring is in mapnik/__init__.py, class _Coord
(arg("x"), arg("y")), (arg("x"), arg("y")),
"Constructs a new point with the given coordinates.\n") "Constructs a new point with the given coordinates.\n")
@ -59,7 +59,7 @@ void export_coord()
.def(self - self) // __sub__ .def(self - self) // __sub__
.def(self - float()) .def(self - float())
.def(self * float()) //__mult__ .def(self * float()) //__mult__
.def(float() * self) .def(float() * self)
.def(self / float()) // __div__ .def(self / float()) // __div__
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -41,7 +41,7 @@ using mapnik::memory_datasource;
using mapnik::layer_descriptor; using mapnik::layer_descriptor;
using mapnik::attribute_descriptor; using mapnik::attribute_descriptor;
namespace namespace
{ {
//user-friendly wrapper that uses Python dictionary //user-friendly wrapper that uses Python dictionary
using namespace boost::python; using namespace boost::python;
@ -54,17 +54,17 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
{ {
std::string key = extract<std::string>(keys[i]); std::string key = extract<std::string>(keys[i]);
object obj = d[key]; object obj = d[key];
if (key == "bind") if (key == "bind")
{ {
bind = extract<bool>(obj)(); bind = extract<bool>(obj)();
continue; continue;
} }
extract<std::string> ex0(obj); extract<std::string> ex0(obj);
extract<int> ex1(obj); extract<int> ex1(obj);
extract<double> ex2(obj); extract<double> ex2(obj);
if (ex0.check()) if (ex0.check())
{ {
params[key] = ex0(); params[key] = ex0();
@ -78,10 +78,10 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
params[key] = ex2(); params[key] = ex2();
} }
} }
return mapnik::datasource_cache::create(params, bind); return mapnik::datasource_cache::create(params, bind);
} }
std::string describe(boost::shared_ptr<mapnik::datasource> const& ds) std::string describe(boost::shared_ptr<mapnik::datasource> const& ds)
{ {
std::stringstream ss; std::stringstream ss;
@ -95,7 +95,7 @@ std::string describe(boost::shared_ptr<mapnik::datasource> const& ds)
} }
return ss.str(); return ss.str();
} }
std::string encoding(boost::shared_ptr<mapnik::datasource> const& ds) std::string encoding(boost::shared_ptr<mapnik::datasource> const& ds)
{ {
layer_descriptor ld = ds->get_descriptor(); layer_descriptor ld = ds->get_descriptor();
@ -134,7 +134,7 @@ boost::python::list field_types(boost::shared_ptr<mapnik::datasource> const& ds)
std::vector<attribute_descriptor>::const_iterator it = desc_ar.begin(); std::vector<attribute_descriptor>::const_iterator it = desc_ar.begin();
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end(); std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
for (; it != end; ++it) for (; it != end; ++it)
{ {
unsigned type = it->get_type(); unsigned type = it->get_type();
if (type == mapnik::Integer) if (type == mapnik::Integer)
// this crashes, so send back strings instead // this crashes, so send back strings instead
@ -162,7 +162,7 @@ boost::python::list field_types(boost::shared_ptr<mapnik::datasource> const& ds)
void export_datasource() void export_datasource()
{ {
using namespace boost::python; using namespace boost::python;
class_<datasource,boost::shared_ptr<datasource>, class_<datasource,boost::shared_ptr<datasource>,
boost::noncopyable>("Datasource",no_init) boost::noncopyable>("Datasource",no_init)
.def("envelope",&datasource::envelope) .def("envelope",&datasource::envelope)
@ -174,11 +174,11 @@ void export_datasource()
.def("encoding",&encoding) //todo expose as property .def("encoding",&encoding) //todo expose as property
.def("name",&name) .def("name",&name)
.def("features_at_point",&datasource::features_at_point) .def("features_at_point",&datasource::features_at_point)
.def("params",&datasource::params,return_value_policy<copy_const_reference>(), .def("params",&datasource::params,return_value_policy<copy_const_reference>(),
"The configuration parameters of the data source. " "The configuration parameters of the data source. "
"These vary depending on the type of data source.") "These vary depending on the type of data source.")
; ;
def("Describe",&describe); def("Describe",&describe);
def("CreateDatasource",&create_datasource); def("CreateDatasource",&create_datasource);

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -36,7 +36,7 @@ void export_datasource_cache()
return_value_policy<reference_existing_object>()) return_value_policy<reference_existing_object>())
.staticmethod("instance") .staticmethod("instance")
; ;
class_<datasource_cache,bases<singleton<datasource_cache,CreateStatic> >, class_<datasource_cache,bases<singleton<datasource_cache,CreateStatic> >,
boost::noncopyable>("DatasourceCache",no_init) boost::noncopyable>("DatasourceCache",no_init)
.def("create",&datasource_cache::create) .def("create",&datasource_cache::create)
@ -44,6 +44,6 @@ void export_datasource_cache()
.def("register_datasources",&datasource_cache::register_datasources) .def("register_datasources",&datasource_cache::register_datasources)
.staticmethod("register_datasources") .staticmethod("register_datasources")
.def("plugin_names",&datasource_cache::plugin_names) .def("plugin_names",&datasource_cache::plugin_names)
.staticmethod("plugin_names") .staticmethod("plugin_names")
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -26,7 +26,7 @@ namespace mapnik {
template <typename EnumWrapper> template <typename EnumWrapper>
class enumeration_ : class enumeration_ :
public boost::python::enum_<typename EnumWrapper::native_type> public boost::python::enum_<typename EnumWrapper::native_type>
{ {
// some short cuts // some short cuts
typedef boost::python::enum_<typename EnumWrapper::native_type> base_type; typedef boost::python::enum_<typename EnumWrapper::native_type> base_type;
@ -46,7 +46,7 @@ public:
enumeration_(const char * python_alias, const char * doc) : enumeration_(const char * python_alias, const char * doc) :
base_type( python_alias, doc ) base_type( python_alias, doc )
#else #else
enumeration_(const char * python_alias, const char * /*doc*/) : enumeration_(const char * python_alias, const char * /*doc*/) :
// Boost.Python < 1.35.0 doesn't support // Boost.Python < 1.35.0 doesn't support
// docstrings for enums so we ignore it. // docstrings for enums so we ignore it.
base_type( python_alias ) base_type( python_alias )

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -102,13 +102,13 @@ void export_envelope()
"Equivalent to Box2d(ll.x, ll.y, ur.x, ur.y).\n")) "Equivalent to Box2d(ll.x, ll.y, ur.x, ur.y).\n"))
.def("from_string",from_string) .def("from_string",from_string)
.staticmethod("from_string") .staticmethod("from_string")
.add_property("minx", &box2d<double>::minx, .add_property("minx", &box2d<double>::minx,
"X coordinate for the lower left corner") "X coordinate for the lower left corner")
.add_property("miny", &box2d<double>::miny, .add_property("miny", &box2d<double>::miny,
"Y coordinate for the lower left corner") "Y coordinate for the lower left corner")
.add_property("maxx", &box2d<double>::maxx, .add_property("maxx", &box2d<double>::maxx,
"X coordinate for the upper right corner") "X coordinate for the upper right corner")
.add_property("maxy", &box2d<double>::maxy, .add_property("maxy", &box2d<double>::maxy,
"Y coordinate for the upper right corner") "Y coordinate for the upper right corner")
.def("center", &box2d<double>::center, .def("center", &box2d<double>::center,
"Returns the coordinates of the center of the bounding box.\n" "Returns the coordinates of the center of the bounding box.\n"
@ -259,13 +259,13 @@ void export_envelope()
">>> e1 = Box2d(0, 0, 100, 100)\n" ">>> e1 = Box2d(0, 0, 100, 100)\n"
">>> e2 = Box2d(50, 50, 150, 150)\n" ">>> e2 = Box2d(50, 50, 150, 150)\n"
">>> e1.intersect(e2)\n" ">>> e1.intersect(e2)\n"
"Box2d(50.0, 50.0, 100.0, 100.0)\n" "Box2d(50.0, 50.0, 100.0, 100.0)\n"
) )
.def(self == self) // __eq__ .def(self == self) // __eq__
.def(self != self) // __neq__ .def(self != self) // __neq__
.def(self + self) // __add__ .def(self + self) // __add__
.def(self * float()) // __mult__ .def(self * float()) // __mult__
.def(float() * self) .def(float() * self)
.def(self / float()) // __div__ .def(self / float()) // __div__
.def("__getitem__",&box2d<double>::operator[]) .def("__getitem__",&box2d<double>::operator[])
.def("valid",&box2d<double>::valid) .def("valid",&box2d<double>::valid)

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -76,7 +76,7 @@ void export_expression()
.def("evaluate", &expression_evaluate_) .def("evaluate", &expression_evaluate_)
.def("__str__",&to_expression_string); .def("__str__",&to_expression_string);
; ;
def("Expression",&parse_expression_,(arg("expr")),"Expression string"); def("Expression",&parse_expression_,(arg("expr")),"Expression string");
class_<mapnik::path_expression ,boost::noncopyable>("PathExpression", class_<mapnik::path_expression ,boost::noncopyable>("PathExpression",
@ -85,6 +85,6 @@ void export_expression()
.def("evaluate", &path_evaluate_) // note: "pass" is a reserved word in Python .def("evaluate", &path_evaluate_) // note: "pass" is a reserved word in Python
.def("__str__",&path_to_string_); .def("__str__",&path_to_string_);
; ;
def("PathExpression",&parse_path_,(arg("expr")),"PathExpression string"); def("PathExpression",&parse_path_,(arg("expr")),"PathExpression string");
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -70,7 +70,7 @@ namespace boost { namespace python {
: public map_indexing_suite2<Container, : public map_indexing_suite2<Container,
NoProxy, final_map_derived_policies<Container, NoProxy> > {}; NoProxy, final_map_derived_policies<Container, NoProxy> > {};
} }
template <class Container,bool NoProxy = false, template <class Container,bool NoProxy = false,
class DerivedPolicies = detail::final_map_derived_policies<Container, NoProxy> > class DerivedPolicies = detail::final_map_derived_policies<Container, NoProxy> >
class map_indexing_suite2 class map_indexing_suite2
@ -97,7 +97,7 @@ namespace boost { namespace python {
static void static void
extension_def(Class& /*cl*/) extension_def(Class& /*cl*/)
{ {
} }
static data_type& static data_type&
@ -111,37 +111,37 @@ namespace boost { namespace python {
} }
return i->second; return i->second;
} }
static void static void
set_item(Container& container, index_type i, data_type const& v) set_item(Container& container, index_type i, data_type const& v)
{ {
container[i] = v; container[i] = v;
} }
static void static void
delete_item(Container& container, index_type i) delete_item(Container& container, index_type i)
{ {
container.props().erase(i); container.props().erase(i);
} }
static size_t static size_t
size(Container& container) size(Container& container)
{ {
return container.props().size(); return container.props().size();
} }
static bool static bool
contains(Container& container, key_type const& key) contains(Container& container, key_type const& key)
{ {
return container.props().find(key) != container.end(); return container.props().find(key) != container.end();
} }
static bool static bool
compare_index(Container& container, index_type a, index_type b) compare_index(Container& container, index_type a, index_type b)
{ {
return container.props().key_comp()(a, b); return container.props().key_comp()(a, b);
} }
static index_type static index_type
convert_index(Container& /*container*/, PyObject* i_) convert_index(Container& /*container*/, PyObject* i_)
{ {
@ -156,13 +156,13 @@ namespace boost { namespace python {
if (i.check()) if (i.check())
return i(); return i();
} }
PyErr_SetString(PyExc_TypeError, "Invalid index type"); PyErr_SetString(PyExc_TypeError, "Invalid index type");
throw_error_already_set(); throw_error_already_set();
return index_type(); return index_type();
} }
}; };
template <typename T1, typename T2> template <typename T1, typename T2>
struct std_pair_to_tuple struct std_pair_to_tuple
@ -173,7 +173,7 @@ namespace boost { namespace python {
boost::python::make_tuple(p.first, p.second).ptr()); boost::python::make_tuple(p.first, p.second).ptr());
} }
}; };
template <typename T1, typename T2> template <typename T1, typename T2>
struct std_pair_to_python_converter struct std_pair_to_python_converter
{ {
@ -201,9 +201,9 @@ struct UnicodeString_from_python_str
{ {
if (!( if (!(
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
PyBytes_Check(obj_ptr) PyBytes_Check(obj_ptr)
#else #else
PyString_Check(obj_ptr) PyString_Check(obj_ptr)
#endif #endif
|| PyUnicode_Check(obj_ptr))) || PyUnicode_Check(obj_ptr)))
return 0; return 0;
@ -245,7 +245,7 @@ void export_feature()
{ {
using namespace boost::python; using namespace boost::python;
using mapnik::Feature; using mapnik::Feature;
implicitly_convertible<int,mapnik::value>(); implicitly_convertible<int,mapnik::value>();
implicitly_convertible<double,mapnik::value>(); implicitly_convertible<double,mapnik::value>();
implicitly_convertible<UnicodeString,mapnik::value>(); implicitly_convertible<UnicodeString,mapnik::value>();
@ -253,7 +253,7 @@ void export_feature()
std_pair_to_python_converter<std::string const,mapnik::value>(); std_pair_to_python_converter<std::string const,mapnik::value>();
UnicodeString_from_python_str(); UnicodeString_from_python_str();
class_<Feature,boost::shared_ptr<Feature>, class_<Feature,boost::shared_ptr<Feature>,
boost::noncopyable>("Feature",init<int>("Default ctor.")) boost::noncopyable>("Feature",init<int>("Default ctor."))
.def("id",&Feature::id) .def("id",&Feature::id)

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -65,21 +65,21 @@ void export_featureset()
using namespace boost::python; using namespace boost::python;
using mapnik::Feature; using mapnik::Feature;
using mapnik::Featureset; using mapnik::Featureset;
class_<Featureset,boost::shared_ptr<Featureset>, class_<Featureset,boost::shared_ptr<Featureset>,
boost::noncopyable>("Featureset",no_init) boost::noncopyable>("Featureset",no_init)
.def("__iter__",pass_through) .def("__iter__",pass_through)
.def("next",next) .def("next",next)
.add_property("features",features, .add_property("features",features,
"The list of features.\n" "The list of features.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> m.query_map_point(0, 10, 10)\n" ">>> m.query_map_point(0, 10, 10)\n"
"<mapnik2._mapnik2.Featureset object at 0x1004d2938>\n" "<mapnik2._mapnik2.Featureset object at 0x1004d2938>\n"
">>> fs = m.query_map_point(0, 10, 10)\n" ">>> fs = m.query_map_point(0, 10, 10)\n"
">>> for f in fs.features:\n" ">>> for f in fs.features:\n"
">>> print f\n" ">>> print f\n"
"<mapnik2.Feature object at 0x105e64140>\n" "<mapnik2.Feature object at 0x105e64140>\n"
) )
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -63,7 +63,7 @@ void from_wkb_impl(path_type& p, std::string const& wkb)
void export_geometry() void export_geometry()
{ {
using namespace boost::python; using namespace boost::python;
enum_<mapnik::eGeomType>("GeometryType") enum_<mapnik::eGeomType>("GeometryType")
.value("Point",mapnik::Point) .value("Point",mapnik::Point)
.value("LineString",mapnik::LineString) .value("LineString",mapnik::LineString)
@ -72,7 +72,7 @@ void export_geometry()
.value("MultiLineString",mapnik::MultiLineString) .value("MultiLineString",mapnik::MultiLineString)
.value("MultiPolygon",mapnik::MultiPolygon) .value("MultiPolygon",mapnik::MultiPolygon)
; ;
using mapnik::geometry_type; using mapnik::geometry_type;
class_<geometry_type, std::auto_ptr<geometry_type>,boost::noncopyable>("Geometry2d",no_init) class_<geometry_type, std::auto_ptr<geometry_type>,boost::noncopyable>("Geometry2d",no_init)
.def("envelope",&geometry_type::envelope) .def("envelope",&geometry_type::envelope)
@ -80,12 +80,12 @@ void export_geometry()
.def("type",&geometry_type::type) .def("type",&geometry_type::type)
// TODO add other geometry_type methods // TODO add other geometry_type methods
; ;
class_<path_type,boost::noncopyable>("Path") class_<path_type,boost::noncopyable>("Path")
.def("__getitem__", getitem_impl,return_value_policy<reference_existing_object>()) .def("__getitem__", getitem_impl,return_value_policy<reference_existing_object>())
.def("__len__", &path_type::size) .def("__len__", &path_type::size)
.def("from_wkt",from_wkt_impl) .def("from_wkt",from_wkt_impl)
.def("from_wkb",from_wkb_impl) .def("from_wkb",from_wkb_impl)
; ;
} }

View file

@ -73,7 +73,7 @@ void export_glyph_symbolizer()
&glyph_symbolizer::set_halo_fill) &glyph_symbolizer::set_halo_fill)
.add_property("halo_radius", .add_property("halo_radius",
&glyph_symbolizer::get_halo_radius, &glyph_symbolizer::get_halo_radius,
&glyph_symbolizer::set_halo_radius) &glyph_symbolizer::set_halo_radius)
.add_property("size", .add_property("size",
@ -117,5 +117,5 @@ void export_glyph_symbolizer()
"defined).\n" "defined).\n"
"Only needed if no explicit color is provided" "Only needed if no explicit color is provided"
) )
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -43,10 +43,10 @@ bool painted(mapnik::grid const& grid)
void export_grid() void export_grid()
{ {
class_<mapnik::grid,boost::shared_ptr<mapnik::grid> >( class_<mapnik::grid,boost::shared_ptr<mapnik::grid> >(
"Grid", "Grid",
"This class represents a feature hitgrid.", "This class represents a feature hitgrid.",
init<int,int,std::string,unsigned>( init<int,int,std::string,unsigned>(
( boost::python::arg("width"), boost::python::arg("height"),boost::python::arg("key")="__id__", boost::python::arg("resolution")=1 ), ( boost::python::arg("width"), boost::python::arg("height"),boost::python::arg("key")="__id__", boost::python::arg("resolution")=1 ),
"Create a mapnik.Grid object\n" "Create a mapnik.Grid object\n"
)) ))
.def("painted",&painted) .def("painted",&painted)
@ -54,16 +54,16 @@ void export_grid()
.def("height",&mapnik::grid::height) .def("height",&mapnik::grid::height)
.def("view",&mapnik::grid::get_view) .def("view",&mapnik::grid::get_view)
.def("encode",encode, .def("encode",encode,
( boost::python::arg("encoding")="utf", boost::python::arg("features")=true,boost::python::arg("resolution")=4 ), ( boost::python::arg("encoding")="utf", boost::python::arg("features")=true,boost::python::arg("resolution")=4 ),
"Encode the grid as as optimized json\n" "Encode the grid as as optimized json\n"
) )
.add_property("key", .add_property("key",
make_function(&mapnik::grid::get_key,return_value_policy<copy_const_reference>()), make_function(&mapnik::grid::get_key,return_value_policy<copy_const_reference>()),
&mapnik::grid::set_key, &mapnik::grid::set_key,
"Get/Set key to be used as unique indentifier for features\n" "Get/Set key to be used as unique indentifier for features\n"
"The value should either be __id__ to refer to the feature.id()\n" "The value should either be __id__ to refer to the feature.id()\n"
"or some globally unique integer or string attribute field\n" "or some globally unique integer or string attribute field\n"
) )
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -40,13 +40,13 @@ static dict (*encode)( mapnik::grid_view const&, std::string, bool, unsigned int
void export_grid_view() void export_grid_view()
{ {
class_<mapnik::grid_view, class_<mapnik::grid_view,
boost::shared_ptr<mapnik::grid_view> >("GridView", boost::shared_ptr<mapnik::grid_view> >("GridView",
"This class represents a feature hitgrid subset.",no_init) "This class represents a feature hitgrid subset.",no_init)
.def("width",&mapnik::grid_view::width) .def("width",&mapnik::grid_view::width)
.def("height",&mapnik::grid_view::height) .def("height",&mapnik::grid_view::height)
.def("encode",encode, .def("encode",encode,
( boost::python::arg("encoding")="utf",boost::python::arg("add_features")=true,boost::python::arg("resolution")=4 ), ( boost::python::arg("encoding")="utf",boost::python::arg("add_features")=true,boost::python::arg("resolution")=4 ),
"Encode the grid as as optimized json\n" "Encode the grid as as optimized json\n"
) )
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -68,7 +68,7 @@ PyObject* tostring1( image_32 const& im)
{ {
int size = im.width() * im.height() * 4; int size = im.width() * im.height() * 4;
return return
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
::PyBytes_FromStringAndSize ::PyBytes_FromStringAndSize
#else #else
::PyString_FromStringAndSize ::PyString_FromStringAndSize
@ -81,24 +81,24 @@ PyObject* tostring2(image_32 const & im, std::string const& format)
{ {
std::string s = save_to_string(im, format); std::string s = save_to_string(im, format);
return return
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
::PyBytes_FromStringAndSize ::PyBytes_FromStringAndSize
#else #else
::PyString_FromStringAndSize ::PyString_FromStringAndSize
#endif #endif
(s.data(),s.size()); (s.data(),s.size());
} }
PyObject* tostring3(image_32 const & im, std::string const& format, mapnik::rgba_palette const& pal) PyObject* tostring3(image_32 const & im, std::string const& format, mapnik::rgba_palette const& pal)
{ {
std::string s = save_to_string(im, format, pal); std::string s = save_to_string(im, format, pal);
return return
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
::PyBytes_FromStringAndSize ::PyBytes_FromStringAndSize
#else #else
::PyString_FromStringAndSize ::PyString_FromStringAndSize
#endif #endif
(s.data(),s.size()); (s.data(),s.size());
} }
@ -131,16 +131,16 @@ boost::shared_ptr<image_32> open_from_file(std::string const& filename)
std::auto_ptr<image_reader> reader(get_image_reader(filename,*type)); std::auto_ptr<image_reader> reader(get_image_reader(filename,*type));
if (reader.get()) if (reader.get())
{ {
boost::shared_ptr<image_32> image_ptr = boost::make_shared<image_32>(reader->width(),reader->height()); boost::shared_ptr<image_32> image_ptr = boost::make_shared<image_32>(reader->width(),reader->height());
reader->read(0,0,image_ptr->data()); reader->read(0,0,image_ptr->data());
return image_ptr; return image_ptr;
} }
throw mapnik::image_reader_exception("Failed to load: " + filename); throw mapnik::image_reader_exception("Failed to load: " + filename);
} }
throw mapnik::image_reader_exception("Unsupported image format:" + filename); throw mapnik::image_reader_exception("Unsupported image format:" + filename);
} }
void blend (image_32 & im, unsigned x, unsigned y, image_32 const& im2, float opacity) void blend (image_32 & im, unsigned x, unsigned y, image_32 const& im2, float opacity)
{ {
im.set_rectangle_alpha2(im2.data(),x,y,opacity); im.set_rectangle_alpha2(im2.data(),x,y,opacity);
@ -169,7 +169,7 @@ void export_image()
.value("src", mapnik::src) .value("src", mapnik::src)
.value("dst", mapnik::dst) .value("dst", mapnik::dst)
.value("src_over", mapnik::src_over) .value("src_over", mapnik::src_over)
.value("dst_over", mapnik::dst_over) .value("dst_over", mapnik::dst_over)
.value("src_in", mapnik::src_in) .value("src_in", mapnik::src_in)
.value("dst_in", mapnik::dst_in) .value("dst_in", mapnik::dst_in)
.value("src_out", mapnik::src_out) .value("src_out", mapnik::src_out)
@ -194,7 +194,7 @@ void export_image()
.value("invert", mapnik::invert) .value("invert", mapnik::invert)
.value("invert_rgb", mapnik::invert_rgb) .value("invert_rgb", mapnik::invert_rgb)
; ;
class_<image_32,boost::shared_ptr<image_32> >("Image","This class represents a 32 bit RGBA image.",init<int,int>()) class_<image_32,boost::shared_ptr<image_32> >("Image","This class represents a 32 bit RGBA image.",init<int,int>())
.def("width",&image_32::width) .def("width",&image_32::width)
.def("height",&image_32::height) .def("height",&image_32::height)
@ -209,7 +209,7 @@ void export_image()
.def("blend",&blend) .def("blend",&blend)
.def("composite",&composite) .def("composite",&composite)
//TODO(haoyu) The method name 'tostring' might be confusing since they actually return bytes in Python 3 //TODO(haoyu) The method name 'tostring' might be confusing since they actually return bytes in Python 3
.def("tostring",&tostring1) .def("tostring",&tostring1)
.def("tostring",&tostring2) .def("tostring",&tostring2)
.def("tostring",&tostring3) .def("tostring",&tostring3)
@ -222,6 +222,6 @@ void export_image()
.def("from_cairo",&from_cairo) .def("from_cairo",&from_cairo)
.staticmethod("from_cairo") .staticmethod("from_cairo")
#endif #endif
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -48,10 +48,10 @@ PyObject* view_tostring1(image_view<image_data_32> const& view)
std::ostringstream ss(std::ios::out|std::ios::binary); std::ostringstream ss(std::ios::out|std::ios::binary);
for (unsigned i=0;i<view.height();i++) for (unsigned i=0;i<view.height();i++)
{ {
ss.write(reinterpret_cast<const char*>(view.getRow(i)), ss.write(reinterpret_cast<const char*>(view.getRow(i)),
view.width() * sizeof(image_view<image_data_32>::pixel_type)); view.width() * sizeof(image_view<image_data_32>::pixel_type));
} }
return return
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
::PyBytes_FromStringAndSize ::PyBytes_FromStringAndSize
#else #else
@ -64,7 +64,7 @@ PyObject* view_tostring1(image_view<image_data_32> const& view)
PyObject* view_tostring2(image_view<image_data_32> const & view, std::string const& format) PyObject* view_tostring2(image_view<image_data_32> const & view, std::string const& format)
{ {
std::string s = save_to_string(view, format); std::string s = save_to_string(view, format);
return return
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
::PyBytes_FromStringAndSize ::PyBytes_FromStringAndSize
#else #else
@ -76,7 +76,7 @@ PyObject* view_tostring2(image_view<image_data_32> const & view, std::string con
PyObject* view_tostring3(image_view<image_data_32> const & view, std::string const& format, mapnik::rgba_palette const& pal) PyObject* view_tostring3(image_view<image_data_32> const & view, std::string const& format, mapnik::rgba_palette const& pal)
{ {
std::string s = save_to_string(view, format, pal); std::string s = save_to_string(view, format, pal);
return return
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
::PyBytes_FromStringAndSize ::PyBytes_FromStringAndSize
#else #else
@ -85,22 +85,22 @@ PyObject* view_tostring3(image_view<image_data_32> const & view, std::string con
(s.data(),s.size()); (s.data(),s.size());
} }
void save_view1(image_view<image_data_32> const& view, void save_view1(image_view<image_data_32> const& view,
std::string const& filename) std::string const& filename)
{ {
save_to_file(view,filename); save_to_file(view,filename);
} }
void save_view2(image_view<image_data_32> const& view, void save_view2(image_view<image_data_32> const& view,
std::string const& filename, std::string const& filename,
std::string const& type) std::string const& type)
{ {
save_to_file(view,filename,type); save_to_file(view,filename,type);
} }
void save_view3(image_view<image_data_32> const& view, void save_view3(image_view<image_data_32> const& view,
std::string const& filename, std::string const& filename,
std::string const& type, std::string const& type,
mapnik::rgba_palette const& pal) mapnik::rgba_palette const& pal)
{ {
save_to_file(view,filename,type,pal); save_to_file(view,filename,type,pal);

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -33,36 +33,36 @@ using mapnik::metawriter_inmem;
using mapnik::metawriter_inmem_ptr; using mapnik::metawriter_inmem_ptr;
namespace { namespace {
std::map<std::string, mapnik::value>::const_iterator std::map<std::string, mapnik::value>::const_iterator
mapnik_value_map_begin(const std::map<std::string, mapnik::value> &m) { mapnik_value_map_begin(const std::map<std::string, mapnik::value> &m) {
return m.begin(); return m.begin();
} }
std::map<std::string, mapnik::value>::const_iterator std::map<std::string, mapnik::value>::const_iterator
mapnik_value_map_end(const std::map<std::string, mapnik::value> &m) { mapnik_value_map_end(const std::map<std::string, mapnik::value> &m) {
return m.end(); return m.end();
} }
} }
void export_inmem_metawriter() { void export_inmem_metawriter() {
using namespace boost::python; using namespace boost::python;
class_<std::map<std::string, mapnik::value> > class_<std::map<std::string, mapnik::value> >
("MapnikProperties", "Retarded.", init<>()) ("MapnikProperties", "Retarded.", init<>())
.def("__iter__", range(&mapnik_value_map_begin, &mapnik_value_map_end)) .def("__iter__", range(&mapnik_value_map_begin, &mapnik_value_map_end))
; ;
class_<metawriter_inmem::meta_instance> class_<metawriter_inmem::meta_instance>
("MetaInstance", "Single rendered instance of meta-information.", no_init) ("MetaInstance", "Single rendered instance of meta-information.", no_init)
.def_readonly("box", &metawriter_inmem::meta_instance::box) .def_readonly("box", &metawriter_inmem::meta_instance::box)
.def_readonly("properties", &metawriter_inmem::meta_instance::properties) .def_readonly("properties", &metawriter_inmem::meta_instance::properties)
; ;
class_<metawriter_inmem, metawriter_inmem_ptr, boost::noncopyable> class_<metawriter_inmem, metawriter_inmem_ptr, boost::noncopyable>
("MetaWriterInMem", ("MetaWriterInMem",
"Collects meta-information about elements rendered.", "Collects meta-information about elements rendered.",
no_init) no_init)
.def("__iter__", range(&metawriter_inmem::inst_begin, .def("__iter__", range(&metawriter_inmem::inst_begin,
&metawriter_inmem::inst_end)) &metawriter_inmem::inst_end))
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -38,86 +38,86 @@ using boost::make_shared;
namespace namespace
{ {
boost::shared_ptr<label_collision_detector4> boost::shared_ptr<label_collision_detector4>
create_label_collision_detector_from_extent(box2d<double> const &extent) create_label_collision_detector_from_extent(box2d<double> const &extent)
{ {
return make_shared<label_collision_detector4>(extent); return make_shared<label_collision_detector4>(extent);
} }
boost::shared_ptr<label_collision_detector4> boost::shared_ptr<label_collision_detector4>
create_label_collision_detector_from_map(Map const &m) create_label_collision_detector_from_map(Map const &m)
{ {
double buffer = m.buffer_size(); double buffer = m.buffer_size();
box2d<double> extent(-buffer, -buffer, m.width() + buffer, m.height() + buffer); box2d<double> extent(-buffer, -buffer, m.width() + buffer, m.height() + buffer);
return make_shared<label_collision_detector4>(extent); return make_shared<label_collision_detector4>(extent);
} }
boost::python::list boost::python::list
make_label_boxes(boost::shared_ptr<label_collision_detector4> det) make_label_boxes(boost::shared_ptr<label_collision_detector4> det)
{ {
boost::python::list boxes; boost::python::list boxes;
for (label_collision_detector4::query_iterator jtr = det->begin(); for (label_collision_detector4::query_iterator jtr = det->begin();
jtr != det->end(); ++jtr) jtr != det->end(); ++jtr)
{ {
boxes.append<box2d<double> >(jtr->box); boxes.append<box2d<double> >(jtr->box);
} }
return boxes; return boxes;
} }
} }
void export_label_collision_detector() void export_label_collision_detector()
{ {
using namespace boost::python; using namespace boost::python;
// for overload resolution
void (label_collision_detector4::*insert_box)(box2d<double> const &) = &label_collision_detector4::insert;
class_<label_collision_detector4, boost::shared_ptr<label_collision_detector4>, boost::noncopyable> // for overload resolution
("LabelCollisionDetector", void (label_collision_detector4::*insert_box)(box2d<double> const &) = &label_collision_detector4::insert;
"Object to detect collisions between labels, used in the rendering process.",
no_init)
.def("__init__", make_constructor(create_label_collision_detector_from_extent), class_<label_collision_detector4, boost::shared_ptr<label_collision_detector4>, boost::noncopyable>
"Creates an empty collision detection object with a given extent. Note " ("LabelCollisionDetector",
"that the constructor from Map objects is a sensible default and usually " "Object to detect collisions between labels, used in the rendering process.",
"what you want to do.\n" no_init)
"\n"
"Example:\n"
">>> m = Map(size_x, size_y)\n"
">>> buf_sz = m.buffer_size\n"
">>> extent = mapnik.Box2d(-buf_sz, -buf_sz, m.width + buf_sz, m.height + buf_sz)\n"
">>> detector = mapnik.LabelCollisionDetector(extent)")
.def("__init__", make_constructor(create_label_collision_detector_from_map), .def("__init__", make_constructor(create_label_collision_detector_from_extent),
"Creates an empty collision detection object matching the given Map object. " "Creates an empty collision detection object with a given extent. Note "
"The created detector will have the same size, including the buffer, as the " "that the constructor from Map objects is a sensible default and usually "
"map object. This is usually what you want to do.\n" "what you want to do.\n"
"\n" "\n"
"Example:\n" "Example:\n"
">>> m = Map(size_x, size_y)\n" ">>> m = Map(size_x, size_y)\n"
">>> detector = mapnik.LabelCollisionDetector(m)") ">>> buf_sz = m.buffer_size\n"
">>> extent = mapnik.Box2d(-buf_sz, -buf_sz, m.width + buf_sz, m.height + buf_sz)\n"
">>> detector = mapnik.LabelCollisionDetector(extent)")
.def("extent", &label_collision_detector4::extent, return_value_policy<copy_const_reference>(), .def("__init__", make_constructor(create_label_collision_detector_from_map),
"Returns the total extent (bounding box) of all labels inside the detector.\n" "Creates an empty collision detection object matching the given Map object. "
"\n" "The created detector will have the same size, including the buffer, as the "
"Example:\n" "map object. This is usually what you want to do.\n"
">>> detector.extent()\n" "\n"
"Box2d(573.252589209,494.789179821,584.261023823,496.83610261)") "Example:\n"
">>> m = Map(size_x, size_y)\n"
">>> detector = mapnik.LabelCollisionDetector(m)")
.def("boxes", &make_label_boxes, .def("extent", &label_collision_detector4::extent, return_value_policy<copy_const_reference>(),
"Returns a list of all the label boxes inside the detector.") "Returns the total extent (bounding box) of all labels inside the detector.\n"
"\n"
"Example:\n"
">>> detector.extent()\n"
"Box2d(573.252589209,494.789179821,584.261023823,496.83610261)")
.def("insert", insert_box, .def("boxes", &make_label_boxes,
"Insert a 2d box into the collision detector. This can be used to ensure that " "Returns a list of all the label boxes inside the detector.")
"some space is left clear on the map for later overdrawing, for example by "
"non-Mapnik processes.\n" .def("insert", insert_box,
"\n" "Insert a 2d box into the collision detector. This can be used to ensure that "
"Example:\n" "some space is left clear on the map for later overdrawing, for example by "
">>> m = Map(size_x, size_y)\n" "non-Mapnik processes.\n"
">>> detector = mapnik.LabelCollisionDetector(m)" "\n"
">>> detector.insert(mapnik.Box2d(196, 254, 291, 389))") "Example:\n"
; ">>> m = Map(size_x, size_y)\n"
">>> detector = mapnik.LabelCollisionDetector(m)"
">>> detector.insert(mapnik.Box2d(196, 254, 291, 389))")
;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -53,7 +53,7 @@ struct layer_pickle_suite : boost::python::pickle_suite
for (unsigned i = 0; i < style_names.size(); ++i) for (unsigned i = 0; i < style_names.size(); ++i)
{ {
s.append(style_names[i]); s.append(style_names[i]);
} }
return boost::python::make_tuple(l.abstract(),l.title(),l.clear_label_cache(),l.getMinZoom(),l.getMaxZoom(),l.isQueryable(),l.datasource()->params(),l.cache_features(),s); return boost::python::make_tuple(l.abstract(),l.title(),l.clear_label_cache(),l.getMinZoom(),l.getMaxZoom(),l.isQueryable(),l.datasource()->params(),l.cache_features(),s);
} }
@ -84,7 +84,7 @@ struct layer_pickle_suite : boost::python::pickle_suite
mapnik::parameters params = extract<parameters>(state[6]); mapnik::parameters params = extract<parameters>(state[6]);
l.set_datasource(datasource_cache::instance()->create(params)); l.set_datasource(datasource_cache::instance()->create(params));
boost::python::list s = extract<boost::python::list>(state[7]); boost::python::list s = extract<boost::python::list>(state[7]);
for (int i=0;i<len(s);++i) for (int i=0;i<len(s);++i)
{ {
@ -103,7 +103,7 @@ void export_layer()
class_<std::vector<std::string> >("Names") class_<std::vector<std::string> >("Names")
.def(vector_indexing_suite<std::vector<std::string>,true >()) .def(vector_indexing_suite<std::vector<std::string>,true >())
; ;
class_<layer>("Layer", "A Mapnik map layer.", init<std::string const&,optional<std::string const&> >( class_<layer>("Layer", "A Mapnik map layer.", init<std::string const&,optional<std::string const&> >(
"Create a Layer with a named string and, optionally, an srs string.\n" "Create a Layer with a named string and, optionally, an srs string.\n"
"\n" "\n"
@ -119,8 +119,8 @@ void export_layer()
)) ))
.def_pickle(layer_pickle_suite()) .def_pickle(layer_pickle_suite())
.def("envelope",&layer::envelope, .def("envelope",&layer::envelope,
"Return the geographic envelope/bounding box." "Return the geographic envelope/bounding box."
"\n" "\n"
"Determined based on the layer datasource.\n" "Determined based on the layer datasource.\n"
@ -131,7 +131,7 @@ void export_layer()
">>> lyr.envelope()\n" ">>> lyr.envelope()\n"
"box2d(-1.0,-1.0,0.0,0.0) # default until a datasource is loaded\n" "box2d(-1.0,-1.0,0.0,0.0) # default until a datasource is loaded\n"
) )
.def("visible", &layer::isVisible, .def("visible", &layer::isVisible,
"Return True if this layer's data is active and visible at a given scale.\n" "Return True if this layer's data is active and visible at a given scale.\n"
"\n" "\n"
@ -151,8 +151,8 @@ void export_layer()
">>> lyr.visible(1.0/1000000)\n" ">>> lyr.visible(1.0/1000000)\n"
"False\n" "False\n"
) )
.add_property("abstract", .add_property("abstract",
make_function(&layer::abstract,return_value_policy<copy_const_reference>()), make_function(&layer::abstract,return_value_policy<copy_const_reference>()),
&layer::set_abstract, &layer::set_abstract,
"Get/Set the abstract of the layer.\n" "Get/Set the abstract of the layer.\n"
@ -181,7 +181,7 @@ void export_layer()
">>> lyr.active\n" ">>> lyr.active\n"
"False\n" "False\n"
) )
.add_property("clear_label_cache", .add_property("clear_label_cache",
&layer::clear_label_cache, &layer::clear_label_cache,
&layer::set_clear_label_cache, &layer::set_clear_label_cache,
@ -190,7 +190,7 @@ void export_layer()
"Usage:\n" "Usage:\n"
">>> lyr.clear_label_cache\n" ">>> lyr.clear_label_cache\n"
"False # False by default, meaning label positions from other layers will impact placement \n" "False # False by default, meaning label positions from other layers will impact placement \n"
">>> lyr.clear_label_cache = True # set to True to clear the label collision detector cache\n" ">>> lyr.clear_label_cache = True # set to True to clear the label collision detector cache\n"
) )
.add_property("cache_features", .add_property("cache_features",
@ -201,9 +201,9 @@ void export_layer()
"Usage:\n" "Usage:\n"
">>> lyr.cache_features\n" ">>> lyr.cache_features\n"
"False # False by default\n" "False # False by default\n"
">>> lyr.cache_features = True # set to True to enable feature caching\n" ">>> lyr.cache_features = True # set to True to enable feature caching\n"
) )
.add_property("datasource", .add_property("datasource",
&layer::datasource, &layer::datasource,
&layer::set_datasource, &layer::set_datasource,
@ -231,7 +231,7 @@ void export_layer()
">>> lyr.maxzoom\n" ">>> lyr.maxzoom\n"
"9.9999999999999995e-07\n" "9.9999999999999995e-07\n"
) )
.add_property("minzoom", .add_property("minzoom",
&layer::getMinZoom, &layer::getMinZoom,
&layer::setMinZoom, &layer::setMinZoom,
@ -245,9 +245,9 @@ void export_layer()
">>> lyr.minzoom = 1.0/1000000\n" ">>> lyr.minzoom = 1.0/1000000\n"
">>> lyr.minzoom\n" ">>> lyr.minzoom\n"
"9.9999999999999995e-07\n" "9.9999999999999995e-07\n"
) )
.add_property("name", .add_property("name",
make_function(&layer::name, return_value_policy<copy_const_reference>()), make_function(&layer::name, return_value_policy<copy_const_reference>()),
&layer::set_name, &layer::set_name,
"Get/Set the name of the layer.\n" "Get/Set the name of the layer.\n"
@ -277,7 +277,7 @@ void export_layer()
"True\n" "True\n"
) )
.add_property("srs", .add_property("srs",
make_function(&layer::srs,return_value_policy<copy_const_reference>()), make_function(&layer::srs,return_value_policy<copy_const_reference>()),
&layer::set_srs, &layer::set_srs,
"Get/Set the SRS of the layer.\n" "Get/Set the SRS of the layer.\n"
@ -309,7 +309,7 @@ void export_layer()
">>> lyr.styles[0]\n" ">>> lyr.styles[0]\n"
"'My Style'\n" "'My Style'\n"
) )
.add_property("title", .add_property("title",
make_function(&layer::title, return_value_policy<copy_const_reference>()), make_function(&layer::title, return_value_policy<copy_const_reference>()),
&layer::set_title, &layer::set_title,
@ -324,6 +324,6 @@ void export_layer()
">>> lyr.title\n" ">>> lyr.title\n"
"'My first layer'\n" "'My first layer'\n"
) )
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -38,14 +38,14 @@ using mapnik::parse_path;
namespace { namespace {
using namespace boost::python; using namespace boost::python;
const std::string get_filename(line_pattern_symbolizer const& t) const std::string get_filename(line_pattern_symbolizer const& t)
{ {
return path_processor_type::to_string(*t.get_filename()); return path_processor_type::to_string(*t.get_filename());
} }
void set_filename(line_pattern_symbolizer & t, std::string const& file_expr) void set_filename(line_pattern_symbolizer & t, std::string const& file_expr)
{ {
t.set_filename(parse_path(file_expr)); t.set_filename(parse_path(file_expr));
} }
} }
@ -56,7 +56,7 @@ struct line_pattern_symbolizer_pickle_suite : boost::python::pickle_suite
getinitargs(const line_pattern_symbolizer& l) getinitargs(const line_pattern_symbolizer& l)
{ {
std::string filename = path_processor_type::to_string(*l.get_filename()); std::string filename = path_processor_type::to_string(*l.get_filename());
// FIXME : Do we need "type" parameter at all ? // FIXME : Do we need "type" parameter at all ?
return boost::python::make_tuple(filename, guess_type(filename)); return boost::python::make_tuple(filename, guess_type(filename));
} }
}; };
@ -64,16 +64,16 @@ struct line_pattern_symbolizer_pickle_suite : boost::python::pickle_suite
void export_line_pattern_symbolizer() void export_line_pattern_symbolizer()
{ {
using namespace boost::python; using namespace boost::python;
class_<line_pattern_symbolizer>("LinePatternSymbolizer", class_<line_pattern_symbolizer>("LinePatternSymbolizer",
init<path_expression_ptr> init<path_expression_ptr>
("<image file expression>")) ("<image file expression>"))
//.def_pickle(line_pattern_symbolizer_pickle_suite()) //.def_pickle(line_pattern_symbolizer_pickle_suite())
.add_property("transform", .add_property("transform",
mapnik::get_svg_transform<line_pattern_symbolizer>, mapnik::get_svg_transform<line_pattern_symbolizer>,
mapnik::set_svg_transform<line_pattern_symbolizer>) mapnik::set_svg_transform<line_pattern_symbolizer>)
.add_property("filename", .add_property("filename",
&get_filename, &get_filename,
&set_filename) &set_filename)
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -43,7 +43,7 @@ struct line_symbolizer_pickle_suite : boost::python::pickle_suite
void export_line_symbolizer() void export_line_symbolizer()
{ {
using namespace boost::python; using namespace boost::python;
enumeration_<line_rasterizer_e>("line_rasterizer") enumeration_<line_rasterizer_e>("line_rasterizer")
.value("FULL",RASTERIZER_FULL) .value("FULL",RASTERIZER_FULL)
.value("FAST",RASTERIZER_FAST) .value("FAST",RASTERIZER_FAST)
@ -62,5 +62,5 @@ void export_line_symbolizer()
(&line_symbolizer::get_stroke, (&line_symbolizer::get_stroke,
return_value_policy<copy_const_reference>()), return_value_policy<copy_const_reference>()),
&line_symbolizer::set_stroke) &line_symbolizer::set_stroke)
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -57,7 +57,7 @@ struct map_pickle_suite : boost::python::pickle_suite
{ {
l.append(m.getLayer(i)); l.append(m.getLayer(i));
} }
boost::python::list s; boost::python::list s;
Map::const_style_iterator it = m.styles().begin(); Map::const_style_iterator it = m.styles().begin();
Map::const_style_iterator end = m.styles().end(); Map::const_style_iterator end = m.styles().end();
@ -91,14 +91,14 @@ struct map_pickle_suite : boost::python::pickle_suite
{ {
color bg = extract<color>(state[1]); color bg = extract<color>(state[1]);
m.set_background(bg); m.set_background(bg);
} }
boost::python::list l=extract<boost::python::list>(state[2]); boost::python::list l=extract<boost::python::list>(state[2]);
for (int i=0;i<len(l);++i) for (int i=0;i<len(l);++i)
{ {
m.addLayer(extract<layer>(l[i])); m.addLayer(extract<layer>(l[i]));
} }
boost::python::list s=extract<boost::python::list>(state[3]); boost::python::list s=extract<boost::python::list>(state[3]);
for (int i=0;i<len(s);++i) for (int i=0;i<len(s);++i)
{ {
@ -112,7 +112,7 @@ struct map_pickle_suite : boost::python::pickle_suite
{ {
std::string base_path = extract<std::string>(state[4]); std::string base_path = extract<std::string>(state[4]);
m.set_base_path(base_path); m.set_base_path(base_path);
} }
} }
}; };
@ -138,17 +138,17 @@ bool has_metawriter(mapnik::Map const& m)
return false; return false;
} }
// returns empty shared_ptr when the metawriter isn't found, or is // returns empty shared_ptr when the metawriter isn't found, or is
// of the wrong type. empty pointers make it back to Python as a None. // of the wrong type. empty pointers make it back to Python as a None.
mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map &m, const std::string &name) { mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map &m, const std::string &name) {
mapnik::metawriter_ptr metawriter = m.find_metawriter(name); mapnik::metawriter_ptr metawriter = m.find_metawriter(name);
mapnik::metawriter_inmem_ptr inmem; mapnik::metawriter_inmem_ptr inmem;
if (metawriter) { if (metawriter) {
inmem = boost::dynamic_pointer_cast<mapnik::metawriter_inmem>(metawriter); inmem = boost::dynamic_pointer_cast<mapnik::metawriter_inmem>(metawriter);
} }
return inmem; return inmem;
} }
// TODO - we likely should allow indexing by negative number from python // TODO - we likely should allow indexing by negative number from python
@ -157,7 +157,7 @@ mapnik::featureset_ptr query_point(mapnik::Map const& m, int index, double x, do
{ {
if (index < 0){ if (index < 0){
PyErr_SetString(PyExc_IndexError, "Please provide a layer index >= 0"); PyErr_SetString(PyExc_IndexError, "Please provide a layer index >= 0");
boost::python::throw_error_already_set(); boost::python::throw_error_already_set();
} }
unsigned idx = index; unsigned idx = index;
return m.query_point(idx, x, y); return m.query_point(idx, x, y);
@ -167,16 +167,16 @@ mapnik::featureset_ptr query_map_point(mapnik::Map const& m, int index, double x
{ {
if (index < 0){ if (index < 0){
PyErr_SetString(PyExc_IndexError, "Please provide a layer index >= 0"); PyErr_SetString(PyExc_IndexError, "Please provide a layer index >= 0");
boost::python::throw_error_already_set(); boost::python::throw_error_already_set();
} }
unsigned idx = index; unsigned idx = index;
return m.query_map_point(idx, x, y); return m.query_map_point(idx, x, y);
} }
void export_map() void export_map()
{ {
using namespace boost::python; using namespace boost::python;
// aspect ratio fix modes // aspect ratio fix modes
mapnik::enumeration_<mapnik::aspect_fix_mode_e>("aspect_fix_mode") mapnik::enumeration_<mapnik::aspect_fix_mode_e>("aspect_fix_mode")
.value("GROW_BBOX", mapnik::Map::GROW_BBOX) .value("GROW_BBOX", mapnik::Map::GROW_BBOX)
@ -188,12 +188,12 @@ void export_map()
.value("ADJUST_CANVAS_WIDTH",mapnik::Map::ADJUST_CANVAS_WIDTH) .value("ADJUST_CANVAS_WIDTH",mapnik::Map::ADJUST_CANVAS_WIDTH)
.value("ADJUST_CANVAS_HEIGHT", mapnik::Map::ADJUST_CANVAS_HEIGHT) .value("ADJUST_CANVAS_HEIGHT", mapnik::Map::ADJUST_CANVAS_HEIGHT)
; ;
python_optional<mapnik::color> (); python_optional<mapnik::color> ();
class_<std::vector<layer> >("Layers") class_<std::vector<layer> >("Layers")
.def(vector_indexing_suite<std::vector<layer> >()) .def(vector_indexing_suite<std::vector<layer> >())
; ;
class_<Map>("Map","The map object.",init<int,int,optional<std::string const&> >( class_<Map>("Map","The map object.",init<int,int,optional<std::string const&> >(
( arg("width"),arg("height"),arg("srs") ), ( arg("width"),arg("height"),arg("srs") ),
"Create a Map with a width and height as integers and, optionally,\n" "Create a Map with a width and height as integers and, optionally,\n"
@ -209,10 +209,10 @@ void export_map()
">>> m.srs\n" ">>> m.srs\n"
"'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'\n" "'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'\n"
)) ))
.def_pickle(map_pickle_suite() .def_pickle(map_pickle_suite()
) )
.def("append_style",&Map::insert_style, .def("append_style",&Map::insert_style,
(arg("style_name"),arg("style_object")), (arg("style_name"),arg("style_object")),
"Insert a Mapnik Style onto the map by appending it.\n" "Insert a Mapnik Style onto the map by appending it.\n"
@ -278,7 +278,7 @@ void export_map()
">>> m.has_metawriter()\n" ">>> m.has_metawriter()\n"
"False\n" "False\n"
) )
.def("pan",&Map::pan, .def("pan",&Map::pan,
(arg("x"),arg("y")), (arg("x"),arg("y")),
"Set the Map center at a given x,y location\n" "Set the Map center at a given x,y location\n"
@ -292,7 +292,7 @@ void export_map()
">>> m.envelope().center()\n" ">>> m.envelope().center()\n"
"Coord(0.00166666666667,-0.835)\n" "Coord(0.00166666666667,-0.835)\n"
) )
.def("pan_and_zoom",&Map::pan_and_zoom, .def("pan_and_zoom",&Map::pan_and_zoom,
(arg("x"),arg("y"),arg("factor")), (arg("x"),arg("y"),arg("factor")),
"Set the Map center at a given x,y location\n" "Set the Map center at a given x,y location\n"
@ -308,7 +308,7 @@ void export_map()
">>> m.scale()\n" ">>> m.scale()\n"
"0.00062500000000000001\n" "0.00062500000000000001\n"
) )
.def("query_map_point",query_map_point, .def("query_map_point",query_map_point,
(arg("layer_idx"),arg("pixel_x"),arg("pixel_y")), (arg("layer_idx"),arg("pixel_x"),arg("pixel_y")),
"Query a Map Layer (by layer index) for features \n" "Query a Map Layer (by layer index) for features \n"
@ -325,7 +325,7 @@ void export_map()
">>> featureset.features\n" ">>> featureset.features\n"
">>> [<mapnik.Feature object at 0x3995630>]\n" ">>> [<mapnik.Feature object at 0x3995630>]\n"
) )
.def("query_point",query_point, .def("query_point",query_point,
(arg("layer idx"),arg("x"),arg("y")), (arg("layer idx"),arg("x"),arg("y")),
"Query a Map Layer (by layer index) for features \n" "Query a Map Layer (by layer index) for features \n"
@ -349,7 +349,7 @@ void export_map()
"Usage:\n" "Usage:\n"
">>> m.remove_all()\n" ">>> m.remove_all()\n"
) )
.def("remove_style",&Map::remove_style, .def("remove_style",&Map::remove_style,
(arg("style_name")), (arg("style_name")),
"Remove a Mapnik Style from the map.\n" "Remove a Mapnik Style from the map.\n"
@ -365,7 +365,7 @@ void export_map()
"Usage:\n" "Usage:\n"
">>> m.resize(64,64)\n" ">>> m.resize(64,64)\n"
) )
.def("scale", &Map::scale, .def("scale", &Map::scale,
"Return the Map Scale.\n" "Return the Map Scale.\n"
"Usage:\n" "Usage:\n"
@ -379,16 +379,16 @@ void export_map()
"\n" "\n"
">>> m.scale_denominator()\n" ">>> m.scale_denominator()\n"
) )
.def("view_transform",&Map::view_transform, .def("view_transform",&Map::view_transform,
"Return the map ViewTransform object\n" "Return the map ViewTransform object\n"
"which is used internally to convert between\n" "which is used internally to convert between\n"
"geographic coordinates and screen coordinates.\n" "geographic coordinates and screen coordinates.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> m.view_transform()\n" ">>> m.view_transform()\n"
) )
.def("zoom",&Map::zoom, .def("zoom",&Map::zoom,
(arg("factor")), (arg("factor")),
"Zoom in or out by a given factor.\n" "Zoom in or out by a given factor.\n"
@ -399,7 +399,7 @@ void export_map()
"\n" "\n"
">>> m.zoom(0.25)\n" ">>> m.zoom(0.25)\n"
) )
.def("zoom_all",&Map::zoom_all, .def("zoom_all",&Map::zoom_all,
"Set the geographical extent of the map\n" "Set the geographical extent of the map\n"
"to the combined extents of all active layers.\n" "to the combined extents of all active layers.\n"
@ -407,7 +407,7 @@ void export_map()
"Usage:\n" "Usage:\n"
">>> m.zoom_all()\n" ">>> m.zoom_all()\n"
) )
.def("zoom_to_box",&Map::zoom_to_box, .def("zoom_to_box",&Map::zoom_to_box,
(arg("Boxd2")), (arg("Boxd2")),
"Set the geographical extent of the map\n" "Set the geographical extent of the map\n"
@ -418,37 +418,37 @@ void export_map()
">>> m.zoom_to_box(extent)\n" ">>> m.zoom_to_box(extent)\n"
) )
.def("get_metawriter_property", &Map::get_metawriter_property, .def("get_metawriter_property", &Map::get_metawriter_property,
(arg("name")), (arg("name")),
"Reads a metawriter property.\n" "Reads a metawriter property.\n"
"These properties are completely user-defined and can be used to" "These properties are completely user-defined and can be used to"
"create filenames, etc.\n" "create filenames, etc.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> map.set_metawriter_property(\"x\", \"10\")\n" ">>> map.set_metawriter_property(\"x\", \"10\")\n"
">>> map.get_metawriter_property(\"x\")\n" ">>> map.get_metawriter_property(\"x\")\n"
"10\n" "10\n"
) )
.def("set_metawriter_property", &Map::set_metawriter_property, .def("set_metawriter_property", &Map::set_metawriter_property,
(arg("name"),arg("value")), (arg("name"),arg("value")),
"Sets a metawriter property.\n" "Sets a metawriter property.\n"
"These properties are completely user-defined and can be used to" "These properties are completely user-defined and can be used to"
"create filenames, etc.\n" "create filenames, etc.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> map.set_metawriter_property(\"x\", str(x))\n" ">>> map.set_metawriter_property(\"x\", str(x))\n"
">>> map.set_metawriter_property(\"y\", str(y))\n" ">>> map.set_metawriter_property(\"y\", str(y))\n"
">>> map.set_metawriter_property(\"z\", str(z))\n" ">>> map.set_metawriter_property(\"z\", str(z))\n"
"\n" "\n"
"Use a path like \"[z]/[x]/[y].json\" to create filenames.\n" "Use a path like \"[z]/[x]/[y].json\" to create filenames.\n"
) )
.def("find_inmem_metawriter", find_inmem_metawriter, .def("find_inmem_metawriter", find_inmem_metawriter,
(arg("name")), (arg("name")),
"Gets an inmem metawriter, or None if no such metawriter " "Gets an inmem metawriter, or None if no such metawriter "
"exists.\n" "exists.\n"
"Use this after the map has been rendered to retrieve information " "Use this after the map has been rendered to retrieve information "
"about the hit areas rendered on the map.\n" "about the hit areas rendered on the map.\n"
) )
.def("extra_attributes",&Map::get_extra_attributes,return_value_policy<copy_const_reference>(),"TODO") .def("extra_attributes",&Map::get_extra_attributes,return_value_policy<copy_const_reference>(),"TODO")
.add_property("aspect_fix_mode", .add_property("aspect_fix_mode",
@ -460,8 +460,8 @@ void export_map()
"Usage:\n" "Usage:\n"
"\n" "\n"
">>> m.aspect_fix_mode = aspect_fix_mode.GROW_BBOX\n" ">>> m.aspect_fix_mode = aspect_fix_mode.GROW_BBOX\n"
) )
.add_property("background",make_function .add_property("background",make_function
(&Map::background,return_value_policy<copy_const_reference>()), (&Map::background,return_value_policy<copy_const_reference>()),
&Map::set_background, &Map::set_background,
@ -480,7 +480,7 @@ void export_map()
"Usage:\n" "Usage:\n"
">>> m.base_path = '.'\n" ">>> m.base_path = '.'\n"
) )
.add_property("buffer_size", .add_property("buffer_size",
&Map::buffer_size, &Map::buffer_size,
&Map::set_buffer_size, &Map::set_buffer_size,
@ -493,7 +493,7 @@ void export_map()
">>> m.buffer_size\n" ">>> m.buffer_size\n"
"2\n" "2\n"
) )
.add_property("height", .add_property("height",
&Map::height, &Map::height,
&Map::set_height, &Map::set_height,
@ -507,9 +507,9 @@ void export_map()
">>> m.height\n" ">>> m.height\n"
"600\n" "600\n"
) )
.add_property("layers",make_function .add_property("layers",make_function
(layers_nonconst,return_value_policy<reference_existing_object>()), (layers_nonconst,return_value_policy<reference_existing_object>()),
"The list of map layers.\n" "The list of map layers.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
@ -548,7 +548,7 @@ void export_map()
"... \n" "... \n"
">>> m.srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over'\n" ">>> m.srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over'\n"
) )
.add_property("width", .add_property("width",
&Map::width, &Map::width,
&Map::set_width, &Map::set_width,

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2010 Artem Pavlenko
@ -33,18 +33,18 @@ using mapnik::symbolizer_with_image;
using mapnik::path_processor_type; using mapnik::path_processor_type;
using mapnik::parse_path; using mapnik::parse_path;
namespace { namespace {
using namespace boost::python; using namespace boost::python;
std::string get_filename(mapnik::markers_symbolizer const& symbolizer) std::string get_filename(mapnik::markers_symbolizer const& symbolizer)
{ {
return path_processor_type::to_string(*symbolizer.get_filename()); return path_processor_type::to_string(*symbolizer.get_filename());
} }
void set_filename(mapnik::markers_symbolizer & symbolizer, std::string const& file_expr) void set_filename(mapnik::markers_symbolizer & symbolizer, std::string const& file_expr)
{ {
symbolizer.set_filename(parse_path(file_expr)); symbolizer.set_filename(parse_path(file_expr));
} }
} }
@ -75,10 +75,10 @@ struct markers_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
p.set_allow_overlap(extract<bool>(state[0])); p.set_allow_overlap(extract<bool>(state[0]));
//p.set_opacity(extract<float>(state[1])); //p.set_opacity(extract<float>(state[1]));
} }
}; };
@ -87,14 +87,14 @@ struct markers_symbolizer_pickle_suite : boost::python::pickle_suite
void export_markers_symbolizer() void export_markers_symbolizer()
{ {
using namespace boost::python; using namespace boost::python;
class_<markers_symbolizer>("MarkersSymbolizer", class_<markers_symbolizer>("MarkersSymbolizer",
init<>("Default Markers Symbolizer - blue arrow")) init<>("Default Markers Symbolizer - blue arrow"))
.def (init<mapnik::path_expression_ptr>("<path expression ptr>")) .def (init<mapnik::path_expression_ptr>("<path expression ptr>"))
//.def_pickle(markers_symbolizer_pickle_suite()) //.def_pickle(markers_symbolizer_pickle_suite())
.add_property("filename", .add_property("filename",
&get_filename, &get_filename,
&set_filename) &set_filename)
.add_property("allow_overlap", .add_property("allow_overlap",
&markers_symbolizer::get_allow_overlap, &markers_symbolizer::get_allow_overlap,
&markers_symbolizer::set_allow_overlap) &markers_symbolizer::set_allow_overlap)

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -40,14 +40,14 @@ static boost::shared_ptr<mapnik::rgba_palette> make_palette( const std::string&
return boost::make_shared<mapnik::rgba_palette>(palette, type); return boost::make_shared<mapnik::rgba_palette>(palette, type);
} }
void export_palette () void export_palette ()
{ {
using namespace boost::python; using namespace boost::python;
class_<boost::shared_ptr<mapnik::rgba_palette> >("Palette",no_init) class_<boost::shared_ptr<mapnik::rgba_palette> >("Palette",no_init)
/*, init<std::string,std::string>( /*, init<std::string,std::string>(
( arg("palette"), arg("type")), ( arg("palette"), arg("type")),
"Creates a new color palette from a file\n" "Creates a new color palette from a file\n"
)*/ )*/
.def( "__init__", boost::python::make_constructor( &make_palette)) .def( "__init__", boost::python::make_constructor( &make_palette))
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -33,14 +33,14 @@ using mapnik::parameters;
struct pickle_value : public boost::static_visitor<> struct pickle_value : public boost::static_visitor<>
{ {
public: public:
pickle_value( boost::python::list vals): pickle_value( boost::python::list vals):
vals_(vals) {} vals_(vals) {}
void operator () ( int val ) void operator () ( int val )
{ {
vals_.append(val); vals_.append(val);
} }
void operator () ( double val ) void operator () ( double val )
{ {
vals_.append(val); vals_.append(val);
@ -50,7 +50,7 @@ public:
{ {
vals_.append(val); vals_.append(val);
} }
private: private:
boost::python::list vals_; boost::python::list vals_;
@ -97,7 +97,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
dict d = extract<dict>(state[0]); dict d = extract<dict>(state[0]);
boost::python::list keys = d.keys(); boost::python::list keys = d.keys();
for (int i=0; i<len(keys); ++i) for (int i=0; i<len(keys); ++i)
@ -107,7 +107,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
extract<std::string> ex0(obj); extract<std::string> ex0(obj);
extract<int> ex1(obj); extract<int> ex1(obj);
extract<double> ex2(obj); extract<double> ex2(obj);
if (ex0.check()) if (ex0.check())
{ {
p[key] = ex0(); p[key] = ex0();
@ -119,14 +119,14 @@ struct parameters_pickle_suite : boost::python::pickle_suite
else if (ex2.check()) else if (ex2.check())
{ {
p[key] = ex2(); p[key] = ex2();
} }
/* /*
extract_value serializer( p, key ); extract_value serializer( p, key );
mapnik::value_holder val = extract<mapnik::value_holder>(d[key]); mapnik::value_holder val = extract<mapnik::value_holder>(d[key]);
boost::apply_visitor( serializer, val ); boost::apply_visitor( serializer, val );
*/ */
} }
} }
}; };

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -39,14 +39,14 @@ using mapnik::parse_path;
namespace { namespace {
using namespace boost::python; using namespace boost::python;
const std::string get_filename(point_symbolizer const& t) const std::string get_filename(point_symbolizer const& t)
{ {
return path_processor_type::to_string(*t.get_filename()); return path_processor_type::to_string(*t.get_filename());
} }
void set_filename(point_symbolizer & t, std::string const& file_expr) void set_filename(point_symbolizer & t, std::string const& file_expr)
{ {
t.set_filename(parse_path(file_expr)); t.set_filename(parse_path(file_expr));
} }
} }
@ -81,12 +81,12 @@ struct point_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
p.set_allow_overlap(extract<bool>(state[0])); p.set_allow_overlap(extract<bool>(state[0]));
p.set_opacity(extract<float>(state[1])); p.set_opacity(extract<float>(state[1]));
p.set_ignore_placement(extract<bool>(state[2])); p.set_ignore_placement(extract<bool>(state[2]));
p.set_point_placement(extract<point_placement_e>(state[3])); p.set_point_placement(extract<point_placement_e>(state[3]));
} }
}; };
@ -100,7 +100,7 @@ void export_point_symbolizer()
.value("CENTROID",CENTROID_POINT_PLACEMENT) .value("CENTROID",CENTROID_POINT_PLACEMENT)
.value("INTERIOR",INTERIOR_POINT_PLACEMENT) .value("INTERIOR",INTERIOR_POINT_PLACEMENT)
; ;
class_<point_symbolizer>("PointSymbolizer", class_<point_symbolizer>("PointSymbolizer",
init<>("Default Point Symbolizer - 4x4 black square")) init<>("Default Point Symbolizer - 4x4 black square"))
.def (init<mapnik::path_expression_ptr>("<path expression ptr>")) .def (init<mapnik::path_expression_ptr>("<path expression ptr>"))

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -38,14 +38,14 @@ using mapnik::guess_type;
namespace { namespace {
using namespace boost::python; using namespace boost::python;
const std::string get_filename(polygon_pattern_symbolizer const& t) const std::string get_filename(polygon_pattern_symbolizer const& t)
{ {
return path_processor_type::to_string(*t.get_filename()); return path_processor_type::to_string(*t.get_filename());
} }
void set_filename(polygon_pattern_symbolizer & t, std::string const& file_expr) void set_filename(polygon_pattern_symbolizer & t, std::string const& file_expr)
{ {
t.set_filename(parse_path(file_expr)); t.set_filename(parse_path(file_expr));
} }
} }
@ -77,7 +77,7 @@ struct polygon_pattern_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
p.set_alignment(extract<pattern_alignment_e>(state[0])); p.set_alignment(extract<pattern_alignment_e>(state[0]));
p.set_gamma(extract<float>(state[1])); p.set_gamma(extract<float>(state[1]));
} }
@ -92,22 +92,22 @@ void export_polygon_pattern_symbolizer()
.value("LOCAL",LOCAL_ALIGNMENT) .value("LOCAL",LOCAL_ALIGNMENT)
.value("GLOBAL",GLOBAL_ALIGNMENT) .value("GLOBAL",GLOBAL_ALIGNMENT)
; ;
class_<polygon_pattern_symbolizer>("PolygonPatternSymbolizer", class_<polygon_pattern_symbolizer>("PolygonPatternSymbolizer",
init<path_expression_ptr>("<path_expression_ptr>")) init<path_expression_ptr>("<path_expression_ptr>"))
.def_pickle(polygon_pattern_symbolizer_pickle_suite()) .def_pickle(polygon_pattern_symbolizer_pickle_suite())
.add_property("alignment", .add_property("alignment",
&polygon_pattern_symbolizer::get_alignment, &polygon_pattern_symbolizer::get_alignment,
&polygon_pattern_symbolizer::set_alignment, &polygon_pattern_symbolizer::set_alignment,
"Set/get the alignment of the pattern") "Set/get the alignment of the pattern")
.add_property("transform", .add_property("transform",
mapnik::get_svg_transform<polygon_pattern_symbolizer>, mapnik::get_svg_transform<polygon_pattern_symbolizer>,
mapnik::set_svg_transform<polygon_pattern_symbolizer>) mapnik::set_svg_transform<polygon_pattern_symbolizer>)
.add_property("filename", .add_property("filename",
&get_filename, &get_filename,
&set_filename) &set_filename)
.add_property("gamma", .add_property("gamma",
&polygon_pattern_symbolizer::get_gamma, &polygon_pattern_symbolizer::get_gamma,
&polygon_pattern_symbolizer::set_gamma) &polygon_pattern_symbolizer::set_gamma)
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -32,7 +32,7 @@ struct polygon_symbolizer_pickle_suite : boost::python::pickle_suite
static boost::python::tuple static boost::python::tuple
getinitargs(const polygon_symbolizer& p) getinitargs(const polygon_symbolizer& p)
{ {
return boost::python::make_tuple(p.get_fill()); return boost::python::make_tuple(p.get_fill());
} }
static boost::python::tuple static boost::python::tuple
@ -53,7 +53,7 @@ struct polygon_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
p.set_opacity(extract<float>(state[0])); p.set_opacity(extract<float>(state[0]));
p.set_gamma(extract<float>(state[1])); p.set_gamma(extract<float>(state[1]));
} }
@ -63,7 +63,7 @@ struct polygon_symbolizer_pickle_suite : boost::python::pickle_suite
void export_polygon_symbolizer() void export_polygon_symbolizer()
{ {
using namespace boost::python; using namespace boost::python;
class_<polygon_symbolizer>("PolygonSymbolizer", class_<polygon_symbolizer>("PolygonSymbolizer",
init<>("Default PolygonSymbolizer - solid fill grey")) init<>("Default PolygonSymbolizer - solid fill grey"))
.def(init<color const&>("TODO")) .def(init<color const&>("TODO"))
@ -78,6 +78,6 @@ void export_polygon_symbolizer()
.add_property("gamma", .add_property("gamma",
&polygon_symbolizer::get_gamma, &polygon_symbolizer::get_gamma,
&polygon_symbolizer::set_gamma) &polygon_symbolizer::set_gamma)
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2009 Artem Pavlenko * Copyright (C) 2009 Artem Pavlenko
@ -25,7 +25,7 @@
#include <mapnik/proj_transform.hpp> #include <mapnik/proj_transform.hpp>
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>
using mapnik::proj_transform; using mapnik::proj_transform;
using mapnik::projection; using mapnik::projection;
@ -54,7 +54,7 @@ mapnik::coord2d forward_transform_c(mapnik::proj_transform& t, mapnik::coord2d c
} }
return mapnik::coord2d(x,y); return mapnik::coord2d(x,y);
} }
mapnik::coord2d backward_transform_c(mapnik::proj_transform& t, mapnik::coord2d const& c) mapnik::coord2d backward_transform_c(mapnik::proj_transform& t, mapnik::coord2d const& c)
{ {
double x = c.x; double x = c.x;
@ -122,7 +122,7 @@ mapnik::box2d<double> backward_transform_env_p(mapnik::proj_transform& t, mapnik
void export_proj_transform () void export_proj_transform ()
{ {
using namespace boost::python; using namespace boost::python;
class_<proj_transform, boost::noncopyable>("ProjTransform", init< projection const&, projection const& >()) class_<proj_transform, boost::noncopyable>("ProjTransform", init< projection const&, projection const& >())
.def_pickle(proj_transform_pickle_suite()) .def_pickle(proj_transform_pickle_suite())
.def("forward", forward_transform_c) .def("forward", forward_transform_c)
@ -132,5 +132,5 @@ void export_proj_transform ()
.def("forward", forward_transform_env_p) .def("forward", forward_transform_env_p)
.def("backward",backward_transform_env_p) .def("backward",backward_transform_env_p)
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -41,7 +41,7 @@ struct projection_pickle_suite : boost::python::pickle_suite
}; };
namespace { namespace {
mapnik::coord2d forward_pt(mapnik::coord2d const& pt, mapnik::coord2d forward_pt(mapnik::coord2d const& pt,
mapnik::projection const& prj) mapnik::projection const& prj)
{ {
double x = pt.x; double x = pt.x;
@ -49,8 +49,8 @@ mapnik::coord2d forward_pt(mapnik::coord2d const& pt,
prj.forward(x,y); prj.forward(x,y);
return mapnik::coord2d(x,y); return mapnik::coord2d(x,y);
} }
mapnik::coord2d inverse_pt(mapnik::coord2d const& pt, mapnik::coord2d inverse_pt(mapnik::coord2d const& pt,
mapnik::projection const& prj) mapnik::projection const& prj)
{ {
double x = pt.x; double x = pt.x;
@ -58,7 +58,7 @@ mapnik::coord2d inverse_pt(mapnik::coord2d const& pt,
prj.inverse(x,y); prj.inverse(x,y);
return mapnik::coord2d(x,y); return mapnik::coord2d(x,y);
} }
mapnik::box2d<double> forward_env(mapnik::box2d<double> const & box, mapnik::box2d<double> forward_env(mapnik::box2d<double> const & box,
mapnik::projection const& prj) mapnik::projection const& prj)
{ {
@ -70,7 +70,7 @@ mapnik::box2d<double> forward_env(mapnik::box2d<double> const & box,
prj.forward(maxx,maxy); prj.forward(maxx,maxy);
return mapnik::box2d<double>(minx,miny,maxx,maxy); return mapnik::box2d<double>(minx,miny,maxx,maxy);
} }
mapnik::box2d<double> inverse_env(mapnik::box2d<double> const & box, mapnik::box2d<double> inverse_env(mapnik::box2d<double> const & box,
mapnik::projection const& prj) mapnik::projection const& prj)
{ {
@ -82,18 +82,18 @@ mapnik::box2d<double> inverse_env(mapnik::box2d<double> const & box,
prj.inverse(maxx,maxy); prj.inverse(maxx,maxy);
return mapnik::box2d<double>(minx,miny,maxx,maxy); return mapnik::box2d<double>(minx,miny,maxx,maxy);
} }
} }
void export_projection () void export_projection ()
{ {
using namespace boost::python; using namespace boost::python;
class_<projection>("Projection", "Represents a map projection.",init<optional<std::string const&> >( class_<projection>("Projection", "Represents a map projection.",init<optional<std::string const&> >(
(arg("proj4_string")), (arg("proj4_string")),
"Constructs a new projection from its PROJ.4 string representation.\n" "Constructs a new projection from its PROJ.4 string representation.\n"
"\n" "\n"
"The parameterless version of this constructor is equivalent to\n" "The parameterless version of this constructor is equivalent to\n"
" Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')\n" " Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')\n"
"\n" "\n"
"The constructor will throw a RuntimeError in case the projection\n" "The constructor will throw a RuntimeError in case the projection\n"
@ -110,10 +110,10 @@ void export_projection ()
"This property is True if the projection is a geographic projection\n" "This property is True if the projection is a geographic projection\n"
"(i.e. it uses lon/lat coordinates)\n") "(i.e. it uses lon/lat coordinates)\n")
; ;
def("forward_",&forward_pt); def("forward_",&forward_pt);
def("inverse_",&inverse_pt); def("inverse_",&inverse_pt);
def("forward_",&forward_env); def("forward_",&forward_env);
def("inverse_",&inverse_env); def("inverse_",&inverse_env);
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -99,53 +99,53 @@ namespace boost { namespace python {
return boost::apply_visitor(value_converter(),v.base()); return boost::apply_visitor(value_converter(),v.base());
} }
}; };
}} }}
void render(const mapnik::Map& map, void render(const mapnik::Map& map,
mapnik::image_32& image, mapnik::image_32& image,
double scale_factor = 1.0,
unsigned offset_x = 0u,
unsigned offset_y = 0u)
{
Py_BEGIN_ALLOW_THREADS
try
{
mapnik::agg_renderer<mapnik::image_32> ren(map,image,scale_factor,offset_x, offset_y);
ren.apply();
}
catch (...)
{
Py_BLOCK_THREADS
throw;
}
Py_END_ALLOW_THREADS
}
void render_with_detector(
const mapnik::Map &map,
mapnik::image_32 &image,
boost::shared_ptr<mapnik::label_collision_detector4> detector,
double scale_factor = 1.0, double scale_factor = 1.0,
unsigned offset_x = 0u, unsigned offset_x = 0u,
unsigned offset_y = 0u) unsigned offset_y = 0u)
{ {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
try try
{ {
mapnik::agg_renderer<mapnik::image_32> ren(map,image,scale_factor,offset_x, offset_y); mapnik::agg_renderer<mapnik::image_32> ren(map,image,detector);
ren.apply(); ren.apply();
} }
catch (...) catch (...)
{ {
Py_BLOCK_THREADS Py_BLOCK_THREADS
throw; throw;
} }
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
void render_with_detector(
const mapnik::Map &map,
mapnik::image_32 &image,
boost::shared_ptr<mapnik::label_collision_detector4> detector,
double scale_factor = 1.0,
unsigned offset_x = 0u,
unsigned offset_y = 0u)
{
Py_BEGIN_ALLOW_THREADS
try
{
mapnik::agg_renderer<mapnik::image_32> ren(map,image,detector);
ren.apply();
}
catch (...)
{
Py_BLOCK_THREADS
throw;
}
Py_END_ALLOW_THREADS
}
void render_layer2(const mapnik::Map& map, void render_layer2(const mapnik::Map& map,
mapnik::image_32& image, mapnik::image_32& image,
unsigned layer_idx) unsigned layer_idx)
{ {
std::vector<mapnik::layer> const& layers = map.layers(); std::vector<mapnik::layer> const& layers = map.layers();
std::size_t layer_num = layers.size(); std::size_t layer_num = layers.size();
@ -157,101 +157,101 @@ void render_layer2(const mapnik::Map& map,
} }
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
try try
{ {
mapnik::layer const& layer = layers[layer_idx]; mapnik::layer const& layer = layers[layer_idx];
mapnik::agg_renderer<mapnik::image_32> ren(map,image,1.0,0,0); mapnik::agg_renderer<mapnik::image_32> ren(map,image,1.0,0,0);
std::set<std::string> names; std::set<std::string> names;
ren.apply(layer,names); ren.apply(layer,names);
} }
catch (...) catch (...)
{ {
Py_BLOCK_THREADS Py_BLOCK_THREADS
throw; throw;
} }
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
void render3(const mapnik::Map& map, void render3(const mapnik::Map& map,
PycairoSurface* surface, PycairoSurface* surface,
unsigned offset_x = 0, unsigned offset_x = 0,
unsigned offset_y = 0) unsigned offset_y = 0)
{ {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
try try
{ {
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface)); Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
mapnik::cairo_renderer<Cairo::Surface> ren(map,s,offset_x, offset_y); mapnik::cairo_renderer<Cairo::Surface> ren(map,s,offset_x, offset_y);
ren.apply(); ren.apply();
} }
catch (...) catch (...)
{ {
Py_BLOCK_THREADS Py_BLOCK_THREADS
throw; throw;
} }
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
void render4(const mapnik::Map& map, PycairoSurface* surface) void render4(const mapnik::Map& map, PycairoSurface* surface)
{ {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
try try
{ {
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface)); Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
mapnik::cairo_renderer<Cairo::Surface> ren(map,s); mapnik::cairo_renderer<Cairo::Surface> ren(map,s);
ren.apply(); ren.apply();
} }
catch (...) catch (...)
{ {
Py_BLOCK_THREADS Py_BLOCK_THREADS
throw; throw;
} }
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
void render5(const mapnik::Map& map, void render5(const mapnik::Map& map,
PycairoContext* context, PycairoContext* context,
unsigned offset_x = 0, unsigned offset_x = 0,
unsigned offset_y = 0) unsigned offset_y = 0)
{ {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
try try
{ {
Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx)); Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
mapnik::cairo_renderer<Cairo::Context> ren(map,c,offset_x, offset_y); mapnik::cairo_renderer<Cairo::Context> ren(map,c,offset_x, offset_y);
ren.apply(); ren.apply();
} }
catch (...) catch (...)
{ {
Py_BLOCK_THREADS Py_BLOCK_THREADS
throw; throw;
} }
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
void render6(const mapnik::Map& map, PycairoContext* context) void render6(const mapnik::Map& map, PycairoContext* context)
{ {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
try try
{ {
Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx)); Cairo::RefPtr<Cairo::Context> c(new Cairo::Context(context->ctx));
mapnik::cairo_renderer<Cairo::Context> ren(map,c); mapnik::cairo_renderer<Cairo::Context> ren(map,c);
ren.apply(); ren.apply();
} }
catch (...) catch (...)
{ {
Py_BLOCK_THREADS Py_BLOCK_THREADS
throw; throw;
} }
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
#endif #endif
void render_tile_to_file(const mapnik::Map& map, void render_tile_to_file(const mapnik::Map& map,
unsigned offset_x, unsigned offset_y, unsigned offset_x, unsigned offset_y,
unsigned width, unsigned height, unsigned width, unsigned height,
const std::string& file, const std::string& file,
@ -274,11 +274,11 @@ void render_to_file1(const mapnik::Map& map,
throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format); throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
#endif #endif
} }
else else
{ {
mapnik::image_32 image(map.width(),map.height()); mapnik::image_32 image(map.width(),map.height());
render(map,image,1.0,0,0); render(map,image,1.0,0,0);
mapnik::save_to_file(image,filename,format); mapnik::save_to_file(image,filename,format);
} }
} }
@ -293,11 +293,11 @@ void render_to_file2(const mapnik::Map& map,const std::string& filename)
throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format); throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
#endif #endif
} }
else else
{ {
mapnik::image_32 image(map.width(),map.height()); mapnik::image_32 image(map.width(),map.height());
render(map,image,1.0,0,0); render(map,image,1.0,0,0);
mapnik::save_to_file(image,filename); mapnik::save_to_file(image,filename);
} }
} }
@ -305,7 +305,7 @@ void render_to_file3(const mapnik::Map& map,
const std::string& filename, const std::string& filename,
const std::string& format, const std::string& format,
double scale_factor = 1.0 double scale_factor = 1.0
) )
{ {
if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24") if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24")
{ {
@ -315,11 +315,11 @@ void render_to_file3(const mapnik::Map& map,
throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format); throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
#endif #endif
} }
else else
{ {
mapnik::image_32 image(map.width(),map.height()); mapnik::image_32 image(map.width(),map.height());
render(map,image,scale_factor,0,0); render(map,image,scale_factor,0,0);
mapnik::save_to_file(image,filename,format); mapnik::save_to_file(image,filename,format);
} }
} }
@ -355,9 +355,9 @@ unsigned mapnik_svn_revision()
bool has_jpeg() bool has_jpeg()
{ {
#if defined(HAVE_JPEG) #if defined(HAVE_JPEG)
return true; return true;
#else #else
return false; return false;
#endif #endif
} }
@ -379,10 +379,10 @@ bool has_pycairo()
if (Pycairo_CAPI == NULL){ if (Pycairo_CAPI == NULL){
/* /*
Case where pycairo support has been compiled into Case where pycairo support has been compiled into
mapnik but at runtime the cairo python module mapnik but at runtime the cairo python module
is unable to be imported and therefore Pycairo surfaces is unable to be imported and therefore Pycairo surfaces
and contexts cannot be passed to mapnik.render() and contexts cannot be passed to mapnik.render()
*/ */
return false; return false;
} }
return true; return true;
@ -401,7 +401,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(render_with_detector_overloads, render_with_dete
BOOST_PYTHON_MODULE(_mapnik2) BOOST_PYTHON_MODULE(_mapnik2)
{ {
using namespace boost::python; using namespace boost::python;
using mapnik::load_map; using mapnik::load_map;
@ -409,7 +409,7 @@ BOOST_PYTHON_MODULE(_mapnik2)
using mapnik::save_map; using mapnik::save_map;
using mapnik::save_map_to_string; using mapnik::save_map_to_string;
using mapnik::render_grid; using mapnik::render_grid;
register_exception_translator<mapnik::config_error>(&config_error_translator); register_exception_translator<mapnik::config_error>(&config_error_translator);
register_exception_translator<mapnik::value_error>(&value_error_translator); register_exception_translator<mapnik::value_error>(&value_error_translator);
register_cairo(); register_cairo();
@ -419,8 +419,8 @@ BOOST_PYTHON_MODULE(_mapnik2)
export_featureset(); export_featureset();
export_datasource(); export_datasource();
export_parameters(); export_parameters();
export_color(); export_color();
export_envelope(); export_envelope();
export_palette(); export_palette();
export_image(); export_image();
export_image_view(); export_image_view();
@ -428,7 +428,7 @@ BOOST_PYTHON_MODULE(_mapnik2)
export_grid_view(); export_grid_view();
export_expression(); export_expression();
export_rule(); export_rule();
export_style(); export_style();
export_layer(); export_layer();
export_stroke(); export_stroke();
export_datasource_cache(); export_datasource_cache();
@ -454,14 +454,14 @@ BOOST_PYTHON_MODULE(_mapnik2)
export_label_collision_detector(); export_label_collision_detector();
def("render_grid",&render_grid, def("render_grid",&render_grid,
( arg("map"), ( arg("map"),
arg("layer"), arg("layer"),
args("key")="__id__", args("key")="__id__",
arg("resolution")=4, arg("resolution")=4,
arg("fields")=boost::python::list() arg("fields")=boost::python::list()
) )
); );
def("render_to_file",&render_to_file1, def("render_to_file",&render_to_file1,
"\n" "\n"
"Render Map to file using explicit image type.\n" "Render Map to file using explicit image type.\n"
@ -503,16 +503,16 @@ BOOST_PYTHON_MODULE(_mapnik2)
">>> render_to_file(m,'image.jpeg',scale_factor)\n" ">>> render_to_file(m,'image.jpeg',scale_factor)\n"
"\n" "\n"
); );
def("render_tile_to_file",&render_tile_to_file, def("render_tile_to_file",&render_tile_to_file,
"\n" "\n"
"TODO\n" "TODO\n"
"\n" "\n"
); );
def("render", &render, render_overloads( def("render", &render, render_overloads(
"\n" "\n"
"Render Map to an AGG image_32 using offsets\n" "Render Map to an AGG image_32 using offsets\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
@ -526,29 +526,29 @@ BOOST_PYTHON_MODULE(_mapnik2)
">>> render(m,im,scale_factor)\n" ">>> render(m,im,scale_factor)\n"
">>> render(m,im,scale_factor,offset[0],offset[1])\n" ">>> render(m,im,scale_factor,offset[0],offset[1])\n"
"\n" "\n"
)); ));
def("render_with_detector", &render_with_detector, render_with_detector_overloads( def("render_with_detector", &render_with_detector, render_with_detector_overloads(
"\n" "\n"
"Render Map to an AGG image_32 using a pre-constructed detector.\n" "Render Map to an AGG image_32 using a pre-constructed detector.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> from mapnik import Map, Image, LabelCollisionDetector, render_with_detector, load_map\n" ">>> from mapnik import Map, Image, LabelCollisionDetector, render_with_detector, load_map\n"
">>> m = Map(256,256)\n" ">>> m = Map(256,256)\n"
">>> load_map(m,'mapfile.xml')\n" ">>> load_map(m,'mapfile.xml')\n"
">>> im = Image(m.width,m.height)\n" ">>> im = Image(m.width,m.height)\n"
">>> detector = LabelCollisionDetector(m)\n" ">>> detector = LabelCollisionDetector(m)\n"
">>> render_with_detector(m, im, detector)\n" ">>> render_with_detector(m, im, detector)\n"
)); ));
def("render_layer", &render_layer2, def("render_layer", &render_layer2,
(arg("map"),arg("image"),args("layer")) (arg("map"),arg("image"),args("layer"))
); );
def("render_layer", &mapnik::render_layer_for_grid, def("render_layer", &mapnik::render_layer_for_grid,
(arg("map"),arg("grid"),args("layer"),arg("fields")=boost::python::list()) (arg("map"),arg("grid"),args("layer"),arg("fields")=boost::python::list())
); );
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
def("render",&render3, def("render",&render3,
"\n" "\n"
@ -587,7 +587,7 @@ BOOST_PYTHON_MODULE(_mapnik2)
">>> from cairo import SVGSurface, Context\n" ">>> from cairo import SVGSurface, Context\n"
">>> surface = SVGSurface('image.svg', m.width, m.height)\n" ">>> surface = SVGSurface('image.svg', m.width, m.height)\n"
">>> ctx = Context(surface)\n" ">>> ctx = Context(surface)\n"
">>> load_map(m,'mapfile.xml')\n" ">>> load_map(m,'mapfile.xml')\n"
">>> render(m,context,1,1)\n" ">>> render(m,context,1,1)\n"
"\n" "\n"
); );
@ -620,7 +620,7 @@ BOOST_PYTHON_MODULE(_mapnik2)
">>> scale_denominator(m,Projection(m.srs).geographic)\n" ">>> scale_denominator(m,Projection(m.srs).geographic)\n"
"\n" "\n"
); );
def("load_map", &load_map, load_map_overloads()); def("load_map", &load_map, load_map_overloads());
def("load_map_from_string", &load_map_string, load_map_string_overloads()); def("load_map_from_string", &load_map_string, load_map_string_overloads());
@ -641,7 +641,7 @@ BOOST_PYTHON_MODULE(_mapnik2)
"\n" "\n"
); );
*/ */
def("save_map_to_string", &save_map_to_string, save_map_to_string_overloads()); def("save_map_to_string", &save_map_to_string, save_map_to_string_overloads());
def("mapnik_version", &mapnik_version,"Get the Mapnik version number"); def("mapnik_version", &mapnik_version,"Get the Mapnik version number");
def("mapnik_svn_revision", &mapnik_svn_revision,"Get the Mapnik svn revision"); def("mapnik_svn_revision", &mapnik_svn_revision,"Get the Mapnik svn revision");

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -32,7 +32,7 @@ struct query_pickle_suite : boost::python::pickle_suite
static boost::python::tuple static boost::python::tuple
getinitargs(query const& q) getinitargs(query const& q)
{ {
return boost::python::make_tuple(q.get_bbox(),q.resolution()); return boost::python::make_tuple(q.get_bbox(),q.resolution());
} }
}; };
@ -40,7 +40,7 @@ void export_query()
{ {
using namespace boost::python; using namespace boost::python;
class_<query>("Query", "a spatial query data object", class_<query>("Query", "a spatial query data object",
init<box2d<double>,query::resolution_type const&,double>() ) init<box2d<double>,query::resolution_type const&,double>() )
.def(init<box2d<double> >()) .def(init<box2d<double> >())
.def_pickle(query_pickle_suite()) .def_pickle(query_pickle_suite())

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2010 Artem Pavlenko
@ -69,98 +69,98 @@ void export_raster_colorizer()
using namespace boost::python; using namespace boost::python;
class_<raster_colorizer,raster_colorizer_ptr>("RasterColorizer", class_<raster_colorizer,raster_colorizer_ptr>("RasterColorizer",
"A Raster Colorizer object.", "A Raster Colorizer object.",
init<colorizer_mode_enum, color>(args("default_mode","default_color")) init<colorizer_mode_enum, color>(args("default_mode","default_color"))
) )
.def(init<>()) .def(init<>())
.add_property("default_color", .add_property("default_color",
make_function(&raster_colorizer::get_default_color, return_value_policy<reference_existing_object>()), make_function(&raster_colorizer::get_default_color, return_value_policy<reference_existing_object>()),
&raster_colorizer::set_default_color, &raster_colorizer::set_default_color,
"The default color for stops added without a color (mapnik.Color).\n") "The default color for stops added without a color (mapnik.Color).\n")
.add_property("default_mode", .add_property("default_mode",
&raster_colorizer::get_default_mode_enum, &raster_colorizer::get_default_mode_enum,
&raster_colorizer::set_default_mode_enum, &raster_colorizer::set_default_mode_enum,
"The default mode (mapnik.ColorizerMode).\n" "The default mode (mapnik.ColorizerMode).\n"
"\n" "\n"
"If a stop is added without a mode, then it will inherit this default mode\n") "If a stop is added without a mode, then it will inherit this default mode\n")
.add_property("stops", .add_property("stops",
make_function(get_stops,return_value_policy<reference_existing_object>()), make_function(get_stops,return_value_policy<reference_existing_object>()),
"The list of stops this RasterColorizer contains\n") "The list of stops this RasterColorizer contains\n")
.add_property("epsilon", .add_property("epsilon",
&raster_colorizer::get_epsilon, &raster_colorizer::get_epsilon,
&raster_colorizer::set_epsilon, &raster_colorizer::set_epsilon,
"Comparison epsilon value for exact mode\n" "Comparison epsilon value for exact mode\n"
"\n" "\n"
"When comparing values in exact mode, values need only be within epsilon to match.\n") "When comparing values in exact mode, values need only be within epsilon to match.\n")
.def("add_stop", add_stop, .def("add_stop", add_stop,
(arg("ColorizerStop")), (arg("ColorizerStop")),
"Add a colorizer stop to the raster colorizer.\n" "Add a colorizer stop to the raster colorizer.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> colorizer = mapnik.RasterColorizer()\n" ">>> colorizer = mapnik.RasterColorizer()\n"
">>> color = mapnik.Color(\"#0044cc\")\n" ">>> color = mapnik.Color(\"#0044cc\")\n"
">>> stop = mapnik.ColorizerStop(3, mapnik.COLORIZER_INHERIT, color)\n" ">>> stop = mapnik.ColorizerStop(3, mapnik.COLORIZER_INHERIT, color)\n"
">>> colorizer.add_stop(stop)\n" ">>> colorizer.add_stop(stop)\n"
) )
.def("add_stop", add_stop2, .def("add_stop", add_stop2,
(arg("value")), (arg("value")),
"Add a colorizer stop to the raster colorizer, using the default mode and color.\n" "Add a colorizer stop to the raster colorizer, using the default mode and color.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> default_color = mapnik.Color(\"#0044cc\")\n" ">>> default_color = mapnik.Color(\"#0044cc\")\n"
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n" ">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
">>> colorizer.add_stop(100)\n" ">>> colorizer.add_stop(100)\n"
) )
.def("add_stop", add_stop3, .def("add_stop", add_stop3,
(arg("value")), (arg("value")),
"Add a colorizer stop to the raster colorizer, using the default mode.\n" "Add a colorizer stop to the raster colorizer, using the default mode.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> default_color = mapnik.Color(\"#0044cc\")\n" ">>> default_color = mapnik.Color(\"#0044cc\")\n"
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n" ">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
">>> colorizer.add_stop(100, mapnik.Color(\"#123456\"))\n" ">>> colorizer.add_stop(100, mapnik.Color(\"#123456\"))\n"
) )
.def("add_stop", add_stop4, .def("add_stop", add_stop4,
(arg("value")), (arg("value")),
"Add a colorizer stop to the raster colorizer, using the default color.\n" "Add a colorizer stop to the raster colorizer, using the default color.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> default_color = mapnik.Color(\"#0044cc\")\n" ">>> default_color = mapnik.Color(\"#0044cc\")\n"
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n" ">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
">>> colorizer.add_stop(100, mapnik2.COLORIZER_EXACT)\n" ">>> colorizer.add_stop(100, mapnik2.COLORIZER_EXACT)\n"
) )
.def("add_stop", add_stop5, .def("add_stop", add_stop5,
(arg("value")), (arg("value")),
"Add a colorizer stop to the raster colorizer.\n" "Add a colorizer stop to the raster colorizer.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> default_color = mapnik.Color(\"#0044cc\")\n" ">>> default_color = mapnik.Color(\"#0044cc\")\n"
">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n" ">>> colorizer = mapnik.RasterColorizer(mapnik2.COLORIZER_LINEAR, default_color)\n"
">>> colorizer.add_stop(100, mapnik.COLORIZER_DISCRETE, mapnik.Color(\"#112233\"))\n" ">>> colorizer.add_stop(100, mapnik.COLORIZER_DISCRETE, mapnik.Color(\"#112233\"))\n"
) )
.def("get_color", &raster_colorizer::get_color, .def("get_color", &raster_colorizer::get_color,
"Get the color assigned to a certain value in raster data.\n" "Get the color assigned to a certain value in raster data.\n"
"\n" "\n"
"Usage:\n" "Usage:\n"
">>> colorizer = mapnik.RasterColorizer()\n" ">>> colorizer = mapnik.RasterColorizer()\n"
">>> color = mapnik.Color(\"#0044cc\")\n" ">>> color = mapnik.Color(\"#0044cc\")\n"
">>> colorizer.add_stop(0, mapnik2.COLORIZER_DISCRETE, mapnik.Color(\"#000000\"))\n" ">>> colorizer.add_stop(0, mapnik2.COLORIZER_DISCRETE, mapnik.Color(\"#000000\"))\n"
">>> colorizer.add_stop(100, mapnik2.COLORIZER_DISCRETE, mapnik.Color(\"#0E0A06\"))\n" ">>> colorizer.add_stop(100, mapnik2.COLORIZER_DISCRETE, mapnik.Color(\"#0E0A06\"))\n"
">>> colorizer.get_color(50)\n" ">>> colorizer.get_color(50)\n"
"Color('#070503')\n" "Color('#070503')\n"
) )
; ;
class_<colorizer_stops>("ColorizerStops", class_<colorizer_stops>("ColorizerStops",
"A RasterColorizer's collection of ordered color stops.\n" "A RasterColorizer's collection of ordered color stops.\n"
"This class is not meant to be instantiated from python. However, " "This class is not meant to be instantiated from python. However, "
"it can be accessed at a RasterColorizer's \"stops\" attribute for " "it can be accessed at a RasterColorizer's \"stops\" attribute for "
"introspection purposes", "introspection purposes",
no_init) no_init)
.def(vector_indexing_suite<colorizer_stops>()) .def(vector_indexing_suite<colorizer_stops>())
; ;
@ -174,32 +174,32 @@ void export_raster_colorizer()
class_<colorizer_stop>("ColorizerStop",init<float, colorizer_mode_enum, color const&>( class_<colorizer_stop>("ColorizerStop",init<float, colorizer_mode_enum, color const&>(
"A Colorizer Stop object.\n" "A Colorizer Stop object.\n"
"Create with a value, ColorizerMode, and Color\n" "Create with a value, ColorizerMode, and Color\n"
"\n" "\n"
"Usage:" "Usage:"
">>> color = mapnik.Color(\"#fff000\")\n" ">>> color = mapnik.Color(\"#fff000\")\n"
">>> stop= mapnik.ColorizerStop(42.42, mapnik.COLORIZER_LINEAR, color)\n" ">>> stop= mapnik.ColorizerStop(42.42, mapnik.COLORIZER_LINEAR, color)\n"
)) ))
.add_property("color", .add_property("color",
make_function(&colorizer_stop::get_color, return_value_policy<reference_existing_object>()), make_function(&colorizer_stop::get_color, return_value_policy<reference_existing_object>()),
&colorizer_stop::set_color, &colorizer_stop::set_color,
"The stop color (mapnik.Color).\n") "The stop color (mapnik.Color).\n")
.add_property("value", .add_property("value",
&colorizer_stop::get_value, &colorizer_stop::get_value,
&colorizer_stop::set_value, &colorizer_stop::set_value,
"The stop value.\n") "The stop value.\n")
.add_property("label", .add_property("label",
make_function(&colorizer_stop::get_label, return_value_policy<copy_const_reference>()), make_function(&colorizer_stop::get_label, return_value_policy<copy_const_reference>()),
&colorizer_stop::set_label, &colorizer_stop::set_label,
"The stop label.\n") "The stop label.\n")
.add_property("mode", .add_property("mode",
&colorizer_stop::get_mode_enum, &colorizer_stop::get_mode_enum,
&colorizer_stop::set_mode_enum, &colorizer_stop::set_mode_enum,
"The stop mode (mapnik.ColorizerMode).\n" "The stop mode (mapnik.ColorizerMode).\n"
"\n" "\n"
"If this is COLORIZER_INHERIT then it will inherit the default mode\n" "If this is COLORIZER_INHERIT then it will inherit the default mode\n"
" from the RasterColorizer it is added to.\n") " from the RasterColorizer it is added to.\n")
.def(self == self) .def(self == self)
.def("__str__",&colorizer_stop::to_string) .def("__str__",&colorizer_stop::to_string)
; ;

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -32,7 +32,7 @@ struct raster_symbolizer_pickle_suite : boost::python::pickle_suite
static boost::python::tuple static boost::python::tuple
getinitargs(const raster_symbolizer& r) getinitargs(const raster_symbolizer& r)
{ {
return boost::python::make_tuple(); return boost::python::make_tuple();
} }
*/ */
@ -54,7 +54,7 @@ struct raster_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
r.set_mode(extract<std::string>(state[0])); r.set_mode(extract<std::string>(state[0]));
r.set_scaling(extract<std::string>(state[1])); r.set_scaling(extract<std::string>(state[1]));
r.set_opacity(extract<float>(state[2])); r.set_opacity(extract<float>(state[2]));
@ -70,9 +70,9 @@ void export_raster_symbolizer()
class_<raster_symbolizer>("RasterSymbolizer", class_<raster_symbolizer>("RasterSymbolizer",
init<>("Default ctor")) init<>("Default ctor"))
.def_pickle(raster_symbolizer_pickle_suite()) .def_pickle(raster_symbolizer_pickle_suite())
.add_property("mode", .add_property("mode",
make_function(&raster_symbolizer::get_mode,return_value_policy<copy_const_reference>()), make_function(&raster_symbolizer::get_mode,return_value_policy<copy_const_reference>()),
&raster_symbolizer::set_mode, &raster_symbolizer::set_mode,
@ -87,7 +87,7 @@ void export_raster_symbolizer()
">>> r = RasterSymbolizer()\n" ">>> r = RasterSymbolizer()\n"
">>> r.mode = 'grain_merge2'\n" ">>> r.mode = 'grain_merge2'\n"
) )
.add_property("scaling", .add_property("scaling",
make_function(&raster_symbolizer::get_scaling,return_value_policy<copy_const_reference>()), make_function(&raster_symbolizer::get_scaling,return_value_policy<copy_const_reference>()),
&raster_symbolizer::set_scaling, &raster_symbolizer::set_scaling,
@ -101,7 +101,7 @@ void export_raster_symbolizer()
">>> r = RasterSymbolizer()\n" ">>> r = RasterSymbolizer()\n"
">>> r.scaling = 'bilinear8'\n" ">>> r.scaling = 'bilinear8'\n"
) )
.add_property("opacity", .add_property("opacity",
&raster_symbolizer::get_opacity, &raster_symbolizer::get_opacity,
&raster_symbolizer::set_opacity, &raster_symbolizer::set_opacity,
@ -162,5 +162,5 @@ void export_raster_symbolizer()
">>> r = RasterSymbolizer()\n" ">>> r = RasterSymbolizer()\n"
">>> r.mesh_size = 32\n" ">>> r.mesh_size = 32\n"
) )
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -51,7 +51,7 @@ using mapnik::to_expression_string;
struct pickle_symbolizer : public boost::static_visitor<> struct pickle_symbolizer : public boost::static_visitor<>
{ {
public: public:
pickle_symbolizer( boost::python::list syms): pickle_symbolizer( boost::python::list syms):
syms_(syms) {} syms_(syms) {}
template <typename T> template <typename T>
@ -59,7 +59,7 @@ public:
{ {
syms_.append(sym); syms_.append(sym);
} }
private: private:
boost::python::list syms_; boost::python::list syms_;
}; };
@ -68,9 +68,9 @@ private:
struct extract_symbolizer : public boost::static_visitor<> struct extract_symbolizer : public boost::static_visitor<>
{ {
public: public:
extract_symbolizer( rule& r): extract_symbolizer( rule& r):
r_(r) {} r_(r) {}
template <typename T> template <typename T>
void operator () ( T const& sym ) void operator () ( T const& sym )
{ {
@ -78,7 +78,7 @@ public:
} }
private: private:
rule& r_; rule& r_;
}; };
struct rule_pickle_suite : boost::python::pickle_suite struct rule_pickle_suite : boost::python::pickle_suite
@ -93,15 +93,15 @@ struct rule_pickle_suite : boost::python::pickle_suite
getstate(const rule& r) getstate(const rule& r)
{ {
boost::python::list syms; boost::python::list syms;
rule::symbolizers::const_iterator begin = r.get_symbolizers().begin(); rule::symbolizers::const_iterator begin = r.get_symbolizers().begin();
rule::symbolizers::const_iterator end = r.get_symbolizers().end(); rule::symbolizers::const_iterator end = r.get_symbolizers().end();
pickle_symbolizer serializer( syms ); pickle_symbolizer serializer( syms );
std::for_each( begin, end , boost::apply_visitor( serializer )); std::for_each( begin, end , boost::apply_visitor( serializer ));
// We serialize filter expressions AST as strings // We serialize filter expressions AST as strings
std::string filter_expr = to_expression_string(*r.get_filter()); std::string filter_expr = to_expression_string(*r.get_filter());
return boost::python::make_tuple(r.get_abstract(),filter_expr,r.has_else_filter(),r.has_also_filter(),syms); return boost::python::make_tuple(r.get_abstract(),filter_expr,r.has_else_filter(),r.has_also_filter(),syms);
} }
@ -117,11 +117,11 @@ struct rule_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
if (state[0]) if (state[0])
{ {
r.set_title(extract<std::string>(state[0])); r.set_title(extract<std::string>(state[0]));
} }
if (state[1]) if (state[1])
{ {
@ -132,25 +132,25 @@ struct rule_pickle_suite : boost::python::pickle_suite
{ {
r.set_filter(mapnik::parse_expression(filter,"utf8")); r.set_filter(mapnik::parse_expression(filter,"utf8"));
} }
} }
if (state[2]) if (state[2])
{ {
r.set_else(true); r.set_else(true);
} }
if (state[3]) if (state[3])
{ {
r.set_also(true); r.set_also(true);
} }
boost::python::list syms=extract<boost::python::list>(state[4]); boost::python::list syms=extract<boost::python::list>(state[4]);
extract_symbolizer serializer( r ); extract_symbolizer serializer( r );
for (int i=0;i<len(syms);++i) for (int i=0;i<len(syms);++i)
{ {
//symbolizer symbol = extract<symbolizer>(syms[i]); //symbolizer symbol = extract<symbolizer>(syms[i]);
//boost::apply_visitor( serializer, symbol ); //boost::apply_visitor( serializer, symbol );
} }
} }
}; };
@ -169,11 +169,11 @@ void export_rule()
implicitly_convertible<text_symbolizer,symbolizer>(); implicitly_convertible<text_symbolizer,symbolizer>();
implicitly_convertible<glyph_symbolizer,symbolizer>(); implicitly_convertible<glyph_symbolizer,symbolizer>();
implicitly_convertible<markers_symbolizer,symbolizer>(); implicitly_convertible<markers_symbolizer,symbolizer>();
class_<rule::symbolizers>("Symbolizers",init<>("TODO")) class_<rule::symbolizers>("Symbolizers",init<>("TODO"))
.def(vector_indexing_suite<rule::symbolizers>()) .def(vector_indexing_suite<rule::symbolizers>())
; ;
class_<rule>("Rule",init<>("default constructor")) class_<rule>("Rule",init<>("default constructor"))
.def(init<std::string const&, .def(init<std::string const&,
boost::python::optional<std::string const&,double,double> >()) boost::python::optional<std::string const&,double,double> >())

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -63,7 +63,7 @@ void set_text_displacement(shield_symbolizer & t, boost::python::tuple arg)
{ {
t.set_displacement(extract<double>(arg[0]),extract<double>(arg[1])); t.set_displacement(extract<double>(arg[0]),extract<double>(arg[1]));
} }
tuple get_anchor(const shield_symbolizer& t) tuple get_anchor(const shield_symbolizer& t)
{ {
boost::tuple<double,double> pos = t.get_anchor(); boost::tuple<double,double> pos = t.get_anchor();
@ -75,15 +75,15 @@ void set_anchor(shield_symbolizer & t, boost::python::tuple arg)
t.set_anchor(extract<double>(arg[0]),extract<double>(arg[1])); t.set_anchor(extract<double>(arg[0]),extract<double>(arg[1]));
} }
const std::string get_filename(shield_symbolizer const& t) const std::string get_filename(shield_symbolizer const& t)
{ {
return path_processor_type::to_string(*t.get_filename()); return path_processor_type::to_string(*t.get_filename());
} }
void set_filename(shield_symbolizer & t, std::string const& file_expr) void set_filename(shield_symbolizer & t, std::string const& file_expr)
{ {
t.set_filename(parse_path(file_expr)); t.set_filename(parse_path(file_expr));
} }
} }
@ -96,7 +96,7 @@ struct shield_symbolizer_pickle_suite : boost::python::pickle_suite
//(name, font name, font size, font color, image file, image type, width, height) //(name, font name, font size, font color, image file, image type, width, height)
return boost::python::make_tuple( "TODO",//s.get_name(), return boost::python::make_tuple( "TODO",//s.get_name(),
s.get_face_name(),s.get_text_size(),s.get_fill(),filename,guess_type(filename)); s.get_face_name(),s.get_text_size(),s.get_fill(),filename,guess_type(filename));
} }
static boost::python::tuple static boost::python::tuple
@ -118,10 +118,10 @@ struct shield_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
}*/ }*/
s.set_halo_fill(extract<color>(state[0])); s.set_halo_fill(extract<color>(state[0]));
s.set_halo_radius(extract<float>(state[1])); s.set_halo_radius(extract<float>(state[1]));
} }
}; };
@ -131,10 +131,10 @@ void export_shield_symbolizer()
{ {
using namespace boost::python; using namespace boost::python;
class_< shield_symbolizer, bases<text_symbolizer> >("ShieldSymbolizer", class_< shield_symbolizer, bases<text_symbolizer> >("ShieldSymbolizer",
init<expression_ptr, init<expression_ptr,
std::string const&, std::string const&,
unsigned, mapnik::color const&, unsigned, mapnik::color const&,
path_expression_ptr>("TODO") path_expression_ptr>("TODO")
) )
//.def_pickle(shield_symbolizer_pickle_suite()) //.def_pickle(shield_symbolizer_pickle_suite())
.add_property("anchor", .add_property("anchor",
@ -159,7 +159,7 @@ void export_shield_symbolizer()
make_function(&shield_symbolizer::get_face_name,return_value_policy<copy_const_reference>()), make_function(&shield_symbolizer::get_face_name,return_value_policy<copy_const_reference>()),
&shield_symbolizer::set_face_name, &shield_symbolizer::set_face_name,
"Set/get the face_name property of the label") "Set/get the face_name property of the label")
.add_property("fill", .add_property("fill",
make_function(&shield_symbolizer::get_fill,return_value_policy<copy_const_reference>()), make_function(&shield_symbolizer::get_fill,return_value_policy<copy_const_reference>()),
&shield_symbolizer::set_fill) &shield_symbolizer::set_fill)
.add_property("fontset", .add_property("fontset",
@ -172,7 +172,7 @@ void export_shield_symbolizer()
make_function(&shield_symbolizer::get_halo_fill,return_value_policy<copy_const_reference>()), make_function(&shield_symbolizer::get_halo_fill,return_value_policy<copy_const_reference>()),
&shield_symbolizer::set_halo_fill) &shield_symbolizer::set_halo_fill)
.add_property("halo_radius", .add_property("halo_radius",
&shield_symbolizer::get_halo_radius, &shield_symbolizer::get_halo_radius,
&shield_symbolizer::set_halo_radius) &shield_symbolizer::set_halo_radius)
.add_property("horizontal_alignment", .add_property("horizontal_alignment",
&shield_symbolizer::get_horizontal_alignment, &shield_symbolizer::get_horizontal_alignment,

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c+mapping toolkit) * This file is part of Mapnik (c+mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -57,7 +57,7 @@ struct stroke_pickle_suite : boost::python::pickle_suite
{ {
return boost::python::make_tuple(s.get_color(),s.get_width()); return boost::python::make_tuple(s.get_color(),s.get_width());
} }
static boost::python::tuple static boost::python::tuple
@ -140,15 +140,15 @@ void export_stroke ()
.add_property("width", .add_property("width",
&stroke::get_width, &stroke::get_width,
&stroke::set_width, &stroke::set_width,
"Gets or sets the stroke width in pixels.\n") "Gets or sets the stroke width in pixels.\n")
.add_property("opacity", .add_property("opacity",
&stroke::get_opacity, &stroke::get_opacity,
&stroke::set_opacity, &stroke::set_opacity,
"Gets or sets the opacity of this stroke.\n" "Gets or sets the opacity of this stroke.\n"
"The value is a float between 0 and 1.\n") "The value is a float between 0 and 1.\n")
.add_property("gamma", .add_property("gamma",
&stroke::get_gamma, &stroke::get_gamma,
&stroke::set_gamma, &stroke::set_gamma,
"Gets or sets the gamma of this stroke.\n" "Gets or sets the gamma of this stroke.\n"
"The value is a float between 0 and 1.\n") "The value is a float between 0 and 1.\n")
.add_property("line_cap", .add_property("line_cap",

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -42,7 +42,7 @@ struct style_pickle_suite : boost::python::pickle_suite
rules::const_iterator end = s.get_rules().end(); rules::const_iterator end = s.get_rules().end();
for (; it != end; ++it) for (; it != end; ++it)
{ {
rule_list.append( *it ); rule_list.append( *it );
} }
return boost::python::make_tuple(rule_list); return boost::python::make_tuple(rule_list);
@ -60,14 +60,14 @@ struct style_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
boost::python::list rules = extract<boost::python::list>(state[0]); boost::python::list rules = extract<boost::python::list>(state[0]);
for (int i=0; i<len(rules); ++i) for (int i=0; i<len(rules); ++i)
{ {
s.add_rule(extract<rule>(rules[i])); s.add_rule(extract<rule>(rules[i]));
} }
} }
}; };
void export_style() void export_style()
@ -97,12 +97,12 @@ void export_style()
">>> print r\n" ">>> print r\n"
"<mapnik2._mapnik2.Rule object at 0x100549910>\n" "<mapnik2._mapnik2.Rule object at 0x100549910>\n"
"<mapnik2._mapnik2.Rule object at 0x100549980>\n" "<mapnik2._mapnik2.Rule object at 0x100549980>\n"
) )
.add_property("filter_mode", .add_property("filter_mode",
&feature_type_style::get_filter_mode, &feature_type_style::get_filter_mode,
&feature_type_style::set_filter_mode, &feature_type_style::set_filter_mode,
"Set/get the placement of the label") "Set/get the placement of the label")
; ;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Robert Coup * Copyright (C) 2010 Robert Coup
@ -47,7 +47,7 @@ void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
{ {
std::stringstream ss; std::stringstream ss;
ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'"; ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'";
throw mapnik::value_error(ss.str()); throw mapnik::value_error(ss.str());
} }
mapnik::transform_type matrix; mapnik::transform_type matrix;
tr.store_to(&matrix[0]); tr.store_to(&matrix[0]);

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -45,52 +45,52 @@ struct get_symbolizer_type : public boost::static_visitor<std::string>
{ {
public: public:
get_symbolizer_type() {} get_symbolizer_type() {}
std::string operator () ( const point_symbolizer & /*sym*/ ) std::string operator () ( const point_symbolizer & /*sym*/ )
{ {
return "point"; return "point";
} }
std::string operator () ( const line_symbolizer & /*sym*/ ) std::string operator () ( const line_symbolizer & /*sym*/ )
{ {
return "line"; return "line";
} }
std::string operator () ( const line_pattern_symbolizer & /*sym*/ ) std::string operator () ( const line_pattern_symbolizer & /*sym*/ )
{ {
return "line_pattern"; return "line_pattern";
} }
std::string operator () ( const polygon_symbolizer & /*sym*/ ) std::string operator () ( const polygon_symbolizer & /*sym*/ )
{ {
return "polygon"; return "polygon";
} }
std::string operator () ( const polygon_pattern_symbolizer & /*sym*/ ) std::string operator () ( const polygon_pattern_symbolizer & /*sym*/ )
{ {
return "polygon_pattern"; return "polygon_pattern";
} }
std::string operator () ( const raster_symbolizer & /*sym*/ ) std::string operator () ( const raster_symbolizer & /*sym*/ )
{ {
return "raster"; return "raster";
} }
std::string operator () ( const shield_symbolizer & /*sym*/ ) std::string operator () ( const shield_symbolizer & /*sym*/ )
{ {
return "shield"; return "shield";
} }
std::string operator () ( const text_symbolizer & /*sym*/ ) std::string operator () ( const text_symbolizer & /*sym*/ )
{ {
return "text"; return "text";
} }
std::string operator () ( const building_symbolizer & /*sym*/ ) std::string operator () ( const building_symbolizer & /*sym*/ )
{ {
return "building"; return "building";
} }
std::string operator () ( const markers_symbolizer & /*sym*/ ) std::string operator () ( const markers_symbolizer & /*sym*/ )
{ {
return "markers"; return "markers";

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
@ -69,7 +69,7 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
return boost::python::make_tuple("TODO",//t.get_name(), return boost::python::make_tuple("TODO",//t.get_name(),
t.get_face_name(),t.get_text_size(),t.get_fill()); t.get_face_name(),t.get_text_size(),t.get_fill());
} }
static boost::python::tuple static boost::python::tuple
@ -77,7 +77,7 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
{ {
boost::python::tuple disp = get_text_displacement(t); boost::python::tuple disp = get_text_displacement(t);
boost::python::tuple anchor = get_anchor(t); boost::python::tuple anchor = get_anchor(t);
// so we do not exceed max args accepted by make_tuple, // so we do not exceed max args accepted by make_tuple,
// lets put the increasing list of parameters in a list // lets put the increasing list of parameters in a list
boost::python::list extras; boost::python::list extras;
@ -91,11 +91,11 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
extras.append(t.get_text_opacity()); extras.append(t.get_text_opacity());
extras.append(t.get_minimum_padding()); extras.append(t.get_minimum_padding());
extras.append(t.get_minimum_path_length()); extras.append(t.get_minimum_path_length());
return boost::python::make_tuple(disp,t.get_label_placement(), return boost::python::make_tuple(disp,t.get_label_placement(),
t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(), t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(),
t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(), t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(),
anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras
); );
} }
@ -103,7 +103,7 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
setstate (text_symbolizer& t, boost::python::tuple state) setstate (text_symbolizer& t, boost::python::tuple state)
{ {
using namespace boost::python; using namespace boost::python;
if (len(state) != 14) if (len(state) != 14)
{ {
PyErr_SetObject(PyExc_ValueError, PyErr_SetObject(PyExc_ValueError,
@ -112,16 +112,16 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
); );
throw_error_already_set(); throw_error_already_set();
} }
tuple disp = extract<tuple>(state[0]); tuple disp = extract<tuple>(state[0]);
double dx = extract<double>(disp[0]); double dx = extract<double>(disp[0]);
double dy = extract<double>(disp[1]); double dy = extract<double>(disp[1]);
t.set_displacement(dx,dy); t.set_displacement(dx,dy);
t.set_label_placement(extract<label_placement_e>(state[1])); t.set_label_placement(extract<label_placement_e>(state[1]));
t.set_vertical_alignment(extract<vertical_alignment_e>(state[2])); t.set_vertical_alignment(extract<vertical_alignment_e>(state[2]));
t.set_halo_radius(extract<unsigned>(state[3])); t.set_halo_radius(extract<unsigned>(state[3]));
t.set_halo_fill(extract<color>(state[4])); t.set_halo_fill(extract<color>(state[4]));
@ -135,14 +135,14 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite
t.set_minimum_distance(extract<double>(state[8])); t.set_minimum_distance(extract<double>(state[8]));
t.set_allow_overlap(extract<bool>(state[9])); t.set_allow_overlap(extract<bool>(state[9]));
tuple anch = extract<tuple>(state[10]); tuple anch = extract<tuple>(state[10]);
double x = extract<double>(anch[0]); double x = extract<double>(anch[0]);
double y = extract<double>(anch[1]); double y = extract<double>(anch[1]);
t.set_anchor(x,y); t.set_anchor(x,y);
t.set_force_odd_labels(extract<bool>(state[11])); t.set_force_odd_labels(extract<bool>(state[11]));
t.set_max_char_angle_delta(extract<double>(state[12])); t.set_max_char_angle_delta(extract<double>(state[12]));
list extras = extract<list>(state[13]); list extras = extract<list>(state[13]);
t.set_wrap_char_from_string(extract<std::string>(extras[0])); t.set_wrap_char_from_string(extract<std::string>(extras[0]));
@ -187,7 +187,7 @@ void export_text_symbolizer()
.value("MIDDLE",J_MIDDLE) .value("MIDDLE",J_MIDDLE)
.value("RIGHT",J_RIGHT) .value("RIGHT",J_RIGHT)
; ;
enumeration_<text_transform_e>("text_transform") enumeration_<text_transform_e>("text_transform")
.value("NONE",NONE) .value("NONE",NONE)
.value("UPPERCASE",UPPERCASE) .value("UPPERCASE",UPPERCASE)
@ -196,19 +196,19 @@ void export_text_symbolizer()
; ;
class_<text_symbolizer>("TextSymbolizer",init<expression_ptr,std::string const&, unsigned,color const&>()) class_<text_symbolizer>("TextSymbolizer",init<expression_ptr,std::string const&, unsigned,color const&>())
/* /*
// todo - all python classes can have kwargs and default constructors // todo - all python classes can have kwargs and default constructors
class_<text_symbolizer>("TextSymbolizer", class_<text_symbolizer>("TextSymbolizer",
init<expression_ptr,std::string const&, unsigned,color const&>( init<expression_ptr,std::string const&, unsigned,color const&>(
( (
arg("name"), arg("name"),
arg("font_face")="DejaVu Sans Book", arg("font_face")="DejaVu Sans Book",
arg("size")=10, arg("size")=10,
arg("color")=color("black") arg("color")=color("black")
), ),
"Create a TextSymbolizer\n" "Create a TextSymbolizer\n"
)) ))
*/ */
//.def_pickle(text_symbolizer_pickle_suite()) //.def_pickle(text_symbolizer_pickle_suite())
.add_property("anchor", .add_property("anchor",
@ -233,7 +233,7 @@ void export_text_symbolizer()
make_function(&text_symbolizer::get_face_name,return_value_policy<copy_const_reference>()), make_function(&text_symbolizer::get_face_name,return_value_policy<copy_const_reference>()),
&text_symbolizer::set_face_name, &text_symbolizer::set_face_name,
"Set/get the face_name property of the label") "Set/get the face_name property of the label")
.add_property("fill", .add_property("fill",
make_function(&text_symbolizer::get_fill,return_value_policy<copy_const_reference>()), make_function(&text_symbolizer::get_fill,return_value_policy<copy_const_reference>()),
&text_symbolizer::set_fill) &text_symbolizer::set_fill)
.add_property("fontset", .add_property("fontset",
@ -246,7 +246,7 @@ void export_text_symbolizer()
make_function(&text_symbolizer::get_halo_fill,return_value_policy<copy_const_reference>()), make_function(&text_symbolizer::get_halo_fill,return_value_policy<copy_const_reference>()),
&text_symbolizer::set_halo_fill) &text_symbolizer::set_halo_fill)
.add_property("halo_radius", .add_property("halo_radius",
&text_symbolizer::get_halo_radius, &text_symbolizer::get_halo_radius,
&text_symbolizer::set_halo_radius) &text_symbolizer::set_halo_radius)
.add_property("horizontal_alignment", .add_property("horizontal_alignment",
&text_symbolizer::get_horizontal_alignment, &text_symbolizer::get_horizontal_alignment,

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -47,23 +47,23 @@ namespace boost { namespace python {
{ {
return ::PyBool_FromLong(val); return ::PyBool_FromLong(val);
} }
PyObject * operator() (UnicodeString const& s) const PyObject * operator() (UnicodeString const& s) const
{ {
std::string buffer; std::string buffer;
mapnik::to_utf8(s,buffer); mapnik::to_utf8(s,buffer);
PyObject *obj = Py_None; PyObject *obj = Py_None;
obj = ::PyUnicode_DecodeUTF8(buffer.c_str(),implicit_cast<ssize_t>(buffer.length()),0); obj = ::PyUnicode_DecodeUTF8(buffer.c_str(),implicit_cast<ssize_t>(buffer.length()),0);
return obj; return obj;
} }
PyObject * operator() (mapnik::value_null const& /*s*/) const PyObject * operator() (mapnik::value_null const& /*s*/) const
{ {
return Py_None; return Py_None;
} }
}; };
} }
} }
#endif // MAPNIK_PYTHON_BINDING_VALUE_CONVERTER_INCLUDED #endif // MAPNIK_PYTHON_BINDING_VALUE_CONVERTER_INCLUDED

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2009 Artem Pavlenko, Jean-Francois Doyon * Copyright (C) 2009 Artem Pavlenko, Jean-Francois Doyon
@ -47,31 +47,31 @@ mapnik::coord2d forward_point(mapnik::CoordTransform const& t, mapnik::coord2d c
t.forward(out); t.forward(out);
return out; return out;
} }
mapnik::coord2d backward_point(mapnik::CoordTransform const& t, mapnik::coord2d const& in) mapnik::coord2d backward_point(mapnik::CoordTransform const& t, mapnik::coord2d const& in)
{ {
mapnik::coord2d out(in); mapnik::coord2d out(in);
t.backward(out); t.backward(out);
return out; return out;
} }
mapnik::box2d<double> forward_envelope(mapnik::CoordTransform const& t, mapnik::box2d<double> const& in) mapnik::box2d<double> forward_envelope(mapnik::CoordTransform const& t, mapnik::box2d<double> const& in)
{ {
return t.forward(in); return t.forward(in);
} }
mapnik::box2d<double> backward_envelope(mapnik::CoordTransform const& t, mapnik::box2d<double> const& in) mapnik::box2d<double> backward_envelope(mapnik::CoordTransform const& t, mapnik::box2d<double> const& in)
{ {
return t.backward(in); return t.backward(in);
} }
} }
void export_view_transform() void export_view_transform()
{ {
using namespace boost::python; using namespace boost::python;
using mapnik::box2d; using mapnik::box2d;
using mapnik::coord2d; using mapnik::coord2d;
class_<CoordTransform>("ViewTransform",init<int,int,box2d<double> const& > ( class_<CoordTransform>("ViewTransform",init<int,int,box2d<double> const& > (
"Create a ViewTransform with a width and height as integers and extent")) "Create a ViewTransform with a width and height as integers and extent"))
.def_pickle(view_transform_pickle_suite()) .def_pickle(view_transform_pickle_suite())

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -40,9 +40,9 @@ namespace mapnik {
template <typename T> template <typename T>
static void grid2utf(T const& grid_type, static void grid2utf(T const& grid_type,
boost::python::list& l, boost::python::list& l,
std::vector<grid::lookup_type>& key_order) std::vector<grid::lookup_type>& key_order)
{ {
typename T::data_type const& data = grid_type.data(); typename T::data_type const& data = grid_type.data();
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys(); typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
@ -51,11 +51,11 @@ static void grid2utf(T const& grid_type,
typename T::feature_key_type::const_iterator feature_pos; typename T::feature_key_type::const_iterator feature_pos;
// start counting at utf8 codepoint 32, aka space character // start counting at utf8 codepoint 32, aka space character
boost::uint16_t codepoint = 32; boost::uint16_t codepoint = 32;
unsigned array_size = data.width(); unsigned array_size = data.width();
for (unsigned y = 0; y < data.height(); ++y) for (unsigned y = 0; y < data.height(); ++y)
{ {
boost::uint16_t idx = 0; boost::uint16_t idx = 0;
boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]); boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]);
typename T::value_type const* row = data.getRow(y); typename T::value_type const* row = data.getRow(y);
for (unsigned x = 0; x < data.width(); ++x) for (unsigned x = 0; x < data.width(); ++x)
@ -71,7 +71,7 @@ static void grid2utf(T const& grid_type,
// can't be encoded directly in JSON. // can't be encoded directly in JSON.
if (codepoint == 34) ++codepoint; // Skip " if (codepoint == 34) ++codepoint; // Skip "
else if (codepoint == 92) ++codepoint; // Skip backslash else if (codepoint == 92) ++codepoint; // Skip backslash
keys[val] = codepoint; keys[val] = codepoint;
key_order.push_back(val); key_order.push_back(val);
line[idx++] = static_cast<Py_UNICODE>(codepoint); line[idx++] = static_cast<Py_UNICODE>(codepoint);
@ -85,17 +85,17 @@ static void grid2utf(T const& grid_type,
// else, shouldn't get here... // else, shouldn't get here...
} }
l.append(boost::python::object( l.append(boost::python::object(
boost::python::handle<>( boost::python::handle<>(
PyUnicode_FromUnicode(line.get(), array_size)))); PyUnicode_FromUnicode(line.get(), array_size))));
} }
} }
template <typename T> template <typename T>
static void grid2utf(T const& grid_type, static void grid2utf(T const& grid_type,
boost::python::list& l, boost::python::list& l,
std::vector<typename T::lookup_type>& key_order, std::vector<typename T::lookup_type>& key_order,
unsigned int resolution) unsigned int resolution)
{ {
//typename T::data_type const& data = grid_type.data(); //typename T::data_type const& data = grid_type.data();
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys(); typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
@ -109,7 +109,7 @@ static void grid2utf(T const& grid_type,
unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution); unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
for (unsigned y = 0; y < grid_type.height(); y=y+resolution) for (unsigned y = 0; y < grid_type.height(); y=y+resolution)
{ {
boost::uint16_t idx = 0; boost::uint16_t idx = 0;
boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]); boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]);
mapnik::grid::value_type const* row = grid_type.getRow(y); mapnik::grid::value_type const* row = grid_type.getRow(y);
for (unsigned x = 0; x < grid_type.width(); x=x+resolution) for (unsigned x = 0; x < grid_type.width(); x=x+resolution)
@ -138,17 +138,17 @@ static void grid2utf(T const& grid_type,
// else, shouldn't get here... // else, shouldn't get here...
} }
l.append(boost::python::object( l.append(boost::python::object(
boost::python::handle<>( boost::python::handle<>(
PyUnicode_FromUnicode(line.get(), array_size)))); PyUnicode_FromUnicode(line.get(), array_size))));
} }
} }
template <typename T> template <typename T>
static void grid2utf2(T const& grid_type, static void grid2utf2(T const& grid_type,
boost::python::list& l, boost::python::list& l,
std::vector<typename T::lookup_type>& key_order, std::vector<typename T::lookup_type>& key_order,
unsigned int resolution) unsigned int resolution)
{ {
typename T::data_type const& data = grid_type.data(); typename T::data_type const& data = grid_type.data();
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys(); typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
@ -194,16 +194,16 @@ static void grid2utf2(T const& grid_type,
// else, shouldn't get here... // else, shouldn't get here...
} }
l.append(boost::python::object( l.append(boost::python::object(
boost::python::handle<>( boost::python::handle<>(
PyUnicode_FromUnicode(line.get(), array_size)))); PyUnicode_FromUnicode(line.get(), array_size))));
} }
} }
template <typename T> template <typename T>
static void write_features(T const& grid_type, static void write_features(T const& grid_type,
boost::python::dict& feature_data, boost::python::dict& feature_data,
std::vector<typename T::lookup_type> const& key_order) std::vector<typename T::lookup_type> const& key_order)
{ {
std::string const& key = grid_type.get_key(); std::string const& key = grid_type.get_key();
std::set<std::string> const& attributes = grid_type.property_names(); std::set<std::string> const& attributes = grid_type.property_names();
@ -218,7 +218,7 @@ static void write_features(T const& grid_type,
if (itr != props.end()) if (itr != props.end())
{ {
typename T::lookup_type const& join_value = itr->second.to_string(); typename T::lookup_type const& join_value = itr->second.to_string();
// only serialize features visible in the grid // only serialize features visible in the grid
if(std::find(key_order.begin(), key_order.end(), join_value) != key_order.end()) { if(std::find(key_order.begin(), key_order.end(), join_value) != key_order.end()) {
boost::python::dict feat; boost::python::dict feat;
@ -236,7 +236,7 @@ static void write_features(T const& grid_type,
boost::python::handle<>( boost::python::handle<>(
boost::apply_visitor( boost::apply_visitor(
boost::python::value_converter(), boost::python::value_converter(),
it->second.base()))); it->second.base())));
} }
} }
else if ( (attributes.find(key_name) != attributes.end()) ) else if ( (attributes.find(key_name) != attributes.end()) )
@ -246,7 +246,7 @@ static void write_features(T const& grid_type,
boost::python::handle<>( boost::python::handle<>(
boost::apply_visitor( boost::apply_visitor(
boost::python::value_converter(), boost::python::value_converter(),
it->second.base()))); it->second.base())));
} }
} }
if (found) if (found)
@ -264,14 +264,14 @@ static void write_features(T const& grid_type,
template <typename T> template <typename T>
static void grid_encode_utf(T const& grid_type, static void grid_encode_utf(T const& grid_type,
boost::python::dict & json, boost::python::dict & json,
bool add_features, bool add_features,
unsigned int resolution) unsigned int resolution)
{ {
// convert buffer to utf and gather key order // convert buffer to utf and gather key order
boost::python::list l; boost::python::list l;
std::vector<typename T::lookup_type> key_order; std::vector<typename T::lookup_type> key_order;
if (resolution != 1) { if (resolution != 1) {
// resample on the fly - faster, less accurate // resample on the fly - faster, less accurate
mapnik::grid2utf<T>(grid_type,l,key_order,resolution); mapnik::grid2utf<T>(grid_type,l,key_order,resolution);
@ -281,7 +281,7 @@ static void grid_encode_utf(T const& grid_type,
} }
else else
{ {
mapnik::grid2utf<T>(grid_type,l,key_order); mapnik::grid2utf<T>(grid_type,l,key_order);
} }
// convert key order to proper python list // convert key order to proper python list
@ -325,9 +325,9 @@ static boost::python::dict grid_encode( T const& grid, std::string format, bool
* whether features are dumped is determined by argument not 'fields' * whether features are dumped is determined by argument not 'fields'
*/ */
static void render_layer_for_grid(const mapnik::Map& map, static void render_layer_for_grid(const mapnik::Map& map,
mapnik::grid& grid, mapnik::grid& grid,
unsigned layer_idx, // TODO - layer by name or index unsigned layer_idx, // TODO - layer by name or index
boost::python::list const& fields) boost::python::list const& fields)
{ {
std::vector<mapnik::layer> const& layers = map.layers(); std::vector<mapnik::layer> const& layers = map.layers();
std::size_t layer_num = layers.size(); std::size_t layer_num = layers.size();
@ -347,9 +347,9 @@ static void render_layer_for_grid(const mapnik::Map& map,
} }
else else
{ {
std::stringstream s; std::stringstream s;
s << "list of field names must be strings"; s << "list of field names must be strings";
throw mapnik::value_error(s.str()); throw mapnik::value_error(s.str());
} }
} }
@ -358,10 +358,10 @@ static void render_layer_for_grid(const mapnik::Map& map,
std::string const& key = grid.get_key(); std::string const& key = grid.get_key();
// if key is special __id__ keyword // if key is special __id__ keyword
if (key == grid.id_name_) if (key == grid.id_name_)
{ {
// TODO - should feature.id() be a first class attribute? // TODO - should feature.id() be a first class attribute?
// if __id__ is requested to be dumped out // if __id__ is requested to be dumped out
// remove it so that datasource queries will not break // remove it so that datasource queries will not break
if (attributes.find(key) != attributes.end()) if (attributes.find(key) != attributes.end())
@ -375,7 +375,7 @@ static void render_layer_for_grid(const mapnik::Map& map,
// them make sure the datasource query includes this field // them make sure the datasource query includes this field
attributes.insert(key); attributes.insert(key);
} }
mapnik::grid_renderer<mapnik::grid> ren(map,grid,1.0,0,0); mapnik::grid_renderer<mapnik::grid> ren(map,grid,1.0,0,0);
mapnik::layer const& layer = layers[layer_idx]; mapnik::layer const& layer = layers[layer_idx];
ren.apply(layer,attributes); ren.apply(layer,attributes);
@ -385,10 +385,10 @@ static void render_layer_for_grid(const mapnik::Map& map,
* grid object is created on the fly at potentially reduced size * grid object is created on the fly at potentially reduced size
*/ */
static boost::python::dict render_grid(const mapnik::Map& map, static boost::python::dict render_grid(const mapnik::Map& map,
unsigned layer_idx, // layer unsigned layer_idx, // layer
std::string const& key, // key_name std::string const& key, // key_name
unsigned int step, // resolution unsigned int step, // resolution
boost::python::list const& fields) boost::python::list const& fields)
{ {
std::vector<mapnik::layer> const& layers = map.layers(); std::vector<mapnik::layer> const& layers = map.layers();
@ -405,7 +405,7 @@ static boost::python::dict render_grid(const mapnik::Map& map,
// TODO - no need to pass step here // TODO - no need to pass step here
mapnik::grid grid(grid_width,grid_height,key,step); mapnik::grid grid(grid_width,grid_height,key,step);
// convert python list to std::vector // convert python list to std::vector
boost::python::ssize_t num_fields = boost::python::len(fields); boost::python::ssize_t num_fields = boost::python::len(fields);
for(boost::python::ssize_t i=0; i<num_fields; i++) { for(boost::python::ssize_t i=0; i<num_fields; i++) {
@ -415,20 +415,20 @@ static boost::python::dict render_grid(const mapnik::Map& map,
} }
else else
{ {
std::stringstream s; std::stringstream s;
s << "list of field names must be strings"; s << "list of field names must be strings";
throw mapnik::value_error(s.str()); throw mapnik::value_error(s.str());
} }
} }
// copy property names // copy property names
std::set<std::string> attributes = grid.property_names(); std::set<std::string> attributes = grid.property_names();
// if key is special __id__ keyword // if key is special __id__ keyword
if (key == grid.id_name_) if (key == grid.id_name_)
{ {
// TODO - should feature.id() be a first class attribute? // TODO - should feature.id() be a first class attribute?
// if __id__ is requested to be dumped out // if __id__ is requested to be dumped out
// remove it so that datasource queries will not break // remove it so that datasource queries will not break
if (attributes.find(key) != attributes.end()) if (attributes.find(key) != attributes.end())
@ -442,7 +442,7 @@ static boost::python::dict render_grid(const mapnik::Map& map,
// them make sure the datasource query includes this field // them make sure the datasource query includes this field
attributes.insert(key); attributes.insert(key);
} }
try try
{ {
mapnik::grid_renderer<mapnik::grid> ren(map,grid,1.0,0,0); mapnik::grid_renderer<mapnik::grid> ren(map,grid,1.0,0,0);
@ -453,7 +453,7 @@ static boost::python::dict render_grid(const mapnik::Map& map,
{ {
throw; throw;
} }
bool add_features = false; bool add_features = false;
if (num_fields > 0) if (num_fields > 0)
add_features = true; add_features = true;

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2007 Artem Pavlenko * Copyright (C) 2007 Artem Pavlenko
@ -68,7 +68,7 @@ struct python_optional : public boost::noncopyable
const registration& converters(registered<T>::converters); const registration& converters(registered<T>::converters);
if (implicit_rvalue_convertible_from_python(source, if (implicit_rvalue_convertible_from_python(source,
converters)) { converters)) {
rvalue_from_python_stage1_data data = rvalue_from_python_stage1_data data =
rvalue_from_python_stage1(source, converters); rvalue_from_python_stage1(source, converters);
@ -82,7 +82,7 @@ struct python_optional : public boost::noncopyable
{ {
using namespace boost::python::converter; using namespace boost::python::converter;
void * const storage = ((rvalue_from_python_storage<T> *) void * const storage = ((rvalue_from_python_storage<T> *)
data)->storage.bytes; data)->storage.bytes;
if (data->convertible == source) // == None if (data->convertible == source) // == None

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
@ -40,69 +40,69 @@
int main ( int argc , char** argv) int main ( int argc , char** argv)
{ {
if (argc != 2) if (argc != 2)
{ {
std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local/lib/mapnik2\n"; std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local/lib/mapnik2\n";
std::cout << "Warning: ./rundemo looks for data in ../data/,\nTherefore must be run from within the demo/c++ folder.\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]);
std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/input/" << "\n"; std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/input/" << "\n";
datasource_cache::instance()->register_datasources(mapnik_dir + "/input/"); datasource_cache::instance()->register_datasources(mapnik_dir + "/input/");
std::cout << " looking for DejaVuSans font in... " << mapnik_dir << "/fonts/DejaVuSans.ttf" << "\n"; std::cout << " looking for DejaVuSans font in... " << mapnik_dir << "/fonts/DejaVuSans.ttf" << "\n";
freetype_engine::register_font(mapnik_dir + "/fonts/DejaVuSans.ttf"); 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"));
// create styles // create styles
// Provinces (polygon) // Provinces (polygon)
feature_type_style provpoly_style; feature_type_style provpoly_style;
rule provpoly_rule_on; rule provpoly_rule_on;
provpoly_rule_on.set_filter(parse_expression("[NAME_EN] = 'Ontario'")); provpoly_rule_on.set_filter(parse_expression("[NAME_EN] = 'Ontario'"));
provpoly_rule_on.append(polygon_symbolizer(color(250, 190, 183))); provpoly_rule_on.append(polygon_symbolizer(color(250, 190, 183)));
provpoly_style.add_rule(provpoly_rule_on); provpoly_style.add_rule(provpoly_rule_on);
rule provpoly_rule_qc; rule provpoly_rule_qc;
provpoly_rule_qc.set_filter(parse_expression("[NOM_FR] = 'Québec'")); provpoly_rule_qc.set_filter(parse_expression("[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);
m.insert_style("provinces",provpoly_style); m.insert_style("provinces",provpoly_style);
// Provinces (polyline) // Provinces (polyline)
feature_type_style provlines_style; feature_type_style provlines_style;
stroke provlines_stk (color(0,0,0),1.0); stroke provlines_stk (color(0,0,0),1.0);
provlines_stk.add_dash(8, 4); provlines_stk.add_dash(8, 4);
provlines_stk.add_dash(2, 2); provlines_stk.add_dash(2, 2);
provlines_stk.add_dash(2, 2); provlines_stk.add_dash(2, 2);
rule provlines_rule; rule provlines_rule;
provlines_rule.append(line_symbolizer(provlines_stk)); provlines_rule.append(line_symbolizer(provlines_stk));
provlines_style.add_rule(provlines_rule); provlines_style.add_rule(provlines_rule);
m.insert_style("provlines",provlines_style); m.insert_style("provlines",provlines_style);
// Drainage // Drainage
feature_type_style qcdrain_style; feature_type_style qcdrain_style;
rule qcdrain_rule; rule qcdrain_rule;
qcdrain_rule.set_filter(parse_expression("[HYC] = 8")); qcdrain_rule.set_filter(parse_expression("[HYC] = 8"));
qcdrain_rule.append(polygon_symbolizer(color(153, 204, 255))); qcdrain_rule.append(polygon_symbolizer(color(153, 204, 255)));
qcdrain_style.add_rule(qcdrain_rule); qcdrain_style.add_rule(qcdrain_rule);
m.insert_style("drainage",qcdrain_style); m.insert_style("drainage",qcdrain_style);
// Roads 3 and 4 (The "grey" roads) // Roads 3 and 4 (The "grey" roads)
feature_type_style roads34_style; feature_type_style roads34_style;
rule roads34_rule; rule roads34_rule;
roads34_rule.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4")); roads34_rule.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
stroke roads34_rule_stk(color(171,158,137),2.0); stroke roads34_rule_stk(color(171,158,137),2.0);
@ -110,9 +110,9 @@ int main ( int argc , char** argv)
roads34_rule_stk.set_line_join(ROUND_JOIN); roads34_rule_stk.set_line_join(ROUND_JOIN);
roads34_rule.append(line_symbolizer(roads34_rule_stk)); roads34_rule.append(line_symbolizer(roads34_rule_stk));
roads34_style.add_rule(roads34_rule); roads34_style.add_rule(roads34_rule);
m.insert_style("smallroads",roads34_style); m.insert_style("smallroads",roads34_style);
// Roads 2 (The thin yellow ones) // Roads 2 (The thin yellow ones)
feature_type_style roads2_style_1; feature_type_style roads2_style_1;
@ -123,9 +123,9 @@ int main ( int argc , char** argv)
roads2_rule_stk_1.set_line_join(ROUND_JOIN); roads2_rule_stk_1.set_line_join(ROUND_JOIN);
roads2_rule_1.append(line_symbolizer(roads2_rule_stk_1)); roads2_rule_1.append(line_symbolizer(roads2_rule_stk_1));
roads2_style_1.add_rule(roads2_rule_1); roads2_style_1.add_rule(roads2_rule_1);
m.insert_style("road-border", roads2_style_1); m.insert_style("road-border", roads2_style_1);
feature_type_style roads2_style_2; feature_type_style roads2_style_2;
rule roads2_rule_2; rule roads2_rule_2;
roads2_rule_2.set_filter(parse_expression("[CLASS] = 2")); roads2_rule_2.set_filter(parse_expression("[CLASS] = 2"));
@ -134,9 +134,9 @@ int main ( int argc , char** argv)
roads2_rule_stk_2.set_line_join(ROUND_JOIN); roads2_rule_stk_2.set_line_join(ROUND_JOIN);
roads2_rule_2.append(line_symbolizer(roads2_rule_stk_2)); roads2_rule_2.append(line_symbolizer(roads2_rule_stk_2));
roads2_style_2.add_rule(roads2_rule_2); roads2_style_2.add_rule(roads2_rule_2);
m.insert_style("road-fill", roads2_style_2); m.insert_style("road-fill", roads2_style_2);
// Roads 1 (The big orange ones, the highways) // Roads 1 (The big orange ones, the highways)
feature_type_style roads1_style_1; feature_type_style roads1_style_1;
rule roads1_rule_1; rule roads1_rule_1;
@ -147,7 +147,7 @@ int main ( int argc , char** argv)
roads1_rule_1.append(line_symbolizer(roads1_rule_stk_1)); roads1_rule_1.append(line_symbolizer(roads1_rule_stk_1));
roads1_style_1.add_rule(roads1_rule_1); roads1_style_1.add_rule(roads1_rule_1);
m.insert_style("highway-border", roads1_style_1); m.insert_style("highway-border", roads1_style_1);
feature_type_style roads1_style_2; feature_type_style roads1_style_2;
rule roads1_rule_2; rule roads1_rule_2;
roads1_rule_2.set_filter(parse_expression("[CLASS] = 1")); roads1_rule_2.set_filter(parse_expression("[CLASS] = 1"));
@ -157,9 +157,9 @@ int main ( int argc , char** argv)
roads1_rule_2.append(line_symbolizer(roads1_rule_stk_2)); roads1_rule_2.append(line_symbolizer(roads1_rule_stk_2));
roads1_style_2.add_rule(roads1_rule_2); roads1_style_2.add_rule(roads1_rule_2);
m.insert_style("highway-fill", roads1_style_2); m.insert_style("highway-fill", roads1_style_2);
// Populated Places // Populated Places
feature_type_style popplaces_style; feature_type_style popplaces_style;
rule popplaces_rule; rule popplaces_rule;
text_symbolizer popplaces_text_symbolizer(parse_expression("[GEONAME]"),"DejaVu Sans Book",10,color(0,0,0)); text_symbolizer popplaces_text_symbolizer(parse_expression("[GEONAME]"),"DejaVu Sans Book",10,color(0,0,0));
@ -167,22 +167,22 @@ int main ( int argc , char** argv)
popplaces_text_symbolizer.set_halo_radius(1); popplaces_text_symbolizer.set_halo_radius(1);
popplaces_rule.append(popplaces_text_symbolizer); popplaces_rule.append(popplaces_text_symbolizer);
popplaces_style.add_rule(popplaces_rule); popplaces_style.add_rule(popplaces_rule);
m.insert_style("popplaces",popplaces_style ); m.insert_style("popplaces",popplaces_style );
// layers // layers
// Provincial polygons // Provincial polygons
{ {
parameters p; parameters p;
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/boundaries"; p["file"]="../data/boundaries";
layer lyr("Provinces"); layer lyr("Provinces");
lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("provinces"); lyr.add_style("provinces");
m.addLayer(lyr); m.addLayer(lyr);
} }
// Drainage // Drainage
{ {
parameters p; parameters p;
@ -190,38 +190,38 @@ int main ( int argc , char** argv)
p["file"]="../data/qcdrainage"; p["file"]="../data/qcdrainage";
layer lyr("Quebec Hydrography"); layer lyr("Quebec Hydrography");
lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("drainage"); lyr.add_style("drainage");
m.addLayer(lyr); m.addLayer(lyr);
} }
{ {
parameters p; parameters p;
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/ontdrainage"; p["file"]="../data/ontdrainage";
layer lyr("Ontario Hydrography"); layer lyr("Ontario Hydrography");
lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("drainage"); lyr.add_style("drainage");
m.addLayer(lyr); m.addLayer(lyr);
} }
// Provincial boundaries // Provincial boundaries
{ {
parameters p; parameters p;
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/boundaries_l"; p["file"]="../data/boundaries_l";
layer lyr("Provincial borders"); layer lyr("Provincial borders");
lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("provlines"); lyr.add_style("provlines");
m.addLayer(lyr); m.addLayer(lyr);
} }
// Roads // Roads
{ {
parameters p; parameters p;
p["type"]="shape"; p["type"]="shape";
p["file"]="../data/roads"; p["file"]="../data/roads";
layer lyr("Roads"); layer lyr("Roads");
lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("smallroads"); lyr.add_style("smallroads");
lyr.add_style("road-border"); lyr.add_style("road-border");
@ -229,7 +229,7 @@ int main ( int argc , char** argv)
lyr.add_style("highway-border"); lyr.add_style("highway-border");
lyr.add_style("highway-fill"); lyr.add_style("highway-fill");
m.addLayer(lyr); m.addLayer(lyr);
} }
// popplaces // popplaces
{ {
@ -239,27 +239,27 @@ int main ( int argc , char** argv)
p["encoding"] = "latin1"; p["encoding"] = "latin1";
layer lyr("Populated Places"); layer lyr("Populated Places");
lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.set_datasource(datasource_cache::instance()->create(p));
lyr.add_style("popplaces"); lyr.add_style("popplaces");
m.addLayer(lyr); m.addLayer(lyr);
} }
m.zoom_to_box(box2d<double>(1405120.04127408,-247003.813399447, m.zoom_to_box(box2d<double>(1405120.04127408,-247003.813399447,
1706357.31328276,-25098.593149577)); 1706357.31328276,-25098.593149577));
image_32 buf(m.width(),m.height()); image_32 buf(m.width(),m.height());
agg_renderer<image_32> ren(m,buf); agg_renderer<image_32> ren(m,buf);
ren.apply(); ren.apply();
save_to_file<image_data_32>(buf.data(),"demo.jpg","jpeg"); save_to_file<image_data_32>(buf.data(),"demo.jpg","jpeg");
save_to_file<image_data_32>(buf.data(),"demo.png","png"); save_to_file<image_data_32>(buf.data(),"demo.png","png");
save_to_file<image_data_32>(buf.data(),"demo256.png","png256"); save_to_file<image_data_32>(buf.data(),"demo256.png","png256");
std::cout << "Three maps have been rendered using AGG in the current directory:\n" std::cout << "Three maps have been rendered using AGG in the current directory:\n"
"- demo.jpg\n" "- demo.jpg\n"
"- demo.png\n" "- demo.png\n"
"- demo256.png\n" "- demo256.png\n"
"Have a look!\n"; "Have a look!\n";
#if defined(HAVE_CAIRO) #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.width(),m.height()); image_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, m.width(),m.height());
@ -280,12 +280,12 @@ int main ( int argc , char** argv)
svg_render.apply(); svg_render.apply();
std::cout << "Three maps have been rendered using Cairo in the current directory:\n" std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
"- cairo-demo.png\n" "- cairo-demo.png\n"
"- cairo-demo256.png\n" "- cairo-demo256.png\n"
"- 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 #endif
} }
catch ( const mapnik::config_error & ex ) catch ( const mapnik::config_error & ex )

View file

@ -114,11 +114,11 @@ feature_ptr occi_featureset::next()
int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);
/* /*
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
if (type_code == OCCI_TYPECODE_OBJECT) if (type_code == OCCI_TYPECODE_OBJECT)
{ {
continue; continue;
} }
*/ */
switch (type_oid) switch (type_oid)

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko * Copyright (C) 2006 Artem Pavlenko
@ -51,18 +51,18 @@ const double MINRATIO=0.5;
const double MAXRATIO=0.8; const double MAXRATIO=0.8;
const double DEFAULT_RATIO=0.55; const double DEFAULT_RATIO=0.55;
int main (int argc,char** argv) int main (int argc,char** argv)
{ {
using namespace mapnik; using namespace mapnik;
namespace po = boost::program_options; namespace po = boost::program_options;
using std::string; using std::string;
using std::vector; using std::vector;
bool verbose=false; bool verbose=false;
unsigned int depth=DEFAULT_DEPTH; unsigned int depth=DEFAULT_DEPTH;
double ratio=DEFAULT_RATIO; double ratio=DEFAULT_RATIO;
vector<string> ogr_files; vector<string> ogr_files;
try try
{ {
po::options_description desc("ogrindex utility"); po::options_description desc("ogrindex utility");
@ -70,23 +70,23 @@ int main (int argc,char** argv)
("help,h", "produce usage message") ("help,h", "produce usage message")
("version,V", "print version string") ("version,V", "print version string")
("verbose,v", "verbose output") ("verbose,v", "verbose output")
("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)") ("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)")
("ratio,r", po::value<double>(), "split ratio (default 0.55)") ("ratio,r", po::value<double>(), "split ratio (default 0.55)")
("ogr_files", po::value<vector<string> >(), "ogr supported files to index: file1 file2 ...fileN") ("ogr_files", po::value<vector<string> >(), "ogr supported files to index: file1 file2 ...fileN")
; ;
po::positional_options_description p; po::positional_options_description p;
p.add("ogr_files",-1); p.add("ogr_files",-1);
po::variables_map vm; po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm); po::notify(vm);
if (vm.count("version")) if (vm.count("version"))
{ {
std::clog<<"version 0.1.0" <<std::endl; std::clog<<"version 0.1.0" <<std::endl;
return 1; return 1;
} }
if (vm.count("help")) if (vm.count("help"))
{ {
std::clog << desc << std::endl; std::clog << desc << std::endl;
return 1; return 1;
@ -109,10 +109,10 @@ int main (int argc,char** argv)
std::clog << "Exception of unknown type!" << std::endl; std::clog << "Exception of unknown type!" << std::endl;
return -1; return -1;
} }
std::clog << "max tree depth:" << depth << std::endl; std::clog << "max tree depth:" << depth << std::endl;
std::clog << "split ratio:" << ratio << std::endl; std::clog << "split ratio:" << ratio << std::endl;
vector<string>::const_iterator itr = ogr_files.begin(); vector<string>::const_iterator itr = ogr_files.begin();
if (itr == ogr_files.end()) if (itr == ogr_files.end())
{ {
@ -124,7 +124,7 @@ int main (int argc,char** argv)
std::clog << "processing " << *itr << std::endl; std::clog << "processing " << *itr << std::endl;
std::string ogrname (*itr++); std::string ogrname (*itr++);
if (! boost::filesystem::exists (ogrname)) if (! boost::filesystem::exists (ogrname))
{ {
std::clog << "error : file " << ogrname << " doesn't exists" << std::endl; std::clog << "error : file " << ogrname << " doesn't exists" << std::endl;
@ -148,7 +148,7 @@ int main (int argc,char** argv)
params["file"] = ogrname; params["file"] = ogrname;
//unsigned first = 0; //unsigned first = 0;
params["layer_by_index"] = 0;//ogrlayername; params["layer_by_index"] = 0;//ogrlayername;
try try
{ {
ogr_datasource ogr (params); ogr_datasource ogr (params);
@ -157,14 +157,14 @@ int main (int argc,char** argv)
box2d<double> extent = ogr.envelope(); box2d<double> extent = ogr.envelope();
quadtree<int> tree (extent, depth, ratio); quadtree<int> tree (extent, depth, ratio);
int count=0; int count=0;
std::clog << "file:" << ogrname << std::endl; std::clog << "file:" << ogrname << std::endl;
std::clog << "layer:" << ogrlayername << std::endl; std::clog << "layer:" << ogrlayername << std::endl;
std::clog << "extent:" << extent << std::endl; std::clog << "extent:" << extent << std::endl;
mapnik::query q (extent, 1.0); mapnik::query q (extent, 1.0);
mapnik::featureset_ptr itr = ogr.features (q); mapnik::featureset_ptr itr = ogr.features (q);
while (true) while (true)
{ {
mapnik::feature_ptr fp = itr->next(); mapnik::feature_ptr fp = itr->next();
@ -172,23 +172,23 @@ int main (int argc,char** argv)
{ {
break; break;
} }
box2d<double> item_ext = fp->envelope(); box2d<double> item_ext = fp->envelope();
tree.insert (count, item_ext); tree.insert (count, item_ext);
if (verbose) { if (verbose) {
std::clog << "record number " << (count + 1) << " box=" << item_ext << std::endl; std::clog << "record number " << (count + 1) << " box=" << item_ext << std::endl;
} }
++count; ++count;
} }
std::clog << " number shapes=" << count << std::endl; std::clog << " number shapes=" << count << std::endl;
std::fstream file((ogrlayername+".ogrindex").c_str(), std::fstream file((ogrlayername+".ogrindex").c_str(),
std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary); std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
if (!file) { if (!file) {
std::clog << "cannot open ogrindex file for writing file \"" std::clog << "cannot open ogrindex file for writing file \""
<< (ogrlayername+".ogrindex") << "\"" << std::endl; << (ogrlayername+".ogrindex") << "\"" << std::endl;
} else { } else {
tree.trim(); tree.trim();
@ -213,7 +213,7 @@ int main (int argc,char** argv)
} }
} }
std::clog << "done!" << std::endl; std::clog << "done!" << std::endl;
return 0; return 0;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2009 Artem Pavlenko * Copyright (C) 2009 Artem Pavlenko
@ -39,13 +39,13 @@
int main ( int argc, char** argv) int main ( int argc, char** argv)
{ {
namespace po = boost::program_options; namespace po = boost::program_options;
po::options_description desc("Postgresql/PostGIS to SQLite3 converter\n Options"); po::options_description desc("Postgresql/PostGIS to SQLite3 converter\n Options");
std::string usage = "usage: pgsql2sqlite --dbname db --table planet_osm_line --file osm.sqlite --query \"select * from planet_osm_line\""; std::string usage = "usage: pgsql2sqlite --dbname db --table planet_osm_line --file osm.sqlite --query \"select * from planet_osm_line\"";
try try
{ {
desc.add_options() desc.add_options()
("help,?","Display this help screen.") ("help,?","Display this help screen.")
("host,h",po::value<std::string>(),"Allows you to specify connection to a database on a machine other than the default.") ("host,h",po::value<std::string>(),"Allows you to specify connection to a database on a machine other than the default.")
@ -56,17 +56,17 @@ int main ( int argc, char** argv)
("query,q",po::value<std::string>(),"Name of the table/or query to pass to postmaster") ("query,q",po::value<std::string>(),"Name of the table/or query to pass to postmaster")
("table,t",po::value<std::string>(),"Name of the output table to create (default: table in query)") ("table,t",po::value<std::string>(),"Name of the output table to create (default: table in query)")
("file,f",po::value<std::string>(),"Use this option to specify the name of the file to create.") ("file,f",po::value<std::string>(),"Use this option to specify the name of the file to create.")
; ;
//po::positional_options_description p; //po::positional_options_description p;
//p.add("table",1); //p.add("table",1);
po::variables_map vm; po::variables_map vm;
//positional(p) //positional(p)
po::store(po::command_line_parser(argc,argv).options(desc).run(),vm); po::store(po::command_line_parser(argc,argv).options(desc).run(),vm);
po::notify(vm); po::notify(vm);
if (vm.count("help")) if (vm.count("help"))
{ {
std::cout << desc << "\n"; std::cout << desc << "\n";
@ -80,31 +80,31 @@ int main ( int argc, char** argv)
std::cout << "Both --dbname, --file and, --query are required\n"; std::cout << "Both --dbname, --file and, --query are required\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
boost::optional<std::string> host; boost::optional<std::string> host;
boost::optional<std::string> port ; boost::optional<std::string> port ;
boost::optional<std::string> dbname; boost::optional<std::string> dbname;
boost::optional<std::string> user; boost::optional<std::string> user;
boost::optional<std::string> password; boost::optional<std::string> password;
boost::optional<std::string> connect_timeout("4"); boost::optional<std::string> connect_timeout("4");
if (vm.count("host")) host = vm["host"].as<std::string>(); if (vm.count("host")) host = vm["host"].as<std::string>();
if (vm.count("port")) port = vm["port"].as<std::string>(); if (vm.count("port")) port = vm["port"].as<std::string>();
if (vm.count("dbname")) dbname = vm["dbname"].as<std::string>(); if (vm.count("dbname")) dbname = vm["dbname"].as<std::string>();
if (vm.count("user")) user = vm["user"].as<std::string>(); if (vm.count("user")) user = vm["user"].as<std::string>();
if (vm.count("password")) password = vm["password"].as<std::string>(); if (vm.count("password")) password = vm["password"].as<std::string>();
ConnectionCreator<Connection> creator(host,port,dbname,user,password,connect_timeout); ConnectionCreator<Connection> creator(host,port,dbname,user,password,connect_timeout);
try try
{ {
boost::shared_ptr<Connection> conn(creator()); boost::shared_ptr<Connection> conn(creator());
std::string query = vm["query"].as<std::string>(); std::string query = vm["query"].as<std::string>();
std::string output_table_name = vm.count("table") ? vm["table"].as<std::string>() : mapnik::sql_utils::table_from_sql(query); std::string output_table_name = vm.count("table") ? vm["table"].as<std::string>() : mapnik::sql_utils::table_from_sql(query);
std::string output_file = vm["file"].as<std::string>(); std::string output_file = vm["file"].as<std::string>();
std::cout << "output_table : " << output_table_name << "\n"; std::cout << "output_table : " << output_table_name << "\n";
mapnik::pgsql2sqlite(conn,query,output_table_name,output_file); mapnik::pgsql2sqlite(conn,query,output_table_name,output_file);
} }
catch (mapnik::datasource_exception & ex) catch (mapnik::datasource_exception & ex)
@ -119,6 +119,6 @@ int main ( int argc, char** argv)
std::cerr << e.what() << "\n"; std::cerr << e.what() << "\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2009 Artem Pavlenko * Copyright (C) 2009 Artem Pavlenko
@ -59,7 +59,7 @@ struct blob_to_hex
char hex[3]; char hex[3];
std::memset(hex,0,3); std::memset(hex,0,3);
for ( unsigned pos=0; pos < size; ++pos) for ( unsigned pos=0; pos < size; ++pos)
{ {
std::sprintf (hex, "%02X", int(blob[pos]) & 0xff); std::sprintf (hex, "%02X", int(blob[pos]) & 0xff);
s << hex; s << hex;
} }
@ -67,33 +67,33 @@ struct blob_to_hex
} }
}; };
*/ */
template <typename Connection> template <typename Connection>
void pgsql2sqlite(Connection conn, void pgsql2sqlite(Connection conn,
std::string const& query, std::string const& query,
std::string const& output_table_name, std::string const& output_table_name,
std::string const& output_filename) std::string const& output_filename)
{ {
namespace sqlite = mapnik::sqlite; namespace sqlite = mapnik::sqlite;
sqlite::database db(output_filename); sqlite::database db(output_filename);
boost::shared_ptr<ResultSet> rs = conn->executeQuery("select * from (" + query + ") as query limit 0;"); boost::shared_ptr<ResultSet> rs = conn->executeQuery("select * from (" + query + ") as query limit 0;");
int count = rs->getNumFields(); int count = rs->getNumFields();
std::ostringstream select_sql; std::ostringstream select_sql;
select_sql << "select "; select_sql << "select ";
for (int i=0; i<count; ++i) for (int i=0; i<count; ++i)
{ {
if (i!=0) select_sql << ","; if (i!=0) select_sql << ",";
select_sql << "\"" << rs->getFieldName(i) << "\""; select_sql << "\"" << rs->getFieldName(i) << "\"";
} }
select_sql << " from (" << query << ") as query"; select_sql << " from (" << query << ") as query";
std::string table_name = mapnik::sql_utils::table_from_sql(query); std::string table_name = mapnik::sql_utils::table_from_sql(query);
std::string schema_name=""; std::string schema_name="";
std::string::size_type idx=table_name.find_last_of('.'); std::string::size_type idx=table_name.find_last_of('.');
if (idx!=std::string::npos) if (idx!=std::string::npos)
@ -105,7 +105,7 @@ void pgsql2sqlite(Connection conn,
{ {
table_name=table_name.substr(0); table_name=table_name.substr(0);
} }
std::ostringstream geom_col_sql; std::ostringstream geom_col_sql;
geom_col_sql << "select f_geometry_column,srid,type from geometry_columns "; geom_col_sql << "select f_geometry_column,srid,type from geometry_columns ";
geom_col_sql << "where f_table_name='" << table_name << "'"; geom_col_sql << "where f_table_name='" << table_name << "'";
@ -113,16 +113,16 @@ void pgsql2sqlite(Connection conn,
{ {
geom_col_sql <<" and f_table_schema='"<< schema_name <<"'"; geom_col_sql <<" and f_table_schema='"<< schema_name <<"'";
} }
rs = conn->executeQuery(geom_col_sql.str()); rs = conn->executeQuery(geom_col_sql.str());
int srid = -1; int srid = -1;
std::string geom_col = "UNKNOWN"; std::string geom_col = "UNKNOWN";
std::string geom_type = "UNKNOWN"; std::string geom_type = "UNKNOWN";
if ( rs->next()) if ( rs->next())
{ {
try try
{ {
srid = boost::lexical_cast<int>(rs->getValue("srid")); srid = boost::lexical_cast<int>(rs->getValue("srid"));
} }
@ -133,7 +133,7 @@ void pgsql2sqlite(Connection conn,
geom_col = rs->getValue("f_geometry_column"); geom_col = rs->getValue("f_geometry_column");
geom_type = rs->getValue("type"); geom_type = rs->getValue("type");
} }
// add AsBinary(<geometry_column>) modifier // add AsBinary(<geometry_column>) modifier
std::string select_sql_str = select_sql.str(); std::string select_sql_str = select_sql.str();
boost::algorithm::replace_all(select_sql_str, "\"" + geom_col + "\"","AsBinary(" + geom_col+") as " + geom_col); boost::algorithm::replace_all(select_sql_str, "\"" + geom_col + "\"","AsBinary(" + geom_col+") as " + geom_col);
@ -141,31 +141,31 @@ void pgsql2sqlite(Connection conn,
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::cout << select_sql_str << "\n"; std::cout << select_sql_str << "\n";
#endif #endif
std::ostringstream cursor_sql; std::ostringstream cursor_sql;
std::string cursor_name("my_cursor"); std::string cursor_name("my_cursor");
cursor_sql << "DECLARE " << cursor_name << " BINARY INSENSITIVE NO SCROLL CURSOR WITH HOLD FOR " << select_sql_str << " FOR READ ONLY"; cursor_sql << "DECLARE " << cursor_name << " BINARY INSENSITIVE NO SCROLL CURSOR WITH HOLD FOR " << select_sql_str << " FOR READ ONLY";
conn->execute(cursor_sql.str()); conn->execute(cursor_sql.str());
boost::shared_ptr<CursorResultSet> cursor(new CursorResultSet(conn,cursor_name,10000)); boost::shared_ptr<CursorResultSet> cursor(new CursorResultSet(conn,cursor_name,10000));
unsigned num_fields = cursor->getNumFields(); unsigned num_fields = cursor->getNumFields();
if (num_fields == 0) return; if (num_fields == 0) return;
std::string feature_id = "fid"; std::string feature_id = "fid";
std::ostringstream create_sql; std::ostringstream create_sql;
create_sql << "create table if not exists " << output_table_name << " (" << feature_id << " INTEGER PRIMARY KEY AUTOINCREMENT,"; create_sql << "create table if not exists " << output_table_name << " (" << feature_id << " INTEGER PRIMARY KEY AUTOINCREMENT,";
int geometry_oid = -1; int geometry_oid = -1;
std::string output_table_insert_sql = "insert into " + output_table_name + " values (?"; std::string output_table_insert_sql = "insert into " + output_table_name + " values (?";
for ( unsigned pos = 0; pos < num_fields ; ++pos) for ( unsigned pos = 0; pos < num_fields ; ++pos)
{ {
if (pos > 0) if (pos > 0)
{ {
create_sql << ","; create_sql << ",";
} }
@ -193,47 +193,47 @@ void pgsql2sqlite(Connection conn,
default: default:
create_sql << "' TEXT"; create_sql << "' TEXT";
break; break;
} }
} }
} }
create_sql << ");"; create_sql << ");";
output_table_insert_sql +=")"; output_table_insert_sql +=")";
std::cout << "client_encoding=" << conn->client_encoding() << "\n"; std::cout << "client_encoding=" << conn->client_encoding() << "\n";
std::cout << "geometry_column=" << geom_col << "(" << geom_type std::cout << "geometry_column=" << geom_col << "(" << geom_type
<< ") srid=" << srid << " oid=" << geometry_oid << "\n"; << ") srid=" << srid << " oid=" << geometry_oid << "\n";
db.execute("begin;"); db.execute("begin;");
// output table sql // output table sql
db.execute(create_sql.str()); db.execute(create_sql.str());
// spatial index sql // spatial index sql
std::string spatial_index_sql = "create virtual table idx_" + output_table_name std::string spatial_index_sql = "create virtual table idx_" + output_table_name
+ "_" + geom_col + " using rtree(pkid, xmin, xmax, ymin, ymax)"; + "_" + geom_col + " using rtree(pkid, xmin, xmax, ymin, ymax)";
db.execute(spatial_index_sql); db.execute(spatial_index_sql);
//blob_to_hex hex; //blob_to_hex hex;
int pkid = 0; int pkid = 0;
std::string spatial_index_insert_sql = "insert into idx_" + output_table_name + "_" std::string spatial_index_insert_sql = "insert into idx_" + output_table_name + "_"
+ geom_col + " values (?,?,?,?,?)" ; + geom_col + " values (?,?,?,?,?)" ;
sqlite::prepared_statement spatial_index(db,spatial_index_insert_sql); sqlite::prepared_statement spatial_index(db,spatial_index_insert_sql);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::cout << output_table_insert_sql << "\n"; std::cout << output_table_insert_sql << "\n";
#endif #endif
sqlite::prepared_statement output_table(db,output_table_insert_sql); sqlite::prepared_statement output_table(db,output_table_insert_sql);
while (cursor->next()) while (cursor->next())
{ {
++pkid; ++pkid;
sqlite::record_type output_rec; sqlite::record_type output_rec;
output_rec.push_back(sqlite::value_type(pkid)); output_rec.push_back(sqlite::value_type(pkid));
bool empty_geom = true; bool empty_geom = true;
@ -245,7 +245,7 @@ void pgsql2sqlite(Connection conn,
int size=cursor->getFieldLength(pos); int size=cursor->getFieldLength(pos);
int oid = cursor->getTypeOID(pos); int oid = cursor->getTypeOID(pos);
buf=cursor->getValue(pos); buf=cursor->getValue(pos);
switch (oid) switch (oid)
{ {
case 25: case 25:
@ -280,19 +280,19 @@ void pgsql2sqlite(Connection conn,
case 1700: case 1700:
{ {
std::string str = mapnik::sql_utils::numeric2string(buf); std::string str = mapnik::sql_utils::numeric2string(buf);
try try
{ {
double val = boost::lexical_cast<double>(str); double val = boost::lexical_cast<double>(str);
output_rec.push_back(sqlite::value_type(val)); output_rec.push_back(sqlite::value_type(val));
} }
catch (boost::bad_lexical_cast & ex) catch (boost::bad_lexical_cast & ex)
{ {
std::clog << ex.what() << "\n"; std::clog << ex.what() << "\n";
} }
break; break;
} }
default: default:
{ {
if (oid == geometry_oid) if (oid == geometry_oid)
{ {
@ -305,46 +305,46 @@ void pgsql2sqlite(Connection conn,
if (bbox.valid()) if (bbox.valid())
{ {
sqlite::record_type rec; sqlite::record_type rec;
rec.push_back(sqlite::value_type(pkid)); rec.push_back(sqlite::value_type(pkid));
rec.push_back(sqlite::value_type(bbox.minx())); rec.push_back(sqlite::value_type(bbox.minx()));
rec.push_back(sqlite::value_type(bbox.maxx())); rec.push_back(sqlite::value_type(bbox.maxx()));
rec.push_back(sqlite::value_type(bbox.miny())); rec.push_back(sqlite::value_type(bbox.miny()));
rec.push_back(sqlite::value_type(bbox.maxy())); rec.push_back(sqlite::value_type(bbox.maxy()));
spatial_index.insert_record(rec); spatial_index.insert_record(rec);
empty_geom = false; empty_geom = false;
} }
} }
//output_rec.push_back(sqlite::value_type("X'" + hex(buf,size) + "'")); //output_rec.push_back(sqlite::value_type("X'" + hex(buf,size) + "'"));
output_rec.push_back(sqlite::blob(buf,size)); output_rec.push_back(sqlite::blob(buf,size));
} }
else else
{ {
output_rec.push_back(sqlite::null_type()); output_rec.push_back(sqlite::null_type());
} }
break; break;
} }
} }
} }
else else
{ {
output_rec.push_back(sqlite::null_type()); output_rec.push_back(sqlite::null_type());
} }
} }
if (!empty_geom) output_table.insert_record(output_rec); if (!empty_geom) output_table.insert_record(output_rec);
if (pkid % 1000 == 0) if (pkid % 1000 == 0)
{ {
std::cout << "\r processing " << pkid << " features"; std::cout << "\r processing " << pkid << " features";
std::cout.flush(); std::cout.flush();
} }
if (pkid % 100000 == 0) if (pkid % 100000 == 0)
{ {
db.execute("commit;begin;"); db.execute("commit;begin;");
} }
} }
// commit // commit

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2009 Artem Pavlenko * Copyright (C) 2009 Artem Pavlenko
@ -33,17 +33,17 @@ namespace mapnik { namespace sqlite {
{ {
sqlite3_close(db); sqlite3_close(db);
throw; throw;
} }
db_ = sqlite_db(db,database_closer()); db_ = sqlite_db(db,database_closer());
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::cerr << "Open database " << name << "\n"; std::cerr << "Open database " << name << "\n";
#endif #endif
} }
database::~database() {} database::~database() {}
bool database::execute(std::string const& sql) bool database::execute(std::string const& sql)
{ {
char * err_msg; char * err_msg;
int res = sqlite3_exec(db_.get(),sql.c_str(),0,0,&err_msg); int res = sqlite3_exec(db_.get(),sql.c_str(),0,0,&err_msg);

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2009 Artem Pavlenko * Copyright (C) 2009 Artem Pavlenko
@ -30,7 +30,7 @@
//stl //stl
//#ifdef MAPNIK_DEBUG //#ifdef MAPNIK_DEBUG
#include <iostream> #include <iostream>
//#endif //#endif
#include <string> #include <string>
#include <vector> #include <vector>
@ -40,7 +40,7 @@ namespace mapnik { namespace sqlite {
class database : private boost::noncopyable class database : private boost::noncopyable
{ {
friend class prepared_statement; friend class prepared_statement;
struct database_closer struct database_closer
{ {
void operator () (sqlite3 * db) void operator () (sqlite3 * db)
@ -51,10 +51,10 @@ namespace mapnik { namespace sqlite {
sqlite3_close(db); sqlite3_close(db);
} }
}; };
typedef boost::shared_ptr<sqlite3> sqlite_db; typedef boost::shared_ptr<sqlite3> sqlite_db;
sqlite_db db_; sqlite_db db_;
public: public:
database(std::string const& name); database(std::string const& name);
~database(); ~database();
@ -62,25 +62,25 @@ namespace mapnik { namespace sqlite {
}; };
struct null_type {}; struct null_type {};
struct blob struct blob
{ {
blob(const char* buf, unsigned size) blob(const char* buf, unsigned size)
: buf_(buf), size_(size) {} : buf_(buf), size_(size) {}
const char * buf_; const char * buf_;
unsigned size_; unsigned size_;
}; };
typedef boost::variant<int,double,std::string, blob,null_type> value_type; typedef boost::variant<int,double,std::string, blob,null_type> value_type;
typedef std::vector<value_type> record_type; typedef std::vector<value_type> record_type;
class prepared_statement : boost::noncopyable class prepared_statement : boost::noncopyable
{ {
struct binder : public boost::static_visitor<bool> struct binder : public boost::static_visitor<bool>
{ {
binder(sqlite3_stmt * stmt, unsigned index) binder(sqlite3_stmt * stmt, unsigned index)
: stmt_(stmt), index_(index) {} : stmt_(stmt), index_(index) {}
bool operator() (null_type ) bool operator() (null_type )
{ {
if (sqlite3_bind_null(stmt_, index_) != SQLITE_OK) if (sqlite3_bind_null(stmt_, index_) != SQLITE_OK)
@ -90,7 +90,7 @@ namespace mapnik { namespace sqlite {
} }
return true; return true;
} }
bool operator() (int val) bool operator() (int val)
{ {
if (sqlite3_bind_int(stmt_, index_ , val ) != SQLITE_OK) if (sqlite3_bind_int(stmt_, index_ , val ) != SQLITE_OK)
@ -100,7 +100,7 @@ namespace mapnik { namespace sqlite {
} }
return true; return true;
} }
bool operator() (double val) bool operator() (double val)
{ {
if (sqlite3_bind_double(stmt_, index_ , val ) != SQLITE_OK) if (sqlite3_bind_double(stmt_, index_ , val ) != SQLITE_OK)
@ -110,7 +110,7 @@ namespace mapnik { namespace sqlite {
} }
return true; return true;
} }
bool operator() (std::string const& val) bool operator() (std::string const& val)
{ {
if (sqlite3_bind_text(stmt_, index_, val.c_str(), val.length(), SQLITE_STATIC) != SQLITE_OK) if (sqlite3_bind_text(stmt_, index_, val.c_str(), val.length(), SQLITE_STATIC) != SQLITE_OK)
@ -120,7 +120,7 @@ namespace mapnik { namespace sqlite {
} }
return true; return true;
} }
bool operator() (blob const& val) bool operator() (blob const& val)
{ {
if (sqlite3_bind_blob(stmt_, index_, val.buf_, val.size_, SQLITE_STATIC) != SQLITE_OK) if (sqlite3_bind_blob(stmt_, index_, val.buf_, val.size_, SQLITE_STATIC) != SQLITE_OK)
@ -130,7 +130,7 @@ namespace mapnik { namespace sqlite {
} }
return true; return true;
} }
sqlite3_stmt * stmt_; sqlite3_stmt * stmt_;
unsigned index_; unsigned index_;
}; };
@ -143,22 +143,22 @@ namespace mapnik { namespace sqlite {
int res = sqlite3_prepare_v2(db_, sql.c_str(),-1, &stmt_,&tail); int res = sqlite3_prepare_v2(db_, sql.c_str(),-1, &stmt_,&tail);
if (res != SQLITE_OK) if (res != SQLITE_OK)
{ {
std::cerr << "ERR:"<< res << "\n"; std::cerr << "ERR:"<< res << "\n";
throw; throw;
} }
} }
~prepared_statement() ~prepared_statement()
{ {
int res = sqlite3_finalize(stmt_); int res = sqlite3_finalize(stmt_);
if (res != SQLITE_OK) if (res != SQLITE_OK)
{ {
std::cerr << "ERR:" << res << "\n"; std::cerr << "ERR:" << res << "\n";
} }
} }
bool insert_record(record_type const& rec) const bool insert_record(record_type const& rec) const
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
assert( unsigned(sqlite3_bind_parameter_count(stmt_)) == rec.size()); assert( unsigned(sqlite3_bind_parameter_count(stmt_)) == rec.size());
#endif #endif
@ -173,7 +173,7 @@ namespace mapnik { namespace sqlite {
return false; return false;
} }
} }
sqlite3_step(stmt_); sqlite3_step(stmt_);
sqlite3_reset(stmt_); sqlite3_reset(stmt_);

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko * Copyright (C) 2006 Artem Pavlenko
@ -24,7 +24,7 @@
#ifndef QUADTREE_HPP #ifndef QUADTREE_HPP
#define QUADTREE_HPP #define QUADTREE_HPP
// stl // stl
#include <cstring> #include <cstring>
#include <vector> #include <vector>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -46,29 +46,29 @@ struct quadtree_node
memset(children_,0,sizeof(quadtree_node<T>*)*4); memset(children_,0,sizeof(quadtree_node<T>*)*4);
} }
~quadtree_node() ~quadtree_node()
{ {
for (int i=0;i<4;++i) for (int i=0;i<4;++i)
{ {
if (children_[i]) if (children_[i])
{ {
delete children_[i],children_[i]=0; delete children_[i],children_[i]=0;
} }
} }
} }
int num_subnodes() const int num_subnodes() const
{ {
int count=0; int count=0;
for (int i=0;i<4;++i) for (int i=0;i<4;++i)
{ {
if (children_[i]) if (children_[i])
{ {
++count; ++count;
} }
} }
return count; return count;
} }
}; };
template <typename T> template <typename T>
@ -88,34 +88,34 @@ public:
{ {
if (root_) delete root_; if (root_) delete root_;
} }
void insert(const T& data,const box2d<double>& item_ext) void insert(const T& data,const box2d<double>& item_ext)
{ {
insert(data,item_ext,root_,maxdepth_); insert(data,item_ext,root_,maxdepth_);
} }
int count() const int count() const
{ {
return count_nodes(root_); return count_nodes(root_);
} }
int count_items() const int count_items() const
{ {
int count=0; int count=0;
count_items(root_,count); count_items(root_,count);
return count; return count;
} }
void print() const void print() const
{ {
print(root_); print(root_);
} }
void trim() void trim()
{ {
trim_tree(root_); trim_tree(root_);
} }
void write(std::ostream& out) void write(std::ostream& out)
{ {
char header[16]; char header[16];
@ -133,25 +133,25 @@ public:
private: private:
void trim_tree(quadtree_node<T>*& node) void trim_tree(quadtree_node<T>*& node)
{ {
if (node) if (node)
{ {
for (int i=0;i<4;++i) for (int i=0;i<4;++i)
{ {
trim_tree(node->children_[i]); trim_tree(node->children_[i]);
} }
if (node->num_subnodes()==1 && node->data_.size()==0) if (node->num_subnodes()==1 && node->data_.size()==0)
{ {
for (int i=0;i<4;++i) for (int i=0;i<4;++i)
{ {
if (node->children_[i]) if (node->children_[i])
{ {
node=node->children_[i]; node=node->children_[i];
break; break;
} }
} }
} }
} }
} }
@ -176,11 +176,11 @@ private:
{ {
if (node) if (node)
{ {
count += node->data_.size(); count += node->data_.size();
for (int i=0;i<4;++i) for (int i=0;i<4;++i)
{ {
count_items(node->children_[i],count); count_items(node->children_[i],count);
} }
} }
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2006 Artem Pavlenko * Copyright (C) 2006 Artem Pavlenko
@ -40,7 +40,7 @@ const double MINRATIO=0.5;
const double MAXRATIO=0.8; const double MAXRATIO=0.8;
const double DEFAULT_RATIO=0.55; const double DEFAULT_RATIO=0.55;
int main (int argc,char** argv) int main (int argc,char** argv)
{ {
using namespace mapnik; using namespace mapnik;
namespace po = boost::program_options; namespace po = boost::program_options;
@ -48,12 +48,12 @@ int main (int argc,char** argv)
using std::vector; using std::vector;
using std::clog; using std::clog;
using std::endl; using std::endl;
bool verbose=false; bool verbose=false;
unsigned int depth=DEFAULT_DEPTH; unsigned int depth=DEFAULT_DEPTH;
double ratio=DEFAULT_RATIO; double ratio=DEFAULT_RATIO;
vector<string> shape_files; vector<string> shape_files;
try try
{ {
po::options_description desc("shapeindex utility"); po::options_description desc("shapeindex utility");
@ -61,29 +61,29 @@ int main (int argc,char** argv)
("help,h", "produce usage message") ("help,h", "produce usage message")
("version,V","print version string") ("version,V","print version string")
("verbose,v","verbose output") ("verbose,v","verbose output")
("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)") ("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)")
("ratio,r",po::value<double>(),"split ratio (default 0.55)") ("ratio,r",po::value<double>(),"split ratio (default 0.55)")
("shape_files",po::value<vector<string> >(),"shape files to index: file1 file2 ...fileN") ("shape_files",po::value<vector<string> >(),"shape files to index: file1 file2 ...fileN")
; ;
po::positional_options_description p; po::positional_options_description p;
p.add("shape_files",-1); p.add("shape_files",-1);
po::variables_map vm; po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm); po::notify(vm);
if (vm.count("version")) if (vm.count("version"))
{ {
clog<<"version 0.3.0" <<std::endl; clog<<"version 0.3.0" <<std::endl;
return 1; return 1;
} }
if (vm.count("help")) if (vm.count("help"))
{ {
clog << desc << endl; clog << desc << endl;
return 1; return 1;
} }
if (vm.count("verbose")) if (vm.count("verbose"))
{ {
verbose = true; verbose = true;
} }
@ -95,7 +95,7 @@ int main (int argc,char** argv)
{ {
ratio = vm["ratio"].as<double>(); ratio = vm["ratio"].as<double>();
} }
if (vm.count("shape_files")) if (vm.count("shape_files"))
{ {
shape_files=vm["shape_files"].as< vector<string> >(); shape_files=vm["shape_files"].as< vector<string> >();
@ -106,10 +106,10 @@ int main (int argc,char** argv)
clog << "Exception of unknown type!" << endl; clog << "Exception of unknown type!" << endl;
return -1; return -1;
} }
clog << "max tree depth:" << depth << endl; clog << "max tree depth:" << depth << endl;
clog << "split ratio:" << ratio << endl; clog << "split ratio:" << ratio << endl;
vector<string>::const_iterator itr = shape_files.begin(); vector<string>::const_iterator itr = shape_files.begin();
if (itr == shape_files.end()) if (itr == shape_files.end())
{ {
@ -135,33 +135,33 @@ int main (int argc,char** argv)
clog << "error : cannot open " << shapename_full << endl; clog << "error : cannot open " << shapename_full << endl;
continue; continue;
} }
int code = shp.read_xdr_integer(); //file_code == 9994 int code = shp.read_xdr_integer(); //file_code == 9994
clog << code << endl; clog << code << endl;
shp.skip(5*4); shp.skip(5*4);
int file_length=shp.read_xdr_integer(); int file_length=shp.read_xdr_integer();
int version=shp.read_ndr_integer(); int version=shp.read_ndr_integer();
int shape_type=shp.read_ndr_integer(); int shape_type=shp.read_ndr_integer();
box2d<double> extent; box2d<double> extent;
shp.read_envelope(extent); shp.read_envelope(extent);
clog << "length=" << file_length << endl; clog << "length=" << file_length << endl;
clog << "version=" << version << endl; clog << "version=" << version << endl;
clog << "type=" << shape_type << endl; clog << "type=" << shape_type << endl;
clog << "extent:" << extent << endl; clog << "extent:" << extent << endl;
int pos=50; int pos=50;
shp.seek(pos*2); shp.seek(pos*2);
quadtree<int> tree(extent,depth,ratio); quadtree<int> tree(extent,depth,ratio);
int count=0; int count=0;
while (true) { while (true) {
long offset=shp.pos(); long offset=shp.pos();
int record_number=shp.read_xdr_integer(); int record_number=shp.read_xdr_integer();
int content_length=shp.read_xdr_integer(); int content_length=shp.read_xdr_integer();
shape_type = shp.read_ndr_integer(); shape_type = shp.read_ndr_integer();
box2d<double> item_ext; box2d<double> item_ext;
if (shape_type==shape_io::shape_null) if (shape_type==shape_io::shape_null)
{ {
@ -172,7 +172,7 @@ int main (int argc,char** argv)
double x=shp.read_double(); double x=shp.read_double();
double y=shp.read_double(); double y=shp.read_double();
item_ext=box2d<double>(x,y,x,y); item_ext=box2d<double>(x,y,x,y);
} }
else if (shape_type==shape_io::shape_pointm) else if (shape_type==shape_io::shape_pointm)
{ {
@ -181,7 +181,7 @@ int main (int argc,char** argv)
// skip m // skip m
shp.read_double(); shp.read_double();
item_ext=box2d<double>(x,y,x,y); item_ext=box2d<double>(x,y,x,y);
} }
else if (shape_type==shape_io::shape_pointz) else if (shape_type==shape_io::shape_pointz)
{ {
@ -190,19 +190,19 @@ int main (int argc,char** argv)
// skip z // skip z
shp.read_double(); shp.read_double();
//skip m if exists //skip m if exists
if ( content_length == 8 + 36) if ( content_length == 8 + 36)
{ {
shp.read_double(); shp.read_double();
} }
item_ext=box2d<double>(x,y,x,y); item_ext=box2d<double>(x,y,x,y);
} }
else else
{ {
shp.read_envelope(item_ext); shp.read_envelope(item_ext);
shp.skip(2*content_length-4*8-4); shp.skip(2*content_length-4*8-4);
} }
tree.insert(offset,item_ext); tree.insert(offset,item_ext);
if (verbose) { if (verbose) {
clog << "record number " << record_number << " box=" << item_ext << endl; clog << "record number " << record_number << " box=" << item_ext << endl;
@ -213,15 +213,15 @@ int main (int argc,char** argv)
if (pos>=file_length) { if (pos>=file_length) {
break; break;
} }
} }
clog << " number shapes=" << count << endl; clog << " number shapes=" << count << endl;
std::fstream file((shapename+".index").c_str(), std::fstream file((shapename+".index").c_str(),
std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary); std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
if (!file) { if (!file) {
clog << "cannot open index file for writing file \"" clog << "cannot open index file for writing file \""
<< (shapename+".index") << "\"" << endl; << (shapename+".index") << "\"" << endl;
} else { } else {
tree.trim(); tree.trim();
@ -232,7 +232,7 @@ int main (int argc,char** argv)
file.close(); file.close();
} }
} }
clog << "done!" << endl; clog << "done!" << endl;
return 0; return 0;
} }

View file

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2010 Artem Pavlenko
@ -45,13 +45,13 @@
#include "agg_scanline_u.h" #include "agg_scanline_u.h"
int main (int argc,char** argv) int main (int argc,char** argv)
{ {
namespace po = boost::program_options; namespace po = boost::program_options;
bool verbose=false; bool verbose=false;
std::vector<std::string> svg_files; std::vector<std::string> svg_files;
try try
{ {
po::options_description desc("svg2png utility"); po::options_description desc("svg2png utility");
@ -61,10 +61,10 @@ int main (int argc,char** argv)
("verbose,v","verbose output") ("verbose,v","verbose output")
("svg",po::value<std::vector<std::string> >(),"svg file to read") ("svg",po::value<std::vector<std::string> >(),"svg file to read")
; ;
po::positional_options_description p; po::positional_options_description p;
p.add("svg",-1); p.add("svg",-1);
po::variables_map vm; po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm); po::notify(vm);
@ -74,12 +74,12 @@ int main (int argc,char** argv)
return 1; return 1;
} }
if (vm.count("help")) if (vm.count("help"))
{ {
std::clog << desc << std::endl; std::clog << desc << std::endl;
return 1; return 1;
} }
if (vm.count("verbose")) if (vm.count("verbose"))
{ {
verbose = true; verbose = true;
} }
@ -107,10 +107,10 @@ int main (int argc,char** argv)
boost::optional<mapnik::marker_ptr> marker_ptr = mapnik::marker_cache::instance()->find(svg_name, false); boost::optional<mapnik::marker_ptr> marker_ptr = mapnik::marker_cache::instance()->find(svg_name, false);
if (marker_ptr) { if (marker_ptr) {
mapnik::marker marker = **marker_ptr; mapnik::marker marker = **marker_ptr;
if (marker.is_vector()) { if (marker.is_vector()) {
typedef agg::pixfmt_rgba32_plain pixfmt; typedef agg::pixfmt_rgba32_plain pixfmt;
typedef agg::renderer_base<pixfmt> renderer_base; typedef agg::renderer_base<pixfmt> renderer_base;
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid; typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
@ -138,10 +138,10 @@ int main (int argc,char** argv)
mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage((*marker.get_vector_data())->source()); mapnik::svg::vertex_stl_adapter<mapnik::svg::svg_path_storage> stl_storage((*marker.get_vector_data())->source());
mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_path_adapter svg_path(stl_storage);
mapnik::svg::svg_renderer<mapnik::svg::svg_path_adapter, mapnik::svg::svg_renderer<mapnik::svg::svg_path_adapter,
agg::pod_bvector<mapnik::svg::path_attributes>, agg::pod_bvector<mapnik::svg::path_attributes>,
renderer_solid, renderer_solid,
agg::pixfmt_rgba32_plain > svg_renderer_this(svg_path, agg::pixfmt_rgba32_plain > svg_renderer_this(svg_path,
(*marker.get_vector_data())->attributes()); (*marker.get_vector_data())->attributes());
svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox); svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox);