Only initialize proj_transform once in metawriter_json_stream.
This commit is contained in:
parent
03718169b1
commit
035e99d2f0
6 changed files with 42 additions and 28 deletions
|
@ -88,18 +88,20 @@ public:
|
|||
#endif
|
||||
Processor & p = static_cast<Processor&>(*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_);
|
||||
}
|
||||
|
|
|
@ -76,11 +76,11 @@ class metawriter
|
|||
* \param properties List of properties to output
|
||||
*/
|
||||
virtual void add_box(box2d<double> 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:
|
||||
|
|
|
@ -41,7 +41,6 @@ public:
|
|||
metawriter_json_stream(metawriter_properties dflt_properties);
|
||||
~metawriter_json_stream();
|
||||
virtual void add_box(box2d<double> 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_;
|
||||
|
|
|
@ -117,7 +117,7 @@ void agg_renderer<T>::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<T>::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ metawriter_properties::metawriter_properties(boost::optional<std::string> 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<double> 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<double> 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<double> 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_);
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
|
|
Loading…
Reference in a new issue