Stub out statistics on common datasources

This commit is contained in:
Tom MacWright 2012-01-30 17:37:36 -05:00
parent 441c13646c
commit 96b3281bd6
10 changed files with 38 additions and 0 deletions

View file

@ -33,6 +33,8 @@
#include <boost/accumulators/statistics/min.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/framework/accumulator_set.hpp>
// stl
@ -43,6 +45,8 @@ namespace mapnik {
typedef boost::accumulators::accumulator_set<
double, boost::accumulators::features<
boost::accumulators::tag::mean,
boost::accumulators::tag::median,
boost::accumulators::tag::variance,
boost::accumulators::tag::min,
boost::accumulators::tag::max
> > statistics_accumulator;

View file

@ -428,6 +428,12 @@ layer_descriptor ogr_datasource::get_descriptor() const
return desc_;
}
std::map<std::string, mapnik::parameters> ogr_datasource::get_statistics() const
{
if (! is_bound_) bind();
return stats_;
}
featureset_ptr ogr_datasource::features(query const& q) const
{
if (! is_bound_) bind();

View file

@ -48,6 +48,7 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
std::map<std::string, mapnik::parameters> get_statistics() const;
void bind() const;
private:
@ -59,6 +60,7 @@ private:
mutable ogr_layer_ptr layer_;
mutable std::string layer_name_;
mutable mapnik::layer_descriptor desc_;
mutable std::map<std::string, mapnik::parameters> stats_;
mutable bool indexed_;
};

View file

@ -358,6 +358,12 @@ layer_descriptor postgis_datasource::get_descriptor() const
}
std::map<std::string, mapnik::parameters> postgis_datasource::get_statistics() const
{
if (! is_bound_) bind();
return stats_;
}
std::string postgis_datasource::sql_bbox(box2d<double> const& env) const
{
std::ostringstream b;

View file

@ -85,11 +85,13 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const;
std::map<std::string, mapnik::parameters> get_statistics() const;
postgis_datasource(const parameters &params, bool bind=true);
~postgis_datasource();
void bind() const;
private:
std::string sql_bbox(box2d<double> const& env) const;
mutable std::map<std::string, mapnik::parameters> stats_;
std::string populate_tokens(const std::string& sql, double scale_denom, box2d<double> const& env) const;
std::string populate_tokens(const std::string& sql) const;
static std::string unquote(const std::string& sql);

View file

@ -240,6 +240,12 @@ layer_descriptor shape_datasource::get_descriptor() const
return desc_;
}
std::map<std::string, mapnik::parameters> shape_datasource::get_statistics() const
{
if (! is_bound_) bind();
return stats_;
}
featureset_ptr shape_datasource::features(const query& q) const
{
if (!is_bound_) bind();

View file

@ -52,6 +52,7 @@ public:
box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const;
std::map<std::string, mapnik::parameters> get_statistics() const;
void bind() const;
private:
shape_datasource(const shape_datasource&);
@ -62,6 +63,7 @@ private:
std::string shape_name_;
mutable boost::shared_ptr<shape_io> shape_;
mutable shape_io::shapeType shape_type_;
mutable std::map<std::string, mapnik::parameters> stats_;
mutable long file_length_;
mutable box2d<double> extent_;
mutable bool indexed_;

View file

@ -484,6 +484,12 @@ box2d<double> sqlite_datasource::envelope() const
return extent_;
}
std::map<std::string, mapnik::parameters> sqlite_datasource::get_statistics() const
{
if (! is_bound_) bind();
return stats_;
}
boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_type() const
{
if (! is_bound_) bind();

View file

@ -49,6 +49,7 @@ public:
mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const;
std::map<std::string, mapnik::parameters> get_statistics() const;
void bind() const;
private:
@ -79,6 +80,7 @@ private:
mutable bool has_spatial_index_;
mutable bool using_subquery_;
mutable std::vector<std::string> init_statements_;
mutable std::map<std::string, mapnik::parameters> stats_;
// Fill init_statements with any statements
// needed to attach auxillary databases

View file

@ -128,7 +128,9 @@ std::map<std::string, mapnik::parameters> memory_datasource::get_statistics() co
for (; it != end; ++it) {
mapnik::parameters p;
p["mean"] = boost::accumulators::mean(it->second);
p["median"] = boost::accumulators::median(it->second);
p["min"] = boost::accumulators::min(it->second);
p["stddev"] = sqrt(boost::accumulators::variance(it->second));
p["max"] = boost::accumulators::max(it->second);
_stats[it->first] = p;
}