Exemple #1
0
    result test(std::string const & name, mapnik::Map const & map, double scale_factor) const
    {
        typename Renderer::image_type image(ren.render(map, scale_factor));
        boost::filesystem::path reference = reference_dir / image_file_name(name, map.width(), map.height(), scale_factor, true, Renderer::ext);
        bool reference_exists = boost::filesystem::exists(reference);
        result res;

        res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
        res.name = name;
        res.renderer_name = Renderer::name;
        res.scale_factor = scale_factor;
        res.size = map_size(map.width(), map.height());
        res.reference_image_path = reference;
        res.diff = reference_exists ? ren.compare(image, reference) : 0;

        if (res.diff)
        {
            boost::filesystem::create_directories(output_dir);
            boost::filesystem::path path = output_dir / image_file_name(name, map.width(), map.height(), scale_factor, false, Renderer::ext);
            res.actual_image_path = path;
            res.state = STATE_FAIL;
            ren.save(image, path);
        }

        if ((res.diff && overwrite) || !reference_exists)
        {
            ren.save(image, reference);
            res.state = STATE_OVERWRITE;
        }

        return res;
    }
Exemple #2
0
 image_type render(mapnik::Map const & map, double scale_factor) const
 {
     mapnik::grid grid(map.width(), map.height(), "__id__");
     mapnik::grid_renderer<mapnik::grid> ren(map, grid, scale_factor);
     ren.apply();
     image_type image(map.width(), map.height());
     convert(grid.data(), image);
     return image;
 }
Exemple #3
0
 image_type render(mapnik::Map const & map, double scale_factor) const
 {
     mapnik::cairo_surface_ptr image_surface(
         cairo_image_surface_create(CAIRO_FORMAT_ARGB32, map.width(), map.height()),
         mapnik::cairo_surface_closer());
     mapnik::cairo_ptr image_context(mapnik::create_context(image_surface));
     mapnik::cairo_renderer<mapnik::cairo_ptr> ren(map, image_context, scale_factor);
     ren.apply();
     image_type image(map.width(), map.height());
     mapnik::cairo_image_to_rgba8(image, image_surface);
     return image;
 }
Exemple #4
0
 image_type render(mapnik::Map const & map, double scale_factor) const
 {
     image_type image(map.width(), map.height());
     mapnik::agg_renderer<image_type> ren(map, image, scale_factor);
     ren.apply();
     return image;
 }
Exemple #5
0
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{
    unsigned width=map.width();
    unsigned height=map.height();

    image_32 buf(width,height);
    mapnik::agg_renderer<image_32> ren(map,buf,scaling_factor);

    try
    {
        mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
        ren.apply();
        QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32);
        pix = QPixmap::fromImage(image.rgbSwapped());
    }
    catch (mapnik::config_error & ex)
    {
        std::cerr << ex.what() << std::endl;
    }
    catch (const std::exception & ex)
    {
        std::cerr << "exception: " << ex.what() << std::endl;
    }
    catch (...)
    {
        std::cerr << "Unknown exception caught!\n";
    }
}
void render_to_file1(mapnik::Map const& map,
                     std::string const& filename,
                     std::string const& format)
{
    if (format == "svg-ng")
    {
#if defined(SVG_RENDERER)
        std::ofstream file (filename.c_str(), std::ios::out|std::ios::trunc|std::ios::binary);
        if (!file)
        {
            throw mapnik::image_writer_exception("could not open file for writing: " + filename);
        }
        using iter_type = std::ostream_iterator<char>;
        iter_type output_stream_iterator(file);
        mapnik::svg_renderer<iter_type> ren(map,output_stream_iterator);
        ren.apply();
#else
        throw mapnik::image_writer_exception("SVG backend not available, cannot write to format: " + format);
#endif
    }
    else if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24")
    {
#if defined(HAVE_CAIRO)
        mapnik::save_to_cairo_file(map,filename,format,1.0);
#else
        throw mapnik::image_writer_exception("Cairo backend not available, cannot write to format: " + format);
#endif
    }
    else
    {
        mapnik::image_any image(map.width(),map.height());
        render(map,image,1.0,0,0);
        mapnik::save_to_file(image,filename,format);
    }
}
Exemple #7
0
 image_type render(mapnik::Map const & map, double scale_factor) const
 {
     std::ostringstream ss(std::stringstream::binary);
     mapnik::cairo_surface_ptr image_surface(
         SurfaceCreateFunction(write, &ss, map.width(), map.height()),
         mapnik::cairo_surface_closer());
     mapnik::cairo_ptr image_context(mapnik::create_context(image_surface));
     mapnik::cairo_renderer<mapnik::cairo_ptr> ren(map, image_context, scale_factor);
     ren.apply();
     cairo_surface_finish(&*image_surface);
     return ss.str();
 }
