reflect new box2d<double>from_bbox() function in python, and add a new value_error class to represent parsing errors (TODO: translate in python to ValueError and throw from other parsers like expression and color)
This commit is contained in:
parent
6cda2b7d96
commit
58c72fc1c9
2 changed files with 76 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/value_error.hpp>
|
||||
|
||||
using mapnik::coord;
|
||||
using mapnik::box2d;
|
||||
|
@ -40,6 +41,22 @@ struct envelope_pickle_suite : boost::python::pickle_suite
|
|||
}
|
||||
};
|
||||
|
||||
box2d<double> from_string(std::string const& s)
|
||||
{
|
||||
box2d<double> 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<double>::*width_p1)(double) = &box2d<double>::width;
|
||||
double (box2d<double>::*width_p2)() const = &box2d<double>::width;
|
||||
|
@ -80,6 +97,8 @@ void export_envelope()
|
|||
.def(init<const coord<double,2>&, const coord<double,2>&>(
|
||||
(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<double>::minx,
|
||||
"X coordinate for the lower left corner")
|
||||
.add_property("miny", &box2d<double>::miny,
|
||||
|
|
57
include/mapnik/value_error.hpp
Normal file
57
include/mapnik/value_error.hpp
Normal file
|
@ -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 <iostream>
|
||||
#include <sstream>
|
||||
|
||||
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
|
Loading…
Reference in a new issue