bool has_placement(box2d<double> const& box, double minimum_distance, mapnik::value_unicode_string const& text, double repeat_distance)
    {
        box2d<double> const& minimum_box = (minimum_distance > 0
                                               ? box2d<double>(box.minx() - minimum_distance, box.miny() - minimum_distance,
                                                               box.maxx() + minimum_distance, box.maxy() + minimum_distance)
                                               : box);

        box2d<double> const& repeat_box = (repeat_distance > 0
                                               ? box2d<double>(box.minx() - repeat_distance, box.miny() - repeat_distance,
                                                               box.maxx() + repeat_distance, box.maxy() + repeat_distance)
                                               : box);

        tree_t::query_iterator itr = tree_.query_in_box(repeat_distance > minimum_distance ? repeat_box : minimum_box);
        tree_t::query_iterator end = tree_.query_end();

        for ( ;itr != end; ++itr)
        {
            if (itr->box.intersects(minimum_box) || (text == itr->text && itr->box.intersects(repeat_box)))
            {
                return false;
            }
        }

        return true;
    }
Beispiel #2
0
void setup_label_transform(agg::trans_affine & tr, box2d<double> const& bbox, mapnik::feature_impl const& feature, T const& sym)
{
    double width = 0;
    double height = 0;

    expression_ptr const& width_expr = sym.get_width();
    if (width_expr)
        width = boost::apply_visitor(evaluate<Feature,value_type>(feature), *width_expr).to_double();

    expression_ptr const& height_expr = sym.get_height();
    if (height_expr)
        height = boost::apply_visitor(evaluate<Feature,value_type>(feature), *height_expr).to_double();

    if (width > 0 && height > 0)
    {
        double sx = width/bbox.width();
        double sy = height/bbox.height();
        tr *= agg::trans_affine_scaling(sx,sy);
    }
    else if (width > 0)
    {
        double sx = width/bbox.width();
        tr *= agg::trans_affine_scaling(sx);
    }
    else if (height > 0)
    {
        double sy = height/bbox.height();
        tr *= agg::trans_affine_scaling(sy);
    }
    else
    {
        evaluate_transform(tr, feature, sym.get_image_transform());
    }
}
Beispiel #3
0
bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d<T> const& box)
{
    double tmin=0.0;
    double tmax=1.0;
    double dx=x1-x0;
    if (clip_test<double>(-dx,x0,tmin,tmax))
    {
        if (clip_test<double>(dx,box.width()-x0,tmin,tmax))
        {
            double dy=y1-y0;
            if (clip_test<double>(-dy,y0,tmin,tmax))
            {
                if (clip_test<double>(dy,box.height()-y0,tmin,tmax))
                {
                    if (tmax<1.0)
                    {
                        x1=static_cast<T>(x0+tmax*dx);
                        y1=static_cast<T>(y0+tmax*dy);
                    }
                    if (tmin>0.0)
                    {
                        x0+=static_cast<T>(tmin*dx);
                        y0+=static_cast<T>(tmin*dy);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
    tiled_multi_file_policy(std::string const& file_pattern,
                            std::string const& format,
                            unsigned tile_size,
                            box2d<double> extent,
                            box2d<double> bbox,
                            unsigned width,
                            unsigned height,
                            unsigned tile_stride)
      : image_width_(width),
        image_height_(height),
        tile_size_(tile_size),
        tile_stride_(tile_stride)
    {
        double lox = extent.minx();
        double loy = extent.miny();
   
        //int max_x = int(std::ceil(double(width) / double(tile_size)));
        //int max_y = int(std::ceil(double(height) / double(tile_size)));

        double pixel_x = extent.width() / double(width);
        double pixel_y = extent.height() / double(height);

#ifdef MAPNIK_DEBUG 
        std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
#endif

        // intersection of query with extent => new query
        box2d<double> e = bbox.intersect(extent);
      
        const int x_min = int(std::floor((e.minx() - lox) / (tile_size * pixel_x)));
        const int y_min = int(std::floor((e.miny() - loy) / (tile_size * pixel_y)));
        const int x_max = int(std::ceil((e.maxx() - lox) / (tile_size * pixel_x)));
        const int y_max = int(std::ceil((e.maxy() - loy) / (tile_size * pixel_y)));

        for (int x = x_min; x < x_max; ++x)
        {
            for (int y = y_min; y < y_max; ++y)
            {
                // x0, y0, x1, y1 => projection-space image coordinates.
                double x0 = lox + x*tile_size*pixel_x;
                double y0 = loy + y*tile_size*pixel_y;
                double x1 = x0 + tile_size*pixel_x;
                double y1 = y0 + tile_size*pixel_y;
            
                // check if it intersects the query
                if (e.intersects(box2d<double>(x0,y0,x1,y1)))
                {
                    // tile_box => intersection of tile with query in projection-space.
                    box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
                    std::string file = interpolate(file_pattern, x, y);
                    raster_info info(file,format,tile_box,tile_size,tile_size);
                    infos_.push_back(info);
                }
            }
        }
#ifdef MAPNIK_DEBUG 
        std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file_pattern << std::endl;
#endif
    }
Beispiel #5
0
 keypoint_container<P, F>::keypoint_container(const box2d& d)
   : index2d_(d, border(10))
 {
   fill_with_border(index2d_, -1);
   keypoint_vector_.reserve((d.nrows() * d.ncols()) / 10);
   feature_vector_.reserve((d.nrows() * d.ncols()) / 10);
   compact_has_run_ = false;
 }
 agg::trans_affine transform(box2d<double> & bbox) const
 {
     bbox *= image_tr_;
     coord<double, 2> c = bbox.center();
     agg::trans_affine mtx = agg::trans_affine_translation(
         0.5 * bbox.width() - c.x,
         0.5 * bbox.height() - c.y);
     return image_tr_ * mtx;
 }
 view_transform(int _width, int _height, box2d<double> const& _extent,
                double _offset_x = 0.0, double _offset_y = 0.0)
     : width_(_width),
       height_(_height),
       extent_(_extent),
       sx_(extent_.width() > 0 ? static_cast<double>(width_) / extent_.width() : 1.0),
       sy_(extent_.height() > 0 ? static_cast<double>(height_) / extent_.height() : 1.0),
       offset_x_(_offset_x),
       offset_y_(_offset_y),
       offset_(0) {}
 inline box2d<double> backward(box2d<double> const& e) const
 {
     double x0 = e.minx();
     double y0 = e.miny();
     double x1 = e.maxx();
     double y1 = e.maxy();
     backward(&x0, &y0);
     backward(&x1, &y1);
     return box2d<double>(x0, y0, x1, y1);
 }
Beispiel #9
0
std::string occi_datasource::sql_bbox(box2d<double> const& env) const
{
    std::ostringstream b;
    b << std::setprecision(16);
    b << "MDSYS.SDO_GEOMETRY(" << SDO_GTYPE_2DPOLYGON << "," << srid_ << ",NULL,";
    b << " MDSYS.SDO_ELEM_INFO_ARRAY(1," << SDO_ETYPE_POLYGON << "," << SDO_INTERPRETATION_RECTANGLE << "),";
    b << " MDSYS.SDO_ORDINATE_ARRAY(";
    b << env.minx() << "," << env.miny() << ", ";
    b << env.maxx() << "," << env.maxy() << "))";
    return b.str();
}
Beispiel #10
0
std::string postgis_datasource::sql_bbox(box2d<double> const& env) const
{
    std::ostringstream b;
    if (srid_ > 0)
        b << "SetSRID(";
    b << "'BOX3D(";
    b << std::setprecision(16);
    b << env.minx() << " " << env.miny() << ",";
    b << env.maxx() << " " << env.maxy() << ")'::box3d";
    if (srid_ > 0)
        b << ", " << srid_ << ")";
    return b.str();
}
 inline box2d<double> backward(box2d<double> const& e,
                               proj_transform const& prj_trans) const
 {
     double x0 = e.minx();
     double y0 = e.miny();
     double x1 = e.maxx();
     double y1 = e.maxy();
     double z = 0.0;
     backward(&x0, &y0);
     prj_trans.forward(x0, y0, z);
     backward(&x1, &y1);
     prj_trans.forward(x1, y1, z);
     return box2d<double>(x0, y0, x1, y1);
 }
    bool has_placement(box2d<double> const& box, double margin, mapnik::value_unicode_string const& text, double repeat_distance)
    {
        // Don't bother with any of the repeat checking unless the repeat distance is greater than the margin
        if (repeat_distance <= margin) {
            return has_placement(box, margin);
        }

        box2d<double> repeat_box(box.minx() - repeat_distance, box.miny() - repeat_distance,
                                 box.maxx() + repeat_distance, box.maxy() + repeat_distance);

        box2d<double> const& margin_box = (margin > 0
                                               ? box2d<double>(box.minx() - margin, box.miny() - margin,
                                                               box.maxx() + margin, box.maxy() + margin)
                                               : box);

        tree_t::query_iterator tree_itr = tree_.query_in_box(repeat_box);
        tree_t::query_iterator tree_end = tree_.query_end();

        for ( ;tree_itr != tree_end; ++tree_itr)
        {
            if (tree_itr->get().box.intersects(margin_box) || (text == tree_itr->get().text && tree_itr->get().box.intersects(repeat_box)))
            {
                return false;
            }
        }

        return true;
    }
Beispiel #13
0
void envelope_points(std::vector< coord<double,2> > & coords, box2d<double>& env, int points)
{
    double width = env.width();
    double height = env.height();

    int steps;

    if (points <= 4) {
        steps = 0;
    } else {
        steps = static_cast<int>(std::ceil((points - 4) / 4.0));
    }

    steps += 1;
    double xstep = width / steps;
    double ystep = height / steps;

    for (int i=0; i<=steps; i++) {
        coords.push_back(coord<double,2>(env.minx() + i * xstep, env.miny()));
        coords.push_back(coord<double,2>(env.minx() + i * xstep, env.maxy()));

    }
    for (int i=1; i<steps; i++) {
        coords.push_back(coord<double,2>(env.minx(), env.miny() + i * ystep));
        coords.push_back(coord<double,2>(env.maxx(), env.miny() + i * ystep));
    }
}
    bool has_point_placement(box2d<double> const& box, double distance)
    {
        box2d<double> bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance);
        tree_t::query_iterator itr = tree_.query_in_box(bigger_box);
        tree_t::query_iterator end = tree_.query_end();

        for ( ;itr != end; ++itr)
        {
            if (itr->box.intersects(bigger_box))
            {
                return false;
            }
        }

        return true;
    }
    bool has_placement(box2d<double> const& box, mapnik::value_unicode_string const& text, double distance)
    {
        box2d<double> bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance);
        tree_t::query_iterator itr = tree_.query_in_box(bigger_box);
        tree_t::query_iterator end = tree_.query_end();

        for ( ;itr != end; ++itr)
        {
            if (itr->box.intersects(box) || (text == itr->text && itr->box.intersects(bigger_box)))
            {
                return false;
            }
        }

        return true;
    }
Beispiel #16
0
void grid_renderer<T>::start_layer_processing(layer const& lay, box2d<double> const& query_extent)
{
    MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: Start processing layer=" << lay.name();
    MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: datasource=" << lay.datasource().get();
    MAPNIK_LOG_DEBUG(grid_renderer) << "grid_renderer: query_extent = " << query_extent;

    if (lay.clear_label_cache())
    {
        detector_->clear();
    }
    query_extent_ = query_extent;
    int buffer_size = lay.buffer_size();
    if (buffer_size != 0 )
    {
        double padding = buffer_size * (double)(query_extent.width()/pixmap_.width());
        double x0 = query_extent_.minx();
        double y0 = query_extent_.miny();
        double x1 = query_extent_.maxx();
        double y1 = query_extent_.maxy();
        query_extent_.init(x0 - padding, y0 - padding, x1 + padding , y1 + padding);
    }

    boost::optional<box2d<double> > const& maximum_extent = lay.maximum_extent();
    if (maximum_extent)
    {
        query_extent_.clip(*maximum_extent);
    }
}
 const_iterator query(const box2d<double>& box)
 {
     if (box.intersects(info_.envelope()))
     {
         return begin();
     }
     return end();
 }
Beispiel #18
0
 /** Rotates the size_ box and translates the position. */
 box2d<double> perform_transform(double angle, double dx, double dy)
 {
     double x1 = size_.minx();
     double x2 = size_.maxx();
     double y1 = size_.miny();
     double y2 = size_.maxy();
     agg::trans_affine tr = tr_ * agg::trans_affine_rotation(angle).translate(dx, dy);
     double xA = x1, yA = y1, xB = x2, yB = y1, xC = x2, yC = y2, xD = x1, yD = y2;
     tr.transform(&xA, &yA);
     tr.transform(&xB, &yB);
     tr.transform(&xC, &yC);
     tr.transform(&xD, &yD);
     box2d<double> result(xA, yA, xC, yC);
     result.expand_to_include(xB, yB);
     result.expand_to_include(xD, yD);
     return result;
 }
Beispiel #19
0
bool proj_transform::backward (box2d<double> & box) const
{
    if (is_source_equal_dest_)
        return true;

    double minx = box.minx();
    double miny = box.miny();
    double maxx = box.maxx();
    double maxy = box.maxy();
    double z = 0.0;
    if (!backward(minx,miny,z))
        return false;
    if (!backward(maxx,maxy,z))
        return false;
    box.init(minx,miny,maxx,maxy);
    return true;
}
Beispiel #20
0
coord<unsigned, 2> offset(Sym const & sym,
                          mapnik::feature_impl const & feature,
                          proj_transform const & prj_trans,
                          renderer_common const & common,
                          box2d<double> const & clip_box)
{
    coord<unsigned, 2> off(0, 0);
    pattern_alignment_enum alignment = get<pattern_alignment_enum, keys::alignment>(sym, feature, common.vars_);
    if (alignment == LOCAL_ALIGNMENT)
    {
        coord<double, 2> alignment(0, 0);
        apply_local_alignment apply(common.t_, prj_trans, clip_box, alignment.x, alignment.y);
        util::apply_visitor(geometry::vertex_processor<apply_local_alignment>(apply), feature.get_geometry());
        off.x = std::abs(clip_box.width() - alignment.x);
        off.y = std::abs(clip_box.height() - alignment.y);
    }
    return off;
}
void draw_rect(image_32 &pixmap, box2d<double> const& box)
{
    double x0 = box.minx();
    double x1 = box.maxx();
    double y0 = box.miny();
    double y1 = box.maxy();
    unsigned color1 = 0xff0000ff;
    for (double x=x0; x<x1; x++)
    {
        pixmap.setPixel(x, y0, color1);
        pixmap.setPixel(x, y1, color1);
    }
    for (double y=y0; y<y1; y++)
    {
        pixmap.setPixel(x0, y, color1);
        pixmap.setPixel(x1, y, color1);
    }
}
    tiled_file_policy(std::string const& file,
                      std::string const& format,
                      unsigned tile_size,
                      box2d<double> extent,
                      box2d<double> bbox,
                      unsigned width,
                      unsigned height)
    {
        double lox = extent.minx();
        double loy = extent.miny();
   
        int max_x = int(std::ceil(double(width) / double(tile_size)));
        int max_y = int(std::ceil(double(height) / double(tile_size)));

        double pixel_x = extent.width() / double(width);
        double pixel_y = extent.height() / double(height);

#ifdef MAPNIK_DEBUG 
        std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
#endif

        box2d<double> e = bbox.intersect(extent);
      
        for (int x = 0; x < max_x; ++x)
        {
            for (int y = 0; y < max_y; ++y)
            {
                double x0 = lox + x * tile_size * pixel_x;
                double y0 = loy + y * tile_size * pixel_y;
                double x1 = x0 + tile_size * pixel_x;
                double y1 = y0 + tile_size * pixel_y;
            
                if (e.intersects(box2d<double>(x0, y0, x1, y1)))
                {
                    box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
                    raster_info info(file,format,tile_box,tile_size,tile_size);
                    infos_.push_back(info);
                }
            }
        }
#ifdef MAPNIK_DEBUG 
        std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl;
#endif
    }
    bool has_placement(box2d<double> const& box, double margin)
    {
        box2d<double> const& margin_box = (margin > 0
                                               ? box2d<double>(box.minx() - margin, box.miny() - margin,
                                                               box.maxx() + margin, box.maxy() + margin)
                                               : box);

        tree_t::query_iterator tree_itr = tree_.query_in_box(margin_box);
        tree_t::query_iterator tree_end = tree_.query_end();

        for (;tree_itr != tree_end; ++tree_itr)
        {
            if (tree_itr->get().box.intersects(margin_box))
            {
                return false;
            }
        }
        return true;
    }
    bool has_placement(box2d<double> const& box, double minimum_distance)
    {
        box2d<double> const& minimum_box = (minimum_distance > 0
                                               ? box2d<double>(box.minx() - minimum_distance, box.miny() - minimum_distance,
                                                               box.maxx() + minimum_distance, box.maxy() + minimum_distance)
                                               : box);

        tree_t::query_iterator itr = tree_.query_in_box(minimum_box);
        tree_t::query_iterator end = tree_.query_end();

        for (;itr != end; ++itr)
        {
            if (itr->box.intersects(minimum_box))
            {
                return false;
            }
        }
        return true;
    }
Beispiel #25
0
    image_gray8 create_bitmap(box2d<T> box)
    {
        if (!box.valid())
        {
            return image_gray8(0, 0);
        }

        try
        {
            return image_gray8(box.width(), box.height());
        }
        catch (std::runtime_error const & e)
        {
            // TODO: Scale down in this case.
            MAPNIK_LOG_ERROR(grid_vertex_adapter) << "grid vertex adapter: Cannot allocate underlaying bitmap. Bbox: "
                << box.to_string() << "; " << e.what();
            return image_gray8(0, 0);
        }
    }
Beispiel #26
0
    grid_vertex_adapter(PathType & path, T dx, T dy, box2d<T> box)
        : dx_(dx), dy_(dy),
        img_(create_bitmap(box)),
        vt_(img_.width(), img_.height(), box),
        si_(box.width() / dx, box.height() / dy)
    {
        transform_path<PathType, coord_type, view_transform> tp(path, vt_);
        tp.rewind(0);
        agg::rasterizer_scanline_aa<> ras;
        ras.add_path(tp);

        agg::rendering_buffer buf(img_.data(), img_.width(), img_.height(), img_.row_size());
        agg::pixfmt_gray8 pixfmt(buf);
        using renderer_base = agg::renderer_base<agg::pixfmt_gray8>;
        using renderer_bin = agg::renderer_scanline_bin_solid<renderer_base>;
        renderer_base rb(pixfmt);
        renderer_bin ren_bin(rb);
        ren_bin.color(agg::gray8(1));
        agg::scanline_bin sl_bin;
        agg::render_scanlines(ras, sl_bin, ren_bin);
    }
Beispiel #27
0
void cairo_context::set_gradient(cairo_gradient const& pattern, const box2d<double> &bbox)
{
    cairo_pattern_t * gradient = pattern.gradient();
    double bx1=bbox.minx();
    double by1=bbox.miny();
    double bx2=bbox.maxx();
    double by2=bbox.maxy();
    if (pattern.units() != USER_SPACE_ON_USE)
    {
        if (pattern.units() == OBJECT_BOUNDING_BOX)
        {
            cairo_path_extents(cairo_.get(), &bx1, &by1, &bx2, &by2);
        }
        cairo_matrix_t cairo_matrix;
        cairo_pattern_get_matrix(gradient, &cairo_matrix);
        cairo_matrix_scale(&cairo_matrix,1.0/(bx2-bx1),1.0/(by2-by1));
        cairo_matrix_translate(&cairo_matrix, -bx1,-by1);
        cairo_pattern_set_matrix(gradient, &cairo_matrix);
    }
    cairo_set_source(cairo_.get(), const_cast<cairo_pattern_t*>(gradient));
    check_object_status_and_throw_exception(*this);
}
Beispiel #28
0
 bool pass(const box2d<double>& extent) const
 {
     if (tol_ == 0)
     {
         return extent.contains(pt_);
     }
     else
     {
         box2d<double> extent2 = extent;
         extent2.pad(tol_);
         return extent2.contains(pt_);
     }
 }
Beispiel #29
0
// Output is centered around (0,0)
static void rotated_box2d(box2d<double> & box, rotation const& rot, pixel_position const& center, double width, double height)
{
    double half_width, half_height;
    if (rot.sin == 0 && rot.cos == 1.)
    {
        half_width  = width / 2.;
        half_height = height / 2.;
    }
    else
    {
        half_width  = (width * rot.cos + height * rot.sin) /2.;
        half_height = (width * rot.sin + height * rot.cos) /2.;
    }
    box.init(center.x - half_width, center.y - half_height, center.x + half_width, center.y + half_height);
}
Beispiel #30
0
bool proj_transform::forward(box2d<double>& env, int points) const
{
    if (is_source_equal_dest_)
        return true;

    std::vector<coord<double,2> > coords;
    envelope_points(coords, env, points);

    double z;
    for (std::vector<coord<double,2> >::iterator it = coords.begin(); it!=coords.end(); ++it) {
        z = 0;
        if (!forward(it->x, it->y, z)) {
            return false;
        }
    }

    box2d<double> result = calculate_bbox(coords);

    env.re_center(result.center().x, result.center().y);
    env.height(result.height());
    env.width(result.width());

    return true;
}