void render_with_vars(mapnik::Map const& map,
            mapnik::image_any& image,
            boost::python::dict const& d,
            double scale_factor = 1.0,
            unsigned offset_x = 0u,
            unsigned offset_y = 0u)
{
    mapnik::attributes vars = mapnik::dict2attr(d);
    mapnik::request req(map.width(),map.height(),map.get_current_extent());
    req.set_buffer_size(map.buffer_size());
    python_unblock_auto_block b;
    mapnik::util::apply_visitor(agg_renderer_visitor_3(map, req, vars, scale_factor, offset_x, offset_y), image);
}
void render_to_file2(const mapnik::Map& map,const std::string& filename)
{
    std::string format = mapnik::guess_type(filename);
    if (format == "pdf" || format == "svg" || format =="ps")
    {
#if defined(HAVE_CAIRO)
        mapnik::save_to_cairo_file(map,filename,format);
#else
        throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
#endif
    }
    else 
    {
        mapnik::image_32 image(map.width(),map.height());
        render(map,image,1.0,0,0);
        mapnik::save_to_file(image,filename); 
    }
}
Exemple #10
0
void render_to_file1(mapnik::Map const& map,
                     std::string const& filename,
                     std::string const& format)
{
    if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24")
    {
#if defined(HAVE_CAIRO)
        mapnik::save_to_cairo_file(map,filename,format,1.0);
#else
        throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format);
#endif
    }
    else
    {
        mapnik::image_32 image(map.width(),map.height());
        render(map,image,1.0,0,0);
        mapnik::save_to_file(image,filename,format);
    }
}
Exemple #11
0
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{
// FIXME
#ifdef HAVE_CAIRO
    mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
                                            mapnik::cairo_surface_closer());
    mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
    if (cairo)
    {
        mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
        mapnik::cairo_renderer<mapnik::cairo_ptr> renderer(map, cairo, scaling_factor);
        renderer.apply();
    }
    mapnik::image_rgba8 data(map.width(), map.height());
    mapnik::cairo_image_to_rgba8(data, image_surface);
    QImage image((uchar*)data.getBytes(),data.width(),data.height(),QImage::Format_ARGB32);
    pix = QPixmap::fromImage(image.rgbSwapped());
#endif
}
Exemple #12
0
 image_type render(mapnik::Map & map, double scale_factor, map_size const & tiles) const
 {
     mapnik::box2d<double> box = map.get_current_extent();
     image_type image(map.width(), map.height());
     map.resize(image.width() / tiles.width, image.height() / tiles.height);
     double tile_box_width = box.width() / tiles.width;
     double tile_box_height = box.height() / tiles.height;
     for (std::size_t tile_y = 0; tile_y < tiles.height; tile_y++)
     {
         for (std::size_t tile_x = 0; tile_x < tiles.width; tile_x++)
         {
             mapnik::box2d<double> tile_box(
                 box.minx() + tile_x * tile_box_width,
                 box.miny() + tile_y * tile_box_height,
                 box.minx() + (tile_x + 1) * tile_box_width,
                 box.miny() + (tile_y + 1) * tile_box_height);
             map.zoom_to_box(tile_box);
             image_type tile(ren.render(map, scale_factor));
             set_rectangle(tile, image, tile_x * tile.width(), (tiles.height - 1 - tile_y) * tile.height());
         }
     }
     return image;
 }
