2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* 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,
|
2006-02-01 00:09:52 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2006-02-01 00:09:52 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2006-02-01 00:09:52 +01:00
|
|
|
//$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>
|
2007-09-25 20:47:12 +02:00
|
|
|
#include <boost/python/exception_translator.hpp>
|
2006-02-01 00:09:52 +01:00
|
|
|
|
2008-03-12 01:37:53 +01:00
|
|
|
void register_cairo();
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_color();
|
2006-10-16 15:44:52 +02:00
|
|
|
void export_coord();
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_layer();
|
|
|
|
void export_parameters();
|
|
|
|
void export_envelope();
|
2006-09-11 11:48:27 +02:00
|
|
|
void export_query();
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_image();
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
void export_image_view();
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_map();
|
|
|
|
void export_python();
|
|
|
|
void export_filter();
|
|
|
|
void export_rule();
|
|
|
|
void export_style();
|
|
|
|
void export_stroke();
|
2006-12-06 21:26:59 +01:00
|
|
|
void export_feature();
|
|
|
|
void export_featureset();
|
2006-10-16 15:44:52 +02:00
|
|
|
void export_datasource();
|
2006-02-01 00:09:52 +01:00
|
|
|
void export_datasource_cache();
|
2006-02-25 12:03:30 +01:00
|
|
|
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_text_symbolizer();
|
2007-07-02 15:39:08 +02:00
|
|
|
void export_shield_symbolizer();
|
2006-03-19 22:55:59 +01:00
|
|
|
void export_font_engine();
|
2006-10-16 15:44:52 +02:00
|
|
|
void export_projection();
|
2006-02-01 00:09:52 +01:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/map.hpp>
|
|
|
|
#include <mapnik/agg_renderer.hpp>
|
2008-03-12 20:14:51 +01:00
|
|
|
#ifdef HAVE_CAIRO
|
2008-03-12 01:37:53 +01:00
|
|
|
#include <mapnik/cairo_renderer.hpp>
|
2008-03-12 20:14:51 +01:00
|
|
|
#endif
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/graphics.hpp>
|
2007-12-06 13:14:29 +01:00
|
|
|
#include <mapnik/image_util.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/load_map.hpp>
|
2007-09-25 20:47:12 +02:00
|
|
|
#include <mapnik/config_error.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/save_map.hpp>
|
2006-09-11 11:48:27 +02:00
|
|
|
|
2008-07-30 09:37:48 +02:00
|
|
|
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
2008-03-12 01:37:53 +01:00
|
|
|
#include <pycairo.h>
|
2008-03-12 20:14:51 +01:00
|
|
|
#endif
|
2006-12-04 21:12:58 +01:00
|
|
|
|
|
|
|
void render(const mapnik::Map& map,mapnik::Image32& image, unsigned offset_x = 0, unsigned offset_y = 0)
|
|
|
|
{
|
|
|
|
mapnik::agg_renderer<mapnik::Image32> ren(map,image,offset_x, offset_y);
|
|
|
|
ren.apply();
|
|
|
|
}
|
|
|
|
|
2006-12-05 16:43:52 +01:00
|
|
|
void render2(const mapnik::Map& map,mapnik::Image32& image)
|
|
|
|
{
|
|
|
|
mapnik::agg_renderer<mapnik::Image32> ren(map,image);
|
|
|
|
ren.apply();
|
|
|
|
}
|
|
|
|
|
2008-07-30 09:37:48 +02:00
|
|
|
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
2008-03-12 20:14:51 +01:00
|
|
|
|
2008-03-12 01:37:53 +01:00
|
|
|
void render3(const mapnik::Map& map,PycairoSurface* surface, unsigned offset_x = 0, unsigned offset_y = 0)
|
|
|
|
{
|
|
|
|
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
|
|
|
|
mapnik::cairo_renderer<Cairo::Surface> ren(map,s,offset_x, offset_y);
|
|
|
|
ren.apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
void render4(const mapnik::Map& map,PycairoSurface* surface)
|
|
|
|
{
|
|
|
|
Cairo::RefPtr<Cairo::Surface> s(new Cairo::Surface(surface->surface));
|
|
|
|
mapnik::cairo_renderer<Cairo::Surface> ren(map,s);
|
|
|
|
ren.apply();
|
|
|
|
}
|
|
|
|
|
2008-03-12 20:14:51 +01:00
|
|
|
#endif
|
|
|
|
|
2007-12-06 13:14:29 +01:00
|
|
|
void render_tile_to_file(const mapnik::Map& map,
|
|
|
|
unsigned offset_x, unsigned offset_y,
|
|
|
|
unsigned width, unsigned height,
|
|
|
|
const std::string& file,
|
|
|
|
const std::string& format)
|
2006-02-01 00:09:52 +01:00
|
|
|
{
|
2006-12-04 21:12:58 +01:00
|
|
|
mapnik::Image32 image(width,height);
|
|
|
|
render(map,image,offset_x, offset_y);
|
2008-01-25 15:40:48 +01:00
|
|
|
mapnik::save_to_file(image.data(),file,format);
|
2006-02-01 00:09:52 +01:00
|
|
|
}
|
|
|
|
|
2007-12-06 13:14:29 +01:00
|
|
|
void render_to_file1(const mapnik::Map& map,
|
|
|
|
const std::string& filename,
|
2006-12-04 21:12:58 +01:00
|
|
|
const std::string& format)
|
2006-02-01 00:09:52 +01:00
|
|
|
{
|
2007-12-06 13:14:29 +01:00
|
|
|
mapnik::Image32 image(map.getWidth(),map.getHeight());
|
|
|
|
render(map,image,0,0);
|
2008-01-25 15:40:48 +01:00
|
|
|
mapnik::save_to_file(image,filename,format);
|
2006-02-01 00:09:52 +01:00
|
|
|
}
|
|
|
|
|
2007-12-06 13:14:29 +01:00
|
|
|
void render_to_file2(const mapnik::Map& map,
|
|
|
|
const std::string& filename)
|
|
|
|
{
|
|
|
|
mapnik::Image32 image(map.getWidth(),map.getHeight());
|
|
|
|
render(map,image,0,0);
|
2008-01-25 15:40:48 +01:00
|
|
|
mapnik::save_to_file(image,filename);
|
2007-12-06 13:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-07 16:20:33 +01:00
|
|
|
double scale_denominator(mapnik::Map const &map, bool geographic)
|
|
|
|
{
|
2007-12-06 13:14:29 +01:00
|
|
|
return mapnik::scale_denominator(map, geographic);
|
2006-12-07 16:20:33 +01:00
|
|
|
}
|
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
void translator(mapnik::config_error const & ex) {
|
|
|
|
PyErr_SetString(PyExc_UserWarning, ex.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_PYTHON_FUNCTION_OVERLOADS(load_map_overloads, load_map, 2, 3);
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
BOOST_PYTHON_MODULE(_mapnik)
|
|
|
|
{
|
Tiling patch from Toby allows for a selected pixel region within an extent
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')
2006-12-01 10:37:37 +01:00
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
using namespace boost::python;
|
|
|
|
|
2006-10-03 12:02:14 +02:00
|
|
|
using mapnik::load_map;
|
|
|
|
using mapnik::save_map;
|
2007-09-25 20:47:12 +02:00
|
|
|
|
|
|
|
register_exception_translator<mapnik::config_error>(translator);
|
2008-03-12 01:37:53 +01:00
|
|
|
register_cairo();
|
Tiling patch from Toby allows for a selected pixel region within an extent
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')
2006-12-01 10:37:37 +01:00
|
|
|
export_query();
|
2006-12-06 21:26:59 +01:00
|
|
|
export_feature();
|
|
|
|
export_featureset();
|
2006-10-16 15:44:52 +02:00
|
|
|
export_datasource();
|
2006-02-01 00:09:52 +01:00
|
|
|
export_parameters();
|
|
|
|
export_color();
|
|
|
|
export_envelope();
|
|
|
|
export_image();
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
export_image_view();
|
2006-02-01 00:09:52 +01:00
|
|
|
export_filter();
|
|
|
|
export_rule();
|
|
|
|
export_style();
|
|
|
|
export_layer();
|
|
|
|
export_stroke();
|
|
|
|
export_datasource_cache();
|
2006-02-25 12:03:30 +01:00
|
|
|
export_point_symbolizer();
|
|
|
|
export_line_symbolizer();
|
|
|
|
export_line_pattern_symbolizer();
|
|
|
|
export_polygon_symbolizer();
|
|
|
|
export_polygon_pattern_symbolizer();
|
|
|
|
export_raster_symbolizer();
|
|
|
|
export_text_symbolizer();
|
2007-07-02 15:39:08 +02:00
|
|
|
export_shield_symbolizer();
|
2006-03-19 22:55:59 +01:00
|
|
|
export_font_engine();
|
2006-10-16 15:44:52 +02:00
|
|
|
export_projection();
|
|
|
|
export_coord();
|
2006-02-01 00:09:52 +01:00
|
|
|
export_map();
|
2008-03-12 01:37:53 +01:00
|
|
|
|
2007-12-06 13:14:29 +01:00
|
|
|
def("render_to_file",&render_to_file1);
|
|
|
|
def("render_to_file",&render_to_file2);
|
2006-12-04 21:12:58 +01:00
|
|
|
def("render_tile_to_file",&render_tile_to_file);
|
2006-12-06 21:26:59 +01:00
|
|
|
def("render",&render);
|
2006-12-05 16:43:52 +01:00
|
|
|
def("render",&render2);
|
2008-07-30 09:37:48 +02:00
|
|
|
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
2008-03-12 01:37:53 +01:00
|
|
|
def("render",&render3);
|
|
|
|
def("render",&render4);
|
2008-03-12 20:14:51 +01:00
|
|
|
#endif
|
2006-12-07 16:20:33 +01:00
|
|
|
def("scale_denominator", &scale_denominator);
|
2006-10-03 12:02:14 +02:00
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
def("load_map", & load_map, load_map_overloads());
|
|
|
|
def("save_map", & save_map, "save Map object to XML");
|
2006-10-03 12:02:14 +02:00
|
|
|
|
2007-08-01 11:59:23 +02:00
|
|
|
using mapnik::symbolizer;
|
|
|
|
class_<symbolizer>("Symbolizer",no_init)
|
|
|
|
;
|
|
|
|
|
Tiling patch from Toby allows for a selected pixel region within an extent
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')
2006-12-01 10:37:37 +01:00
|
|
|
register_ptr_to_python<mapnik::filter_ptr>();
|
2006-02-01 00:09:52 +01:00
|
|
|
}
|