+ close linear_rings in WKT parser

This commit is contained in:
artemp 2012-08-15 16:42:46 +01:00
parent e2b657251d
commit c4765d72ce
3 changed files with 34 additions and 1 deletions

View file

@ -126,6 +126,14 @@ public:
push_vertex(x,y,SEG_CLOSE);
}
void close()
{
if (cont_.size() > 3)
{
cont_.set_command(cont_.size() - 1, SEG_CLOSE);
}
}
unsigned vertex(double* x, double* y) const
{
return cont_.get_vertex(itr_++,x,y);

View file

@ -115,6 +115,14 @@ public:
return commands_[block] [pos & block_mask];
}
void set_command(unsigned pos, unsigned command)
{
if (pos < pos_)
{
unsigned block = pos >> block_shift;
commands_[block] [pos & block_mask] = command;
}
}
private:
void allocate_block(unsigned block)
{

View file

@ -59,6 +59,22 @@ namespace mapnik { namespace wkt {
}
};
struct close_path
{
template <typename T>
struct result
{
typedef void type;
};
template <typename T>
void operator() (T path) const
{
BOOST_ASSERT( path!=0 );
path->close();
}
};
struct cleanup
{
template <typename T0>
@ -119,7 +135,7 @@ namespace mapnik { namespace wkt {
;
// <polygon text> ::= <empty set> | <left paren> <linestring text> {<comma> <linestring text>}* <right paren>
polygon_text = (lit('(') >> linestring_text(_r1) % lit(',') >> lit(')')) | empty_set;
polygon_text = (lit('(') >> linestring_text(_r1)[close_path_(_r1)] % lit(',') >> lit(')')) | empty_set;
//<multipoint tagged text> ::= multipoint <multipoint text>
@ -191,6 +207,7 @@ namespace mapnik { namespace wkt {
qi::rule<Iterator,qi::locals<CommandType>,void(geometry_type*),ascii::space_type> points;
qi::rule<Iterator,ascii::space_type> empty_set;
boost::phoenix::function<push_vertex> push_vertex_;
boost::phoenix::function<close_path> close_path_;
boost::phoenix::function<cleanup> cleanup_;
};