== topojson ==

+ use boost::variant<> for storing properties
+ parse properties as top level key/value pairs
This commit is contained in:
artemp 2013-10-03 15:32:07 +01:00
parent 5b3e89df94
commit ac8ececf1c
4 changed files with 23 additions and 5 deletions

View file

@ -67,7 +67,8 @@ private:
qi::int_parser<mapnik::value_integer,10,1,-1> int__; qi::int_parser<mapnik::value_integer,10,1,-1> int__;
qi::rule<Iterator,std::string(), space_type> string_; qi::rule<Iterator,std::string(), space_type> string_;
qi::rule<Iterator,space_type> key_value; qi::rule<Iterator,space_type> key_value;
qi::rule<Iterator,space_type> number; qi::rule<Iterator,space_type, boost::variant<value_null,bool,
value_integer,value_double>()> number;
qi::rule<Iterator,space_type> object; qi::rule<Iterator,space_type> object;
qi::rule<Iterator,space_type> array; qi::rule<Iterator,space_type> array;
qi::rule<Iterator,space_type> pairs; qi::rule<Iterator,space_type> pairs;
@ -88,7 +89,9 @@ private:
qi::rule<Iterator, space_type, std::vector<index_type>()> ring; qi::rule<Iterator, space_type, std::vector<index_type>()> ring;
// properties // properties
qi::rule<Iterator,space_type, mapnik::topojson::properties()> properties; qi::rule<Iterator, space_type, mapnik::topojson::properties()> properties;
qi::rule<Iterator, space_type, mapnik::topojson::properties()> attributes;
qi::rule<Iterator, space_type, mapnik::topojson::value()> attribute_value;
// error // error
boost::phoenix::function<where_message> where_message_; boost::phoenix::function<where_message> where_message_;

View file

@ -144,9 +144,14 @@ topojson_grammar<Iterator>::topojson_grammar()
properties = lit("\"properties\"") properties = lit("\"properties\"")
>> lit(':') >> lit(':')
>> object >> (( lit('{') >> attributes >> lit('}')) | object)
; ;
attributes = (string_ >> lit(':') >> attribute_value) % lit(',')
;
attribute_value %= number | string_ ;
arcs = lit("\"arcs\"") >> lit(':') arcs = lit("\"arcs\"") >> lit(':')
>> lit('[') >> -( arc % lit(',')) >> lit(']') ; >> lit('[') >> -( arc % lit(',')) >> lit(']') ;

View file

@ -28,8 +28,8 @@
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/adapted/std_tuple.hpp> #include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/spirit/include/support_utree.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <mapnik/feature.hpp>
namespace mapnik { namespace topojson { namespace mapnik { namespace topojson {
@ -41,7 +41,9 @@ struct coordinate
double y; double y;
}; };
typedef boost::spirit::utree properties; typedef boost::variant<value_null,bool,value_integer,value_double,std::string> value;
typedef std::tuple<std::string, value > property;
typedef std::vector<property> properties;
struct point struct point
{ {

View file

@ -98,6 +98,14 @@ struct feature_generator : public boost::static_visitor<mapnik::feature_ptr>
poly_ptr->close_path(); poly_ptr->close_path();
} }
feature->paths().push_back(poly_ptr.release()); feature->paths().push_back(poly_ptr.release());
if (poly.props)
{
for (auto const& p : *poly.props)
{
feature->put_new(std::get<0>(p), mapnik::value(1LL)/*std::get<1>(p)*/);
}
}
return feature; return feature;
} }