BBox clipping fails when there's no intersection #127

Closed
artemp opened this Issue Oct 11, 2011 · 3 comments

1 participant

@artemp
Mapnik member

When Mapnik is processing layers, it tries to clip the map bbox to the
layer extent... unfortunately it doesn't test for intersection first,
so the "clipped" bbox is completely bogus. The layer is then asked for
features for this bbox, and if you have a lot of small raster layers
then this has a big performance impact.

I've attached a patch that fixes this, and also returns something
slightly more sensible from Envelope.intersects in the same situation.

@artemp
Mapnik member

[randomjunk] sorry, can't attach patch properly...
{{{
Trac Error

expected integer, got u'1048576 # 1MB'
}}}

patch is:
{{{

Index: include/mapnik/feature_style_processor.hpp

--- include/mapnik/feature_style_processor.hpp (revision 729)
+++ include/mapnik/feature_style_processor.hpp (working copy)
@@ -123,6 +123,12 @@
// back project layers extent into main map projection
prj_trans.backward(lx0,ly0,lz0);
prj_trans.backward(lx1,ly1,lz1);
+

  • // if no intersection then nothing to do for layer
  • if ( lx0 > ext.maxx() || lx1 < ext.minx() || ly0 > ext.maxy() || ly1 < ext.miny() ) {
  • return;
  • } + // clip query bbox lx0 = std::max(ext.minx(),lx0); ly0 = std::max(ext.miny(),ly0); Index: src/envelope.cpp =================================================================== --- src/envelope.cpp (revision 729) +++ src/envelope.cpp (working copy) @@ -239,14 +239,17 @@ #endif Envelope Envelope::intersect(const EnvelopeType& other) const {
  • if (intersects(other)) {
  • T x0=std::max(minx_,other.minx_);
  •        T y0=std::max(miny_,other.miny_);
    
  •    T x0=std::max(minx_,other.minx_);
    
  • T y0=std::max(miny_,other.miny_);
  • T x1=std::min(maxx_,other.maxx_);
  •        T y1=std::min(maxy_,other.maxy_);
    
  •    T x1=std::min(maxx_,other.maxx_);
    

- T y1=std::min(maxy_,other.maxy_);

  • return Envelope(x0,y0,x1,y1);
  • return Envelope(x0,y0,x1,y1);
  • } else {
  • return Envelope();
  •    }
    

    }

    template
    }}}

@artemp
Mapnik member

[artem] Applied, thanks!

@artemp
Mapnik member

[springmeyer] will appear in the 0.6.0 release, so back-assigning to 0.6.0 milestone.

@artemp artemp closed this Oct 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment