fix feature-cache for rasters - TODO: no intersection check option for memory_featureset

This commit is contained in:
Dane Springmeyer 2012-10-26 18:18:35 -07:00
parent f7bd53c0d3
commit 9040d2ac9d
4 changed files with 23 additions and 16 deletions

View file

@ -458,7 +458,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
} }
else if (cache_features) else if (cache_features)
{ {
memory_datasource cache; memory_datasource cache(ds->type());
featureset_ptr features = ds->features(q); featureset_ptr features = ds->features(q);
if (features) { if (features) {
// Cache all features into the memory_datasource before rendering. // Cache all features into the memory_datasource before rendering.

View file

@ -36,7 +36,7 @@ class MAPNIK_DECL memory_datasource : public datasource
{ {
friend class memory_featureset; friend class memory_featureset;
public: public:
memory_datasource(); memory_datasource(datasource::datasource_t type=datasource::Vector);
virtual ~memory_datasource(); virtual ~memory_datasource();
void push(feature_ptr feature); void push(feature_ptr feature);
datasource::datasource_t type() const; datasource::datasource_t type() const;
@ -50,6 +50,7 @@ public:
private: private:
std::vector<feature_ptr> features_; std::vector<feature_ptr> features_;
mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
datasource::datasource_t type_;
}; };
} }

View file

@ -24,7 +24,6 @@
#define MAPNIK_MEMORY_FEATURESET_HPP #define MAPNIK_MEMORY_FEATURESET_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/memory_datasource.hpp> #include <mapnik/memory_datasource.hpp>
// boost // boost
@ -38,13 +37,15 @@ public:
memory_featureset(box2d<double> const& bbox, memory_datasource const& ds) memory_featureset(box2d<double> const& bbox, memory_datasource const& ds)
: bbox_(bbox), : bbox_(bbox),
pos_(ds.features_.begin()), pos_(ds.features_.begin()),
end_(ds.features_.end()) end_(ds.features_.end()),
type_(ds.type())
{} {}
memory_featureset(box2d<double> const& bbox, std::vector<feature_ptr> const& features) memory_featureset(box2d<double> const& bbox, std::vector<feature_ptr> const& features)
: bbox_(bbox), : bbox_(bbox),
pos_(features.begin()), pos_(features.begin()),
end_(features.end()) end_(features.end()),
type_(datasource::Vector)
{} {}
virtual ~memory_featureset() {} virtual ~memory_featureset() {}
@ -53,20 +54,23 @@ public:
{ {
while (pos_ != end_) while (pos_ != end_)
{ {
for (unsigned i=0; i<(*pos_)->num_geometries();++i) if (type_ == datasource::Raster)
{ {
geometry_type & geom = (*pos_)->get_geometry(i); return *pos_++;
}
MAPNIK_LOG_DEBUG(memory_featureset) << "memory_featureset: BBox=" << bbox_ << ",Envelope=" << geom.envelope(); else
{
if (bbox_.intersects(geom.envelope())) for (unsigned i=0; i<(*pos_)->num_geometries();++i)
{ {
return *pos_++; geometry_type & geom = (*pos_)->get_geometry(i);
if (bbox_.intersects(geom.envelope()))
{
return *pos_++;
}
} }
} }
++pos_; ++pos_;
} }
return feature_ptr(); return feature_ptr();
} }
@ -74,6 +78,7 @@ private:
box2d<double> bbox_; box2d<double> bbox_;
std::vector<feature_ptr>::const_iterator pos_; std::vector<feature_ptr>::const_iterator pos_;
std::vector<feature_ptr>::const_iterator end_; std::vector<feature_ptr>::const_iterator end_;
datasource::datasource_t type_;
}; };
} }

View file

@ -62,9 +62,10 @@ struct accumulate_extent
bool first_; bool first_;
}; };
memory_datasource::memory_datasource() memory_datasource::memory_datasource(datasource::datasource_t type)
: datasource(parameters()), : datasource(parameters()),
desc_("in-memory datasource","utf-8") {} desc_("in-memory datasource","utf-8"),
type_(type) {}
memory_datasource::~memory_datasource() {} memory_datasource::~memory_datasource() {}
@ -77,7 +78,7 @@ void memory_datasource::push(feature_ptr feature)
datasource::datasource_t memory_datasource::type() const datasource::datasource_t memory_datasource::type() const
{ {
return datasource::Vector; return type_;
} }
featureset_ptr memory_datasource::features(const query& q) const featureset_ptr memory_datasource::features(const query& q) const