From 044c21db1330507c15799f84208e82a1f8bb811e Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Thu, 14 Jan 2016 08:36:12 -0600 Subject: [PATCH] Made it possible to change the type of a memory datasource by inspecting the features that are added to the memory datasource --- include/mapnik/memory_datasource.hpp | 1 + src/memory_datasource.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/mapnik/memory_datasource.hpp b/include/mapnik/memory_datasource.hpp index cd2b61130..9b589741f 100644 --- a/include/mapnik/memory_datasource.hpp +++ b/include/mapnik/memory_datasource.hpp @@ -55,6 +55,7 @@ private: mapnik::layer_descriptor desc_; datasource::datasource_t type_; bool bbox_check_; + bool type_set_; mutable box2d extent_; mutable bool dirty_extent_ = true; }; diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp index f7bd61d4e..86a08cf7e 100644 --- a/src/memory_datasource.cpp +++ b/src/memory_datasource.cpp @@ -73,7 +73,8 @@ memory_datasource::memory_datasource(parameters const& params) desc_(memory_datasource::name(), *params.get("encoding","utf-8")), type_(datasource::Vector), - bbox_check_(*params.get("bbox_check", true)) {} + bbox_check_(*params.get("bbox_check", true)), + type_set_(false) {} memory_datasource::~memory_datasource() {} @@ -81,6 +82,30 @@ void memory_datasource::push(feature_ptr feature) { // TODO - collect attribute descriptors? //desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer)); + if (feature->get_raster()) + { + // if a feature has a raster_ptr set it must be of raster type. + if (!type_set_) + { + type_ = datasource::Raster; + type_set_ = true; + } + else if (type_ == datasource::Vector) + { + throw std::runtime_error("Can not add a raster feature to a memory datasource that contains vectors"); + } + } + else + { + if (!type_set_) + { + type_set_ = true; + } + else if (type_ == datasource::Raster) + { + throw std::runtime_error("Can not add a vector feature to a memory datasource that contains rasters"); + } + } features_.push_back(feature); dirty_extent_ = true; }