2011-09-01 02:44:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-07-25 03:35:41 +02:00
|
|
|
// mapnik
|
2011-09-01 06:49:59 +02:00
|
|
|
#include <mapnik/feature_style_processor.hpp>
|
2012-07-25 04:08:26 +02:00
|
|
|
#include <mapnik/query.hpp>
|
2012-07-25 03:35:41 +02:00
|
|
|
#include <mapnik/feature_type_style.hpp>
|
2011-09-01 02:44:27 +02:00
|
|
|
#include <mapnik/box2d.hpp>
|
|
|
|
#include <mapnik/datasource.hpp>
|
2012-04-08 02:20:56 +02:00
|
|
|
#include <mapnik/memory_datasource.hpp>
|
2011-09-01 02:44:27 +02:00
|
|
|
#include <mapnik/layer.hpp>
|
|
|
|
#include <mapnik/attribute_collector.hpp>
|
|
|
|
#include <mapnik/expression_evaluator.hpp>
|
|
|
|
#include <mapnik/utils.hpp>
|
|
|
|
#include <mapnik/scale_denominator.hpp>
|
|
|
|
#include <mapnik/agg_renderer.hpp>
|
|
|
|
#include <mapnik/grid/grid_renderer.hpp>
|
|
|
|
|
|
|
|
// boost
|
|
|
|
#include <boost/foreach.hpp>
|
2012-03-21 10:29:37 +01:00
|
|
|
#include <boost/concept_check.hpp>
|
2012-07-25 03:35:41 +02:00
|
|
|
|
|
|
|
// stl
|
2011-09-01 02:44:27 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#if defined(HAVE_CAIRO)
|
|
|
|
#include <mapnik/cairo_renderer.hpp>
|
|
|
|
#endif
|
|
|
|
|
2011-09-16 18:18:10 +02:00
|
|
|
#if defined(SVG_RENDERER)
|
|
|
|
#include <mapnik/svg_renderer.hpp>
|
|
|
|
#endif
|
|
|
|
|
2011-09-01 07:14:25 +02:00
|
|
|
#if defined(RENDERING_STATS)
|
|
|
|
#include <mapnik/timer.hpp>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#endif
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
|
2012-03-21 10:29:37 +01:00
|
|
|
template <typename T0,typename T1> struct has_process;
|
|
|
|
|
|
|
|
template <bool>
|
|
|
|
struct process_impl
|
|
|
|
{
|
|
|
|
template <typename T0, typename T1, typename T2, typename T3>
|
2012-06-16 04:17:26 +02:00
|
|
|
static void process(T0 & ren, T1 const& sym, T2 & f, T3 const& tr)
|
2012-03-21 10:29:37 +01:00
|
|
|
{
|
|
|
|
ren.process(sym,f,tr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> // No-op specialization
|
|
|
|
struct process_impl<false>
|
|
|
|
{
|
|
|
|
template <typename T0, typename T1, typename T2, typename T3>
|
2012-06-16 04:17:26 +02:00
|
|
|
static void process(T0 & ren, T1 const& sym, T2 & f, T3 const& tr)
|
2012-03-21 10:29:37 +01:00
|
|
|
{
|
|
|
|
boost::ignore_unused_variable_warning(ren);
|
|
|
|
boost::ignore_unused_variable_warning(f);
|
|
|
|
boost::ignore_unused_variable_warning(tr);
|
|
|
|
#ifdef MAPNIK_DEBUG
|
|
|
|
std::clog << "NO-OP ...\n";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
/** Calls the renderer's process function,
|
2012-01-10 22:32:51 +01:00
|
|
|
* \param output Renderer
|
|
|
|
* \param f Feature to process
|
|
|
|
* \param prj_trans Projection
|
|
|
|
* \param sym Symbolizer object
|
|
|
|
*/
|
2011-09-01 02:44:27 +02:00
|
|
|
template <typename Processor>
|
|
|
|
struct feature_style_processor<Processor>::symbol_dispatch : public boost::static_visitor<>
|
|
|
|
{
|
|
|
|
symbol_dispatch (Processor & output,
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl & f,
|
2011-09-01 02:44:27 +02:00
|
|
|
proj_transform const& prj_trans)
|
|
|
|
: output_(output),
|
|
|
|
f_(f),
|
|
|
|
prj_trans_(prj_trans) {}
|
2012-08-01 12:07:45 +02:00
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
template <typename T>
|
|
|
|
void operator () (T const& sym) const
|
|
|
|
{
|
2012-03-21 10:29:37 +01:00
|
|
|
process_impl<has_process<Processor,T>::value>::process(output_,sym,f_,prj_trans_);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
2012-08-01 12:07:45 +02:00
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
Processor & output_;
|
2012-06-16 04:17:26 +02:00
|
|
|
mapnik::feature_impl & f_;
|
2011-09-01 02:44:27 +02:00
|
|
|
proj_transform const& prj_trans_;
|
|
|
|
};
|
|
|
|
|
2012-08-01 12:07:45 +02:00
|
|
|
typedef char (&no_tag)[1];
|
|
|
|
typedef char (&yes_tag)[2];
|
2012-03-21 10:29:37 +01:00
|
|
|
|
2012-06-16 04:17:26 +02:00
|
|
|
template <typename T0, typename T1, void (T0::*)(T1 const&, mapnik::feature_impl &, proj_transform const&) >
|
2012-08-01 12:07:45 +02:00
|
|
|
struct process_memfun_helper {};
|
|
|
|
|
|
|
|
template <typename T0, typename T1> no_tag has_process_helper(...);
|
2012-03-21 10:29:37 +01:00
|
|
|
template <typename T0, typename T1> yes_tag has_process_helper(process_memfun_helper<T0, T1, &T0::process>* p);
|
2012-08-01 12:07:45 +02:00
|
|
|
|
|
|
|
template<typename T0,typename T1>
|
2012-03-21 10:29:37 +01:00
|
|
|
struct has_process
|
2012-08-01 12:07:45 +02:00
|
|
|
{
|
2012-05-03 13:19:26 +02:00
|
|
|
typedef typename T0::processor_impl_type processor_impl_type;
|
2012-08-01 12:07:45 +02:00
|
|
|
BOOST_STATIC_CONSTANT(bool
|
|
|
|
, value = sizeof(has_process_helper<processor_impl_type,T1>(0)) == sizeof(yes_tag)
|
|
|
|
);
|
|
|
|
};
|
2012-03-21 10:29:37 +01:00
|
|
|
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
template <typename Processor>
|
|
|
|
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
|
|
|
|
: m_(m), scale_factor_(scale_factor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Processor>
|
|
|
|
void feature_style_processor<Processor>::apply()
|
|
|
|
{
|
2011-09-01 07:14:25 +02:00
|
|
|
#if defined(RENDERING_STATS)
|
|
|
|
std::clog << "\n//-- starting rendering timer...\n";
|
|
|
|
mapnik::progress_timer t(std::clog, "total map rendering");
|
|
|
|
#endif
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
Processor & p = static_cast<Processor&>(*this);
|
|
|
|
p.start_map_processing(m_);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
projection proj(m_.srs());
|
|
|
|
|
|
|
|
start_metawriters(m_,proj);
|
|
|
|
|
|
|
|
double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic());
|
|
|
|
scale_denom *= scale_factor_;
|
2011-09-01 06:49:59 +02:00
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
BOOST_FOREACH ( layer const& lyr, m_.layers() )
|
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
if (lyr.visible(scale_denom))
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
|
|
|
std::set<std::string> names;
|
|
|
|
apply_to_layer(lyr, p, proj, scale_denom, names);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_metawriters(m_);
|
|
|
|
}
|
|
|
|
catch (proj_init_error& ex)
|
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: proj_init_error=" << ex.what();
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
p.end_map_processing(m_);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-09-01 07:14:25 +02:00
|
|
|
#if defined(RENDERING_STATS)
|
|
|
|
t.stop();
|
|
|
|
std::clog << "//-- rendering timer stopped...\n\n";
|
|
|
|
#endif
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Processor>
|
|
|
|
void feature_style_processor<Processor>::apply(mapnik::layer const& lyr, std::set<std::string>& names)
|
|
|
|
{
|
|
|
|
Processor & p = static_cast<Processor&>(*this);
|
|
|
|
p.start_map_processing(m_);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
projection proj(m_.srs());
|
|
|
|
double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic());
|
|
|
|
scale_denom *= scale_factor_;
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
if (lyr.visible(scale_denom))
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
|
|
|
apply_to_layer(lyr, p, proj, scale_denom, names);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (proj_init_error& ex)
|
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_ERROR(feature_style_processor) << "feature_style_processor: proj_init_error=" << ex.what();
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
p.end_map_processing(m_);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Processor>
|
|
|
|
void feature_style_processor<Processor>::start_metawriters(Map const& m_, projection const& proj)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Processor>
|
|
|
|
void feature_style_processor<Processor>::stop_metawriters(Map const& m_)
|
|
|
|
{
|
|
|
|
Map::const_metawriter_iterator metaItr = m_.begin_metawriters();
|
|
|
|
Map::const_metawriter_iterator metaItrEnd = m_.end_metawriters();
|
|
|
|
for (;metaItr!=metaItrEnd; ++metaItr)
|
|
|
|
{
|
|
|
|
metaItr->second->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Processor>
|
|
|
|
void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Processor & p,
|
2012-01-10 22:32:51 +01:00
|
|
|
projection const& proj0,
|
|
|
|
double scale_denom,
|
|
|
|
std::set<std::string>& names)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
|
|
|
std::vector<std::string> const& style_names = lay.styles();
|
|
|
|
|
|
|
|
unsigned int num_styles = style_names.size();
|
2012-04-08 02:20:56 +02:00
|
|
|
if (! num_styles)
|
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No style for layer=" << lay.name();
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
return;
|
2011-09-01 07:14:25 +02:00
|
|
|
}
|
2011-09-01 02:44:27 +02:00
|
|
|
|
|
|
|
mapnik::datasource_ptr ds = lay.datasource();
|
2012-04-08 02:20:56 +02:00
|
|
|
if (! ds)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(feature_style_processor) << "feature_style_processor: No datasource for layer=" << lay.name();
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-01 07:14:25 +02:00
|
|
|
#if defined(RENDERING_STATS)
|
|
|
|
progress_timer layer_timer(std::clog, "rendering total for layer: '" + lay.name() + "'");
|
|
|
|
#endif
|
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
projection proj1(lay.srs());
|
|
|
|
proj_transform prj_trans(proj0,proj1);
|
|
|
|
|
2011-09-01 07:14:25 +02:00
|
|
|
#if defined(RENDERING_STATS)
|
2012-04-09 21:41:56 +02:00
|
|
|
if (! prj_trans.equal())
|
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
std::clog << "notice: reprojecting layer: '" << lay.name() << "' from/to:\n\t'"
|
2012-01-10 22:32:51 +01:00
|
|
|
<< lay.srs() << "'\n\t'"
|
|
|
|
<< m_.srs() << "'\n";
|
2012-04-09 21:41:56 +02:00
|
|
|
}
|
2011-09-01 07:14:25 +02:00
|
|
|
#endif
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2012-04-04 21:43:32 +02:00
|
|
|
box2d<double> buffered_query_ext = m_.get_buffered_extent(); // buffered
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
// clip buffered extent by maximum extent, if supplied
|
|
|
|
boost::optional<box2d<double> > const& maximum_extent = m_.maximum_extent();
|
|
|
|
if (maximum_extent) {
|
2012-04-04 21:43:32 +02:00
|
|
|
buffered_query_ext.clip(*maximum_extent);
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
box2d<double> layer_ext = lay.envelope();
|
2012-04-04 21:43:32 +02:00
|
|
|
bool fw_success = false;
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
// first, try intersection of map extent forward projected into layer srs
|
2012-04-04 21:43:32 +02:00
|
|
|
if (prj_trans.forward(buffered_query_ext, PROJ_ENVELOPE_POINTS) && buffered_query_ext.intersects(layer_ext))
|
2011-09-15 00:58:08 +02:00
|
|
|
{
|
2012-04-04 21:43:32 +02:00
|
|
|
fw_success = true;
|
|
|
|
layer_ext.clip(buffered_query_ext);
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
// if no intersection and projections are also equal, early return
|
|
|
|
else if (prj_trans.equal())
|
|
|
|
{
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-09-12 19:54:39 +02:00
|
|
|
layer_timer.discard();
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-09-01 06:49:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// next try intersection of layer extent back projected into map srs
|
2012-04-04 21:43:32 +02:00
|
|
|
else if (prj_trans.backward(layer_ext, PROJ_ENVELOPE_POINTS) && buffered_query_ext.intersects(layer_ext))
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2012-04-04 21:43:32 +02:00
|
|
|
layer_ext.clip(buffered_query_ext);
|
2011-09-01 06:49:59 +02:00
|
|
|
// forward project layer extent back into native projection
|
2012-04-09 21:41:56 +02:00
|
|
|
if (! prj_trans.forward(layer_ext, PROJ_ENVELOPE_POINTS))
|
2012-03-23 00:35:33 +01:00
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(feature_style_processor)
|
|
|
|
<< "feature_style_processor: Layer=" << lay.name()
|
|
|
|
<< " extent=" << layer_ext << " in map projection "
|
|
|
|
<< " did not reproject properly back to layer projection";
|
2012-03-23 00:35:33 +01:00
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if no intersection then nothing to do for layer
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-09-01 07:14:25 +02:00
|
|
|
layer_timer.discard();
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-09-01 06:49:59 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-04-04 21:43:32 +02:00
|
|
|
// if we've got this far, now prepare the unbuffered extent
|
|
|
|
// which is used as a bbox for clipping geometries
|
|
|
|
box2d<double> query_ext = m_.get_current_extent(); // unbuffered
|
|
|
|
if (maximum_extent) {
|
|
|
|
query_ext.clip(*maximum_extent);
|
|
|
|
}
|
|
|
|
box2d<double> layer_ext2 = lay.envelope();
|
|
|
|
if (fw_success)
|
|
|
|
{
|
|
|
|
if (prj_trans.forward(query_ext, PROJ_ENVELOPE_POINTS))
|
|
|
|
{
|
|
|
|
layer_ext2.clip(query_ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prj_trans.backward(layer_ext2, PROJ_ENVELOPE_POINTS))
|
|
|
|
{
|
|
|
|
layer_ext2.clip(query_ext);
|
|
|
|
prj_trans.forward(layer_ext2, PROJ_ENVELOPE_POINTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.start_layer_processing(lay, layer_ext2);
|
|
|
|
|
2012-03-09 02:02:58 +01:00
|
|
|
double qw = query_ext.width()>0 ? query_ext.width() : 1;
|
|
|
|
double qh = query_ext.height()>0 ? query_ext.height() : 1;
|
|
|
|
query::resolution_type res(m_.width()/qw,
|
|
|
|
m_.height()/qh);
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2012-03-23 00:35:33 +01:00
|
|
|
query q(layer_ext,res,scale_denom,m_.get_current_extent());
|
2011-09-01 06:49:59 +02:00
|
|
|
std::vector<feature_type_style*> active_styles;
|
|
|
|
attribute_collector collector(names);
|
2012-08-01 12:07:45 +02:00
|
|
|
double filt_factor = 1.0;
|
|
|
|
directive_collector d_collector(filt_factor);
|
2011-09-01 06:49:59 +02:00
|
|
|
|
|
|
|
// iterate through all named styles collecting active styles and attribute names
|
|
|
|
BOOST_FOREACH(std::string const& style_name, style_names)
|
|
|
|
{
|
|
|
|
boost::optional<feature_type_style const&> style=m_.find_style(style_name);
|
|
|
|
if (!style)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(feature_style_processor)
|
|
|
|
<< "feature_style_processor: Style=" << style_name
|
|
|
|
<< " required for layer=" << lay.name() << " does not exist.";
|
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
continue;
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
const std::vector<rule>& rules=(*style).get_rules();
|
|
|
|
bool active_rules=false;
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-09-01 06:49:59 +02:00
|
|
|
BOOST_FOREACH(rule const& r, rules)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-09-01 06:49:59 +02:00
|
|
|
if (r.active(scale_denom))
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-09-01 06:49:59 +02:00
|
|
|
active_rules = true;
|
|
|
|
if (ds->type() == datasource::Vector)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-09-01 06:49:59 +02:00
|
|
|
collector(r);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
// TODO - in the future rasters should be able to be filtered.
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
if (active_rules)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-09-01 06:49:59 +02:00
|
|
|
active_styles.push_back(const_cast<feature_type_style*>(&(*style)));
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
// Don't even try to do more work if there are no active styles.
|
|
|
|
if (active_styles.size() > 0)
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
// push all property names
|
|
|
|
BOOST_FOREACH(std::string const& name, names)
|
|
|
|
{
|
|
|
|
q.add_property_name(name);
|
|
|
|
}
|
2011-09-01 07:14:25 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
// Update filter_factor for all enabled raster layers.
|
|
|
|
BOOST_FOREACH (feature_type_style * style, active_styles)
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
BOOST_FOREACH(rule const& r, style->get_rules())
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
if (r.active(scale_denom) &&
|
|
|
|
ds->type() == datasource::Raster &&
|
|
|
|
ds->params().get<double>("filter_factor",0.0) == 0.0)
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
|
|
|
rule::symbolizers const& symbols = r.get_symbolizers();
|
|
|
|
rule::symbolizers::const_iterator symIter = symbols.begin();
|
|
|
|
rule::symbolizers::const_iterator symEnd = symbols.end();
|
|
|
|
while (symIter != symEnd)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-09-01 06:49:59 +02:00
|
|
|
// if multiple raster symbolizers, last will be respected
|
|
|
|
// should we warn or throw?
|
|
|
|
boost::apply_visitor(d_collector,*symIter++);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
q.set_filter_factor(filt_factor);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
// Also query the group by attribute
|
|
|
|
std::string group_by = lay.group_by();
|
|
|
|
if (group_by != "")
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
q.add_property_name(group_by);
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
2011-10-13 01:30:18 +02:00
|
|
|
|
|
|
|
bool cache_features = lay.cache_features() && active_styles.size() > 1;
|
|
|
|
|
|
|
|
// Render incrementally when the column that we group by
|
|
|
|
// changes value.
|
|
|
|
if (group_by != "")
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
featureset_ptr features = ds->features(q);
|
|
|
|
if (features) {
|
|
|
|
// Cache all features into the memory_datasource before rendering.
|
|
|
|
memory_datasource cache;
|
|
|
|
feature_ptr feature, prev;
|
|
|
|
|
|
|
|
while ((feature = features->next()))
|
|
|
|
{
|
2012-01-12 10:33:43 +01:00
|
|
|
if (prev && prev->get(group_by) != feature->get(group_by))
|
2011-10-13 01:30:18 +02:00
|
|
|
{
|
|
|
|
// We're at a value boundary, so render what we have
|
|
|
|
// up to this point.
|
|
|
|
int i = 0;
|
|
|
|
BOOST_FOREACH (feature_type_style * style, active_styles)
|
|
|
|
{
|
|
|
|
render_style(lay, p, style, style_names[i++],
|
2012-01-10 22:32:51 +01:00
|
|
|
cache.features(q), prj_trans, scale_denom);
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
cache.clear();
|
|
|
|
}
|
|
|
|
cache.push(feature);
|
|
|
|
prev = feature;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
BOOST_FOREACH (feature_type_style * style, active_styles)
|
|
|
|
{
|
|
|
|
render_style(lay, p, style, style_names[i++],
|
2012-01-10 22:32:51 +01:00
|
|
|
cache.features(q), prj_trans, scale_denom);
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
2011-10-13 01:30:18 +02:00
|
|
|
else if (cache_features)
|
|
|
|
{
|
|
|
|
featureset_ptr features = ds->features(q);
|
|
|
|
if (features) {
|
|
|
|
// Cache all features into the memory_datasource before rendering.
|
|
|
|
memory_datasource cache;
|
|
|
|
feature_ptr feature;
|
|
|
|
while ((feature = features->next()))
|
|
|
|
{
|
|
|
|
cache.push(feature);
|
|
|
|
}
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
int i = 0;
|
|
|
|
BOOST_FOREACH (feature_type_style * style, active_styles)
|
|
|
|
{
|
|
|
|
render_style(lay, p, style, style_names[i++],
|
2012-01-10 22:32:51 +01:00
|
|
|
cache.features(q), prj_trans, scale_denom);
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We only have a single style and no grouping.
|
|
|
|
else
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
int i = 0;
|
|
|
|
BOOST_FOREACH (feature_type_style * style, active_styles)
|
2011-09-01 02:44:27 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
featureset_ptr features = ds->features(q);
|
|
|
|
if (features) {
|
|
|
|
render_style(lay, p, style, style_names[i++],
|
2012-01-10 22:32:51 +01:00
|
|
|
features, prj_trans, scale_denom);
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
|
|
|
layer_timer.stop();
|
|
|
|
#endif
|
2011-10-13 01:30:18 +02:00
|
|
|
|
|
|
|
p.end_layer_processing(lay);
|
|
|
|
}
|
|
|
|
|
2011-09-01 07:14:25 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
template <typename Processor>
|
|
|
|
void feature_style_processor<Processor>::render_style(
|
2012-01-10 22:32:51 +01:00
|
|
|
layer const& lay,
|
|
|
|
Processor & p,
|
|
|
|
feature_type_style* style,
|
|
|
|
std::string const& style_name,
|
|
|
|
featureset_ptr features,
|
|
|
|
proj_transform const& prj_trans,
|
|
|
|
double scale_denom)
|
2011-10-13 01:30:18 +02:00
|
|
|
{
|
2012-04-03 14:09:08 +02:00
|
|
|
|
|
|
|
p.start_style_processing(*style);
|
2012-08-01 12:07:45 +02:00
|
|
|
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
std::ostringstream s1;
|
|
|
|
s1 << "rendering style for layer: '" << lay.name()
|
|
|
|
<< "' and style '" << style_name << "'";
|
|
|
|
mapnik::progress_timer style_timer(std::clog, s1.str());
|
|
|
|
|
|
|
|
int feature_processed_count = 0;
|
|
|
|
int feature_count = 0;
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-10-13 01:30:18 +02:00
|
|
|
|
|
|
|
feature_ptr feature;
|
|
|
|
while ((feature = features->next()))
|
|
|
|
{
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
feature_count++;
|
|
|
|
bool feat_processed = false;
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-10-13 01:30:18 +02:00
|
|
|
|
|
|
|
bool do_else = true;
|
|
|
|
bool do_also = false;
|
|
|
|
|
|
|
|
BOOST_FOREACH(rule * r, style->get_if_rules(scale_denom) )
|
|
|
|
{
|
|
|
|
expression_ptr const& expr=r->get_filter();
|
|
|
|
value_type result = boost::apply_visitor(evaluate<Feature,value_type>(*feature),*expr);
|
|
|
|
if (result.to_bool())
|
|
|
|
{
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
feat_processed = true;
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-09-01 07:14:25 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
p.painted(true);
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
do_else=false;
|
|
|
|
do_also=true;
|
|
|
|
rule::symbolizers const& symbols = r->get_symbolizers();
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
// if the underlying renderer is not able to process the complete set of symbolizers,
|
|
|
|
// process one by one.
|
2012-06-16 04:17:26 +02:00
|
|
|
if(!p.process(symbols,*feature,prj_trans))
|
2011-10-13 01:30:18 +02:00
|
|
|
{
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
BOOST_FOREACH (symbolizer const& sym, symbols)
|
|
|
|
{
|
2012-06-16 04:17:26 +02:00
|
|
|
boost::apply_visitor(symbol_dispatch(p,*feature,prj_trans),sym);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
2011-09-01 06:49:59 +02:00
|
|
|
}
|
2011-10-13 01:30:18 +02:00
|
|
|
if (style->get_filter_mode() == FILTER_FIRST)
|
2011-09-01 06:49:59 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
// Stop iterating over rules and proceed with next feature.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (do_else)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( rule * r, style->get_else_rules(scale_denom) )
|
|
|
|
{
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
feat_processed = true;
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-10-13 01:30:18 +02:00
|
|
|
|
|
|
|
p.painted(true);
|
|
|
|
|
|
|
|
rule::symbolizers const& symbols = r->get_symbolizers();
|
|
|
|
// if the underlying renderer is not able to process the complete set of symbolizers,
|
|
|
|
// process one by one.
|
2012-06-16 04:17:26 +02:00
|
|
|
if(!p.process(symbols,*feature,prj_trans))
|
2011-09-02 15:10:14 +02:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
BOOST_FOREACH (symbolizer const& sym, symbols)
|
2011-09-02 15:10:14 +02:00
|
|
|
{
|
2012-06-16 04:17:26 +02:00
|
|
|
boost::apply_visitor(symbol_dispatch(p,*feature,prj_trans),sym);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (do_also)
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( rule * r, style->get_also_rules(scale_denom) )
|
|
|
|
{
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
feat_processed = true;
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-09-01 07:14:25 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
p.painted(true);
|
2011-09-01 07:14:25 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
rule::symbolizers const& symbols = r->get_symbolizers();
|
|
|
|
// if the underlying renderer is not able to process the complete set of symbolizers,
|
|
|
|
// process one by one.
|
2012-06-16 04:17:26 +02:00
|
|
|
if(!p.process(symbols,*feature,prj_trans))
|
2011-10-13 01:30:18 +02:00
|
|
|
{
|
|
|
|
BOOST_FOREACH (symbolizer const& sym, symbols)
|
|
|
|
{
|
2012-06-16 04:17:26 +02:00
|
|
|
boost::apply_visitor(symbol_dispatch(p,*feature,prj_trans),sym);
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-01 07:14:25 +02:00
|
|
|
}
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
if (feat_processed)
|
|
|
|
feature_processed_count++;
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
2011-10-13 01:30:18 +02:00
|
|
|
|
2012-01-10 22:32:51 +01:00
|
|
|
#if defined(RENDERING_STATS)
|
2011-10-13 01:30:18 +02:00
|
|
|
style_timer.stop();
|
2011-09-15 00:58:08 +02:00
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
// done with style
|
|
|
|
std::ostringstream s;
|
2012-02-02 02:53:35 +01:00
|
|
|
if (feature_count > 0)
|
2012-01-10 22:32:51 +01:00
|
|
|
{
|
2011-10-13 01:30:18 +02:00
|
|
|
double perc_processed = ((double)feature_processed_count/(double)feature_count)*100.0;
|
2011-09-01 02:44:27 +02:00
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
s << "percent rendered: " << perc_processed << "% - " << feature_processed_count
|
2011-10-13 01:30:18 +02:00
|
|
|
<< " rendered for " << feature_count << " queried for ";
|
2012-01-10 22:32:51 +01:00
|
|
|
s << std::setw(15 - (int)s.tellp()) << " layer '" << lay.name() << "' and style '" << style_name << "'\n";
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
|
|
|
else
|
2012-01-10 22:32:51 +01:00
|
|
|
{
|
|
|
|
s << "" << std::setw(15) << "- no features returned from query for layer '" << lay.name() << "' and style '" << style_name << "'\n";
|
2011-10-13 01:30:18 +02:00
|
|
|
}
|
|
|
|
std::clog << s.str();
|
|
|
|
style_timer.discard();
|
2012-01-10 22:32:51 +01:00
|
|
|
#endif
|
2012-04-03 14:09:08 +02:00
|
|
|
p.end_style_processing(*style);
|
2011-09-01 02:44:27 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 01:30:18 +02:00
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
#if defined(HAVE_CAIRO)
|
|
|
|
template class feature_style_processor<cairo_renderer<Cairo::Context> >;
|
|
|
|
template class feature_style_processor<cairo_renderer<Cairo::Surface> >;
|
|
|
|
#endif
|
|
|
|
|
2011-09-16 18:18:10 +02:00
|
|
|
#if defined(SVG_RENDERER)
|
|
|
|
template class feature_style_processor<svg_renderer<std::ostream_iterator<char> > >;
|
|
|
|
#endif
|
|
|
|
|
2011-09-01 02:44:27 +02:00
|
|
|
template class feature_style_processor<grid_renderer<grid> >;
|
|
|
|
template class feature_style_processor<agg_renderer<image_32> >;
|
|
|
|
|
|
|
|
}
|