merge with 2.3.x branch
This commit is contained in:
commit
9c8f7cc90d
7 changed files with 107 additions and 17 deletions
|
@ -441,7 +441,7 @@ struct test11a
|
|||
{
|
||||
throw std::runtime_error("Failed to parse WKT");
|
||||
}
|
||||
BOOST_FOREACH (geometry_type & geom , paths)
|
||||
for (geometry_type & geom : paths)
|
||||
{
|
||||
conv_clip clipped(geom);
|
||||
clipped.clip_box(
|
||||
|
@ -472,7 +472,7 @@ struct test11a
|
|||
}
|
||||
for (unsigned i=0;i<iter_;++i)
|
||||
{
|
||||
BOOST_FOREACH (geometry_type & geom , paths)
|
||||
for (geometry_type & geom : paths)
|
||||
{
|
||||
conv_clip clipped(geom);
|
||||
clipped.clip_box(
|
||||
|
@ -523,7 +523,7 @@ struct test11
|
|||
ps.line_to(extent_.maxx(), extent_.maxy());
|
||||
ps.line_to(extent_.maxx(), extent_.miny());
|
||||
ps.close_polygon();
|
||||
BOOST_FOREACH (geometry_type & geom , paths)
|
||||
for (geometry_type & geom : paths)
|
||||
{
|
||||
poly_clipper clipped(geom,ps,
|
||||
agg::clipper_and,
|
||||
|
@ -604,7 +604,7 @@ struct test12
|
|||
{
|
||||
throw std::runtime_error("Failed to parse WKT");
|
||||
}
|
||||
BOOST_FOREACH ( geometry_type & geom , paths)
|
||||
for ( geometry_type & geom : paths)
|
||||
{
|
||||
poly_clipper clipped(extent_, geom);
|
||||
unsigned cmd;
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
// boost
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
#include <boost/variant/static_visitor.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
// stl
|
||||
#include <vector>
|
||||
|
@ -531,7 +530,7 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
p.start_layer_processing(mat.lay_, mat.layer_ext2_);
|
||||
|
||||
layer const& lay = mat.lay_;
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <boost/variant/variant.hpp>
|
||||
#include <boost/variant/static_visitor.hpp>
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
// stl
|
||||
#include <vector>
|
||||
|
@ -223,7 +222,7 @@ inline std::ostream& operator<< (std::ostream& os, colorize_alpha const& filter)
|
|||
{
|
||||
os << "colorize-alpha(";
|
||||
bool first = true;
|
||||
BOOST_FOREACH( mapnik::filter::color_stop const& stop, filter)
|
||||
for ( mapnik::filter::color_stop const& stop : filter)
|
||||
{
|
||||
if (!first) os << ",";
|
||||
else first = false;
|
||||
|
|
|
@ -55,7 +55,7 @@ using mapnik::parameters;
|
|||
DATASOURCE_PLUGIN(topojson_datasource)
|
||||
|
||||
topojson_datasource::topojson_datasource(parameters const& params)
|
||||
: datasource(params),
|
||||
: datasource(params),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params.get<std::string>("type"),
|
||||
*params.get<std::string>("encoding","utf-8")),
|
||||
|
@ -90,8 +90,6 @@ topojson_datasource::topojson_datasource(parameters const& params)
|
|||
boost::spirit::multi_pass<base_iterator_type> end =
|
||||
boost::spirit::make_default_multi_pass(base_iterator_type());
|
||||
|
||||
//mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
|
||||
|
||||
mapnik::topojson::topojson_grammar<boost::spirit::multi_pass<base_iterator_type> > g;
|
||||
bool result = boost::spirit::qi::phrase_parse(begin, end, g, boost::spirit::standard_wide::space, topo_);
|
||||
if (!result)
|
||||
|
@ -105,16 +103,19 @@ topojson_datasource::topojson_datasource(parameters const& params)
|
|||
mapnik::box2d<double> bbox = boost::apply_visitor(mapnik::topojson::bounding_box_visitor(topo_), geom);
|
||||
if (bbox.valid())
|
||||
{
|
||||
if (count == 0) extent_ = bbox;
|
||||
else extent_.expand_to_include(bbox);
|
||||
tree_.insert(box_type(point_type(bbox.minx(),bbox.miny()),point_type(bbox.maxx(),bbox.maxy())), count++);
|
||||
}
|
||||
}
|
||||
std::cerr << extent_ << std::endl;
|
||||
}
|
||||
|
||||
topojson_datasource::~topojson_datasource() { }
|
||||
|
||||
const char * topojson_datasource::name()
|
||||
{
|
||||
return "geojson";
|
||||
return "topojson";
|
||||
}
|
||||
|
||||
boost::optional<mapnik::datasource::geometry_t> topojson_datasource::get_geometry_type() const
|
||||
|
|
|
@ -22,19 +22,106 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
// boost
|
||||
#include <boost/variant/static_visitor.hpp>
|
||||
#include <boost/variant/apply_visitor.hpp>
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
|
||||
#include "topojson_featureset.hpp"
|
||||
|
||||
namespace mapnik { namespace topojson {
|
||||
|
||||
template <typename Context>
|
||||
struct feature_generator : public boost::static_visitor<mapnik::feature_ptr>
|
||||
{
|
||||
feature_generator(Context & ctx, topology const& topo, std::size_t feature_id)
|
||||
: ctx_(ctx),
|
||||
topo_(topo),
|
||||
feature_id_(feature_id) {}
|
||||
|
||||
feature_ptr operator() (point const& pt) const
|
||||
{
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
feature_ptr operator() (linestring const& line) const
|
||||
{
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
feature_ptr operator() (polygon const& poly) const
|
||||
{
|
||||
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
|
||||
std::unique_ptr<geometry_type> poly_ptr(new geometry_type(geometry_type::types::Polygon));
|
||||
|
||||
for (auto const& ring : poly.rings)
|
||||
{
|
||||
bool first = true;
|
||||
for (auto const& index : ring)
|
||||
{
|
||||
double px = 0, py = 0;
|
||||
bool reversed = index < 0;
|
||||
index_type arc_index = reversed ? std::abs(index) - 1 : index;
|
||||
auto const& coords = topo_.arcs[arc_index].coordinates;
|
||||
std::deque<mapnik::topojson::coordinate> processed_coords;
|
||||
for (auto const& pt : coords )
|
||||
{
|
||||
double x = pt.x;
|
||||
double y = pt.y;
|
||||
|
||||
if (topo_.tr)
|
||||
{
|
||||
x = (px += x) * (*topo_.tr).scale_x + (*topo_.tr).translate_x;
|
||||
y = (py += y) * (*topo_.tr).scale_y + (*topo_.tr).translate_y;
|
||||
}
|
||||
if (reversed)
|
||||
processed_coords.emplace_front(coordinate{x,y});
|
||||
else
|
||||
processed_coords.emplace_back(coordinate{x,y});
|
||||
}
|
||||
|
||||
for (auto const& c : processed_coords)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
poly_ptr->move_to(c.x,c.y);
|
||||
}
|
||||
else poly_ptr->line_to(c.x,c.y);
|
||||
}
|
||||
}
|
||||
poly_ptr->close_path();
|
||||
}
|
||||
feature->paths().push_back(poly_ptr.release());
|
||||
return feature;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
feature_ptr operator() (T const& ) const
|
||||
{
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
Context & ctx_;
|
||||
topology const& topo_;
|
||||
std::size_t feature_id_;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
topojson_featureset::topojson_featureset(mapnik::topojson::topology const& topo,
|
||||
std::deque<std::size_t>::const_iterator index_itr,
|
||||
std::deque<std::size_t>::const_iterator index_end)
|
||||
: topo_(topo),
|
||||
: ctx_(std::make_shared<mapnik::context_type>()),
|
||||
topo_(topo),
|
||||
index_itr_(index_itr),
|
||||
index_end_(index_end) {}
|
||||
index_end_(index_end),
|
||||
feature_id_ (0) {}
|
||||
|
||||
topojson_featureset::~topojson_featureset() {}
|
||||
|
||||
|
@ -46,9 +133,12 @@ mapnik::feature_ptr topojson_featureset::next()
|
|||
if ( index < topo_.geometries.size())
|
||||
{
|
||||
mapnik::topojson::geometry const& geom = topo_.geometries[index];
|
||||
|
||||
return mapnik::feature_ptr(); // TODO
|
||||
mapnik::feature_ptr feature = boost::apply_visitor(
|
||||
mapnik::topojson::feature_generator<mapnik::context_ptr>(ctx_, topo_, feature_id_++),
|
||||
geom);
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
|
||||
return mapnik::feature_ptr();
|
||||
}
|
||||
|
|
|
@ -39,10 +39,12 @@ public:
|
|||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
mapnik::context_ptr ctx_;
|
||||
mapnik::box2d<double> box_;
|
||||
mapnik::topojson::topology const& topo_;
|
||||
std::deque<std::size_t>::const_iterator index_itr_;
|
||||
std::deque<std::size_t>::const_iterator index_end_;
|
||||
std::size_t feature_id_;
|
||||
};
|
||||
|
||||
#endif // TOPOJSON_FEATURESET_HPP
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <mapnik/scale_denominator.hpp>
|
||||
#include <mapnik/feature_style_processor.hpp>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "utils.hpp"
|
||||
|
|
Loading…
Reference in a new issue