collect context before featureset creation in sqlite
This commit is contained in:
parent
62cf7cb2fe
commit
aa6da2dce9
3 changed files with 21 additions and 10 deletions
|
@ -547,19 +547,24 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
||||||
mapnik::box2d<double> const& e = q.get_bbox();
|
mapnik::box2d<double> const& e = q.get_bbox();
|
||||||
|
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
||||||
|
|
||||||
s << "SELECT " << geometry_field_;
|
s << "SELECT " << geometry_field_;
|
||||||
if (!key_field_.empty())
|
if (!key_field_.empty())
|
||||||
|
{
|
||||||
s << "," << key_field_;
|
s << "," << key_field_;
|
||||||
|
ctx->push(key_field_);
|
||||||
|
}
|
||||||
std::set<std::string> const& props = q.property_names();
|
std::set<std::string> const& props = q.property_names();
|
||||||
std::set<std::string>::const_iterator pos = props.begin();
|
std::set<std::string>::const_iterator pos = props.begin();
|
||||||
std::set<std::string>::const_iterator end = props.end();
|
std::set<std::string>::const_iterator end = props.end();
|
||||||
while (pos != end)
|
|
||||||
|
for ( ;pos != end;++pos)
|
||||||
{
|
{
|
||||||
// TODO - should we restrict duplicate key query?
|
// TODO - should we restrict duplicate key query?
|
||||||
//if (*pos != key_field_)
|
//if (*pos != key_field_)
|
||||||
s << ",[" << *pos << "]";
|
s << ",[" << *pos << "]";
|
||||||
++pos;
|
ctx->push(*pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
s << " FROM ";
|
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()));
|
boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str()));
|
||||||
|
|
||||||
return boost::make_shared<sqlite_featureset>(rs,
|
return boost::make_shared<sqlite_featureset>(rs,
|
||||||
|
ctx,
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
format_,
|
format_,
|
||||||
using_subquery_);
|
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);
|
mapnik::box2d<double> const e(pt.x, pt.y, pt.x, pt.y);
|
||||||
|
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
||||||
|
|
||||||
s << "SELECT " << geometry_field_;
|
s << "SELECT " << geometry_field_;
|
||||||
if (!key_field_.empty())
|
if (!key_field_.empty())
|
||||||
|
{
|
||||||
s << "," << key_field_;
|
s << "," << key_field_;
|
||||||
|
ctx->push(key_field_);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
|
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
|
||||||
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
|
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();
|
std::string fld_name = itr->get_name();
|
||||||
if (fld_name != key_field_)
|
if (fld_name != key_field_)
|
||||||
{
|
{
|
||||||
s << ",[" << itr->get_name() << "]";
|
s << ",[" << itr->get_name() << "]";
|
||||||
|
ctx->push(itr->get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
++itr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s << " FROM ";
|
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()));
|
boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str()));
|
||||||
|
|
||||||
return boost::make_shared<sqlite_featureset>(rs,
|
return boost::make_shared<sqlite_featureset>(rs,
|
||||||
|
ctx,
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
format_,
|
format_,
|
||||||
using_subquery_);
|
using_subquery_);
|
||||||
|
|
|
@ -45,6 +45,7 @@ using mapnik::transcoder;
|
||||||
using mapnik::feature_factory;
|
using mapnik::feature_factory;
|
||||||
|
|
||||||
sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
|
sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
|
||||||
|
mapnik::context_ptr const& ctx,
|
||||||
std::string const& encoding,
|
std::string const& encoding,
|
||||||
mapnik::wkbFormat format,
|
mapnik::wkbFormat format,
|
||||||
bool using_subquery)
|
bool using_subquery)
|
||||||
|
@ -52,12 +53,8 @@ sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
|
||||||
tr_(new transcoder(encoding)),
|
tr_(new transcoder(encoding)),
|
||||||
format_(format),
|
format_(format),
|
||||||
using_subquery_(using_subquery),
|
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()
|
sqlite_featureset::~sqlite_featureset()
|
||||||
|
|
|
@ -40,6 +40,7 @@ class sqlite_featureset : public mapnik::Featureset
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
|
sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
|
||||||
|
mapnik::context_ptr const& ctx,
|
||||||
std::string const& encoding,
|
std::string const& encoding,
|
||||||
mapnik::wkbFormat format,
|
mapnik::wkbFormat format,
|
||||||
bool using_subquery);
|
bool using_subquery);
|
||||||
|
|
Loading…
Reference in a new issue