+ fix context init
+ cleanup
This commit is contained in:
parent
748adf8229
commit
e49fcb83b1
5 changed files with 58 additions and 40 deletions
|
@ -38,6 +38,7 @@
|
|||
|
||||
// boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
using mapnik::datasource;
|
||||
using mapnik::parameters;
|
||||
|
@ -439,13 +440,16 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
std::vector<attribute_descriptor>::const_iterator it = desc_ar.begin();
|
||||
std::vector<attribute_descriptor>::const_iterator end = desc_ar.end();
|
||||
std::vector<std::string> known_fields;
|
||||
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
known_fields.push_back(it->get_name());
|
||||
ctx->push(it->get_name());
|
||||
}
|
||||
|
||||
|
||||
const std::set<std::string>& attribute_names = q.property_names();
|
||||
std::set<std::string>::const_iterator pos = attribute_names.begin();
|
||||
|
||||
while (pos != attribute_names.end())
|
||||
{
|
||||
bool found_name = false;
|
||||
|
@ -454,6 +458,7 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
if (known_fields[i] == *pos)
|
||||
{
|
||||
found_name = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +482,8 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
{
|
||||
filter_in_box filter(q.get_bbox());
|
||||
|
||||
return featureset_ptr(new ogr_index_featureset<filter_in_box>(*dataset_,
|
||||
return featureset_ptr(new ogr_index_featureset<filter_in_box>(ctx,
|
||||
*dataset_,
|
||||
*layer,
|
||||
filter,
|
||||
index_name_,
|
||||
|
@ -486,7 +492,8 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
}
|
||||
else
|
||||
{
|
||||
return featureset_ptr(new ogr_featureset (*dataset_,
|
||||
return featureset_ptr(new ogr_featureset (ctx,
|
||||
*dataset_,
|
||||
*layer,
|
||||
q.get_bbox(),
|
||||
desc_.get_encoding()
|
||||
|
@ -503,13 +510,17 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
|||
|
||||
if (dataset_ && layer_.is_valid())
|
||||
{
|
||||
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
|
||||
// TODO : push all attribute names here
|
||||
|
||||
OGRLayer* layer = layer_.layer();
|
||||
|
||||
|
||||
if (indexed_)
|
||||
{
|
||||
filter_at_point filter(pt);
|
||||
|
||||
return featureset_ptr(new ogr_index_featureset<filter_at_point> (*dataset_,
|
||||
|
||||
return featureset_ptr(new ogr_index_featureset<filter_at_point> (ctx,
|
||||
*dataset_,
|
||||
*layer,
|
||||
filter,
|
||||
index_name_,
|
||||
|
@ -522,7 +533,8 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
|||
point.setX (pt.x);
|
||||
point.setY (pt.y);
|
||||
|
||||
return featureset_ptr(new ogr_featureset (*dataset_,
|
||||
return featureset_ptr(new ogr_featureset (ctx,
|
||||
*dataset_,
|
||||
*layer,
|
||||
point,
|
||||
desc_.get_encoding()
|
||||
|
|
|
@ -46,26 +46,30 @@ using mapnik::transcoder;
|
|||
using mapnik::feature_factory;
|
||||
|
||||
|
||||
ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
||||
ogr_featureset::ogr_featureset(mapnik::context_ptr const & ctx,
|
||||
OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
OGRGeometry & extent,
|
||||
const std::string& encoding)
|
||||
: dataset_(dataset),
|
||||
std::string const& encoding)
|
||||
: ctx_(ctx),
|
||||
dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn ()),
|
||||
count_(0),
|
||||
ctx_(boost::make_shared<mapnik::context_type>())
|
||||
count_(0)
|
||||
|
||||
{
|
||||
layer_.SetSpatialFilter (&extent);
|
||||
}
|
||||
|
||||
ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
||||
ogr_featureset::ogr_featureset(mapnik::context_ptr const& ctx,
|
||||
OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
const mapnik::box2d<double> & extent,
|
||||
const std::string& encoding)
|
||||
: dataset_(dataset),
|
||||
mapnik::box2d<double> const& extent,
|
||||
std::string const& encoding)
|
||||
: ctx_(ctx),
|
||||
dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
tr_(new transcoder(encoding)),
|
||||
|
|
|
@ -37,29 +37,30 @@
|
|||
class ogr_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
ogr_featureset(OGRDataSource & dataset,
|
||||
ogr_featureset(mapnik::context_ptr const& ctx,
|
||||
OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
OGRGeometry & extent,
|
||||
const std::string& encoding);
|
||||
std::string const& encoding);
|
||||
|
||||
ogr_featureset(OGRDataSource & dataset,
|
||||
ogr_featureset(mapnik::context_ptr const& ctx,
|
||||
OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
const mapnik::box2d<double> & extent,
|
||||
const std::string& encoding);
|
||||
mapnik::box2d<double> const& extent,
|
||||
std::string const& encoding);
|
||||
|
||||
virtual ~ogr_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
ogr_featureset(const ogr_featureset&);
|
||||
const ogr_featureset& operator=(const ogr_featureset&);
|
||||
|
||||
mapnik::context_ptr ctx_;
|
||||
OGRDataSource& dataset_;
|
||||
OGRLayer& layer_;
|
||||
OGRFeatureDefn* layerdef_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
const char* fidcolumn_;
|
||||
mutable int count_;
|
||||
mapnik::context_ptr ctx_;
|
||||
|
||||
};
|
||||
|
||||
#endif // OGR_FEATURESET_HPP
|
||||
|
|
|
@ -52,18 +52,19 @@ using mapnik::transcoder;
|
|||
using mapnik::feature_factory;
|
||||
|
||||
template <typename filterT>
|
||||
ogr_index_featureset<filterT>::ogr_index_featureset(OGRDataSource & dataset,
|
||||
ogr_index_featureset<filterT>::ogr_index_featureset(mapnik::context_ptr const & ctx,
|
||||
OGRDataSource & dataset,
|
||||
OGRLayer & layer,
|
||||
const filterT& filter,
|
||||
const std::string& index_file,
|
||||
const std::string& encoding)
|
||||
: dataset_(dataset),
|
||||
filterT const& filter,
|
||||
std::string const& index_file,
|
||||
std::string const& encoding)
|
||||
: ctx_(ctx),
|
||||
dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
filter_(filter),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn()),
|
||||
ctx_(boost::make_shared<mapnik::context_type>())
|
||||
fidcolumn_(layer_.GetFIDColumn())
|
||||
{
|
||||
|
||||
boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::find(index_file.c_str(),true);
|
||||
|
|
|
@ -32,18 +32,18 @@ template <typename filterT>
|
|||
class ogr_index_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
ogr_index_featureset(OGRDataSource& dataset,
|
||||
ogr_index_featureset(mapnik::context_ptr const& ctx,
|
||||
OGRDataSource& dataset,
|
||||
OGRLayer& layer,
|
||||
const filterT& filter,
|
||||
const std::string& index_file,
|
||||
const std::string& encoding);
|
||||
filterT const& filter,
|
||||
std::string const& index_file,
|
||||
std::string const& encoding);
|
||||
|
||||
virtual ~ogr_index_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
ogr_index_featureset(const ogr_index_featureset&);
|
||||
ogr_index_featureset& operator=(const ogr_index_featureset&);
|
||||
|
||||
mapnik::context_ptr ctx_;
|
||||
OGRDataSource& dataset_;
|
||||
OGRLayer& layer_;
|
||||
OGRFeatureDefn* layerdef_;
|
||||
|
@ -52,7 +52,7 @@ private:
|
|||
std::vector<int>::iterator itr_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
const char* fidcolumn_;
|
||||
mapnik::context_ptr ctx_;
|
||||
|
||||
};
|
||||
|
||||
#endif // OGR_INDEX_FEATURESET_HPP
|
||||
|
|
Loading…
Reference in a new issue