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