Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render-time feature cache should support rasters #1543

Closed
springmeyer opened this issue Oct 21, 2012 · 2 comments
Closed

Render-time feature cache should support rasters #1543

springmeyer opened this issue Oct 21, 2012 · 2 comments
Milestone

Comments

@springmeyer
Copy link
Member

Currently it does not. Rasters are blindly added to the cache but cannot be pulled back out because the memory datasource/featureset api depends on checking geometry intersections. Rasters have no geometries.

@springmeyer
Copy link
Member Author

This gets things working:

diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp
index 629b84a..48a4e54 100644
--- a/include/mapnik/feature_style_processor_impl.hpp
+++ b/include/mapnik/feature_style_processor_impl.hpp
@@ -458,7 +458,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
         }
         else if (cache_features)
         {
-            memory_datasource cache;
+            memory_datasource cache(ds->type());
             featureset_ptr features = ds->features(q);
             if (features) {
                 // Cache all features into the memory_datasource before rendering.
diff --git a/include/mapnik/memory_datasource.hpp b/include/mapnik/memory_datasource.hpp
index 8966fe0..ef30d5f 100644
--- a/include/mapnik/memory_datasource.hpp
+++ b/include/mapnik/memory_datasource.hpp
@@ -36,7 +36,7 @@ class MAPNIK_DECL memory_datasource : public datasource
 {
     friend class memory_featureset;
 public:
-    memory_datasource();
+    memory_datasource(datasource::datasource_t type=datasource::Vector);
     virtual ~memory_datasource();
     void push(feature_ptr feature);
     datasource::datasource_t type() const;
@@ -50,6 +50,7 @@ public:
 private:
     std::vector<feature_ptr> features_;
     mapnik::layer_descriptor desc_;
+    datasource::datasource_t type_;
 };

 }
diff --git a/include/mapnik/memory_featureset.hpp b/include/mapnik/memory_featureset.hpp
index 8f14940..5bf5c45 100644
--- a/include/mapnik/memory_featureset.hpp
+++ b/include/mapnik/memory_featureset.hpp
@@ -24,7 +24,6 @@
 #define MAPNIK_MEMORY_FEATURESET_HPP

 // mapnik
-#include <mapnik/debug.hpp>
 #include <mapnik/memory_datasource.hpp>

 // boost
@@ -38,13 +37,15 @@ public:
     memory_featureset(box2d<double> const& bbox, memory_datasource const& ds)
         : bbox_(bbox),
           pos_(ds.features_.begin()),
-          end_(ds.features_.end())
+          end_(ds.features_.end()),
+          type_(ds.type())
     {}

     memory_featureset(box2d<double> const& bbox, std::vector<feature_ptr> const& features)
         : bbox_(bbox),
           pos_(features.begin()),
-          end_(features.end())
+          end_(features.end()),
+          type_(datasource::Vector)
     {}

     virtual ~memory_featureset() {}
@@ -53,20 +54,23 @@ public:
     {
         while (pos_ != end_)
         {
-            for  (unsigned i=0; i<(*pos_)->num_geometries();++i)
+            if (type_ == datasource::Raster)
             {
-                geometry_type & geom = (*pos_)->get_geometry(i);
-
-                MAPNIK_LOG_DEBUG(memory_featureset) << "memory_featureset: BBox=" << bbox_ << ",Envelope=" << geom.envelope();
-
-                if (bbox_.intersects(geom.envelope()))
+                return *pos_++;
+            }
+            else
+            {
+                for (unsigned i=0; i<(*pos_)->num_geometries();++i)
                 {
-                    return *pos_++;
+                    geometry_type & geom = (*pos_)->get_geometry(i);
+                    if (bbox_.intersects(geom.envelope()))
+                    {
+                        return *pos_++;
+                    }
                 }
             }
             ++pos_;
         }
-
         return feature_ptr();
     }

@@ -74,6 +78,7 @@ private:
     box2d<double> bbox_;
     std::vector<feature_ptr>::const_iterator pos_;
     std::vector<feature_ptr>::const_iterator end_;
+    datasource::datasource_t type_;
 };
 }

diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp
index 0549a92..66cf83d 100644
--- a/src/memory_datasource.cpp
+++ b/src/memory_datasource.cpp
@@ -62,9 +62,10 @@ struct accumulate_extent
     bool first_;
 };

-memory_datasource::memory_datasource()
+memory_datasource::memory_datasource(datasource::datasource_t type)
     : datasource(parameters()),
-      desc_("in-memory datasource","utf-8") {}
+      desc_("in-memory datasource","utf-8"),
+      type_(type) {}

 memory_datasource::~memory_datasource() {}

@@ -77,7 +78,7 @@ void memory_datasource::push(feature_ptr feature)

 datasource::datasource_t memory_datasource::type() const
 {
-    return datasource::Vector;
+    return type_;
 }

 featureset_ptr memory_datasource::features(const query& q) const

@artemp
Copy link
Member

artemp commented Oct 22, 2012

@springmeyer - great, will give it a try! btw rasters do have bounding boxes:) When caching features per layer we should disable bounding box test anyway ??

PetrDlouhy pushed a commit to PetrDlouhy/mapnik that referenced this issue Aug 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants