4d4e9f5d91
to be rendered. This allows for a large extent (larger than can be rendered into a single image in memory) to be rendered out as tiles. Since the full extent is used for the placement calculations text crossing tile boundaries will be consistent. This method is a little inefficient when a large number of labels need placed, an improved method would be to cache these placements between tiles, but the attached is a start. c++ users should simple call the render method with a start X and Y coordinate specified, for (int TileX = 0;TileX < 5;++TileX) { for(int TileY = 0;TileY < 5; ++TileY) { int TileSize=250; int StartX = TileX*TileSize; int StartY = TileY*TileSize; Image32 buf(TileSize,TileSize); agg_renderer<Image32> ren(m,buf,StartX,StartY); ren.apply(); char name[324]; sprintf(name,"tile_%d_%d.png",TileX,TileY); ImageUtils::save_to_file(name,"png",buf); } } python users should call render_tile_to_file for y in range(tile_count_y): for x in range(tile_count_x): if not os.path.exists("tiles/%d/%d/" % (map_scale, y)): os.makedirs("tiles/%d/%d/" % (map_scale, y)) render_tile_to_file(m, x*tile_size, y*tile_size, tile_size, tile_size, 'tiles/%d/%d/%d.png' % (map_scale,y,x), 'png')
118 lines
3.4 KiB
C++
118 lines
3.4 KiB
C++
/*****************************************************************************
|
|
*
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
*
|
|
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
*****************************************************************************/
|
|
//$Id: mapnik_python.cc 27 2005-03-30 21:45:40Z pavlenko $
|
|
|
|
#include <boost/python.hpp>
|
|
#include <boost/get_pointer.hpp>
|
|
#include <boost/python/detail/api_placeholder.hpp>
|
|
|
|
void export_color();
|
|
void export_coord();
|
|
void export_layer();
|
|
void export_parameters();
|
|
void export_envelope();
|
|
void export_query();
|
|
void export_image();
|
|
void export_image_view();
|
|
void export_map();
|
|
void export_python();
|
|
void export_filter();
|
|
void export_rule();
|
|
void export_style();
|
|
void export_stroke();
|
|
void export_datasource();
|
|
void export_datasource_cache();
|
|
void export_point_symbolizer();
|
|
void export_line_symbolizer();
|
|
void export_line_pattern_symbolizer();
|
|
void export_polygon_symbolizer();
|
|
void export_polygon_pattern_symbolizer();
|
|
void export_raster_symbolizer();
|
|
void export_shield_symbolizer();
|
|
void export_text_symbolizer();
|
|
void export_font_engine();
|
|
void export_projection();
|
|
|
|
#include <mapnik/map.hpp>
|
|
#include <mapnik/agg_renderer.hpp>
|
|
#include <mapnik/graphics.hpp>
|
|
#include <mapnik/load_map.hpp>
|
|
#include <mapnik/save_map.hpp>
|
|
|
|
void render_to_file(const mapnik::Map& map,
|
|
const std::string& file,
|
|
const std::string& format)
|
|
{
|
|
mapnik::Image32 image(map.getWidth(),map.getHeight());
|
|
mapnik::agg_renderer<mapnik::Image32> ren(map,image);
|
|
ren.apply();
|
|
image.saveToFile(file,format);
|
|
}
|
|
|
|
void render(const mapnik::Map& map,mapnik::Image32& image)
|
|
{
|
|
mapnik::agg_renderer<mapnik::Image32> ren(map,image);
|
|
ren.apply();
|
|
}
|
|
|
|
|
|
BOOST_PYTHON_MODULE(_mapnik)
|
|
{
|
|
using namespace boost::python;
|
|
|
|
using mapnik::load_map;
|
|
using mapnik::save_map;
|
|
|
|
export_query();
|
|
export_datasource();
|
|
export_parameters();
|
|
export_color();
|
|
export_envelope();
|
|
export_image();
|
|
export_image_view();
|
|
export_filter();
|
|
export_rule();
|
|
export_style();
|
|
export_layer();
|
|
export_stroke();
|
|
export_datasource_cache();
|
|
export_point_symbolizer();
|
|
export_line_symbolizer();
|
|
export_line_pattern_symbolizer();
|
|
export_polygon_symbolizer();
|
|
export_polygon_pattern_symbolizer();
|
|
export_raster_symbolizer();
|
|
export_shield_symbolizer();
|
|
export_text_symbolizer();
|
|
export_font_engine();
|
|
export_projection();
|
|
export_coord();
|
|
export_map();
|
|
|
|
def("render_to_file",&render_to_file);
|
|
def("render",&render);
|
|
|
|
def("load_map",&load_map,"load Map object from XML");
|
|
def("save_map",&load_map,"sace Map object to XML");
|
|
|
|
register_ptr_to_python<mapnik::filter_ptr>();
|
|
}
|