bool make_vector_tile(tile &tile,
                      unsigned int path_multiplier,
                      mapnik::Map const& map,
                      int buffer_size,
                      double scale_factor,
                      unsigned int offset_x,
                      unsigned int offset_y,
                      unsigned int tolerance,
                      const std::string &image_format,
                      mapnik::scaling_method_e scaling_method,
                      double scale_denominator,
                      boost::optional<const post_processor &> pp) {
  
  typedef backend backend_type;
  typedef mapnik::vector::processor<backend_type> renderer_type;
  
  backend_type backend(tile.mapnik_tile(), path_multiplier, map, pp);
  
  mapnik::request request(map.width(),
                          map.height(),
                          map.get_current_extent());
  request.set_buffer_size(buffer_size);
  
  renderer_type ren(backend,
                    map,
                    request,
                    scale_factor,
                    offset_x,
                    offset_y,
                    tolerance,
                    image_format,
                    scaling_method);
  ren.apply(scale_denominator);
  
  return ren.painted();
}
            mapnik::font_set fontset("fontset");
            // NOTE: this is a valid font, but will fail because none are registered
            fontset.add_face_name("DejaVu Sans Book");
            m.insert_fontset("fontset", fontset);
            mapnik::layer lyr("layer");
            lyr.set_datasource(ds);
            lyr.add_style("style");
            m.add_layer(lyr);
            mapnik::feature_type_style the_style;
            mapnik::rule r;
            mapnik::text_symbolizer text_sym;
            mapnik::text_placements_ptr placement_finder = std::make_shared<mapnik::text_placements_dummy>();
            placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
            placement_finder->defaults.format_defaults.text_size = 10.0;
            placement_finder->defaults.format_defaults.fill = mapnik::color(0,0,0);
            placement_finder->defaults.format_defaults.fontset = fontset;
            placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(mapnik::parse_expression("[name]")));
            mapnik::put<mapnik::text_placements_ptr>(text_sym, mapnik::keys::text_placements_, placement_finder);
            r.append(std::move(text_sym));
            the_style.add_rule(std::move(r));
            m.insert_style("style", std::move(the_style) );
            m.zoom_to_box(mapnik::box2d<double>(-256,-256,
                                                256,256));
            mapnik::image_rgba8 buf(m.width(),m.height());
            mapnik::agg_renderer<mapnik::image_rgba8> ren(m,buf);
            ren.apply();
        } catch (std::exception const& ex) {
            REQUIRE(std::string(ex.what()) == std::string("Unable to find specified font face 'DejaVu Sans Book' in font set: 'fontset'"));
        }
    }
}
Exemple #15
0
#include "catch.hpp"

#include <mapnik/map.hpp>
#include <mapnik/feature_type_style.hpp>
#include <mapnik/rule.hpp>

