collect context before featureset creation in sqlite

This commit is contained in:
Dane Springmeyer 2012-01-23 23:51:31 -08:00
parent 62cf7cb2fe
commit aa6da2dce9
3 changed files with 21 additions and 10 deletions

View file

@ -547,19 +547,24 @@ featureset_ptr sqlite_datasource::features(query const& q) const
mapnik::box2d<double> const& e = q.get_bbox();
std::ostringstream s;
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
s << "SELECT " << geometry_field_;
if (!key_field_.empty())
{
s << "," << key_field_;
ctx->push(key_field_);
}
std::set<std::string> const& props = q.property_names();
std::set<std::string>::const_iterator pos = props.begin();
std::set<std::string>::const_iterator end = props.end();
while (pos != end)
for ( ;pos != end;++pos)
{
// TODO - should we restrict duplicate key query?
//if (*pos != key_field_)
s << ",[" << *pos << "]";
++pos;
ctx->push(*pos);
}
s << " FROM ";
@ -601,6 +606,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const
boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str()));
return boost::make_shared<sqlite_featureset>(rs,
ctx,
desc_.get_encoding(),
format_,
using_subquery_);
@ -619,20 +625,26 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
mapnik::box2d<double> const e(pt.x, pt.y, pt.x, pt.y);
std::ostringstream s;
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
s << "SELECT " << geometry_field_;
if (!key_field_.empty())
{
s << "," << key_field_;
ctx->push(key_field_);
}
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
while (itr != end)
for ( ; itr != end; ++itr)
{
std::string fld_name = itr->get_name();
if (fld_name != key_field_)
{
s << ",[" << itr->get_name() << "]";
ctx->push(itr->get_name());
}
++itr;
}
s << " FROM ";
@ -674,6 +686,7 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str()));
return boost::make_shared<sqlite_featureset>(rs,
ctx,
desc_.get_encoding(),
format_,
using_subquery_);

View file

@ -45,6 +45,7 @@ using mapnik::transcoder;
using mapnik::feature_factory;
sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
mapnik::context_ptr const& ctx,
std::string const& encoding,
mapnik::wkbFormat format,
bool using_subquery)
@ -52,12 +53,8 @@ sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
tr_(new transcoder(encoding)),
format_(format),
using_subquery_(using_subquery),
ctx_(boost::make_shared<mapnik::context_type>())
ctx_(ctx)
{
for (int i = 2; i < rs_->column_count(); ++i)
{
ctx_->push(rs_->column_name(i));
}
}
sqlite_featureset::~sqlite_featureset()

View file

@ -40,6 +40,7 @@ class sqlite_featureset : public mapnik::Featureset
{
public:
sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
mapnik::context_ptr const& ctx,
std::string const& encoding,
mapnik::wkbFormat format,
bool using_subquery);