diff --git a/include/mapnik/feature_style_processor.hpp b/include/mapnik/feature_style_processor.hpp index 798ff43d1..878e6f754 100644 --- a/include/mapnik/feature_style_processor.hpp +++ b/include/mapnik/feature_style_processor.hpp @@ -88,18 +88,20 @@ public: #endif Processor & p = static_cast(*this); p.start_map_processing(m_); - Map::const_metawriter_iterator metaItr = m_.begin_metawriters(); - Map::const_metawriter_iterator metaItrEnd = m_.end_metawriters(); - - for (;metaItr!=metaItrEnd; ++metaItr) - { - metaItr->second->start(m_.metawriter_output_properties); - metaItr->second->set_size(m_.width(), m_.height()); - } try { projection proj(m_.srs()); // map projection + + Map::const_metawriter_iterator metaItr = m_.begin_metawriters(); + Map::const_metawriter_iterator metaItrEnd = m_.end_metawriters(); + for (;metaItr!=metaItrEnd; ++metaItr) + { + metaItr->second->set_size(m_.width(), m_.height()); + metaItr->second->set_map_srs(proj); + metaItr->second->start(m_.metawriter_output_properties); + } + double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic()); scale_denom *= scale_factor_; #ifdef MAPNIK_DEBUG @@ -112,17 +114,17 @@ public: apply_to_layer(lyr, p, proj, scale_denom); } } + + metaItr = m_.begin_metawriters(); + for (;metaItr!=metaItrEnd; ++metaItr) + { + metaItr->second->stop(); + } } catch (proj_init_error& ex) { std::clog << "proj_init_error:" << ex.what() << "\n"; } - - metaItr = m_.begin_metawriters(); - for (;metaItr!=metaItrEnd; ++metaItr) - { - metaItr->second->stop(); - } p.end_map_processing(m_); } diff --git a/include/mapnik/metawriter.hpp b/include/mapnik/metawriter.hpp index fdad9ad94..194e8444a 100644 --- a/include/mapnik/metawriter.hpp +++ b/include/mapnik/metawriter.hpp @@ -76,11 +76,11 @@ class metawriter * \param properties List of properties to output */ virtual void add_box(box2d box, Feature const &feature, - proj_transform const& prj_trans, CoordTransform const &t, metawriter_properties const& properties = metawriter_properties())=0; virtual void start(metawriter_property_map const& properties) {}; void set_size(int width, int height) { width_ = width; height_ = height; } + virtual void set_map_srs(projection const& proj) = 0; virtual void stop() {}; metawriter_properties const& get_default_properties() const { return dflt_properties_;} protected: diff --git a/include/mapnik/metawriter_json.hpp b/include/mapnik/metawriter_json.hpp index 438c25626..6caf7215b 100644 --- a/include/mapnik/metawriter_json.hpp +++ b/include/mapnik/metawriter_json.hpp @@ -41,7 +41,6 @@ public: metawriter_json_stream(metawriter_properties dflt_properties); ~metawriter_json_stream(); virtual void add_box(box2d box, Feature const &feature, - proj_transform const& prj_trans, CoordTransform const& t, metawriter_properties const& properties); @@ -51,10 +50,12 @@ public: std::ostream *get_stream() const { return f_; } void set_only_nonempty(bool only_nonempty) { only_nonempty_ = only_nonempty; } bool get_only_nonempty() { return only_nonempty_; } - + virtual void set_map_srs(projection const& proj); protected: int count_; bool only_nonempty_; + proj_transform *trans_; + projection output_srs_; virtual void write_header(); private: std::ostream *f_; diff --git a/src/agg/process_point_symbolizer.cpp b/src/agg/process_point_symbolizer.cpp index ff4ca7fe5..100924eed 100644 --- a/src/agg/process_point_symbolizer.cpp +++ b/src/agg/process_point_symbolizer.cpp @@ -117,7 +117,7 @@ void agg_renderer::process(point_symbolizer const& sym, metawriter_with_properties writer = sym.get_metawriter(); if (writer.first) { - writer.first->add_box(extent, feature, prj_trans, t_, writer.second); + writer.first->add_box(extent, feature, t_, writer.second); } } } @@ -158,7 +158,7 @@ void agg_renderer::process(point_symbolizer const& sym, metawriter_with_properties writer = sym.get_metawriter(); if (writer.first) { - writer.first->add_box(label_ext, feature, prj_trans, t_, writer.second); + writer.first->add_box(label_ext, feature, t_, writer.second); } } } diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 7b5e53058..e30161ea3 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -780,7 +780,7 @@ void cairo_renderer_base::process(point_symbolizer const& sym, metawriter_with_properties writer = sym.get_metawriter(); if (writer.first) { - writer.first->add_box(label_ext, feature, prj_trans, t_, writer.second); + writer.first->add_box(label_ext, feature, t_, writer.second); } } } diff --git a/src/metawriter.cpp b/src/metawriter.cpp index 78bc291ca..f59c88923 100644 --- a/src/metawriter.cpp +++ b/src/metawriter.cpp @@ -57,6 +57,7 @@ metawriter_properties::metawriter_properties(boost::optional str) void metawriter_json_stream::start(metawriter_property_map const& properties) { + assert(trans_); if (!only_nonempty_) { write_header(); } else { @@ -87,14 +88,19 @@ metawriter_json_stream::~metawriter_json_stream() #endif stop(); } + if (trans_) delete trans_; } + metawriter_json_stream::metawriter_json_stream(metawriter_properties dflt_properties) - : metawriter(dflt_properties), count_(-1), only_nonempty_(true), f_(0) {} + : metawriter(dflt_properties), count_(-1), only_nonempty_(true), + trans_(0), output_srs_("+proj=latlong +datum=WGS84"), f_(0) +{ +} + void metawriter_json_stream::add_box(box2d box, Feature const &feature, - proj_transform const& prj_trans, CoordTransform const &t, - const metawriter_properties& properties) + CoordTransform const &t, const metawriter_properties& properties) { /* Check if feature is in bounds. */ if (box.maxx() < 0 || box.maxy() < 0 || box.minx() > width_ || box.miny() > height_) return; @@ -117,14 +123,13 @@ void metawriter_json_stream::add_box(box2d box, Feature const &feature, Our transform: input: pixels t_.backward() - intermediate: map srs (available via prj_trans.source()) - trans.forward() + intermediate: map srs + trans_.forward() output: WGS84 */ - proj_transform trans(prj_trans.source(), projection("+proj=latlong +datum=WGS84")); - //t_ coord transform has transform for box2d combined with prj_trans - box = t.backward(box, trans); + //t_ coord transform has transform for box2d combined with proj_transform + box = t.backward(box, *trans_); double minx = box.minx(); double miny = box.miny(); @@ -156,6 +161,12 @@ void metawriter_json_stream::add_box(box2d box, Feature const &feature, *f_ << "\n} }"; } +void metawriter_json_stream::set_map_srs(projection const& input_srs_) +{ + if (trans_) delete trans_; + trans_ = new proj_transform(input_srs_, output_srs_); +} + /********************************************************************************************/