memory_datasource: support datasource interface

This commit is contained in:
artemp 2014-05-30 10:16:49 +01:00
parent 2812735dfd
commit f9cf23b59f
5 changed files with 26 additions and 11 deletions

View file

@ -191,7 +191,7 @@ void export_datasource()
class_<memory_datasource,
bases<datasource>, std::shared_ptr<memory_datasource>,
boost::noncopyable>("MemoryDatasource", init<>())
boost::noncopyable>("MemoryDatasource", no_init)
.def("add_feature",&memory_datasource::push,
"Adds a Feature:\n"
">>> ms = MemoryDatasource()\n"

View file

@ -36,7 +36,8 @@ class MAPNIK_DECL memory_datasource : public datasource
{
friend class memory_featureset;
public:
memory_datasource(datasource::datasource_t type=datasource::Vector, bool bbox_check=true);
memory_datasource(parameters const& params);
static const char * name();
virtual ~memory_datasource();
virtual datasource::datasource_t type() const;
virtual featureset_ptr features(query const& q) const;

View file

@ -53,7 +53,7 @@ layer::layer(layer const& rhs)
cache_features_(rhs.cache_features_),
group_by_(rhs.group_by_),
styles_(rhs.styles_),
ds_(rhs.ds_),
ds_(datasource_cache::instance().create(rhs.ds_->params())),
buffer_size_(rhs.buffer_size_),
maximum_extent_(rhs.maximum_extent_) {}

View file

@ -26,12 +26,17 @@
#include <mapnik/box2d.hpp>
#include <mapnik/memory_datasource.hpp>
#include <mapnik/memory_featureset.hpp>
#include <mapnik/boolean.hpp>
// boost
// stl
#include <algorithm>
using mapnik::datasource;
using mapnik::parameters;
DATASOURCE_PLUGIN(mapnik::memory_datasource)
namespace mapnik {
struct accumulate_extent
@ -60,11 +65,16 @@ struct accumulate_extent
bool first_;
};
memory_datasource::memory_datasource(datasource::datasource_t type, bool bbox_check)
: datasource(parameters()),
desc_("in-memory datasource","utf-8"),
type_(type),
bbox_check_(bbox_check) {}
const char * memory_datasource::name()
{
return "memory";
}
memory_datasource::memory_datasource(parameters const& params)
: datasource(params),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")),
type_(datasource::Vector),
bbox_check_(*params.get<boolean>("bbox_check", true)) {}
memory_datasource::~memory_datasource() {}

View file

@ -1,6 +1,7 @@
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
#include <mapnik/memory_datasource.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/unicode.hpp>
@ -47,7 +48,10 @@ int main(int argc, char** argv)
auto pt = std::make_unique<mapnik::geometry_type>(mapnik::geometry_type::types::Point);
pt->move_to(128,128);
feature->add_geometry(pt.release());
std::shared_ptr<mapnik::memory_datasource> ds = std::make_shared<mapnik::memory_datasource>();
mapnik::parameters params;
params["type"]="memory";
auto ds = std::make_shared<mapnik::memory_datasource>(params);
ds->push(feature);
mapnik::Map m(256,256);
mapnik::font_set fontset("fontset");
@ -57,7 +61,7 @@ int main(int argc, char** argv)
mapnik::layer lyr("layer");
lyr.set_datasource(ds);
lyr.add_style("style");
m.add_layer(lyr);
m.add_layer(std::move(lyr));
mapnik::feature_type_style the_style;
mapnik::rule r;
mapnik::text_symbolizer text_sym;