TEST_CASE("map")
{
    SECTION("map resize")
    {
        mapnik::Map map(256, 256);

        CHECK(map.width() == 256);
        CHECK(map.height() == 256);

        map.resize(0, 0);

        CHECK(map.width() == 256);
        CHECK(map.height() == 256);

        map.resize(0, 1);

        CHECK(map.width() == 256);
        CHECK(map.height() == 256);

        map.resize(1, 0);

        CHECK(map.width() == 256);
        CHECK(map.height() == 256);

        map.resize(1, 1);
//------------------------------------------------------------------------------
void TileRenderer::RenderTile(std::string tile_uri, mapnik::Map m, int x, int y, int zoom, GoogleProjection tileproj, mapnik::projection prj, bool verbose, bool overrideTile, bool lockEnabled, std::string compositionLayerPath, std::string compositionMode, double compositionAlpha)
{
   if(!overrideTile && FileSystem::FileExists(tile_uri))
   {
      return;
   }
   else
   {
	   
       
      // Calculate pixel positions of bottom-left & top-right
      ituple p0(x * 256, (y + 1) * 256);
      ituple p1((x + 1) * 256, y * 256);

      // Convert to LatLong (EPSG:4326)
      dtuple l0 = tileproj.pixel2GeoCoord(p0, zoom);
      dtuple l1 = tileproj.pixel2GeoCoord(p1, zoom);

	  

      // Convert to map projection (e.g. mercator co-ords EPSG:900913)
      dtuple c0(l0.a,l0.b);
      dtuple c1(l1.a,l1.b);
      prj.forward(c0.a, c0.b);
      prj.forward(c1.a, c1.b);

      // Bounding box for the tile
#ifndef MAPNIK_2
      mapnik::Envelope<double> bbox = mapnik::Envelope<double>(c0.a,c0.b,c1.a,c1.b);
      m.resize(256,256);
      m.zoomToBox(bbox);
#else
      mapnik::box2d<double> bbox(c0.a,c0.b,c1.a,c1.b);
      m.resize(256,256);
      m.zoom_to_box(bbox);
#endif
      m.set_buffer_size(128);

      // Render image with default Agg renderer

#ifndef MAPNIK_2
      mapnik::Image32 buf(m.getWidth(),m.getHeight());
      mapnik::agg_renderer<mapnik::Image32> ren(m,buf);
#else
      mapnik::image_32 buf(m.width(), m.height());
      mapnik::agg_renderer<mapnik::image_32> ren(m,buf);
#endif
      ren.apply();
      if(lockEnabled)
      {
         int lockhandle = FileSystem::Lock(tile_uri);
#ifndef MAPNIK_2
		 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.getWidth(),m.getHeight(),&buf, zoom, x,y);
         mapnik::save_to_file<mapnik::ImageData32>(buf.data(),tile_uri,"png");
#else
	 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.width(),m.height(),&buf, zoom, x,y);
	 mapnik::save_to_file<mapnik::image_data_32>(buf.data(),tile_uri,"png");
#endif
         FileSystem::Unlock(tile_uri, lockhandle);
      }
      else
      {
#ifndef MAPNIK_2
		 Compose(compositionLayerPath, compositionMode, compositionAlpha, m.getWidth(),m.getHeight(),&buf, zoom, x,y);
         mapnik::save_to_file<mapnik::ImageData32>(buf.data(),tile_uri,"png");
#else
		Compose(compositionLayerPath, compositionMode, compositionAlpha, m.width(),m.height(),&buf, zoom, x,y);
		mapnik::save_to_file<mapnik::image_data_32>(buf.data(),tile_uri,"png");
#endif
      }
   }
}
Exemple #17
0
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{

#ifdef HAVE_CAIRO
    mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
                                            mapnik::cairo_surface_closer());
    mapnik::cairo_renderer<mapnik::cairo_surface_ptr> renderer(map, image_surface, scaling_factor);
    {
        mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
        renderer.apply();
    }
    image_32 buf(image_surface);
    QImage image((uchar*)buf.raw_data(),buf.width(),buf.height(),QImage::Format_ARGB32);
    pix = QPixmap::fromImage(image.rgbSwapped());
#endif
}
#include <streambuf>

TEST_CASE( "pbf vector tile input", "should be able to parse message and render point" ) {
    typedef mapnik::vector_tile_impl::backend_pbf backend_type;
    typedef mapnik::vector_tile_impl::processor<backend_type> renderer_type;
    typedef vector_tile::Tile tile_type;
    tile_type tile;
    backend_type backend(tile,16);
    unsigned tile_size = 256;
    mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
    mapnik::Map map(tile_size,tile_size,"+init=epsg:3857");
    mapnik::layer lyr("layer",map.srs());
    lyr.set_datasource(testing::build_ds(0,0));
    map.add_layer(lyr);
    map.zoom_to_box(bbox);
    mapnik::request m_req(map.width(),map.height(),map.get_current_extent());
    renderer_type ren(backend,map,m_req);
    ren.apply();
    // serialize to message
    std::string buffer;
    CHECK(tile.SerializeToString(&buffer));
    CHECK(151 == buffer.size());
    // now create new objects
    mapnik::Map map2(tile_size,tile_size,"+init=epsg:3857");
    tile_type tile2;
    CHECK(tile2.ParseFromString(buffer));
    std::string key("");
    CHECK(false == mapnik::vector_tile_impl::is_solid_extent(tile2,key));
    CHECK("" == key);
    CHECK(false == mapnik::vector_tile_impl::is_solid_extent(buffer,key));
    CHECK("" == key);