Skip to content

Commit

Permalink
memory_datasource: support datasource interface
Browse files Browse the repository at this point in the history
  • Loading branch information
artemp committed May 30, 2014
1 parent 2812735 commit f9cf23b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bindings/python/mapnik_datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion include/mapnik/memory_datasource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {}

Expand Down
22 changes: 16 additions & 6 deletions src/memory_datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {}

Expand Down
8 changes: 6 additions & 2 deletions tests/cpp_tests/fontset_runtime_test.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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);

This comment has been minimized.

Copy link
@artemp

artemp Jun 26, 2014

Author Member

@springmeyer - I should've spotted this one! btw, this is not how we should create datasources, we should be using
datasource_cache::create(params) but it doesn't work for memory_datasource .. doh
I'm going to fix all plugins not to query 'type' parameter because it's redundant anyway and creates potential problems when creating datasources directly

ds->push(feature);
mapnik::Map m(256,256);
mapnik::font_set fontset("fontset");
Expand All @@ -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;
Expand Down

0 comments on commit f9cf23b

Please sign in to comment.