diff --git a/bindings/python/mapnik_envelope.cpp b/bindings/python/mapnik_envelope.cpp index 553abea6a..64d0f1a80 100644 --- a/bindings/python/mapnik_envelope.cpp +++ b/bindings/python/mapnik_envelope.cpp @@ -26,6 +26,7 @@ // mapnik #include +#include using mapnik::coord; using mapnik::box2d; @@ -40,6 +41,22 @@ struct envelope_pickle_suite : boost::python::pickle_suite } }; +box2d from_string(std::string const& s) +{ + box2d bbox; + bool success = bbox.from_string(s); + if (success) + { + return bbox; + } + else + { + std::stringstream ss; + ss << "Could not parse bbox from string: '" << s << "'"; + throw mapnik::value_error(ss.str()); + } +} + //define overloads here void (box2d::*width_p1)(double) = &box2d::width; double (box2d::*width_p2)() const = &box2d::width; @@ -80,6 +97,8 @@ void export_envelope() .def(init&, const coord&>( (arg("ll"),arg("ur")), "Equivalent to Box2d(ll.x, ll.y, ur.x, ur.y).\n")) + .def("from_string",from_string) + .staticmethod("from_string") .add_property("minx", &box2d::minx, "X coordinate for the lower left corner") .add_property("miny", &box2d::miny, diff --git a/include/mapnik/value_error.hpp b/include/mapnik/value_error.hpp new file mode 100644 index 000000000..a83631f5d --- /dev/null +++ b/include/mapnik/value_error.hpp @@ -0,0 +1,57 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2006 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_VALUE_ERROR_INCLUDED +#define MAPNIK_VALUE_ERROR_INCLUDED + +#include +#include + +namespace mapnik { + +class value_error : public std::exception +{ +public: + value_error() {} + + value_error( const std::string & what ) : + what_( what ) + { + } + virtual ~value_error() throw() {}; + + virtual const char * what() const throw() + { + return what_.c_str(); + } + + void append_context(const std::string & ctx) const + { + what_ += " " + ctx; + } + +protected: + mutable std::string what_; +}; +} + +#endif // MAPNIK_VALUE_ERROR_INCLUDED