implement new debug system

This commit is contained in:
kunitoki 2012-04-08 02:20:56 +02:00
parent 19f5f77417
commit 1f351e0e09
133 changed files with 1870 additions and 1065 deletions

View file

@ -325,7 +325,7 @@ opts.AddVariables(
# Variables affecting rendering back-ends # Variables affecting rendering back-ends
BoolVariable('RENDERING_STATS', 'Output rendering statistics during style processing', 'False'), BoolVariable('RENDERING_STATS', 'Output rendering statistics during style processing', 'False'),
BoolVariable('INTERNAL_LIBAGG', 'Use provided libagg', 'True'), BoolVariable('INTERNAL_LIBAGG', 'Use provided libagg', 'True'),
BoolVariable('SVG_RENDERER', 'build support for native svg renderer', 'False'), BoolVariable('SVG_RENDERER', 'build support for native svg renderer', 'False'),
@ -345,7 +345,12 @@ opts.AddVariables(
PathVariable('SQLITE_LIBS', 'Search path for SQLITE library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept), PathVariable('SQLITE_LIBS', 'Search path for SQLITE library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept),
PathVariable('RASTERLITE_INCLUDES', 'Search path for RASTERLITE include files', '/usr/include/', PathVariable.PathAccept), PathVariable('RASTERLITE_INCLUDES', 'Search path for RASTERLITE include files', '/usr/include/', PathVariable.PathAccept),
PathVariable('RASTERLITE_LIBS', 'Search path for RASTERLITE library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept), PathVariable('RASTERLITE_LIBS', 'Search path for RASTERLITE library files', '/usr/' + LIBDIR_SCHEMA, PathVariable.PathAccept),
# Variables for logging and statistics
BoolVariable('ENABLE_LOG', 'Enable logging, which is enabled by default when building in *debug*', 'False'),
BoolVariable('ENABLE_STATS', 'Enable global statistics during map processing', 'False'),
('LOG_FORMAT_STRING', 'The format string used before log output string, piped through strftime (max length of 255 characters)', 'Mapnik LOG> %Y-%m-%d %H:%M:%S:'),
# Other variables # Other variables
BoolVariable('SHAPE_MEMORY_MAPPED_FILE', 'Utilize memory-mapped files in Shapefile Plugin (higher memory usage, better performance)', 'True'), BoolVariable('SHAPE_MEMORY_MAPPED_FILE', 'Utilize memory-mapped files in Shapefile Plugin (higher memory usage, better performance)', 'True'),
('SYSTEM_FONTS','Provide location for python bindings to register fonts (if given aborts installation of bundled DejaVu fonts)',''), ('SYSTEM_FONTS','Provide location for python bindings to register fonts (if given aborts installation of bundled DejaVu fonts)',''),
@ -1163,7 +1168,7 @@ if not preconfigured:
env.Append(CXXFLAGS = '-DBOOST_REGEX_HAS_ICU') env.Append(CXXFLAGS = '-DBOOST_REGEX_HAS_ICU')
else: else:
env['SKIPPED_DEPS'].append('boost_regex_icu') env['SKIPPED_DEPS'].append('boost_regex_icu')
env['REQUESTED_PLUGINS'] = [ driver.strip() for driver in Split(env['INPUT_PLUGINS'])] env['REQUESTED_PLUGINS'] = [ driver.strip() for driver in Split(env['INPUT_PLUGINS'])]
if len(env['REQUESTED_PLUGINS']): if len(env['REQUESTED_PLUGINS']):
@ -1411,10 +1416,26 @@ if not preconfigured:
# Common debugging flags. # Common debugging flags.
# http://lists.fedoraproject.org/pipermail/devel/2010-November/144952.html # http://lists.fedoraproject.org/pipermail/devel/2010-November/144952.html
debug_flags = '-g -fno-omit-frame-pointer -DDEBUG -DMAPNIK_DEBUG' debug_flags = '-g -fno-omit-frame-pointer -DDEBUG -DMAPNIK_DEBUG'
ndebug_flags = '-DNDEBUG' ndebug_flags = '-DNDEBUG'
# Enable logging in debug mode (always) and release mode (when specified)
log_enabled = ' -DMAPNIK_LOG -DMAPNIK_LOG_FORMAT="%s"' % env['LOG_FORMAT_STRING']
if env['DEBUG']:
debug_flags += log_enabled
else:
if env['ENABLE_LOG']:
ndebug_flags += log_enabled
# Enable statistics reporting
if env['ENABLE_STATS']:
debug_flags += ' -DMAPNIK_STATS'
ndebug_flags += ' -DMAPNIK_STATS'
# Add rdynamic to allow using statics between application and plugins
# http://stackoverflow.com/questions/8623657/multiple-instances-of-singleton-across-shared-libraries-on-linux
env.MergeFlags('-rdynamic')
# Customizing the C++ compiler flags depending on: # Customizing the C++ compiler flags depending on:
# (1) the C++ compiler used; and # (1) the C++ compiler used; and
# (2) whether debug binaries are requested. # (2) whether debug binaries are requested.

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,10 +19,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/python/detail/api_placeholder.hpp> #include <boost/python/detail/api_placeholder.hpp>
// stl // stl
#include <sstream> #include <sstream>
#include <vector> #include <vector>
@ -89,6 +90,7 @@ boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
description["name"] = ld.get_name(); description["name"] = ld.get_name();
description["geometry_type"] = ds->get_geometry_type(); description["geometry_type"] = ds->get_geometry_type();
description["encoding"] = ld.get_encoding(); description["encoding"] = ld.get_encoding();
description["log"] = ds->log_enabled();
return description; return description;
} }

View file

@ -20,8 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id: mapnik_envelope.cc 27 2005-03-30 21:45:40Z pavlenko $
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,9 +19,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/variant.hpp>
// mapnik // mapnik
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
#include <mapnik/expression.hpp> #include <mapnik/expression.hpp>
@ -30,7 +32,6 @@
#include <mapnik/parse_path.hpp> #include <mapnik/parse_path.hpp>
#include <mapnik/value.hpp> #include <mapnik/value.hpp>
#include <boost/variant.hpp>
using mapnik::Feature; using mapnik::Feature;
using mapnik::expression_ptr; using mapnik::expression_ptr;

View file

@ -19,13 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python/suite/indexing/indexing_suite.hpp> #include <boost/python/suite/indexing/indexing_suite.hpp>
//#include <boost/python/suite/indexing/map_indexing_suite.hpp> //#include <boost/python/suite/indexing/map_indexing_suite.hpp>
#include <boost/python/iterator.hpp> #include <boost/python/iterator.hpp>
#include <boost/python/call_method.hpp> #include <boost/python/call_method.hpp>
#include <boost/python/tuple.hpp> #include <boost/python/tuple.hpp>

View file

@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>
// mapnik // mapnik
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include <mapnik/font_engine_freetype.hpp> #include <mapnik/font_engine_freetype.hpp>

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
extern "C" extern "C"
{ {

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
extern "C" extern "C"
{ {

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,8 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id: mapnik_layer.cc 17 2005-03-08 23:58:43Z pavlenko $
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include "mapnik_enumeration.hpp" #include "mapnik_enumeration.hpp"

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id: mapnik_map.cc 17 2005-03-08 23:58:43Z pavlenko $
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,9 +19,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include <mapnik/graphics.hpp> #include <mapnik/graphics.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/markers_symbolizer.hpp> #include <mapnik/markers_symbolizer.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -25,6 +25,7 @@
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/params.hpp> #include <mapnik/params.hpp>
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
#include <mapnik/value.hpp> #include <mapnik/value.hpp>
@ -102,7 +103,9 @@ struct parameters_pickle_suite : boost::python::pickle_suite
} }
else else
{ {
std::clog << "could not unpickle key: " << key << "\n"; #ifdef MAPNIK_LOG
mapnik::log() << "parameters_pickle_suite: Could not unpickle key=" << key;
#endif
} }
} }
} }

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include "mapnik_enumeration.hpp" #include "mapnik_enumeration.hpp"

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/python.hpp> #include <boost/python.hpp>
#include "mapnik_enumeration.hpp" #include "mapnik_enumeration.hpp"

View file

@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// mapnik // mapnik
#include <mapnik/proj_transform.hpp> #include <mapnik/proj_transform.hpp>
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,9 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
//boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>
// mapnik // mapnik

View file

@ -19,11 +19,14 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
// mapnik
#include <mapnik/query.hpp> #include <mapnik/query.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
using mapnik::query; using mapnik::query;
using mapnik::box2d; using mapnik::box2d;

View file

@ -19,10 +19,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
// mapnik
#include <mapnik/raster_colorizer.hpp> #include <mapnik/raster_colorizer.hpp>
using mapnik::raster_colorizer; using mapnik::raster_colorizer;

View file

@ -19,9 +19,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
// mapnik
#include <mapnik/raster_symbolizer.hpp> #include <mapnik/raster_symbolizer.hpp>
using mapnik::raster_symbolizer; using mapnik::raster_symbolizer;

View file

@ -19,13 +19,14 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/python/implicit.hpp> #include <boost/python/implicit.hpp>
#include <boost/python/detail/api_placeholder.hpp> #include <boost/python/detail/api_placeholder.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
// mapnik
#include <mapnik/rule.hpp> #include <mapnik/rule.hpp>
#include <mapnik/expression.hpp> #include <mapnik/expression.hpp>
#include <mapnik/expression_string.hpp> #include <mapnik/expression_string.hpp>

View file

@ -20,9 +20,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
// mapnik
#include <mapnik/shield_symbolizer.hpp> #include <mapnik/shield_symbolizer.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/path_expression_grammar.hpp> #include <mapnik/path_expression_grammar.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,11 +19,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
// mapnik
#include "mapnik_enumeration.hpp" #include "mapnik_enumeration.hpp"
#include <mapnik/feature_type_style.hpp> #include <mapnik/feature_type_style.hpp>

View file

@ -19,10 +19,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost
#include <boost/python.hpp> #include <boost/python.hpp>
// mapnik
//symbolizer typdef here rather than mapnik/symbolizer.hpp //symbolizer typdef here rather than mapnik/symbolizer.hpp
#include <mapnik/rule.hpp> #include <mapnik/rule.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// boost // boost
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)

View file

@ -28,6 +28,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/grid/grid_renderer.hpp> #include <mapnik/grid/grid_renderer.hpp>
#include <mapnik/grid/grid.hpp> #include <mapnik/grid/grid.hpp>
#include <mapnik/grid/grid_util.hpp> #include <mapnik/grid/grid_util.hpp>
@ -271,7 +272,9 @@ static void write_features(T const& grid_type,
} }
else else
{ {
std::clog << "should not get here: key '" << key << "' not found in grid feature properties\n"; #ifdef MAPNIK_LOG
mapnik::log() << "write_features: Should not get here: key " << key << " not found in grid feature properties";
#endif
} }
} }
} }

View file

@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#include <boost/optional/optional.hpp> #include <boost/optional/optional.hpp>
#include <boost/python.hpp> #include <boost/python.hpp>

View file

@ -24,6 +24,7 @@
#define MAPNIK_CTRANS_HPP #define MAPNIK_CTRANS_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/vertex.hpp> #include <mapnik/vertex.hpp>
#include <mapnik/coord_array.hpp> #include <mapnik/coord_array.hpp>
@ -239,9 +240,9 @@ struct MAPNIK_DECL coord_transform_parallel
angle_a = atan2((m_pre_y-m_cur_y),(m_pre_x-m_cur_x)); angle_a = atan2((m_pre_y-m_cur_y),(m_pre_x-m_cur_x));
dx_pre = cos(angle_a + pi_by_2); dx_pre = cos(angle_a + pi_by_2);
dy_pre = sin(angle_a + pi_by_2); dy_pre = sin(angle_a + pi_by_2);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "offsetting line by: " << offset_ << "\n"; mapnik::log() << "coord_transform_parallel: Offsetting line by=" << offset_;
std::clog << "initial dx=" << (dx_pre * offset_) << " dy=" << (dy_pre * offset_) << "\n"; mapnik::log() << "coord_transform_parallel: Initial dx=" << (dx_pre * offset_) << ",dy=" << (dy_pre * offset_);
#endif #endif
*x = m_pre_x + (dx_pre * offset_); *x = m_pre_x + (dx_pre * offset_);
*y = m_pre_y + (dy_pre * offset_); *y = m_pre_y + (dy_pre * offset_);
@ -290,14 +291,14 @@ struct MAPNIK_DECL coord_transform_parallel
else // skip sharp spikes else // skip sharp spikes
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
dx_curr = cos(angle_a + pi_by_2); dx_curr = cos(angle_a + pi_by_2);
dy_curr = sin(angle_a + pi_by_2); dy_curr = sin(angle_a + pi_by_2);
sin_curve = dx_curr*dy_pre-dy_curr*dx_pre; sin_curve = dx_curr*dy_pre-dy_curr*dx_pre;
std::clog << "angle a: " << angle_a << "\n"; mapnik::log() << "coord_transform_parallel: angle a=" << angle_a;
std::clog << "angle b: " << angle_b << "\n"; mapnik::log() << "coord_transform_parallel: angle b=" << angle_b;
std::clog << "h: " << h << "\n"; mapnik::log() << "coord_transform_parallel: h=" << h;
std::clog << "sin_curve: " << sin_curve << "\n"; mapnik::log() << "coord_transform_parallel: sin_curve=" << sin_curve;
#endif #endif
m_status = process; m_status = process;
break; break;
@ -309,21 +310,21 @@ struct MAPNIK_DECL coord_transform_parallel
sin_curve = dx_curr*dy_pre-dy_curr*dx_pre; sin_curve = dx_curr*dy_pre-dy_curr*dx_pre;
cos_curve = -dx_pre*dx_curr-dy_pre*dy_curr; cos_curve = -dx_pre*dx_curr-dy_pre*dy_curr;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "sin_curve value: " << sin_curve << "\n"; mapnik::log() << "coord_transform_parallel: sin_curve value=" << sin_curve;
#endif #endif
if(sin_curve > -0.3 && sin_curve < 0.3) { if(sin_curve > -0.3 && sin_curve < 0.3) {
angle_b = atan2((m_cur_y-m_next_y),(m_cur_x-m_next_x)); angle_b = atan2((m_cur_y-m_next_y),(m_cur_x-m_next_x));
h = tan((angle_b - angle_a)/2.0); h = tan((angle_b - angle_a)/2.0);
*x = m_cur_x + (dx_curr * offset_) - h * (dy_curr * offset_); *x = m_cur_x + (dx_curr * offset_) - h * (dy_curr * offset_);
*y = m_cur_y + (dy_curr * offset_) + h * (dx_curr * offset_); *y = m_cur_y + (dy_curr * offset_) + h * (dx_curr * offset_);
} else { } else {
if (angle_b - angle_a > 0) if (angle_b - angle_a > 0)
h = -1.0*(1.0+cos_curve)/sin_curve; h = -1.0*(1.0+cos_curve)/sin_curve;
else else
h = (1.0+cos_curve)/sin_curve; h = (1.0+cos_curve)/sin_curve;
*x = m_cur_x + (dx_curr + base_shift*dy_curr)*offset_; *x = m_cur_x + (dx_curr + base_shift*dy_curr)*offset_;
*y = m_cur_y + (dy_curr - base_shift*dx_curr)*offset_; *y = m_cur_y + (dy_curr - base_shift*dx_curr)*offset_;
} }
*/ */

View file

@ -88,6 +88,7 @@ public:
datasource (parameters const& params) datasource (parameters const& params)
: params_(params), : params_(params),
log_enabled_(false),
is_bound_(false) is_bound_(false)
{ {
} }
@ -104,6 +105,15 @@ public:
return params_; return params_;
} }
/*!
* @brief Get the status of detasource logging
* @return Return true if log is enabled, false otherwise
*/
bool log_enabled() const
{
return log_enabled_;
}
/*! /*!
* @brief Get the type of the datasource * @brief Get the type of the datasource
* @return The type of the datasource (Vector or Raster) * @return The type of the datasource (Vector or Raster)
@ -123,6 +133,7 @@ public:
virtual ~datasource() {} virtual ~datasource() {}
protected: protected:
parameters params_; parameters params_;
bool log_enabled_;
mutable bool is_bound_; mutable bool is_bound_;
}; };

127
include/mapnik/debug.hpp Normal file
View file

@ -0,0 +1,127 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* 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
*
*****************************************************************************/
#ifndef MAPNIK_DEBUG_HPP
#define MAPNIK_DEBUG_HPP
// mapnik
#include <mapnik/global.hpp>
// boost
#ifdef MAPNIK_THREADSAFE
#include <boost/thread/mutex.hpp>
#endif
// std
#include <iostream>
#include <cassert>
#include <sstream>
#include <ctime>
#include <ostream>
#include <fstream>
#ifdef MAPNIK_DEBUG
#define MAPNIK_DEBUG_AS_BOOL true
#else
#define MAPNIK_DEBUG_AS_BOOL false
#endif
#ifndef MAPNIK_LOG_FORMAT
#error Must run configure again to regenerate the correct log format string. See LOG_FORMAT_STRING scons option.
#endif
namespace mapnik {
namespace logger {
#define __xstr__(s) __str__(s)
#define __str__(s) #s
static inline std::string format_logger() {
char buf[256];
const time_t tm = time(0);
strftime(buf, sizeof(buf), __xstr__(MAPNIK_LOG_FORMAT), localtime(&tm));
return buf;
}
#undef __xstr__
#undef __str__
template<class Ch, class Tr, class A>
class no_output {
private:
struct null_buffer {
template<class T>
null_buffer &operator<<(const T &) {
return *this;
}
};
public:
typedef null_buffer stream_buffer;
public:
void operator()(const stream_buffer &) {
}
};
template<class Ch, class Tr, class A>
class output_to_clog {
public:
typedef std::basic_ostringstream<Ch, Tr, A> stream_buffer;
public:
void operator()(const stream_buffer &s) {
#ifdef MAPNIK_THREADSAFE
static boost::mutex mutex;
boost::mutex::scoped_lock lock(mutex);
#endif
std::clog << format_logger() << " " << s.str() << std::endl;
}
};
template<template <class Ch, class Tr, class A> class OutputPolicy,
class Ch = char,
class Tr = std::char_traits<Ch>,
class A = std::allocator<Ch> >
class base_log {
typedef OutputPolicy<Ch, Tr, A> output_policy;
public:
~base_log() {
output_policy()(streambuf_);
}
public:
template<class T>
base_log &operator<<(const T &x) {
streambuf_ << x;
return *this;
}
private:
typename output_policy::stream_buffer streambuf_;
};
}
class log : public logger::base_log<logger::output_to_clog>
{
};
}
#endif

View file

@ -24,6 +24,7 @@
#define MAPNIK_FONT_ENGINE_FREETYPE_HPP #define MAPNIK_FONT_ENGINE_FREETYPE_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/utils.hpp> #include <mapnik/utils.hpp>
#include <mapnik/ctrans.hpp> #include <mapnik/ctrans.hpp>
@ -138,9 +139,8 @@ public:
~font_face() ~font_face()
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "~font_face: Clean up face \"" << family_name() mapnik::log() << "font_face: Clean up face \"" << family_name() << " " << style_name() << "\"";
<< " " << style_name() << "\"" << std::endl;
#endif #endif
FT_Done_Face(face_); FT_Done_Face(face_);
} }
@ -225,9 +225,10 @@ public:
~stroker() ~stroker()
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "~stroker: destroy stroker:" << s_ << std::endl; mapnik::log() << "stroker: Destroy stroker=" << s_;
#endif #endif
FT_Stroker_Done(s_); FT_Stroker_Done(s_);
} }
private: private:
@ -310,6 +311,7 @@ public:
face_set->add(face); face_set->add(face);
} else { } else {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
// TODO - handle with mapnik::log
std::cerr << "Failed to find face '" << *name << "' in font set '" << fset.get_name() << "'\n"; std::cerr << "Failed to find face '" << *name << "' in font set '" << fset.get_name() << "'\n";
#endif #endif
} }

View file

@ -25,6 +25,7 @@
// mapnik // mapnik
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/image_data.hpp> #include <mapnik/image_data.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/grid/grid_view.hpp> #include <mapnik/grid/grid_view.hpp>
@ -72,7 +73,6 @@ private:
public: public:
hit_grid(int width, int height, std::string const& key, unsigned int resolution) hit_grid(int width, int height, std::string const& key, unsigned int resolution)
:width_(width), :width_(width),
height_(height), height_(height),
@ -136,7 +136,9 @@ public:
} }
else else
{ {
std::clog << "should not get here: key '" << key_ << "' not found in feature properties\n"; #ifdef MAPNIK_LOG
mapnik::log() << "hit_grid: Should not get here: key '" << key_ << "' not found in feature properties";
#endif
} }
} }
@ -153,7 +155,9 @@ public:
} }
else else
{ {
std::clog << "### Warning: key '" << key_ << "' was blank for " << *feature << "\n"; #ifdef MAPNIK_LOG
mapnik::log() << "hit_grid: Warning - key '" << key_ << "' was blank for " << *feature;
#endif
} }
} }

View file

@ -103,7 +103,7 @@ struct feature_collection_grammar :
qi::on_error<qi::fail> qi::on_error<qi::fail>
( (
feature_collection feature_collection
, std::clog , std::cerr
<< phoenix::val("Error parsing GeoJSON ") << phoenix::val("Error parsing GeoJSON ")
<< qi::_4 << qi::_4
<< phoenix::val(" here: \"") << phoenix::val(" here: \"")

View file

@ -24,6 +24,7 @@
#define MAPNIK_MEMORY_FEATURESET_HPP #define MAPNIK_MEMORY_FEATURESET_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/memory_datasource.hpp> #include <mapnik/memory_datasource.hpp>
// boost // boost
@ -52,10 +53,11 @@ public:
{ {
while (pos_ != end_) while (pos_ != end_)
{ {
for (unsigned i=0; i<(*pos_)->num_geometries();++i) { for (unsigned i=0; i<(*pos_)->num_geometries();++i)
{
geometry_type & geom = (*pos_)->get_geometry(i); geometry_type & geom = (*pos_)->get_geometry(i);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "bbox_=" << bbox_ << ", geom.envelope=" << geom.envelope() << "\n"; mapnik::log() << "memory_featureset: BBox=" << bbox_ << ",Envelope=" << geom.envelope();
#endif #endif
if (bbox_.intersects(geom.envelope())) if (bbox_.intersects(geom.envelope()))
{ {

View file

@ -87,7 +87,7 @@ protected:
bool pixel_coordinates_; bool pixel_coordinates_;
virtual void write_header(); virtual void write_header();
inline void write_feature_header(std::string type) { inline void write_feature_header(std::string type) {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
if (count_ == STOPPED) if (count_ == STOPPED)
{ {
std::cerr << "WARNING: Metawriter not started before using it.\n"; std::cerr << "WARNING: Metawriter not started before using it.\n";

View file

@ -24,6 +24,7 @@
#define MAPNIK_POOL_HPP #define MAPNIK_POOL_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/utils.hpp> #include <mapnik/utils.hpp>
// boost // boost
@ -100,8 +101,8 @@ public:
typename ContType::iterator itr=unusedPool_.begin(); typename ContType::iterator itr=unusedPool_.begin();
while ( itr!=unusedPool_.end()) while ( itr!=unusedPool_.end())
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog<<"borrow "<<(*itr).get()<<"\n"; mapnik::log() << "pool: Borrow instance=" << (*itr).get();
#endif #endif
if ((*itr)->isOK()) if ((*itr)->isOK())
{ {
@ -111,8 +112,8 @@ public:
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog<<"bad connection (erase)" << (*itr).get()<<"\n"; mapnik::log() << "pool: Bad connection (erase) instance=" << (*itr).get();
#endif #endif
itr=unusedPool_.erase(itr); itr=unusedPool_.erase(itr);
} }
@ -123,8 +124,8 @@ public:
if (conn->isOK()) if (conn->isOK())
{ {
usedPool_.push_back(conn); usedPool_.push_back(conn);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "create << " << conn.get() << "\n"; mapnik::log() << "pool: Create connection=" << conn.get();
#endif #endif
return conn; return conn;
} }
@ -142,8 +143,8 @@ public:
{ {
if (obj.get()==(*itr).get()) if (obj.get()==(*itr).get())
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog<<"return "<<(*itr).get()<<"\n"; mapnik::log() << "pool: Return instance=" << (*itr).get();
#endif #endif
unusedPool_.push_back(*itr); unusedPool_.push_back(*itr);
usedPool_.erase(itr); usedPool_.erase(itr);

View file

@ -203,7 +203,7 @@ private:
template <class T> template <class T>
void copy_text_ptr(T & sym) const void copy_text_ptr(T & sym) const
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::cerr << "Warning: Deep copying TextSymbolizers is broken!\n"; std::cerr << "Warning: Deep copying TextSymbolizers is broken!\n";
#endif #endif
} }

View file

@ -24,6 +24,7 @@
#define MAPNIK_SVG_RENDERER_HPP #define MAPNIK_SVG_RENDERER_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/svg/svg_path_attributes.hpp> #include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/gradient.hpp> #include <mapnik/gradient.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
@ -141,11 +142,13 @@ public:
BOOST_FOREACH ( mapnik::stop_pair const& st, grad.get_stop_array() ) BOOST_FOREACH ( mapnik::stop_pair const& st, grad.get_stop_array() )
{ {
mapnik::color const& stop_color = st.second; mapnik::color const& stop_color = st.second;
unsigned r= stop_color.red(); unsigned r = stop_color.red();
unsigned g= stop_color.green(); unsigned g = stop_color.green();
unsigned b= stop_color.blue(); unsigned b = stop_color.blue();
unsigned a= stop_color.alpha(); unsigned a = stop_color.alpha();
//std::clog << "r: " << r << " g: " << g << " b: " << b << "a: " << a << "\n"; #ifdef MAPNIK_LOG
//mapnik::log() << "svg_renderer: r=" << r << ",g=" << g << ",b=" << b << ",a=" << a;
#endif
m_gradient_lut.add_color(st.first, agg::rgba8(r, g, b, int(a * opacity))); m_gradient_lut.add_color(st.first, agg::rgba8(r, g, b, int(a * opacity)));
} }
m_gradient_lut.build_lut(); m_gradient_lut.build_lut();

View file

@ -30,8 +30,34 @@
#include <iomanip> #include <iomanip>
#include <ctime> #include <ctime>
#ifndef WIN32
#include <sys/time.h> // for gettimeofday() on unix
#include <sys/resource.h>
#else
#include <windows.h>
#endif
namespace mapnik { namespace mapnik {
// Try to return the time now
inline double time_now()
{
#ifndef WIN32
struct timeval t;
struct timezone tzp;
gettimeofday(&t, &tzp);
return t.tv_sec + t.tv_usec * 1e-6;
#else
LARGE_INTEGER t, f;
QueryPerformanceCounter(&t);
QueryPerformanceFrequency(&f);
return double(t.QuadPart) / double(f.QuadPart);
#endif
}
// Measure times in both wall clock time and CPU times. Results are returned in milliseconds. // Measure times in both wall clock time and CPU times. Results are returned in milliseconds.
class timer class timer
{ {
@ -41,44 +67,50 @@ public:
restart(); restart();
} }
virtual ~timer()
{
}
void restart() void restart()
{ {
_stopped = false; stopped_ = false;
gettimeofday(&_wall_clock_start, NULL); wall_clock_start_ = time_now();
_cpu_start = clock(); cpu_start_ = clock();
} }
virtual void stop() const virtual void stop() const
{ {
_stopped = true; stopped_ = true;
_cpu_end = clock(); cpu_end_ = clock();
gettimeofday(&_wall_clock_end, NULL); wall_clock_end_ = time_now();
} }
double cpu_elapsed() const double cpu_elapsed() const
{ {
// return elapsed CPU time in ms // return elapsed CPU time in ms
if (!_stopped) if (! stopped_)
{
stop(); stop();
}
return ((double) (_cpu_end - _cpu_start)) / CLOCKS_PER_SEC * 1000.0; return ((double) (cpu_end_ - cpu_start_)) / CLOCKS_PER_SEC * 1000.0;
} }
double wall_clock_elapsed() const double wall_clock_elapsed() const
{ {
// return elapsed wall clock time in ms // return elapsed wall clock time in ms
if (!_stopped) if (! stopped_)
{
stop(); stop();
}
long seconds = _wall_clock_end.tv_sec - _wall_clock_start.tv_sec; return (wall_clock_end_ - wall_clock_start_) * 1000.0;
long useconds = _wall_clock_end.tv_usec - _wall_clock_start.tv_usec;
return ((seconds) * 1000 + useconds / 1000.0) + 0.5;
} }
protected: protected:
mutable timeval _wall_clock_start, _wall_clock_end; mutable double wall_clock_start_, wall_clock_end_;
mutable clock_t _cpu_start, _cpu_end; mutable clock_t cpu_start_, cpu_end_;
mutable bool _stopped; mutable bool stopped_;
}; };
// A progress_timer behaves like a timer except that the destructor displays // A progress_timer behaves like a timer except that the destructor displays
@ -86,15 +118,17 @@ protected:
class progress_timer : public timer class progress_timer : public timer
{ {
public: public:
progress_timer(std::ostream & os, std::string const& base_message): progress_timer(std::ostream & os, std::string const& base_message)
os_(os), : os_(os),
base_message_(base_message) base_message_(base_message)
{} {}
~progress_timer() ~progress_timer()
{ {
if (!_stopped) if (! stopped_)
{
stop(); stop();
}
} }
void stop() const void stop() const
@ -112,8 +146,9 @@ public:
catch (...) {} // eat any exceptions catch (...) {} // eat any exceptions
} }
void discard() { void discard()
_stopped = true; {
stopped_ = true;
} }
private: private:
@ -122,4 +157,5 @@ private:
}; };
}; };
#endif // MAPNIK_TIMER_HPP #endif // MAPNIK_TIMER_HPP

View file

@ -23,10 +23,14 @@
#ifndef MAPNIK_UTILS_HPP #ifndef MAPNIK_UTILS_HPP
#define MAPNIK_UTILS_HPP #define MAPNIK_UTILS_HPP
// boost
#ifdef MAPNIK_THREADSAFE #ifdef MAPNIK_THREADSAFE
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#endif #endif
// mapnik
#include <mapnik/debug.hpp>
// stl // stl
#include <stdexcept> #include <stdexcept>
#include <cstdlib> #include <cstdlib>
@ -86,7 +90,7 @@ public:
// Sun C++ Compiler doesn't handle `volatile` keyword same as GCC. // Sun C++ Compiler doesn't handle `volatile` keyword same as GCC.
static void destroy(T* obj) static void destroy(T* obj)
#else #else
static void destroy(volatile T* obj) static void destroy(volatile T* obj)
#endif #endif
{ {
obj->~T(); obj->~T();
@ -109,6 +113,7 @@ template <typename T,
static bool destroyed_; static bool destroyed_;
singleton(const singleton &rhs); singleton(const singleton &rhs);
singleton& operator=(const singleton&); singleton& operator=(const singleton&);
static void onDeadReference() static void onDeadReference()
{ {
throw std::runtime_error("dead reference!"); throw std::runtime_error("dead reference!");
@ -119,8 +124,9 @@ template <typename T,
CreatePolicy<T>::destroy(pInstance_); CreatePolicy<T>::destroy(pInstance_);
pInstance_ = 0; pInstance_ = 0;
destroyed_=true; destroyed_=true;
#ifdef MAPNIK_DEBUG
std::clog << " destroyed singleton \n"; #ifdef MAPNIK_LOG
mapnik::log() << "singleton: Destroyed instance";
#endif #endif
} }
@ -132,21 +138,25 @@ protected:
public: public:
static T* instance() static T* instance()
{ {
if (!pInstance_) if (! pInstance_)
{ {
#ifdef MAPNIK_THREADSAFE #ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_); mutex::scoped_lock lock(mutex_);
#endif #endif
if (!pInstance_) if (! pInstance_)
{ {
if (destroyed_) if (destroyed_)
{ {
onDeadReference(); onDeadReference();
} }
else else
{ {
pInstance_=CreatePolicy<T>::create(); pInstance_ = CreatePolicy<T>::create();
#ifdef MAPNIK_LOG
mapnik::log() << "singleton: Created instance";
#endif
// register destruction // register destruction
std::atexit(&DestroySingleton); std::atexit(&DestroySingleton);
} }

View file

@ -1,3 +1,25 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* 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
*
*****************************************************************************/
#include "csv_datasource.hpp" #include "csv_datasource.hpp"
// boost // boost
@ -9,6 +31,7 @@
#include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_operator.hpp>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/feature_layer_desc.hpp> #include <mapnik/feature_layer_desc.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -31,24 +54,26 @@ using namespace boost::spirit;
DATASOURCE_PLUGIN(csv_datasource) DATASOURCE_PLUGIN(csv_datasource)
csv_datasource::csv_datasource(parameters const& params, bool bind) csv_datasource::csv_datasource(parameters const& params, bool bind)
: datasource(params), : datasource(params),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")), desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
extent_(), extent_(),
filename_(), filename_(),
inline_string_(), inline_string_(),
file_length_(0), file_length_(0),
row_limit_(*params_.get<int>("row_limit", 0)), row_limit_(*params_.get<int>("row_limit", 0)),
features_(), features_(),
escape_(*params_.get<std::string>("escape", "")), escape_(*params_.get<std::string>("escape", "")),
separator_(*params_.get<std::string>("separator", "")), separator_(*params_.get<std::string>("separator", "")),
quote_(*params_.get<std::string>("quote", "")), quote_(*params_.get<std::string>("quote", "")),
headers_(), headers_(),
manual_headers_(boost::trim_copy(*params_.get<std::string>("headers", ""))), manual_headers_(boost::trim_copy(*params_.get<std::string>("headers", ""))),
strict_(*params_.get<mapnik::boolean>("strict", false)), strict_(*params_.get<mapnik::boolean>("strict", false)),
quiet_(*params_.get<mapnik::boolean>("quiet", false)), quiet_(*params_.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params_.get<float>("filesize_max", 20.0)), // MB filesize_max_(*params_.get<float>("filesize_max", 20.0)), // MB
ctx_(boost::make_shared<mapnik::context_type>()) ctx_(boost::make_shared<mapnik::context_type>())
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
/* TODO: /* TODO:
general: general:
- refactor parser into generic class - refactor parser into generic class
@ -197,8 +222,9 @@ void csv_datasource::parse_csv(T& stream,
if (num_tabs > num_commas) if (num_tabs > num_commas)
{ {
sep = "\t"; sep = "\t";
#ifdef MAPNIK_DEBUG
std::clog << "CSV Plugin: auto detected tab separator\n"; #ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "csv_datasource: auto detected tab separator";
#endif #endif
} }
} }
@ -208,8 +234,9 @@ void csv_datasource::parse_csv(T& stream,
if (num_pipes > num_commas) if (num_pipes > num_commas)
{ {
sep = "|"; sep = "|";
#ifdef MAPNIK_DEBUG
std::clog << "CSV Plugin: auto detected '|' separator\n"; #ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "csv_datasource: auto detected '|' separator";
#endif #endif
} }
else // semicolons else // semicolons
@ -218,8 +245,9 @@ void csv_datasource::parse_csv(T& stream,
if (num_semicolons > num_commas) if (num_semicolons > num_commas)
{ {
sep = ";"; sep = ";";
#ifdef MAPNIK_DEBUG
std::clog << "CSV Plugin: auto detected ';' separator\n"; #ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "csv_datasource: auto detected ';' separator";
#endif #endif
} }
} }
@ -237,8 +265,8 @@ void csv_datasource::parse_csv(T& stream,
std::string quo = boost::trim_copy(quote); std::string quo = boost::trim_copy(quote);
if (quo.empty()) quo = "\""; if (quo.empty()) quo = "\"";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "CSV Plugin: csv grammer: sep: '" << sep << "' quo: '" << quo << "' esc: '" << esc << "'\n"; if (log_enabled_) mapnik::log() << "csv_datasource: csv grammer: sep: '" << sep << "' quo: '" << quo << "' esc: '" << esc;
#endif #endif
boost::escaped_list_separator<char> grammer; boost::escaped_list_separator<char> grammer;
@ -404,8 +432,8 @@ void csv_datasource::parse_csv(T& stream,
{ {
if ((row_limit_ > 0) && (line_number > row_limit_)) if ((row_limit_ > 0) && (line_number > row_limit_))
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "CSV Plugin: row limit hit, exiting at feature: " << feature_count << "\n"; if (log_enabled_) mapnik::log() << "csv_datasource: row limit hit, exiting at feature: " << feature_count;
#endif #endif
break; break;
} }
@ -417,12 +445,15 @@ void csv_datasource::parse_csv(T& stream,
{ {
std::string trimmed = csv_line; std::string trimmed = csv_line;
boost::trim_if(trimmed,boost::algorithm::is_any_of("\",'\r\n")); boost::trim_if(trimmed,boost::algorithm::is_any_of("\",'\r\n"));
if (trimmed.empty()){ if (trimmed.empty())
{
++line_number; ++line_number;
continue;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "CSV Plugin: empty row encountered at line: " << line_number << "\n"; if (log_enabled_) mapnik::log() << "csv_datasource: empty row encountered at line: " << line_number;
#endif #endif
continue;
} }
} }
@ -524,7 +555,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
} }
} }
} }
@ -548,7 +580,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
} }
} }
} }
@ -585,7 +618,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
} }
} }
} }
@ -618,7 +652,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
} }
} }
} }
@ -711,7 +746,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
continue; continue;
} }
} }
@ -744,7 +780,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
continue; continue;
} }
} }
@ -795,7 +832,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
continue; continue;
} }
} }
@ -810,7 +848,8 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << ex.what() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << ex.what() << "\n";
} }
} }
catch(const std::exception & ex) catch(const std::exception & ex)
@ -825,13 +864,15 @@ void csv_datasource::parse_csv(T& stream,
} }
else else
{ {
if (!quiet_) std::clog << s.str() << "\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << s.str() << "\n";
} }
} }
} }
if (!feature_count > 0) if (!feature_count > 0)
{ {
if (!quiet_) std::clog << "CSV Plugin: could not parse any lines of data\n"; // TODO - handle this with mapnik::log
if (!quiet_) std::cerr << "CSV Plugin: could not parse any lines of data\n";
} }
} }

View file

@ -1,3 +1,25 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* 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
*
*****************************************************************************/
#ifndef MAPNIK_CSV_DATASOURCE_HPP #ifndef MAPNIK_CSV_DATASOURCE_HPP
#define MAPNIK_CSV_DATASOURCE_HPP #define MAPNIK_CSV_DATASOURCE_HPP
@ -20,11 +42,13 @@ public:
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const; void bind() const;
template <typename T> template <typename T>
void parse_csv(T& stream, void parse_csv(T& stream,
std::string const& escape, std::string const& escape,
std::string const& separator, std::string const& separator,
std::string const& quote) const; std::string const& quote) const;
private: private:
mutable mapnik::layer_descriptor desc_; mutable mapnik::layer_descriptor desc_;
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
@ -44,5 +68,4 @@ private:
mutable mapnik::context_ptr ctx_; mutable mapnik::context_ptr ctx_;
}; };
#endif // MAPNIK_CSV_DATASOURCE_HPP #endif // MAPNIK_CSV_DATASOURCE_HPP

View file

@ -25,8 +25,10 @@
#include "gdal_featureset.hpp" #include "gdal_featureset.hpp"
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
#include <mapnik/timer.hpp>
#include <gdal_version.h> #include <gdal_version.h>
@ -49,9 +51,8 @@ using mapnik::datasource_exception;
*/ */
inline GDALDataset* gdal_datasource::open_dataset() const inline GDALDataset* gdal_datasource::open_dataset() const
{ {
#ifdef MAPNIK_LOG
#ifdef MAPNIK_DEBUG if (log_enabled_) mapnik::log() << "gdal_datasource: Opening " << dataset_name_;
std::clog << "GDAL Plugin: opening: " << dataset_name_ << std::endl;
#endif #endif
GDALDataset *dataset; GDALDataset *dataset;
@ -81,8 +82,10 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
filter_factor_(*params_.get<double>("filter_factor", 0.0)), filter_factor_(*params_.get<double>("filter_factor", 0.0)),
nodata_value_(params_.get<double>("nodata")) nodata_value_(params_.get<double>("nodata"))
{ {
#ifdef MAPNIK_DEBUG log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
std::clog << "GDAL Plugin: Initializing..." << std::endl;
#ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "gdal_datasource: Initializing...";
#endif #endif
GDALAllRegister(); GDALAllRegister();
@ -110,6 +113,10 @@ void gdal_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::bind");
#endif
shared_dataset_ = *params_.get<mapnik::boolean>("shared", false); shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
band_ = *params_.get<int>("band", -1); band_ = *params_.get<int>("band", -1);
@ -124,8 +131,8 @@ void gdal_datasource::bind() const
boost::optional<std::string> bbox_s = params_.get<std::string>("bbox"); boost::optional<std::string> bbox_s = params_.get<std::string>("bbox");
if (bbox_s) if (bbox_s)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: bbox parameter=" << *bbox_s << std::endl; if (log_enabled_) mapnik::log() << "gdal_datasource: BBox Parameter=" << *bbox_s;
#endif #endif
bbox_override = extent_.from_string(*bbox_s); bbox_override = extent_.from_string(*bbox_s);
@ -149,10 +156,13 @@ void gdal_datasource::bind() const
dataset->GetGeoTransform(tr); dataset->GetGeoTransform(tr);
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: geotransform=" << tr[0] << "," << tr[1] << "," if (log_enabled_)
<< tr[2] << "," << tr[3] << "," {
<< tr[4] << "," << tr[5] << std::endl; mapnik::log() << "gdal_datasource Geotransform=" << tr[0] << "," << tr[1] << ","
<< tr[2] << "," << tr[3] << ","
<< tr[4] << "," << tr[5];
}
#endif #endif
// TODO - We should throw for true non-north up images, but the check // TODO - We should throw for true non-north up images, but the check
@ -188,9 +198,12 @@ void gdal_datasource::bind() const
GDALClose(dataset); GDALClose(dataset);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Raster Size=" << width_ << "," << height_ << std::endl; if (log_enabled_)
std::clog << "GDAL Plugin: Raster Extent=" << extent_ << std::endl; {
mapnik::log() << "gdal_datasource: Raster Size=" << width_ << "," << height_;
mapnik::log() << "gdal_datasource: Raster Extent=" << extent_;
}
#endif #endif
is_bound_ = true; is_bound_ = true;
@ -231,6 +244,10 @@ featureset_ptr gdal_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features");
#endif
gdal_query gq = q; gdal_query gq = q;
// TODO - move to boost::make_shared, but must reduce # of args to <= 9 // TODO - move to boost::make_shared, but must reduce # of args to <= 9
@ -251,6 +268,10 @@ featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "gdal_datasource::features_at_point");
#endif
gdal_query gq = pt; gdal_query gq = pt;
// TODO - move to boost::make_shared, but must reduce # of args to <= 9 // TODO - move to boost::make_shared, but must reduce # of args to <= 9

View file

@ -46,6 +46,7 @@ public:
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const; void bind() const;
private: private:
GDALDataset* open_dataset() const;
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
std::string dataset_name_; std::string dataset_name_;
mutable int band_; mutable int band_;
@ -58,8 +59,6 @@ private:
mutable bool shared_dataset_; mutable bool shared_dataset_;
double filter_factor_; double filter_factor_;
boost::optional<double> nodata_value_; boost::optional<double> nodata_value_;
inline GDALDataset* open_dataset() const;
}; };
#endif // GDAL_DATASOURCE_HPP #endif // GDAL_DATASOURCE_HPP

View file

@ -22,14 +22,15 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
#include "gdal_featureset.hpp"
#include <gdal_priv.h>
// boost // boost
#include <boost/format.hpp> #include <boost/format.hpp>
#include "gdal_featureset.hpp"
#include <gdal_priv.h>
using mapnik::query; using mapnik::query;
using mapnik::coord2d; using mapnik::coord2d;
using mapnik::box2d; using mapnik::box2d;
@ -75,8 +76,8 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
gdal_featureset::~gdal_featureset() gdal_featureset::~gdal_featureset()
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: closing dataset = " << &dataset_ << std::endl; mapnik::log() << "gdal_featureset: Closing Dataset=" << &dataset_;
#endif #endif
GDALClose(&dataset_); GDALClose(&dataset_);
@ -87,8 +88,9 @@ feature_ptr gdal_featureset::next()
if (first_) if (first_)
{ {
first_ = false; first_ = false;
#ifdef MAPNIK_DEBUG
std::clog << "GDAL Plugin: featureset, dataset = " << &dataset_ << std::endl; #ifdef MAPNIK_LOG
mapnik::log() << "gdal_featureset: Next feature in Dataset=" << &dataset_;
#endif #endif
query *q = boost::get<query>(&gquery_); query *q = boost::get<query>(&gquery_);
@ -125,7 +127,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
double dx = tr[1]; double dx = tr[1];
double dy = tr[5]; double dy = tr[5];
std::clog << "dx_: " << dx_ << " dx: " << dx << " dy_: " << dy_ << "dy: " << dy << "\n"; #ifdef MAPNIK_DEBUG
mapnik::log() << "gdal_featureset: dx_=" << dx_ << " dx=" << dx << " dy_=" << dy_ << "dy=" << dy;
#endif
*/ */
CoordTransform t(raster_width_, raster_height_, raster_extent_, 0, 0); CoordTransform t(raster_width_, raster_height_, raster_extent_, 0, 0);
@ -184,11 +188,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height); box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
intersect = t.backward(feature_raster_extent); intersect = t.backward(feature_raster_extent);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Raster extent=" << raster_extent_ << std::endl; mapnik::log() << "gdal_featureset: Raster extent=" << raster_extent_;
std::clog << "GDAL Plugin: View extent=" << intersect << std::endl; mapnik::log() << "gdal_featureset: View extent=" << intersect;
std::clog << "GDAL Plugin: Query resolution=" << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution()) << std::endl; mapnik::log() << "gdal_featureset: Query resolution=" << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution());
std::clog << boost::format("GDAL Plugin: StartX=%d StartY=%d Width=%d Height=%d") % x_off % y_off % width % height << std::endl; mapnik::log() << boost::format("gdal_featureset: StartX=%d StartY=%d Width=%d Height=%d") % x_off % y_off % width % height;
#endif #endif
if (width > 0 && height > 0) if (width > 0 && height > 0)
@ -203,8 +207,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{ {
im_width *= filter_factor_; im_width *= filter_factor_;
im_height *= filter_factor_; im_height *= filter_factor_;
#ifdef MAPNIK_DEBUG
std::clog << "GDAL Plugin: applying layer filter_factor: " << filter_factor_ << "\n"; #ifdef MAPNIK_LOG
mapnik::log() << "gdal_featureset: Applying layer filter_factor=" << filter_factor_;
#endif #endif
} }
// otherwise respect symbolizer level factor applied to query, default of 1.0 // otherwise respect symbolizer level factor applied to query, default of 1.0
@ -228,9 +233,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
mapnik::image_data_32 image(im_width, im_height); mapnik::image_data_32 image(im_width, im_height);
image.set(0xffffffff); image.set(0xffffffff);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Image Size=(" << im_width << "," << im_height << ")" << std::endl; mapnik::log() << "gdal_featureset: Image Size=(" << im_width << "," << im_height << ")";
std::clog << "GDAL Plugin: Reading band " << band_ << std::endl; mapnik::log() << "gdal_featureset: Reading band=" << band_;
#endif #endif
typedef std::vector<int,int> pallete; typedef std::vector<int,int> pallete;
@ -270,7 +275,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{ {
GDALRasterBand * band = dataset_.GetRasterBand(i + 1); GDALRasterBand * band = dataset_.GetRasterBand(i + 1);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
get_overview_meta(band); get_overview_meta(band);
#endif #endif
@ -279,68 +284,68 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{ {
case GCI_RedBand: case GCI_RedBand:
red = band; red = band;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found red band" << std::endl; mapnik::log() << "gdal_featureset: Found red band";
#endif #endif
break; break;
case GCI_GreenBand: case GCI_GreenBand:
green = band; green = band;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found green band" << std::endl; mapnik::log() << "gdal_featureset: Found green band";
#endif #endif
break; break;
case GCI_BlueBand: case GCI_BlueBand:
blue = band; blue = band;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found blue band" << std::endl; mapnik::log() << "gdal_featureset: Found blue band";
#endif #endif
break; break;
case GCI_AlphaBand: case GCI_AlphaBand:
alpha = band; alpha = band;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found alpha band" << std::endl; mapnik::log() << "gdal_featureset: Found alpha band";
#endif #endif
break; break;
case GCI_GrayIndex: case GCI_GrayIndex:
grey = band; grey = band;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found gray band" << std::endl; mapnik::log() << "gdal_featureset: Found gray band";
#endif #endif
break; break;
case GCI_PaletteIndex: case GCI_PaletteIndex:
{ {
grey = band; grey = band;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found gray band, and colortable..." << std::endl; mapnik::log() << "gdal_featureset: Found gray band, and colortable...";
#endif #endif
GDALColorTable *color_table = band->GetColorTable(); GDALColorTable *color_table = band->GetColorTable();
if (color_table) if (color_table)
{ {
int count = color_table->GetColorEntryCount(); int count = color_table->GetColorEntryCount();
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Color Table count = " << count << std::endl; mapnik::log() << "gdal_featureset: Color Table count=" << count;
#endif #endif
for (int j = 0; j < count; j++) for (int j = 0; j < count; j++)
{ {
const GDALColorEntry *ce = color_table->GetColorEntry (j); const GDALColorEntry *ce = color_table->GetColorEntry (j);
if (! ce) continue; if (! ce) continue;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Color entry RGB (" << ce->c1 << "," <<ce->c2 << "," << ce->c3 << ")" << std::endl; mapnik::log() << "gdal_featureset: Color entry RGB=" << ce->c1 << "," <<ce->c2 << "," << ce->c3;
#endif #endif
} }
} }
break; break;
} }
case GCI_Undefined: case GCI_Undefined:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Found undefined band (assumming gray band)" << std::endl; mapnik::log() << "gdal_featureset: Found undefined band (assumming gray band)";
#endif #endif
grey = band; grey = band;
break; break;
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: band type unknown!" << std::endl; mapnik::log() << "gdal_featureset: Band type unknown!";
#endif #endif
break; break;
} }
@ -348,8 +353,8 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
if (red && green && blue) if (red && green && blue)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: processing rgb bands..." << std::endl; mapnik::log() << "gdal_featureset: Processing rgb bands...";
#endif #endif
int hasNoData(0); int hasNoData(0);
double nodata(0); double nodata(0);
@ -401,8 +406,8 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
} }
else if (grey) else if (grey)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: processing gray band..." << std::endl; mapnik::log() << "gdal_featureset: Processing gray band...";
#endif #endif
int hasNoData(0); int hasNoData(0);
double nodata(0); double nodata(0);
@ -419,13 +424,10 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
if (hasNoData && ! color_table) if (hasNoData && ! color_table)
{ {
if (hasNoData) #ifdef MAPNIK_LOG
{ mapnik::log() << "gdal_featureset: No data value for layer=" << nodata;
feature->put("NODATA",nodata);
}
#ifdef MAPNIK_DEBUG
std::clog << "\tno data value for layer: " << nodata << std::endl;
#endif #endif
feature->put("NODATA",nodata);
// first read the data in and create an alpha channel from the nodata values // first read the data in and create an alpha channel from the nodata values
float* imageData = (float*)image.getBytes(); float* imageData = (float*)image.getBytes();
grey->RasterIO(GF_Read, x_off, y_off, width, height, grey->RasterIO(GF_Read, x_off, y_off, width, height,
@ -456,8 +458,8 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
if (color_table) if (color_table)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: Loading colour table..." << std::endl; mapnik::log() << "gdal_featureset: Loading colour table...";
#endif #endif
unsigned nodata_value = static_cast<unsigned>(nodata); unsigned nodata_value = static_cast<unsigned>(nodata);
if (hasNoData) if (hasNoData)
@ -496,8 +498,8 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
} }
if (alpha) if (alpha)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GDAL Plugin: processing alpha band..." << std::endl; mapnik::log() << "gdal_featureset: processing alpha band...";
#endif #endif
alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 3, alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 3,
image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
@ -533,9 +535,9 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
if (x < raster_xsize && y < raster_ysize) if (x < raster_xsize && y < raster_ysize)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << boost::format("GDAL Plugin: pt.x=%f pt.y=%f") % pt.x % pt.y << std::endl; mapnik::log() << boost::format("gdal_featureset: pt.x=%f pt.y=%f") % pt.x % pt.y;
std::clog << boost::format("GDAL Plugin: x=%f y=%f") % x % y << std::endl; mapnik::log() << boost::format("gdal_featureset: x=%f y=%f") % x % y;
#endif #endif
GDALRasterBand* band = dataset_.GetRasterBand(band_); GDALRasterBand* band = dataset_.GetRasterBand(band_);
int hasNoData; int hasNoData;
@ -558,24 +560,24 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
return feature_ptr(); return feature_ptr();
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
void gdal_featureset::get_overview_meta(GDALRasterBand* band) void gdal_featureset::get_overview_meta(GDALRasterBand* band)
{ {
int band_overviews = band->GetOverviewCount(); int band_overviews = band->GetOverviewCount();
if (band_overviews > 0) if (band_overviews > 0)
{ {
std::clog << "GDAL Plugin: "<< band_overviews << " overviews found!" << std::endl; mapnik::log() << "gdal_featureset: " << band_overviews << " overviews found!";
for (int b = 0; b < band_overviews; b++) for (int b = 0; b < band_overviews; b++)
{ {
GDALRasterBand * overview = band->GetOverview(b); GDALRasterBand * overview = band->GetOverview(b);
std::clog << boost::format("GDAL Plugin: Overview=%d Width=%d Height=%d") mapnik::log() << boost::format("gdal_featureset: Overview=%d Width=%d Height=%d")
% b % overview->GetXSize() % overview->GetYSize() << std::endl; % b % overview->GetXSize() % overview->GetYSize();
} }
} }
else else
{ {
std::clog << "GDAL Plugin: No overviews found!" << std::endl; mapnik::log() << "gdal_featureset: No overviews found!";
} }
int bsx,bsy; int bsx,bsy;
@ -583,8 +585,8 @@ void gdal_featureset::get_overview_meta(GDALRasterBand* band)
band->GetBlockSize(&bsx, &bsy); band->GetBlockSize(&bsx, &bsy);
scale = band->GetScale(); scale = band->GetScale();
std::clog << boost::format("GDAL Plugin: Block=%dx%d Scale=%f Type=%s Color=%s") % bsx % bsy % scale mapnik::log() << boost::format("gdal_featureset: Block=%dx%d Scale=%f Type=%s Color=%s") % bsx % bsy % scale
% GDALGetDataTypeName(band->GetRasterDataType()) % GDALGetDataTypeName(band->GetRasterDataType())
% GDALGetColorInterpretationName(band->GetColorInterpretation()) << std::endl; % GDALGetColorInterpretationName(band->GetColorInterpretation());
} }
#endif #endif

View file

@ -55,7 +55,7 @@ public:
private: private:
mapnik::feature_ptr get_feature(mapnik::query const& q); mapnik::feature_ptr get_feature(mapnik::query const& q);
mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p); mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
void get_overview_meta(GDALRasterBand * band); void get_overview_meta(GDALRasterBand * band);
#endif #endif
GDALDataset & dataset_; GDALDataset & dataset_;

View file

@ -30,8 +30,10 @@
#include <cstdarg> #include <cstdarg>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
#include <mapnik/timer.hpp>
// boost // boost
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -63,8 +65,10 @@ DATASOURCE_PLUGIN(geos_datasource)
void geos_notice(const char* fmt, ...) void geos_notice(const char* fmt, ...)
{ {
// TODO - handle with mapnik::log
va_list ap; va_list ap;
fprintf( stdout, "GEOS Plugin: (GEOS NOTICE) "); fprintf( stdout, "Mapnik LOG> geos_datasource: (GEOS NOTICE) ");
va_start (ap, fmt); va_start (ap, fmt);
vfprintf( stdout, fmt, ap); vfprintf( stdout, fmt, ap);
@ -74,8 +78,10 @@ void geos_notice(const char* fmt, ...)
void geos_error(const char* fmt, ...) void geos_error(const char* fmt, ...)
{ {
// TODO - handle with mapnik::log
va_list ap; va_list ap;
fprintf( stdout, "GEOS Plugin: (GEOS ERROR) "); fprintf( stdout, "Mapnik LOG> geos_datasource: (GEOS ERROR) ");
va_start (ap, fmt); va_start (ap, fmt);
vfprintf( stdout, fmt, ap); vfprintf( stdout, fmt, ap);
@ -94,6 +100,8 @@ geos_datasource::geos_datasource(parameters const& params, bool bind)
geometry_data_name_("name"), geometry_data_name_("name"),
geometry_id_(1) geometry_id_(1)
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
boost::optional<std::string> geometry = params.get<std::string>("wkt"); boost::optional<std::string> geometry = params.get<std::string>("wkt");
if (! geometry) throw datasource_exception("missing <wkt> parameter"); if (! geometry) throw datasource_exception("missing <wkt> parameter");
geometry_string_ = *geometry; geometry_string_ = *geometry;
@ -132,6 +140,10 @@ void geos_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::bind");
#endif
// open geos driver // open geos driver
initGEOS(geos_notice, geos_error); initGEOS(geos_notice, geos_error);
@ -145,8 +157,12 @@ void geos_datasource::bind() const
// try to obtain the extent from the geometry itself // try to obtain the extent from the geometry itself
if (! extent_initialized_) if (! extent_initialized_)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_STATS
std::clog << "GEOS Plugin: initializing extent from geometry" << std::endl; mapnik::progress_timer __stats2__(std::clog, "geos_datasource::bind(initialize_extent)");
#endif
#ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "geos_datasource: Initializing extent from geometry";
#endif #endif
if (GEOSGeomTypeId(*geometry_) == GEOS_POINT) if (GEOSGeomTypeId(*geometry_) == GEOS_POINT)
@ -168,10 +184,13 @@ void geos_datasource::bind() const
geos_feature_ptr envelope (GEOSEnvelope(*geometry_)); geos_feature_ptr envelope (GEOSEnvelope(*geometry_));
if (*envelope != NULL && GEOSisValid(*envelope)) if (*envelope != NULL && GEOSisValid(*envelope))
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
char* wkt = GEOSGeomToWKT(*envelope); if (log_enabled_)
std::clog << "GEOS Plugin: getting coord sequence from: " << wkt << std::endl; {
GEOSFree(wkt); char* wkt = GEOSGeomToWKT(*envelope);
mapnik::log() << "geos_datasource: Getting coord sequence from=" << wkt;
GEOSFree(wkt);
}
#endif #endif
const GEOSGeometry* exterior = GEOSGetExteriorRing(*envelope); const GEOSGeometry* exterior = GEOSGetExteriorRing(*envelope);
@ -180,8 +199,8 @@ void geos_datasource::bind() const
const GEOSCoordSequence* cs = GEOSGeom_getCoordSeq(exterior); const GEOSCoordSequence* cs = GEOSGeom_getCoordSeq(exterior);
if (cs != NULL) if (cs != NULL)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GEOS Plugin: iterating boundary points" << std::endl; if (log_enabled_) mapnik::log() << "geos_datasource: Iterating boundary points";
#endif #endif
double x, y; double x, y;
@ -242,6 +261,10 @@ boost::optional<mapnik::datasource::geometry_t> geos_datasource::get_geometry_ty
if (! is_bound_) bind(); if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result; boost::optional<mapnik::datasource::geometry_t> result;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::get_geometry_type");
#endif
// get geometry type // get geometry type
const int type = GEOSGeomTypeId(*geometry_); const int type = GEOSGeomTypeId(*geometry_);
switch (type) switch (type)
@ -280,6 +303,10 @@ featureset_ptr geos_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::features");
#endif
const mapnik::box2d<double> extent = q.get_bbox(); const mapnik::box2d<double> extent = q.get_bbox();
std::ostringstream s; std::ostringstream s;
@ -291,8 +318,8 @@ featureset_ptr geos_datasource::features(query const& q) const
<< extent.minx() << " " << extent.miny() << extent.minx() << " " << extent.miny()
<< "))"; << "))";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GEOS Plugin: using extent: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "geos_datasource: Using extent=" << s.str();
#endif #endif
return boost::make_shared<geos_featureset>(*geometry_, return boost::make_shared<geos_featureset>(*geometry_,
@ -307,11 +334,15 @@ featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "geos_datasource::features_at_point");
#endif
std::ostringstream s; std::ostringstream s;
s << "POINT(" << pt.x << " " << pt.y << ")"; s << "POINT(" << pt.x << " " << pt.y << ")";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GEOS Plugin: using point: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "geos_datasource: Using point=" << s.str();
#endif #endif
return boost::make_shared<geos_featureset>(*geometry_, return boost::make_shared<geos_featureset>(*geometry_,

View file

@ -26,6 +26,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -104,8 +105,8 @@ feature_ptr geos_featureset::next()
break; break;
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "GEOS Plugin: unknown extent geometry_type=" << type << std::endl; mapnik::log() << "geos_featureset: Unknown extent geometry_type=" << type;
#endif #endif
break; break;
} }

View file

@ -34,6 +34,7 @@
// mapnik // mapnik
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/debug.hpp>
// boost // boost
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -79,6 +80,8 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"), srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")) desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8"))
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
boost::optional<std::string> host = params_.get<std::string>("host"); boost::optional<std::string> host = params_.get<std::string>("host");
if (host) if (host)
{ {
@ -156,7 +159,9 @@ featureset_ptr kismet_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
// std::clog << "kismet_datasource::features()" << endl; #ifdef MAPNIK_LOG
// mapnik::log() << "kismet_datasource::features()";
#endif
// TODO: use box2d to filter bbox before adding to featureset_ptr // TODO: use box2d to filter bbox before adding to featureset_ptr
// mapnik::box2d<double> const& e = q.get_bbox(); // mapnik::box2d<double> const& e = q.get_bbox();
@ -174,15 +179,17 @@ featureset_ptr kismet_datasource::features_at_point(coord2d const& pt) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
// std::clog << "kismet_datasource::features_at_point()" << endl; #ifdef MAPNIK_LOG
// mapnik::log() << "kismet_datasource::features_at_point()";
#endif
return featureset_ptr(); return featureset_ptr();
} }
void kismet_datasource::run(const std::string& ip_host, const unsigned int port) void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Kismet Plugin: enter run" << std::endl; if (log_enabled_) mapnik::log() << "kismet_datasource: Enter run";
#endif #endif
int sockfd, n; int sockfd, n;
@ -219,7 +226,7 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
if (connect(sockfd, (struct sockaddr*) &sock_addr, sizeof(sock_addr))) if (connect(sockfd, (struct sockaddr*) &sock_addr, sizeof(sock_addr)))
{ {
std::cerr << "KISMET Plugin: Error while connecting" << std::endl; std::cerr << "Kismet Plugin: Error while connecting" << std::endl;
return; return;
} }
@ -227,7 +234,7 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
if (write(sockfd, command.c_str(), command.length()) != (signed)command.length()) if (write(sockfd, command.c_str(), command.length()) != (signed)command.length())
{ {
std::cerr << "KISMET Plugin: Error sending command to " << ip_host << std::endl; std::cerr << "Kismet Plugin: Error sending command to " << ip_host << std::endl;
close(sockfd); close(sockfd);
return; return;
@ -248,8 +255,8 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
buffer[n] = '\0'; buffer[n] = '\0';
std::string bufferObj(buffer); // TCP data send from kismet_server as STL string std::string bufferObj(buffer); // TCP data send from kismet_server as STL string
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Kismet Plugin: buffer_obj=" << bufferObj << "[END]" << std::endl; if (log_enabled_) mapnik::log() << "kismet_datasource: buffer_obj=" << bufferObj;
#endif #endif
std::string::size_type found = 0; std::string::size_type found = 0;
@ -262,8 +269,8 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
{ {
kismet_line.assign(bufferObj, search_start, found - search_start); kismet_line.assign(bufferObj, search_start, found - search_start);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Kismet Plugin: line=" << kismet_line << " [ENDL]" << std::endl; if (log_enabled_) mapnik::log() << "kismet_datasource: line=" << kismet_line;
#endif #endif
int param_number = 5; // the number of parameters to parse int param_number = 5; // the number of parameters to parse
@ -277,9 +284,12 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
&bestlat, &bestlat,
&bestlon) == param_number) &bestlon) == param_number)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Kismet Plugin: ssid=" << ssid << ", bssid=" << bssid if (log_enabled_)
<< ", crypt=" << crypt << ", bestlat=" << bestlat << ", bestlon=" << bestlon << std::endl; {
mapnik::log() << "kismet_datasource: ssid=" << ssid << ", bssid=" << bssid
<< ", crypt=" << crypt << ", bestlat=" << bestlat << ", bestlon=" << bestlon;
}
#endif #endif
kismet_network_data knd(ssid, bssid, bestlat, bestlon, crypt); kismet_network_data knd(ssid, bssid, bestlat, bestlon, crypt);
@ -312,8 +322,8 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
close(sockfd); close(sockfd);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Kismet Plugin: exit run" << std::endl; if (log_enabled_) mapnik::log() << "kismet_datasource: Exit run";
#endif #endif
} }

View file

@ -25,8 +25,10 @@
#include "occi_featureset.hpp" #include "occi_featureset.hpp"
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp> #include <mapnik/sql_utils.hpp>
#include <mapnik/timer.hpp>
// boost // boost
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -68,18 +70,21 @@ const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA";
DATASOURCE_PLUGIN(occi_datasource) DATASOURCE_PLUGIN(occi_datasource)
occi_datasource::occi_datasource(parameters const& params, bool bind) occi_datasource::occi_datasource(parameters const& params, bool bind)
: datasource (params), : datasource (params),
type_(datasource::Vector), type_(datasource::Vector),
fields_(*params_.get<std::string>("fields", "*")), fields_(*params_.get<std::string>("fields", "*")),
geometry_field_(*params_.get<std::string>("geometry_field", "")), geometry_field_(*params_.get<std::string>("geometry_field", "")),
srid_initialized_(false), srid_initialized_(false),
extent_initialized_(false), extent_initialized_(false),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")), desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
row_limit_(*params_.get<int>("row_limit", 0)), use_wkb_(*params_.get<mapnik::boolean>("use_wkb", false)),
row_prefetch_(*params_.get<int>("row_prefetch", 100)), row_limit_(*params_.get<int>("row_limit", 0)),
pool_(0), row_prefetch_(*params_.get<int>("row_prefetch", 100)),
conn_(0) pool_(0),
conn_(0)
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
if (! params_.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified"); if (! params_.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified");
if (! params_.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified"); if (! params_.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified");
if (! params_.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified"); if (! params_.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified");
@ -140,6 +145,10 @@ void occi_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::bind");
#endif
// connect to environment // connect to environment
if (use_connection_pool_) if (use_connection_pool_)
{ {
@ -184,6 +193,10 @@ void occi_datasource::bind() const
// get SRID and/or GEOMETRY_FIELD from metadata table only if we need to // get SRID and/or GEOMETRY_FIELD from metadata table only if we need to
if (! srid_initialized_ || geometry_field_ == "") if (! srid_initialized_ || geometry_field_ == "")
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_srid_and_geometry_field");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE"; s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE";
s << " LOWER(table_name) = LOWER('" << table_name_ << "')"; s << " LOWER(table_name) = LOWER('" << table_name_ << "')";
@ -193,8 +206,8 @@ void occi_datasource::bind() const
s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')";
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: " << s.str();
#endif #endif
try try
@ -226,11 +239,15 @@ void occi_datasource::bind() const
// get columns description // get columns description
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_column_description");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT " << fields_ << " FROM (" << table_name_ << ") WHERE rownum < 1"; s << "SELECT " << fields_ << " FROM (" << table_name_ << ") WHERE rownum < 1";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: " << s.str();
#endif #endif
try try
@ -321,16 +338,22 @@ void occi_datasource::bind() const
case oracle::occi::OCCI_SQLT_CLOB: case oracle::occi::OCCI_SQLT_CLOB:
case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_BLOB:
case oracle::occi::OCCI_SQLT_RSET: case oracle::occi::OCCI_SQLT_RSET:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: unsupported datatype " if (log_enabled_)
<< occi_enums::resolve_datatype(type_oid) {
<< " (type_oid=" << type_oid << ")" << std::endl; mapnik::log() << "occi_datasource: Unsupported datatype "
<< occi_enums::resolve_datatype(type_oid)
<< " (type_oid=" << type_oid << ")";
}
#endif #endif
break; break;
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: unknown datatype " if (log_enabled_)
<< "(type_oid=" << type_oid << ")" << std::endl; {
mapnik::log() << "occi_datasource: Unknown datatype "
<< "(type_oid=" << type_oid << ")";
}
#endif #endif
break; break;
} }
@ -368,13 +391,17 @@ box2d<double> occi_datasource::envelope() const
if (estimate_extent && *estimate_extent) if (estimate_extent && *estimate_extent)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::envelope(estimate_extent)");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT MIN(c.x), MIN(c.y), MAX(c.x), MAX(c.y) FROM "; s << "SELECT MIN(c.x), MIN(c.y), MAX(c.x), MAX(c.y) FROM ";
s << " (SELECT SDO_AGGR_MBR(" << geometry_field_ << ") shape FROM " << table_ << ") a, "; s << " (SELECT SDO_AGGR_MBR(" << geometry_field_ << ") shape FROM " << table_ << ") a, ";
s << " TABLE(SDO_UTIL.GETVERTICES(a.shape)) c"; s << " TABLE(SDO_UTIL.GETVERTICES(a.shape)) c";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: " << s.str();
#endif #endif
try try
@ -397,7 +424,7 @@ box2d<double> occi_datasource::envelope() const
} }
catch (bad_lexical_cast& ex) catch (bad_lexical_cast& ex)
{ {
std::clog << "OCCI Plugin: " << ex.what() << std::endl; std::cerr << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
} }
@ -408,6 +435,10 @@ box2d<double> occi_datasource::envelope() const
} }
else if (use_spatial_index_) else if (use_spatial_index_)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::envelope(use_spatial_index)");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT dim.sdo_lb, dim.sdo_ub FROM "; s << "SELECT dim.sdo_lb, dim.sdo_ub FROM ";
s << METADATA_TABLE << " m, TABLE(m.diminfo) dim "; s << METADATA_TABLE << " m, TABLE(m.diminfo) dim ";
@ -417,8 +448,8 @@ box2d<double> occi_datasource::envelope() const
s << METADATA_TABLE << " m, TABLE(m.diminfo) dim "; s << METADATA_TABLE << " m, TABLE(m.diminfo) dim ";
s << " WHERE LOWER(m.table_name) = LOWER('" << table_name_ << "') AND dim.sdo_dimname = 'Y'"; s << " WHERE LOWER(m.table_name) = LOWER('" << table_name_ << "') AND dim.sdo_dimname = 'Y'";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: " << s.str();
#endif #endif
try try
@ -439,7 +470,7 @@ box2d<double> occi_datasource::envelope() const
} }
catch (bad_lexical_cast& ex) catch (bad_lexical_cast& ex)
{ {
std::clog << "OCCI Plugin: " << ex.what() << std::endl; std::cerr << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
@ -452,7 +483,7 @@ box2d<double> occi_datasource::envelope() const
} }
catch (bad_lexical_cast& ex) catch (bad_lexical_cast& ex)
{ {
std::clog << "OCCI Plugin: " << ex.what() << std::endl; std::cerr << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
@ -493,15 +524,27 @@ featureset_ptr occi_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::features");
#endif
box2d<double> const& box = q.get_bbox(); box2d<double> const& box = q.get_bbox();
std::ostringstream s; std::ostringstream s;
s << "SELECT " << geometry_field_; s << "SELECT ";
if (use_wkb_)
{
s << "SDO_UTIL.TO_WKBGEOMETRY(" << geometry_field_ << ")";
}
else
{
s << geometry_field_;
}
std::set<std::string> const& props = q.property_names(); std::set<std::string> const& props = q.property_names();
std::set<std::string>::const_iterator pos = props.begin(); std::set<std::string>::const_iterator pos = props.begin();
std::set<std::string>::const_iterator end = props.end(); std::set<std::string>::const_iterator end = props.end();
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>(); mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
for ( ;pos != end;++pos) for (; pos != end; ++pos)
{ {
s << ", " << *pos; s << ", " << *pos;
ctx->push(*pos); ctx->push(*pos);
@ -532,8 +575,8 @@ featureset_ptr occi_datasource::features(query const& q) const
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: cannot determine where to add the spatial filter declaration" << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: cannot determine where to add the spatial filter declaration";
#endif #endif
} }
} }
@ -552,16 +595,16 @@ featureset_ptr occi_datasource::features(query const& q) const
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: cannot determine where to add the row limit declaration" << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: Cannot determine where to add the row limit declaration";
#endif #endif
} }
} }
s << query; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: " << s.str();
#endif #endif
return boost::make_shared<occi_featureset>(pool_, return boost::make_shared<occi_featureset>(pool_,
@ -570,6 +613,7 @@ featureset_ptr occi_datasource::features(query const& q) const
s.str(), s.str(),
desc_.get_encoding(), desc_.get_encoding(),
use_connection_pool_, use_connection_pool_,
use_wkb_,
row_prefetch_); row_prefetch_);
} }
@ -577,8 +621,20 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "occi_datasource::features_at_point");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT " << geometry_field_; s << "SELECT ";
if (use_wkb_)
{
s << "SDO_UTIL.TO_WKBGEOMETRY(" << geometry_field_ << ")";
}
else
{
s << geometry_field_;
}
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin(); std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end(); std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>(); mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
@ -613,8 +669,8 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: cannot determine where to add the spatial filter declaration" << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: Cannot determine where to add the spatial filter declaration";
#endif #endif
} }
} }
@ -633,16 +689,16 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: cannot determine where to add the row limit declaration" << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: Cannot determine where to add the row limit declaration";
#endif #endif
} }
} }
s << query; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "occi_datasource: " << s.str();
#endif #endif
return boost::make_shared<occi_featureset>(pool_, return boost::make_shared<occi_featureset>(pool_,
@ -651,5 +707,6 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
s.str(), s.str(),
desc_.get_encoding(), desc_.get_encoding(),
use_connection_pool_, use_connection_pool_,
use_wkb_,
row_prefetch_); row_prefetch_);
} }

View file

@ -50,6 +50,8 @@ public:
void bind() const; void bind() const;
private: private:
static const std::string METADATA_TABLE;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable std::string table_; mutable std::string table_;
mutable std::string table_name_; mutable std::string table_name_;
@ -60,13 +62,13 @@ private:
mutable bool extent_initialized_; mutable bool extent_initialized_;
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
mutable mapnik::layer_descriptor desc_; mutable mapnik::layer_descriptor desc_;
mutable bool use_wkb_;
int row_limit_; int row_limit_;
int row_prefetch_; int row_prefetch_;
mutable oracle::occi::StatelessConnectionPool* pool_; mutable oracle::occi::StatelessConnectionPool* pool_;
mutable oracle::occi::Connection* conn_; mutable oracle::occi::Connection* conn_;
bool use_connection_pool_; bool use_connection_pool_;
bool use_spatial_index_; bool use_spatial_index_;
static const std::string METADATA_TABLE;
}; };
#endif // OCCI_DATASOURCE_HPP #endif // OCCI_DATASOURCE_HPP

View file

@ -22,6 +22,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -61,10 +62,12 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool,
std::string const& sqlstring, std::string const& sqlstring,
std::string const& encoding, std::string const& encoding,
bool use_connection_pool, bool use_connection_pool,
bool use_wkb,
unsigned prefetch_rows) unsigned prefetch_rows)
: tr_(new transcoder(encoding)), : tr_(new transcoder(encoding)),
feature_id_(1), feature_id_(1),
ctx_(ctx) ctx_(ctx),
use_wkb_(use_wkb)
{ {
if (use_connection_pool) if (use_connection_pool)
{ {
@ -81,7 +84,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool,
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
std::clog << "OCCI Plugin: error processing " << sqlstring << " : " << ex.getMessage() << std::endl; std::cerr << "OCCI Plugin: error processing " << sqlstring << " : " << ex.getMessage() << std::endl;
} }
} }
@ -96,10 +99,31 @@ feature_ptr occi_featureset::next()
feature_ptr feature(feature_factory::create(ctx_,feature_id_)); feature_ptr feature(feature_factory::create(ctx_,feature_id_));
++feature_id_; ++feature_id_;
boost::scoped_ptr<SDOGeometry> geom(dynamic_cast<SDOGeometry*>(rs_->getObject(1))); if (use_wkb_)
if (geom.get())
{ {
convert_geometry(geom.get(), feature); Blob blob = rs_->getBlob (1);
blob.open(oracle::occi::OCCI_LOB_READONLY);
int size = blob.length();
if (buffer_.size() < size)
{
buffer_.resize(size);
}
oracle::occi::Stream* instream = blob.getStream(1,0);
instream->readBuffer(buffer_.data(), size);
blob.closeStream(instream);
blob.close();
geometry_utils::from_wkb(feature->paths(), buffer_.data(), size);
}
else
{
boost::scoped_ptr<SDOGeometry> geom(dynamic_cast<SDOGeometry*>(rs_->getObject(1)));
if (geom.get())
{
convert_geometry(geom.get(), feature);
}
} }
std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData(); std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData();
@ -180,18 +204,22 @@ feature_ptr occi_featureset::next()
case oracle::occi::OCCI_SQLT_CLOB: case oracle::occi::OCCI_SQLT_CLOB:
case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_BLOB:
case oracle::occi::OCCI_SQLT_RSET: case oracle::occi::OCCI_SQLT_RSET:
#ifdef MAPNIK_DEBUG {
std::clog << "OCCI Plugin: unsupported datatype " #ifdef MAPNIK_LOG
<< occi_enums::resolve_datatype(type_oid) mapnik::log() << "occi_featureset: Unsupported datatype "
<< " (type_oid=" << type_oid << ")" << std::endl; << occi_enums::resolve_datatype(type_oid)
<< " (type_oid=" << type_oid << ")";
#endif #endif
break; break;
}
default: // shouldn't get here default: // shouldn't get here
#ifdef MAPNIK_DEBUG {
std::clog << "OCCI Plugin: unknown datatype " #ifdef MAPNIK_LOG
<< "(type_oid=" << type_oid << ")" << std::endl; mapnik::log() << "occi_featureset: Unknown datatype "
<< "(type_oid=" << type_oid << ")";
#endif #endif
break; break;
}
} }
} }
@ -209,20 +237,6 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature)
int lrsvalue = (gtype - dimensions * 1000) / 100; int lrsvalue = (gtype - dimensions * 1000) / 100;
int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100); int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100);
#if 0
std::clog << "-----------Geometry Object ------------" << std::endl;
std::clog << "SDO GTYPE = " << gtype << std::endl;
std::clog << "SDO DIMENSIONS = " << dimensions << std::endl;
std::clog << "SDO LRS = " << lrsvalue << std::endl;
std::clog << "SDO GEOMETRY TYPE = " << geomtype << std::endl;
Number sdo_srid = geom->getSdo_srid();
if (sdo_srid.isNull())
std::clog << "SDO SRID = " << "Null" << std::endl;
else
std::clog << "SDO SRID = " << (int)sdo_srid << std::endl;
#endif
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); const std::vector<Number>& elem_info = geom->getSdo_elem_info();
const std::vector<Number>& ordinates = geom->getSdo_ordinates(); const std::vector<Number>& ordinates = geom->getSdo_ordinates();
const int ordinates_size = (int)ordinates.size(); const int ordinates_size = (int)ordinates.size();
@ -344,12 +358,14 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature)
break; break;
case SDO_GTYPE_UNKNOWN: case SDO_GTYPE_UNKNOWN:
default: default:
#ifdef MAPNIK_DEBUG {
std::clog << "OCCI Plugin: unknown <occi> " #ifdef MAPNIK_LOG
<< occi_enums::resolve_gtype(geomtype) mapnik::log() << "occi_featureset: Unknown oracle enum "
<< "(gtype=" << gtype << ")" << std::endl; << occi_enums::resolve_gtype(geomtype)
<< "(gtype=" << gtype << ")";
#endif #endif
break; }
break;
} }
} }

View file

@ -35,6 +35,8 @@
// oci // oci
#include "occi_types.hpp" #include "occi_types.hpp"
#include <vector>
class occi_featureset : public mapnik::Featureset class occi_featureset : public mapnik::Featureset
{ {
public: public:
@ -44,6 +46,7 @@ public:
std::string const& sqlstring, std::string const& sqlstring,
std::string const& encoding, std::string const& encoding,
bool use_connection_pool, bool use_connection_pool,
bool use_wkb,
unsigned prefetch_rows); unsigned prefetch_rows);
virtual ~occi_featureset(); virtual ~occi_featureset();
mapnik::feature_ptr next(); mapnik::feature_ptr next();
@ -70,6 +73,8 @@ private:
const char* fidcolumn_; const char* fidcolumn_;
mutable int feature_id_; mutable int feature_id_;
mapnik::context_ptr ctx_; mapnik::context_ptr ctx_;
bool use_wkb_;
std::vector<char> buffer_;
}; };
#endif // OCCI_FEATURESET_HPP #endif // OCCI_FEATURESET_HPP

View file

@ -24,6 +24,7 @@
#define OCCI_TYPES_HPP #define OCCI_TYPES_HPP
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/utils.hpp> #include <mapnik/utils.hpp>
// occi // occi
@ -87,8 +88,8 @@ public:
{ {
if (env_ == 0) if (env_ == 0)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: occi_environment constructor" << std::endl; mapnik::log() << "occi_environment: constructor";
#endif #endif
const int mode = oracle::occi::Environment::OBJECT const int mode = oracle::occi::Environment::OBJECT
@ -111,8 +112,8 @@ private:
{ {
if (env_) if (env_)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OCCI Plugin: occi_environment destructor" << std::endl; mapnik::log() << "occi_environment: destructor";
#endif #endif
oracle::occi::Environment::terminateEnvironment(env_); oracle::occi::Environment::terminateEnvironment(env_);

View file

@ -22,6 +22,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
@ -68,10 +69,12 @@ void ogr_converter::convert_geometry(OGRGeometry* geom, feature_ptr feature)
case wkbNone: case wkbNone:
case wkbUnknown: case wkbUnknown:
default: default:
#ifdef MAPNIK_DEBUG {
std::clog << "OGR Plugin: unknown <ogr> geometry_type=" #ifdef MAPNIK_LOG
<< wkbFlatten(geom->getGeometryType()) << std::endl; mapnik::log() << "ogr_converter: unknown <ogr> geometry_type="
<< wkbFlatten(geom->getGeometryType());
#endif #endif
}
break; break;
} }
} }

View file

@ -33,8 +33,10 @@
#include <gdal_version.h> #include <gdal_version.h>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
#include <mapnik/timer.hpp>
// boost // boost
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -63,6 +65,8 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")), desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
indexed_(false) indexed_(false)
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
boost::optional<std::string> file = params.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
boost::optional<std::string> string = params.get<std::string>("string"); boost::optional<std::string> string = params.get<std::string>("string");
if (! file && ! string) if (! file && ! string)
@ -108,6 +112,10 @@ void ogr_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::bind");
#endif
// initialize ogr formats // initialize ogr formats
OGRRegisterAll(); OGRRegisterAll();
@ -182,6 +190,10 @@ void ogr_datasource::bind() const
} }
else if (layer_by_sql) else if (layer_by_sql)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats_sql__(std::clog, "ogr_datasource::bind(layer_by_sql)");
#endif
layer_.layer_by_sql(dataset_, *layer_by_sql); layer_.layer_by_sql(dataset_, *layer_by_sql);
layer_name_ = layer_.layer_name(); layer_name_ = layer_.layer_name();
} }
@ -259,15 +271,23 @@ void ogr_datasource::bind() const
indexed_ = true; indexed_ = true;
index_file.close(); index_file.close();
} }
#ifdef MAPNIK_LOG
#if 0 #if 0
// TODO - enable this warning once the ogrindex tool is a bit more stable/mature // TODO - enable this warning once the ogrindex tool is a bit more stable/mature
else else
{ {
std::clog << "### Notice: no ogrindex file found for " << dataset_name_ if (log_enabled_)
<< ", use the 'ogrindex' program to build an index for faster rendering" {
<< std::endl; mapnik::log() << "ogr_datasource: no ogrindex file found for " << dataset_name_
<< ", use the 'ogrindex' program to build an index for faster rendering";
}
} }
#endif #endif
#endif // MAPNIK_LOG
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "ogr_datasource::bind(get_column_description)");
#endif
// deal with attributes descriptions // deal with attributes descriptions
OGRFeatureDefn* def = layer->GetLayerDefn(); OGRFeatureDefn* def = layer->GetLayerDefn();
@ -304,16 +324,16 @@ void ogr_datasource::bind() const
case OFTRealList: case OFTRealList:
case OFTStringList: case OFTStringList:
case OFTWideStringList: // deprecated ! case OFTWideStringList: // deprecated !
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; if (log_enabled_) mapnik::log() << "ogr_datasource: Unhandled type_oid=" << type_oid;
#endif #endif
break; break;
case OFTDate: case OFTDate:
case OFTTime: case OFTTime:
case OFTDateTime: // unhandled ! case OFTDateTime: // unhandled !
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; if (log_enabled_) mapnik::log() << "ogr_datasource: Unhandled type_oid=" << type_oid;
#endif #endif
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object)); desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object));
break; break;
@ -350,7 +370,7 @@ boost::optional<mapnik::datasource::geometry_t> ogr_datasource::get_geometry_typ
#if GDAL_VERSION_NUM < 1800 #if GDAL_VERSION_NUM < 1800
switch (wkbFlatten(layer->GetLayerDefn()->GetGeomType())) switch (wkbFlatten(layer->GetLayerDefn()->GetGeomType()))
#else #else
switch (wkbFlatten(layer->GetGeomType())) switch (wkbFlatten(layer->GetGeomType()))
#endif #endif
{ {
case wkbPoint: case wkbPoint:
@ -464,6 +484,10 @@ featureset_ptr ogr_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features");
#endif
if (dataset_ && layer_.is_valid()) if (dataset_ && layer_.is_valid())
{ {
// First we validate query fields: https://github.com/mapnik/mapnik/issues/792 // First we validate query fields: https://github.com/mapnik/mapnik/issues/792
@ -511,6 +535,10 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
{ {
if (!is_bound_) bind(); if (!is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "ogr_datasource::features_at_point");
#endif
if (dataset_ && layer_.is_valid()) if (dataset_ && layer_.is_valid())
{ {
std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors(); std::vector<attribute_descriptor> const& desc_ar = desc_.get_descriptors();
@ -532,8 +560,7 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
*layer, *layer,
filter, filter,
index_name_, index_name_,
desc_.get_encoding() desc_.get_encoding()));
));
} }
else else
{ {
@ -545,8 +572,7 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
*dataset_, *dataset_,
*layer, *layer,
point, point,
desc_.get_encoding() desc_.get_encoding()));
));
} }
} }

View file

@ -22,6 +22,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -102,11 +103,10 @@ feature_ptr ogr_featureset::next()
{ {
ogr_converter::convert_geometry(geom, feature); ogr_converter::convert_geometry(geom, feature);
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
else else
{ {
std::clog << "OGR Plugin: feature with null geometry: " mapnik::log() << "ogr_featureset: Feature with null geometry=" << (*feat)->GetFID();
<< (*feat)->GetFID() << std::endl;
} }
#endif #endif
++count_; ++count_;
@ -145,16 +145,16 @@ feature_ptr ogr_featureset::next()
case OFTStringList: case OFTStringList:
case OFTWideStringList: // deprecated ! case OFTWideStringList: // deprecated !
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_featureset: Unhandled type_oid=" << type_oid;
#endif #endif
break; break;
} }
case OFTBinary: case OFTBinary:
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_featureset: Unhandled type_oid=" << type_oid;
#endif #endif
//feature->put(name,feat->GetFieldAsBinary (i, size)); //feature->put(name,feat->GetFieldAsBinary (i, size));
break; break;
@ -164,16 +164,16 @@ feature_ptr ogr_featureset::next()
case OFTTime: case OFTTime:
case OFTDateTime: // unhandled ! case OFTDateTime: // unhandled !
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_featureset: Unhandled type_oid=" << type_oid;
#endif #endif
break; break;
} }
default: // unknown default: // unknown
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_featureset: Unknown type_oid=" << type_oid;
#endif #endif
break; break;
} }
@ -182,8 +182,9 @@ feature_ptr ogr_featureset::next()
return feature; return feature;
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: " << count_ << " features" << std::endl; mapnik::log() << "ogr_featureset: " << count_ << " features";
#endif #endif
return feature_ptr(); return feature_ptr();
} }

View file

@ -23,6 +23,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -76,8 +77,8 @@ ogr_index_featureset<filterT>::ogr_index_featureset(mapnik::context_ptr const &
std::sort(ids_.begin(),ids_.end()); std::sort(ids_.begin(),ids_.end());
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: query size=" << ids_.size() << std::endl; mapnik::log() << "ogr_index_featureset: Query size=" << ids_.size();
#endif #endif
itr_ = ids_.begin(); itr_ = ids_.begin();
@ -110,10 +111,10 @@ feature_ptr ogr_index_featureset<filterT>::next()
{ {
ogr_converter::convert_geometry (geom, feature); ogr_converter::convert_geometry (geom, feature);
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
else else
{ {
std::clog << "### Warning: feature with null geometry: " << (*feat)->GetFID() << "\n"; mapnik::log() << "ogr_index_featureset: Feature with null geometry=" << (*feat)->GetFID();
} }
#endif #endif
@ -151,16 +152,16 @@ feature_ptr ogr_index_featureset<filterT>::next()
case OFTStringList: case OFTStringList:
case OFTWideStringList: // deprecated ! case OFTWideStringList: // deprecated !
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_index_featureset: Unhandled type_oid=" << type_oid;
#endif #endif
break; break;
} }
case OFTBinary: case OFTBinary:
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_index_featureset: Unhandled type_oid=" << type_oid;
#endif #endif
//feature->put(name,feat->GetFieldAsBinary (i, size)); //feature->put(name,feat->GetFieldAsBinary (i, size));
break; break;
@ -170,8 +171,8 @@ feature_ptr ogr_index_featureset<filterT>::next()
case OFTTime: case OFTTime:
case OFTDateTime: // unhandled ! case OFTDateTime: // unhandled !
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; mapnik::log() << "ogr_index_featureset: Unhandled type_oid=" << type_oid;
#endif #endif
break; break;
} }
@ -186,4 +187,3 @@ feature_ptr ogr_index_featureset<filterT>::next()
template class ogr_index_featureset<mapnik::filter_in_box>; template class ogr_index_featureset<mapnik::filter_in_box>;
template class ogr_index_featureset<mapnik::filter_at_point>; template class ogr_index_featureset<mapnik::filter_at_point>;

View file

@ -23,6 +23,9 @@
#ifndef OGR_LAYER_PTR_HPP #ifndef OGR_LAYER_PTR_HPP
#define OGR_LAYER_PTR_HPP #define OGR_LAYER_PTR_HPP
// mapnik
#include <mapnik/debug.hpp>
// stl // stl
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -75,12 +78,12 @@ public:
layer_ = ogr_layer; layer_ = ogr_layer;
is_valid_ = true; is_valid_ = true;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: layer_from_name layer is " << layer_name_ << std::endl; mapnik::log() << "ogr_layer_ptr: layer_from_name layer=" << layer_name_;
#endif #endif
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
debug_print_last_error(); debug_print_last_error();
#endif #endif
} }
@ -102,13 +105,13 @@ public:
layer_name_ = def->GetName(); layer_name_ = def->GetName();
is_valid_ = true; is_valid_ = true;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: layer_from_index layer is " << layer_name_ << std::endl; mapnik::log() << "ogr_layer_ptr: layer_from_index layer=" << layer_name_;
#endif #endif
} }
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
debug_print_last_error(); debug_print_last_error();
#endif #endif
} }
@ -138,13 +141,13 @@ public:
layer_name_ = def->GetName(); layer_name_ = def->GetName();
is_valid_ = true; is_valid_ = true;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "OGR Plugin: layer_from_sql layer is " << layer_name_ << std::endl; mapnik::log() << "ogr_layer_ptr: layer_from_sql layer=" << layer_name_;
#endif #endif
} }
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
debug_print_last_error(); debug_print_last_error();
#endif #endif
} }
@ -166,7 +169,7 @@ public:
private: private:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
void debug_print_last_error() void debug_print_last_error()
{ {
if (! is_valid_) if (! is_valid_)
@ -174,11 +177,11 @@ private:
const std::string err = CPLGetLastErrorMsg(); const std::string err = CPLGetLastErrorMsg();
if (err.size() == 0) if (err.size() == 0)
{ {
std::clog << "OGR Plugin: error getting layer" << std::endl; mapnik::log() << "ogr_layer_ptr: Error getting layer";
} }
else else
{ {
std::clog << "OGR Plugin: " << err << std::endl; mapnik::log() << "ogr_layer_ptr: " << err;
} }
} }
} }

View file

@ -20,11 +20,18 @@
* *
*****************************************************************************/ *****************************************************************************/
// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
// boost
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
// std
#include <sstream>
#include "dataset_deliverer.h" #include "dataset_deliverer.h"
#include "basiccurl.h" #include "basiccurl.h"
#include <sstream>
osm_dataset * dataset_deliverer::dataset = NULL; osm_dataset * dataset_deliverer::dataset = NULL;
std::string dataset_deliverer::last_bbox = ""; std::string dataset_deliverer::last_bbox = "";
@ -76,8 +83,8 @@ osm_dataset* dataset_deliverer::load_from_url(const string& url, const string& b
} }
else if (bbox != last_bbox) else if (bbox != last_bbox)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::cerr << "Osm Plugin: BBOXES ARE DIFFERENT: " << last_bbox << "," << bbox << std::endl; mapnik::log() << "osm_dataset_deliverer: BBoxes are different=" << last_bbox << "," << bbox;
#endif #endif
// Reload the dataset // Reload the dataset

View file

@ -24,6 +24,8 @@
#include "osmparser.h" #include "osmparser.h"
#include "basiccurl.h" #include "basiccurl.h"
#include <mapnik/debug.hpp>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -47,8 +49,8 @@ bool osm_dataset::load_from_url(const std::string& url,
{ {
if (parser == "libxml2") if (parser == "libxml2")
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: osm_dataset::load_from_url url=" << url << " bbox=" << bbox << std::endl; mapnik::log() << "osm_dataset: load_from_url url=" << url << ",bbox=" << bbox;
#endif #endif
std::ostringstream str; std::ostringstream str;
@ -57,8 +59,8 @@ bool osm_dataset::load_from_url(const std::string& url,
str << url << "?bbox=" << bbox; str << url << "?bbox=" << bbox;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: FULL URL " << str.str() << std::endl; mapnik::log() << "osm_dataset: Full url=" << str.str();
#endif #endif
CURL_LOAD_DATA* resp = grab_http_response(str.str().c_str()); CURL_LOAD_DATA* resp = grab_http_response(str.str().c_str());
@ -69,8 +71,8 @@ bool osm_dataset::load_from_url(const std::string& url,
memcpy(blx, resp->data, resp->nbytes); memcpy(blx, resp->data, resp->nbytes);
blx[resp->nbytes] = '\0'; blx[resp->nbytes] = '\0';
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: CURL RESPONSE: " << blx << std::endl; mapnik::log() << "osm_dataset: CURL Response=" << blx;
#endif #endif
delete[] blx; delete[] blx;
@ -88,36 +90,32 @@ osm_dataset::~osm_dataset()
void osm_dataset::clear() void osm_dataset::clear()
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: osm_dataset::clear()" << std::endl; mapnik::log() << "osm_dataset: Clear";
std::clog << "Osm Plugin: deleting ways" << std::endl;
#endif #endif
#ifdef MAPNIK_LOG
mapnik::log() << "osm_dataset: -- Deleting ways";
#endif
for (unsigned int count = 0; count < ways.size(); ++count) for (unsigned int count = 0; count < ways.size(); ++count)
{ {
delete ways[count]; delete ways[count];
ways[count] = NULL; ways[count] = NULL;
} }
ways.clear();
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: deleting nodes" << std::endl; mapnik::log() << "osm_dataset: -- Deleting nodes";
#endif #endif
for (unsigned int count = 0; count < nodes.size(); ++count) for (unsigned int count = 0; count < nodes.size(); ++count)
{ {
delete nodes[count]; delete nodes[count];
nodes[count] = NULL; nodes[count] = NULL;
} }
#ifdef MAPNIK_DEBUG
std::clog << "Osm Plugin: clearing ways/nodes" << std::endl;
#endif
ways.clear();
nodes.clear(); nodes.clear();
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: done" << std::endl; mapnik::log() << "osm_dataset: Clear done";
#endif #endif
} }

View file

@ -28,8 +28,10 @@
#include <set> #include <set>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
#include <mapnik/query.hpp> #include <mapnik/query.hpp>
#include <mapnik/boolean.hpp>
// boost // boost
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
@ -51,11 +53,13 @@ using mapnik::attribute_descriptor;
DATASOURCE_PLUGIN(osm_datasource) DATASOURCE_PLUGIN(osm_datasource)
osm_datasource::osm_datasource(const parameters& params, bool bind) osm_datasource::osm_datasource(const parameters& params, bool bind)
: datasource (params), : datasource (params),
extent_(), extent_(),
type_(datasource::Vector), type_(datasource::Vector),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")) desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8"))
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
if (bind) if (bind)
{ {
this->bind(); this->bind();
@ -77,9 +81,10 @@ void osm_datasource::bind() const
if (url != "" && bbox != "") if (url != "" && bbox != "")
{ {
// if we supplied a url and a bounding box, load from the url // if we supplied a url and a bounding box, load from the url
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Osm Plugin: loading_from_url: url=" << url << " bbox=" << bbox << std::endl; if (log_enabled_) mapnik::log() << "osm_datasource: loading_from_url url=" << url << ",bbox=" << bbox;
#endif #endif
if ((osm_data_ = dataset_deliverer::load_from_url(url, bbox, parser)) == NULL) if ((osm_data_ = dataset_deliverer::load_from_url(url, bbox, parser)) == NULL)
{ {
throw datasource_exception("Error loading from URL"); throw datasource_exception("Error loading from URL");
@ -94,7 +99,9 @@ void osm_datasource::bind() const
s << "OSM Plugin: Error loading from file '" << osm_filename << "'"; s << "OSM Plugin: Error loading from file '" << osm_filename << "'";
throw datasource_exception(s.str()); throw datasource_exception(s.str());
} }
} else { }
else
{
throw datasource_exception("OSM Plugin: Neither 'file' nor 'url' and 'bbox' specified"); throw datasource_exception("OSM Plugin: Neither 'file' nor 'url' and 'bbox' specified");
} }

View file

@ -43,21 +43,19 @@ public:
osm_datasource(const parameters& params, bool bind = true); osm_datasource(const parameters& params, bool bind = true);
virtual ~osm_datasource(); virtual ~osm_datasource();
mapnik::datasource::datasource_t type() const; mapnik::datasource::datasource_t type() const;
static std::string name();
featureset_ptr features(const query& q) const; featureset_ptr features(const query& q) const;
featureset_ptr features_at_point(coord2d const& pt) const; featureset_ptr features_at_point(coord2d const& pt) const;
box2d<double> envelope() const; box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const; layer_descriptor get_descriptor() const;
static std::string name();
void bind() const; void bind() const;
private: private:
mutable box2d<double> extent_; mutable box2d<double> extent_;
mutable osm_dataset* osm_data_; mutable osm_dataset* osm_data_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
mutable layer_descriptor desc_; mutable layer_descriptor desc_;
// no copying
osm_datasource(const osm_datasource&);
osm_datasource& operator=(const osm_datasource&);
}; };
#endif // OSM_DATASOURCE_HPP #endif // OSM_DATASOURCE_HPP

View file

@ -20,10 +20,15 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef CONNECTION_HPP #ifndef POSTGIS_CONNECTION_HPP
#define CONNECTION_HPP #define POSTGIS_CONNECTION_HPP
// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/timer.hpp>
// boost
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
// std // std
@ -38,14 +43,10 @@ extern "C" {
class Connection class Connection
{ {
private:
PGconn *conn_;
int cursorId;
bool closed_;
public: public:
Connection(std::string const& connection_str) Connection(std::string const& connection_str)
:cursorId(0), : cursorId(0),
closed_(false) closed_(false)
{ {
conn_ = PQconnectdb(connection_str.c_str()); conn_ = PQconnectdb(connection_str.c_str());
if (PQstatus(conn_) != CONNECTION_OK) if (PQstatus(conn_) != CONNECTION_OK)
@ -54,10 +55,10 @@ public:
s << "Postgis Plugin: "; s << "Postgis Plugin: ";
if (conn_ ) if (conn_ )
{ {
std::string msg = PQerrorMessage( conn_ ); std::string msg = PQerrorMessage(conn_);
if ( ! msg.empty() ) if (! msg.empty())
{ {
s << msg.substr( 0, msg.size() - 1 ); s << msg.substr(0, msg.size() - 1);
} }
else else
{ {
@ -69,39 +70,62 @@ public:
s << "unable to connect to postgres server"; s << "unable to connect to postgres server";
} }
s << "\n" << connection_str; s << "\n" << connection_str;
throw mapnik::datasource_exception( s.str() );
throw mapnik::datasource_exception(s.str());
}
}
~Connection()
{
if (! closed_)
{
PQfinish(conn_);
#ifdef MAPNIK_LOG
mapnik::log() << "postgis_connection: postgresql connection closed - " << conn_;
#endif
closed_ = true;
} }
} }
bool execute(const std::string& sql) const bool execute(const std::string& sql) const
{ {
PGresult *result = PQexec(conn_,sql.c_str()); #ifdef MAPNIK_STATS
bool ok=(result && (PQresultStatus(result) == PGRES_COMMAND_OK)); mapnik::progress_timer __stats__(std::clog, std::string("postgis_connection::execute ") + sql);
#endif
PGresult *result = PQexec(conn_, sql.c_str());
bool ok = (result && (PQresultStatus(result) == PGRES_COMMAND_OK));
PQclear(result); PQclear(result);
return ok; return ok;
} }
boost::shared_ptr<ResultSet> executeQuery(const std::string& sql,int type=0) const boost::shared_ptr<ResultSet> executeQuery(const std::string& sql, int type = 0) const
{ {
PGresult *result=0; #ifdef MAPNIK_STATS
if (type==1) mapnik::progress_timer __stats__(std::clog, std::string("postgis_connection::execute_query ") + sql);
#endif
PGresult* result = 0;
if (type == 1)
{ {
result = PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1); result = PQexecParams(conn_,sql.c_str(), 0, 0, 0, 0, 0, 1);
} }
else else
{ {
result = PQexec(conn_,sql.c_str()); result = PQexec(conn_, sql.c_str());
} }
if(!result || (PQresultStatus(result) != PGRES_TUPLES_OK))
if (! result || (PQresultStatus(result) != PGRES_TUPLES_OK))
{ {
std::ostringstream s; std::ostringstream s;
s << "Postgis Plugin: PSQL error"; s << "Postgis Plugin: PSQL error";
if (conn_ ) if (conn_)
{ {
std::string msg = PQerrorMessage( conn_ ); std::string msg = PQerrorMessage(conn_);
if ( ! msg.empty() ) if (! msg.empty())
{ {
s << ":\n" << msg.substr( 0, msg.size() - 1 ); s << ":\n" << msg.substr(0, msg.size() - 1);
} }
s << "\nFull sql was: '" << sql << "'\n"; s << "\nFull sql was: '" << sql << "'\n";
@ -110,9 +134,13 @@ public:
{ {
s << "unable to connect to database"; s << "unable to connect to database";
} }
if (result) if (result)
{
PQclear(result); PQclear(result);
throw mapnik::datasource_exception( s.str() ); }
throw mapnik::datasource_exception(s.str());
} }
return boost::make_shared<ResultSet>(result); return boost::make_shared<ResultSet>(result);
@ -120,7 +148,7 @@ public:
std::string client_encoding() const std::string client_encoding() const
{ {
return PQparameterStatus(conn_,"client_encoding"); return PQparameterStatus(conn_, "client_encoding");
} }
bool isOK() const bool isOK() const
@ -130,11 +158,12 @@ public:
void close() void close()
{ {
if (!closed_) if (! closed_)
{ {
PQfinish(conn_); PQfinish(conn_);
#ifdef MAPNIK_DEBUG
std::clog << "PostGIS: datasource closed, also closing connection - " << conn_ << std::endl; #ifdef MAPNIK_LOG
mapnik::log() << "postgis_connection: datasource closed, also closing connection - " << conn_;
#endif #endif
closed_ = true; closed_ = true;
} }
@ -147,17 +176,10 @@ public:
return s.str(); return s.str();
} }
~Connection() private:
{ PGconn *conn_;
if (!closed_) int cursorId;
{ bool closed_;
PQfinish(conn_);
#ifdef MAPNIK_DEBUG
std::clog << "PostGIS: postgresql connection closed - " << conn_ << std::endl;
#endif
closed_ = true;
}
}
}; };
#endif //CONNECTION_HPP #endif //CONNECTION_HPP

View file

@ -20,23 +20,28 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef CONNECTION_MANAGER_HPP #ifndef POSTGIS_CONNECTION_MANAGER_HPP
#define CONNECTION_MANAGER_HPP #define POSTGIS_CONNECTION_MANAGER_HPP
#include <string> #include "connection.hpp"
#include <sstream>
// mapnik
#include <mapnik/pool.hpp> #include <mapnik/pool.hpp>
#include <mapnik/utils.hpp> #include <mapnik/utils.hpp>
#include "connection.hpp"
// boost
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#ifdef MAPNIK_THREADSAFE #ifdef MAPNIK_THREADSAFE
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
//using boost::mutex; //using boost::mutex;
#endif #endif
// stl
#include <string>
#include <sstream>
using mapnik::Pool; using mapnik::Pool;
using mapnik::singleton; using mapnik::singleton;
using mapnik::CreateStatic; using mapnik::CreateStatic;
@ -150,4 +155,4 @@ private:
ConnectionManager& operator=(const ConnectionManager); ConnectionManager& operator=(const ConnectionManager);
}; };
#endif //CONNECTION_MANAGER_HPP #endif // POSTGIS_CONNECTION_MANAGER_HPP

View file

@ -1,33 +1,35 @@
#ifndef CURSORRESULTSET_HPP /*****************************************************************************
#define CURSORRESULTSET_HPP *
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* 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
*
*****************************************************************************/
#ifndef POSTGIS_CURSORRESULTSET_HPP
#define POSTGIS_CURSORRESULTSET_HPP
#include <mapnik/debug.hpp>
#include "connection.hpp" #include "connection.hpp"
#include "resultset.hpp" #include "resultset.hpp"
class CursorResultSet : public IResultSet class CursorResultSet : public IResultSet
{ {
private:
boost::shared_ptr<Connection> conn_;
std::string cursorName_;
boost::shared_ptr<ResultSet> rs_;
int fetch_size_;
bool is_closed_;
int *refCount_;
void getNextResultSet()
{
std::ostringstream s;
s << "FETCH FORWARD " << fetch_size_ << " FROM " << cursorName_;
#ifdef MAPNIK_DEBUG
std::clog << "Postgis Plugin: " << s.str() << std::endl;
#endif
rs_ = conn_->executeQuery(s.str());
is_closed_ = false;
#ifdef MAPNIK_DEBUG
std::clog << "Postgis Plugin: FETCH result (" << cursorName_ << "): " << rs_->size() << " rows" << std::endl;
#endif
}
public: public:
CursorResultSet(boost::shared_ptr<Connection> const &conn, std::string cursorName, int fetch_count) CursorResultSet(boost::shared_ptr<Connection> const &conn, std::string cursorName, int fetch_count)
: conn_(conn), : conn_(conn),
@ -50,6 +52,15 @@ public:
(*refCount_)++; (*refCount_)++;
} }
virtual ~CursorResultSet()
{
if (--(*refCount_)==0)
{
close();
delete refCount_,refCount_=0;
}
}
CursorResultSet& operator=(const CursorResultSet& rhs) CursorResultSet& operator=(const CursorResultSet& rhs)
{ {
if (this==&rhs) return *this; if (this==&rhs) return *this;
@ -73,25 +84,18 @@ public:
if (!is_closed_) if (!is_closed_)
{ {
rs_.reset(); rs_.reset();
std::ostringstream s; std::ostringstream s;
s << "CLOSE " << cursorName_; s << "CLOSE " << cursorName_;
#ifdef MAPNIK_DEBUG
std::clog << "Postgis Plugin: " << s.str() << std::endl; #ifdef MAPNIK_LOG
mapnik::log() << "postgis_cursor_resultset: " << s.str();
#endif #endif
conn_->execute(s.str()); conn_->execute(s.str());
is_closed_ = true; is_closed_ = true;
} }
} }
virtual ~CursorResultSet()
{
if (--(*refCount_)==0)
{
close();
delete refCount_,refCount_=0;
}
}
virtual int getNumFields() const virtual int getNumFields() const
{ {
return rs_->getNumFields(); return rs_->getNumFields();
@ -148,6 +152,30 @@ public:
{ {
return rs_->getValue(name); return rs_->getValue(name);
} }
private:
void getNextResultSet()
{
std::ostringstream s;
s << "FETCH FORWARD " << fetch_size_ << " FROM " << cursorName_;
#ifdef MAPNIK_LOG
mapnik::log() << "postgis_cursor_resultset: " << s.str();
#endif
rs_ = conn_->executeQuery(s.str());
is_closed_ = false;
#ifdef MAPNIK_LOG
mapnik::log() << "postgis_cursor_resultset: FETCH result (" << cursorName_ << "): " << rs_->size() << " rows";
#endif
}
boost::shared_ptr<Connection> conn_;
std::string cursorName_;
boost::shared_ptr<ResultSet> rs_;
int fetch_size_;
bool is_closed_;
int *refCount_;
}; };
#endif //CURSORRESULTSET_HPP #endif // POSTGIS_CURSORRESULTSET_HPP

View file

@ -25,10 +25,12 @@
#include "postgis_featureset.hpp" #include "postgis_featureset.hpp"
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp> #include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp> #include <mapnik/util/conversions.hpp>
#include <mapnik/timer.hpp>
// boost // boost
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -79,8 +81,9 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
// params below are for testing purposes only (will likely be removed at any time) // params below are for testing purposes only (will likely be removed at any time)
intersect_min_scale_(*params_.get<int>("intersect_min_scale", 0)), intersect_min_scale_(*params_.get<int>("intersect_min_scale", 0)),
intersect_max_scale_(*params_.get<int>("intersect_max_scale", 0)) intersect_max_scale_(*params_.get<int>("intersect_max_scale", 0))
//show_queries_(*params_.get<mapnik::boolean>("show_queries",false))
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
if (table_.empty()) if (table_.empty())
{ {
throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter"); throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
@ -105,6 +108,10 @@ void postgis_datasource::bind() const
return; return;
} }
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::bind");
#endif
boost::optional<int> initial_size = params_.get<int>("initial_size", 1); boost::optional<int> initial_size = params_.get<int>("initial_size", 1);
boost::optional<int> max_size = params_.get<int>("max_size", 10); boost::optional<int> max_size = params_.get<int>("max_size", 10);
boost::optional<mapnik::boolean> autodetect_key_field = params_.get<mapnik::boolean>("autodetect_key_field", false); boost::optional<mapnik::boolean> autodetect_key_field = params_.get<mapnik::boolean>("autodetect_key_field", false);
@ -148,6 +155,10 @@ void postgis_datasource::bind() const
geometryColumn_ = geometry_field_; geometryColumn_ = geometry_field_;
if (geometryColumn_.empty() || srid_ == 0) if (geometryColumn_.empty() || srid_ == 0)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "postgis_datasource::bind(get_srid_and_geometry_column)");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT f_geometry_column, srid FROM " s << "SELECT f_geometry_column, srid FROM "
<< GEOMETRY_COLUMNS <<" WHERE f_table_name='" << GEOMETRY_COLUMNS <<" WHERE f_table_name='"
@ -168,13 +179,6 @@ void postgis_datasource::bind() const
<< "'"; << "'";
} }
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
}
*/
shared_ptr<ResultSet> rs = conn->executeQuery(s.str()); shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
if (rs->next()) if (rs->next())
{ {
@ -205,13 +209,6 @@ void postgis_datasource::bind() const
s << "SELECT ST_SRID(\"" << geometryColumn_ << "\") AS srid FROM " s << "SELECT ST_SRID(\"" << geometryColumn_ << "\") AS srid FROM "
<< populate_tokens(table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT NULL LIMIT 1;"; << populate_tokens(table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT NULL LIMIT 1;";
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
}
*/
shared_ptr<ResultSet> rs = conn->executeQuery(s.str()); shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
if (rs->next()) if (rs->next())
{ {
@ -232,6 +229,10 @@ void postgis_datasource::bind() const
// detect primary key // detect primary key
if (*autodetect_key_field && key_field_.empty()) if (*autodetect_key_field && key_field_.empty())
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "postgis_datasource::bind(get_primary_key)");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT a.attname, a.attnum, t.typname, t.typname in ('int2','int4','int8') " s << "SELECT a.attname, a.attnum, t.typname, t.typname in ('int2','int4','int8') "
"AS is_int FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n, pg_index i " "AS is_int FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n, pg_index i "
@ -267,9 +268,11 @@ void postgis_datasource::bind() const
{ {
key_field_ = std::string(key_field_string); key_field_ = std::string(key_field_string);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "PostGIS Plugin: auto-detected key field of '" if (log_enabled_)
<< key_field_ << "' on table '" {
<< geometry_table_ << "'\n"; mapnik::log() << "postgis_datasource: auto-detected key field of '"
<< key_field_ << "' on table '" << geometry_table_ << "'";
}
#endif #endif
} }
} }
@ -310,31 +313,29 @@ void postgis_datasource::bind() const
{ {
srid_ = -1; srid_ = -1;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Postgis Plugin: SRID warning, using srid=-1 for '" << table_ << "'" << std::endl; if (log_enabled_) mapnik::log() << "postgis_datasource: Table " << table_ << " is using SRID=-1";
#endif #endif
} }
// At this point the geometry_field may still not be known // At this point the geometry_field may still not be known
// but we'll catch that where more useful... // but we'll catch that where more useful...
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Postgis Plugin: using SRID=" << srid_ << std::endl; if (log_enabled_)
std::clog << "Postgis Plugin: using geometry_column=" << geometryColumn_ << std::endl; {
mapnik::log() << "postgis_datasource: Using SRID=" << srid_;
mapnik::log() << "postgis_datasource: Using geometry_column=" << geometryColumn_;
}
#endif #endif
// collect attribute desc // collect attribute desc
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "postgis_datasource::bind(get_column_description)");
#endif
std::ostringstream s; std::ostringstream s;
s << "SELECT * FROM " << populate_tokens(table_) << " LIMIT 0"; s << "SELECT * FROM " << populate_tokens(table_) << " LIMIT 0";
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
}
*/
shared_ptr<ResultSet> rs = conn->executeQuery(s.str()); shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
int count = rs->getNumFields(); int count = rs->getNumFields();
bool found_key_field = false; bool found_key_field = false;
@ -400,28 +401,24 @@ void postgis_datasource::bind() const
desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String));
break; break;
default: // should not get here default: // should not get here
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
s.str(""); if (log_enabled_)
s << "SELECT oid, typname FROM pg_type WHERE oid = " << type_oid;
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
}
*/
shared_ptr<ResultSet> rs_oid = conn->executeQuery(s.str());
if (rs_oid->next())
{ {
std::clog << "Postgis Plugin: unknown type = " << rs_oid->getValue("typname") s.str("");
<< " (oid:" << rs_oid->getValue("oid") << ")" << std::endl; s << "SELECT oid, typname FROM pg_type WHERE oid = " << type_oid;
shared_ptr<ResultSet> rs_oid = conn->executeQuery(s.str());
if (rs_oid->next())
{
mapnik::log() << "postgis_datasource: Unknown type=" << rs_oid->getValue("typname")
<< " (oid:" << rs_oid->getValue("oid") << ")";
}
else
{
mapnik::log() << "postgis_datasource: Unknown type_oid=" << type_oid;
}
rs_oid->close();
} }
else
{
std::clog << "Postgis Plugin: unknown oid type =" << type_oid << std::endl;
}
rs_oid->close();
#endif #endif
break; break;
} }
@ -435,6 +432,23 @@ void postgis_datasource::bind() const
} }
} }
postgis_datasource::~postgis_datasource()
{
if (is_bound_ && ! persist_connection_)
{
ConnectionManager* mgr = ConnectionManager::instance();
shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
if (conn)
{
conn->close();
}
}
}
}
std::string postgis_datasource::name() std::string postgis_datasource::name()
{ {
return "postgis"; return "postgis";
@ -547,13 +561,6 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
csql << "DECLARE " << cursor_name << " BINARY INSENSITIVE NO SCROLL CURSOR WITH HOLD FOR " << sql << " FOR READ ONLY"; csql << "DECLARE " << cursor_name << " BINARY INSENSITIVE NO SCROLL CURSOR WITH HOLD FOR " << sql << " FOR READ ONLY";
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % csql.str();
}
*/
if (! conn->execute(csql.str())) if (! conn->execute(csql.str()))
{ {
// TODO - better error // TODO - better error
@ -567,13 +574,6 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
{ {
// no cursor // no cursor
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % sql;
}
*/
return conn->executeQuery(sql, 1); return conn->executeQuery(sql, 1);
} }
} }
@ -585,6 +585,10 @@ featureset_ptr postgis_datasource::features(const query& q) const
bind(); bind();
} }
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features");
#endif
box2d<double> const& box = q.get_bbox(); box2d<double> const& box = q.get_bbox();
double scale_denom = q.scale_denominator(); double scale_denom = q.scale_denominator();
@ -678,6 +682,10 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
bind(); bind();
} }
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features_at_point");
#endif
ConnectionManager* mgr = ConnectionManager::instance(); ConnectionManager* mgr = ConnectionManager::instance();
shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id()); shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
if (pool) if (pool)
@ -836,13 +844,6 @@ box2d<double> postgis_datasource::envelope() const
} }
} }
/*
if (show_queries_)
{
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
}
*/
shared_ptr<ResultSet> rs = conn->executeQuery(s.str()); shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
if (rs->next() && ! rs->isNull(0)) if (rs->next() && ! rs->isNull(0))
{ {
@ -857,7 +858,9 @@ box2d<double> postgis_datasource::envelope() const
} }
else else
{ {
std::clog << boost::format("Postgis Plugin: warning: could not determine extent from query: %s\n") % s.str() << std::endl; #ifdef MAPNIK_LOG
mapnik::log() << boost::format("Mapnik LOG> postgis_datasource: Could not determine extent from query: %s") % s.str();
#endif
} }
} }
rs->close(); rs->close();
@ -990,20 +993,3 @@ boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry
return result; return result;
} }
postgis_datasource::~postgis_datasource()
{
if (is_bound_ && ! persist_connection_)
{
ConnectionManager* mgr = ConnectionManager::instance();
shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
if (conn)
{
conn->close();
}
}
}
}

View file

@ -20,8 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
//$Id: postgis.hpp 44 2005-04-22 18:53:54Z pavlenko $
#ifndef POSTGIS_DATASOURCE_HPP #ifndef POSTGIS_DATASOURCE_HPP
#define POSTGIS_DATASOURCE_HPP #define POSTGIS_DATASOURCE_HPP
@ -67,12 +65,11 @@ private:
std::string populate_tokens(const std::string& sql) const; std::string populate_tokens(const std::string& sql) const;
static std::string unquote(const std::string& sql); static std::string unquote(const std::string& sql);
boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, std::string const& sql) const; boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, std::string const& sql) const;
postgis_datasource(const postgis_datasource&);
postgis_datasource& operator=(const postgis_datasource&);
static const std::string GEOMETRY_COLUMNS; static const std::string GEOMETRY_COLUMNS;
static const std::string SPATIAL_REF_SYS; static const std::string SPATIAL_REF_SYS;
static const double FMAX; static const double FMAX;
const std::string uri_; const std::string uri_;
const std::string username_; const std::string username_;
const std::string password_; const std::string password_;
@ -100,4 +97,4 @@ private:
//bool show_queries_; //bool show_queries_;
}; };
#endif //POSTGIS_DATASOURCE_HPP #endif // POSTGIS_DATASOURCE_HPP

View file

@ -26,6 +26,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/wkb.hpp> #include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
#include <mapnik/sql_utils.hpp> #include <mapnik/sql_utils.hpp>
@ -197,8 +198,8 @@ feature_ptr postgis_featureset::next()
default: default:
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Postgis Plugin: uknown OID = " << oid << std::endl; mapnik::log() << "postgis_featureset: Uknown type_oid=" << oid;
#endif #endif
break; break;
} }

View file

@ -20,8 +20,8 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef RESULTSET_HPP #ifndef POSTGIS_RESULTSET_HPP
#define RESULTSET_HPP #define POSTGIS_RESULTSET_HPP
extern "C" { extern "C" {
#include "libpq-fe.h" #include "libpq-fe.h"
@ -187,4 +187,4 @@ private:
int *refCount_; int *refCount_;
}; };
#endif //RESULTSET_HPP #endif // POSTGIS_RESULTSET_HPP

View file

@ -26,7 +26,9 @@
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/image_reader.hpp> #include <mapnik/image_reader.hpp>
#include <mapnik/boolean.hpp>
#include "raster_featureset.hpp" #include "raster_featureset.hpp"
#include "raster_info.hpp" #include "raster_info.hpp"
@ -46,12 +48,14 @@ using mapnik::image_reader;
DATASOURCE_PLUGIN(raster_datasource) DATASOURCE_PLUGIN(raster_datasource)
raster_datasource::raster_datasource(const parameters& params, bool bind) raster_datasource::raster_datasource(const parameters& params, bool bind)
: datasource(params), : datasource(params),
desc_(*params.get<std::string>("type"), "utf-8"), desc_(*params.get<std::string>("type"), "utf-8"),
extent_initialized_(false) extent_initialized_(false)
{ {
#ifdef MAPNIK_DEBUG log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
std::clog << "Raster Plugin: Initializing..." << std::endl;
#ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "raster_datasource: Initializing...";
#endif #endif
boost::optional<std::string> file = params.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
@ -148,8 +152,8 @@ void raster_datasource::bind() const
} }
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: RASTER SIZE(" << width_ << "," << height_ << ")" << std::endl; if (log_enabled_) mapnik::log() << "raster_datasource: Raster size=" << width_ << "," << height_;
#endif #endif
is_bound_ = true; is_bound_ = true;
@ -195,14 +199,14 @@ featureset_ptr raster_datasource::features(query const& q) const
const int width = int(ext.maxx() + 0.5) - int(ext.minx() + 0.5); const int width = int(ext.maxx() + 0.5) - int(ext.minx() + 0.5);
const int height = int(ext.maxy() + 0.5) - int(ext.miny() + 0.5); const int height = int(ext.maxy() + 0.5) - int(ext.miny() + 0.5);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: BOX SIZE(" << width << " " << height << ")" << std::endl; if (log_enabled_) mapnik::log() << "raster_datasource: Box size=" << width << "," << height;
#endif #endif
if (multi_tiles_) if (multi_tiles_)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: MULTI-TILED policy" << std::endl; if (log_enabled_) mapnik::log() << "raster_datasource: Multi-Tiled policy";
#endif #endif
tiled_multi_file_policy policy(filename_, format_, tile_size_, extent_, q.get_bbox(), width_, height_, tile_stride_); tiled_multi_file_policy policy(filename_, format_, tile_size_, extent_, q.get_bbox(), width_, height_, tile_stride_);
@ -211,8 +215,8 @@ featureset_ptr raster_datasource::features(query const& q) const
} }
else if (width * height > 512*512) else if (width * height > 512*512)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: TILED policy" << std::endl; if (log_enabled_) mapnik::log() << "raster_datasource: Tiled policy";
#endif #endif
tiled_file_policy policy(filename_, format_, 256, extent_, q.get_bbox(), width_, height_); tiled_file_policy policy(filename_, format_, 256, extent_, q.get_bbox(), width_, height_);
@ -221,8 +225,8 @@ featureset_ptr raster_datasource::features(query const& q) const
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: SINGLE FILE" << std::endl; if (log_enabled_) mapnik::log() << "raster_datasource: Single file";
#endif #endif
raster_info info(filename_, format_, extent_, width_, height_); raster_info info(filename_, format_, extent_, width_, height_);
@ -234,8 +238,8 @@ featureset_ptr raster_datasource::features(query const& q) const
featureset_ptr raster_datasource::features_at_point(coord2d const&) const featureset_ptr raster_datasource::features_at_point(coord2d const&) const
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: feature_at_point not supported for raster.input" << std::endl; if (log_enabled_) mapnik::log() << "raster_datasource: feature_at_point not supported";
#endif #endif
return featureset_ptr(); return featureset_ptr();

View file

@ -40,7 +40,9 @@ public:
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
bool log_enabled() const;
void bind() const; void bind() const;
private: private:
mapnik::layer_descriptor desc_; mapnik::layer_descriptor desc_;
std::string filename_; std::string filename_;
@ -52,9 +54,6 @@ private:
unsigned tile_stride_; unsigned tile_stride_;
mutable unsigned width_; mutable unsigned width_;
mutable unsigned height_; mutable unsigned height_;
//no copying
raster_datasource(const raster_datasource&);
raster_datasource& operator=(const raster_datasource&);
}; };
#endif // RASTER_DATASOURCE_HPP #endif // RASTER_DATASOURCE_HPP

View file

@ -21,6 +21,7 @@
*****************************************************************************/ *****************************************************************************/
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/image_reader.hpp> #include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
@ -69,9 +70,9 @@ feature_ptr raster_featureset<LookupPolicy>::next()
{ {
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(curIter_->file(),curIter_->format())); std::auto_ptr<image_reader> reader(mapnik::get_image_reader(curIter_->file(),curIter_->format()));
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file() mapnik::log() << "raster_featureset: Reader=" << curIter_->format() << "," << curIter_->file()
<< " size(" << curIter_->width() << "," << curIter_->height() << ")" << std::endl; << ",size(" << curIter_->width() << "," << curIter_->height() << ")";
#endif #endif
if (reader.get()) if (reader.get())

View file

@ -26,6 +26,9 @@
#include "raster_datasource.hpp" #include "raster_datasource.hpp"
#include "raster_info.hpp" #include "raster_info.hpp"
// mapnik
#include <mapnik/debug.hpp>
// stl // stl
#include <vector> #include <vector>
@ -137,8 +140,8 @@ public:
double pixel_x = extent.width() / double(width); double pixel_x = extent.width() / double(width);
double pixel_y = extent.height() / double(height); double pixel_y = extent.height() / double(height);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl; mapnik::log() << "tiled_file_policy: Raster Plugin PIXEL SIZE("<< pixel_x << "," << pixel_y << ")";
#endif #endif
box2d<double> e = bbox.intersect(extent); box2d<double> e = bbox.intersect(extent);
@ -160,8 +163,9 @@ public:
} }
} }
} }
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl; #ifdef MAPNIK_LOG
mapnik::log() << "tiled_file_policy: Raster Plugin INFO SIZE=" << infos_.size() << " " << file;
#endif #endif
} }
@ -223,8 +227,8 @@ public:
double pixel_x = extent.width() / double(width); double pixel_x = extent.width() / double(width);
double pixel_y = extent.height() / double(height); double pixel_y = extent.height() / double(height);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl; mapnik::log() << "tiled_multi_file_policy: Raster Plugin PIXEL SIZE(" << pixel_x << "," << pixel_y << ")";
#endif #endif
// intersection of query with extent => new query // intersection of query with extent => new query
@ -256,8 +260,9 @@ public:
} }
} }
} }
#ifdef MAPNIK_DEBUG
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file_pattern << std::endl; #ifdef MAPNIK_LOG
mapnik::log() << "tiled_multi_file_policy: Raster Plugin INFO SIZE=" << infos_.size() << " " << file_pattern;
#endif #endif
} }

View file

@ -29,6 +29,7 @@
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
@ -45,7 +46,6 @@ using mapnik::layer_descriptor;
using mapnik::datasource_exception; using mapnik::datasource_exception;
/* /*
* Opens a GDALDataset and returns a pointer to it. * Opens a GDALDataset and returns a pointer to it.
* Caller is responsible for calling GDALClose on it * Caller is responsible for calling GDALClose on it
@ -74,8 +74,10 @@ rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind
: datasource(params), : datasource(params),
desc_(*params.get<std::string>("type"),"utf-8") desc_(*params.get<std::string>("type"),"utf-8")
{ {
#ifdef MAPNIK_DEBUG log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
std::clog << "Rasterlite Plugin: Initializing..." << std::endl;
#ifdef MAPNIK_LOG
if (log_enabled_) mapnik::log() << "rasterlite_datasource: Initializing...";
#endif #endif
boost::optional<std::string> file = params.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
@ -118,40 +120,43 @@ void rasterlite_datasource::bind() const
extent_.init(x0,y0,x1,y1); extent_.init(x0,y0,x1,y1);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
int srid, auth_srid; if (log_enabled_)
const char *auth_name;
const char *ref_sys_name;
const char *proj4text;
int tile_count;
double pixel_x_size, pixel_y_size;
int levels = rasterliteGetLevels (dataset);
if (rasterliteGetSrid(dataset, &srid, &auth_name, &auth_srid, &ref_sys_name, &proj4text) != RASTERLITE_OK)
{ {
std::string error (rasterliteGetLastError(dataset)); int srid, auth_srid;
const char *auth_name;
const char *ref_sys_name;
const char *proj4text;
rasterliteClose (dataset); int tile_count;
double pixel_x_size, pixel_y_size;
int levels = rasterliteGetLevels (dataset);
throw datasource_exception(error); if (rasterliteGetSrid(dataset, &srid, &auth_name, &auth_srid, &ref_sys_name, &proj4text) != RASTERLITE_OK)
}
std::clog << "Rasterlite Plugin: Data Source=" << rasterliteGetTablePrefix(dataset) << std::endl;
std::clog << "Rasterlite Plugin: SRID=" << srid << std::endl;
std::clog << "Rasterlite Plugin: Authority=" << auth_name << std::endl;
std::clog << "Rasterlite Plugin: AuthSRID=" << auth_srid << std::endl;
std::clog << "Rasterlite Plugin: RefSys Name=" << ref_sys_name << std::endl;
std::clog << "Rasterlite Plugin: Proj4Text=" << proj4text << std::endl;
std::clog << "Rasterlite Plugin: Extent(" << x0 << "," << y0 << " " << x1 << "," << y1 << ")" << std::endl;
std::clog << "Rasterlite Plugin: Levels=" << levels << std::endl;
for (int i = 0; i < levels; i++)
{
if (rasterliteGetResolution(dataset, i, &pixel_x_size, &pixel_y_size, &tile_count) == RASTERLITE_OK)
{ {
std::clog << "Rasterlite Plugin: Level=" << i std::string error (rasterliteGetLastError(dataset));
<< " x=" << pixel_x_size << " y=" << pixel_y_size << " tiles=" << tile_count << std::endl;
rasterliteClose (dataset);
throw datasource_exception(error);
}
mapnik::log() << "rasterlite_datasource: Data Source=" << rasterliteGetTablePrefix(dataset);
mapnik::log() << "rasterlite_datasource: SRID=" << srid;
mapnik::log() << "rasterlite_datasource: Authority=" << auth_name;
mapnik::log() << "rasterlite_datasource: AuthSRID=" << auth_srid;
mapnik::log() << "rasterlite_datasource: RefSys Name=" << ref_sys_name;
mapnik::log() << "rasterlite_datasource: Proj4Text=" << proj4text;
mapnik::log() << "rasterlite_datasource: Extent=" << x0 << "," << y0 << " " << x1 << "," << y1 << ")";
mapnik::log() << "rasterlite_datasource: Levels=" << levels;
for (int i = 0; i < levels; i++)
{
if (rasterliteGetResolution(dataset, i, &pixel_x_size, &pixel_y_size, &tile_count) == RASTERLITE_OK)
{
mapnik::log() << "rasterlite_datasource: Level=" << i
<< " x=" << pixel_x_size << " y=" << pixel_y_size << " tiles=" << tile_count;
}
} }
} }
#endif #endif

View file

@ -46,7 +46,8 @@ public:
void bind() const; void bind() const;
private: private:
inline void* open_dataset() const; void* open_dataset() const;
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
std::string dataset_name_; std::string dataset_name_;
std::string table_name_; std::string table_name_;

View file

@ -23,6 +23,7 @@
#include "rasterlite_featureset.hpp" #include "rasterlite_featureset.hpp"
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
@ -53,8 +54,8 @@ rasterlite_featureset::rasterlite_featureset(void* dataset, rasterlite_query q)
rasterlite_featureset::~rasterlite_featureset() rasterlite_featureset::~rasterlite_featureset()
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Rasterlite Plugin: closing dataset" << std::endl; mapnik::log() << "rasterlite_featureset: Closing";
#endif #endif
rasterliteClose(dataset_); rasterliteClose(dataset_);
@ -86,8 +87,8 @@ feature_ptr rasterlite_featureset::next()
feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q) feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Rasterlite Plugin: get_feature" << std::endl; mapnik::log() << "rasterlite_featureset: Running get_feature";
#endif #endif
feature_ptr feature(feature_factory::create(ctx_,1)); feature_ptr feature(feature_factory::create(ctx_,1));
@ -104,14 +105,13 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
const double pixel_size = (intersect.width() >= intersect.height()) ? const double pixel_size = (intersect.width() >= intersect.height()) ?
(intersect.width() / (double) width) : (intersect.height() / (double) height); (intersect.width() / (double) width) : (intersect.height() / (double) height);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Rasterlite Plugin: Raster extent=" << raster_extent << std::endl; mapnik::log() << "rasterlite_featureset: Raster extent=" << raster_extent;
std::clog << "Rasterlite Plugin: View extent=" << q.get_bbox() << std::endl; mapnik::log() << "rasterlite_featureset: View extent=" << q.get_bbox();
std::clog << "Rasterlite Plugin: Intersect extent=" << intersect << std::endl; mapnik::log() << "rasterlite_featureset: Intersect extent=" << intersect;
std::clog << "Rasterlite Plugin: Query resolution=" mapnik::log() << "rasterlite_featureset: Query resolution=" << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution());
<< boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution()) << std::endl; mapnik::log() << "rasterlite_featureset: Size=" << width << " " << height;
std::clog << "Rasterlite Plugin: Size=" << width << " " << height << std::endl; mapnik::log() << "rasterlite_featureset: Pixel Size=" << pixel_size;
std::clog << "Rasterlite Plugin: Pixel Size=" << pixel_size << std::endl;
#endif #endif
if (width > 0 && height > 0) if (width > 0 && height > 0)
@ -145,15 +145,13 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
free (raster); free (raster);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Rasterlite Plugin: done" << std::endl; mapnik::log() << "rasterlite_featureset: Done";
#endif #endif
} }
else else
{ {
#ifdef MAPNIK_DEBUG std::cerr << "Rasterlite Plugin: Error " << rasterliteGetLastError (dataset_) << std::endl;
std::clog << "Rasterlite Plugin: error=" << rasterliteGetLastError (dataset_) << std::endl;
#endif
} }
} }

View file

@ -20,8 +20,9 @@
* *
*****************************************************************************/ *****************************************************************************/
// mapnik #include "shape_datasource.hpp"
#include <mapnik/geom_util.hpp> #include "shape_featureset.hpp"
#include "shape_index_featureset.hpp"
// boost // boost
#include <boost/version.hpp> #include <boost/version.hpp>
@ -30,15 +31,20 @@
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/global.hpp>
#include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/geom_util.hpp>
#include <mapnik/timer.hpp>
// stl // stl
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <stdexcept> #include <stdexcept>
#include "shape_datasource.hpp"
#include "shape_featureset.hpp"
#include "shape_index_featureset.hpp"
DATASOURCE_PLUGIN(shape_datasource) DATASOURCE_PLUGIN(shape_datasource)
using mapnik::String; using mapnik::String;
@ -57,6 +63,8 @@ shape_datasource::shape_datasource(const parameters &params, bool bind)
row_limit_(*params_.get<int>("row_limit",0)), row_limit_(*params_.get<int>("row_limit",0)),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")) desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8"))
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
boost::optional<std::string> file = params.get<std::string>("file"); boost::optional<std::string> file = params.get<std::string>("file");
if (!file) throw datasource_exception("Shape Plugin: missing <file> parameter"); if (!file) throw datasource_exception("Shape Plugin: missing <file> parameter");
@ -78,6 +86,10 @@ void shape_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::bind");
#endif
if (!boost::filesystem::exists(shape_name_ + ".shp")) if (!boost::filesystem::exists(shape_name_ + ".shp"))
{ {
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist"); throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist");
@ -96,6 +108,10 @@ void shape_datasource::bind() const
try try
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "shape_datasource::bind(get_column_description)");
#endif
boost::shared_ptr<shape_io> shape_ref = boost::make_shared<shape_io>(shape_name_); boost::shared_ptr<shape_io> shape_ref = boost::make_shared<shape_io>(shape_name_);
init(*shape_ref); init(*shape_ref);
for (int i=0;i<shape_ref->dbf().num_fields();++i) for (int i=0;i<shape_ref->dbf().num_fields();++i)
@ -126,11 +142,11 @@ void shape_datasource::bind() const
break; break;
} }
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
// I - long // I - long
// G - ole // G - ole
// + - autoincrement // + - autoincrement
std::clog << "Shape Plugin: unknown type " << fd.type_ << std::endl; if (log_enabled_) mapnik::log() << "shape_datasource: Unknown type=" << fd.type_;
#endif #endif
break; break;
} }
@ -143,17 +159,17 @@ void shape_datasource::bind() const
} }
catch (const datasource_exception& ex) catch (const datasource_exception& ex)
{ {
std::clog << "Shape Plugin: error processing field attributes, " << ex.what() << std::endl; std::cerr << "Shape Plugin: error processing field attributes, " << ex.what() << std::endl;
throw; throw;
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {
std::clog << "Shape Plugin: error processing field attributes, " << ex.what() << std::endl; std::cerr << "Shape Plugin: error processing field attributes, " << ex.what() << std::endl;
throw; throw;
} }
catch (...) // exception: pipe_select_interrupter: Too many open files catch (...) // exception: pipe_select_interrupter: Too many open files
{ {
std::clog << "Shape Plugin: error processing field attributes" << std::endl; std::cerr << "Shape Plugin: error processing field attributes" << std::endl;
throw; throw;
} }
@ -162,8 +178,12 @@ void shape_datasource::bind() const
shape_datasource::~shape_datasource() {} shape_datasource::~shape_datasource() {}
void shape_datasource::init(shape_io& shape) const void shape_datasource::init(shape_io& shape) const
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::init");
#endif
//first read header from *.shp //first read header from *.shp
int file_code=shape.shp().read_xdr_integer(); int file_code=shape.shp().read_xdr_integer();
if (file_code!=9994) if (file_code!=9994)
@ -188,14 +208,17 @@ void shape_datasource::init(shape_io& shape) const
shape.shp().read_envelope(extent_); shape.shp().read_envelope(extent_);
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
double zmin = shape.shp().read_double(); if (log_enabled_)
double zmax = shape.shp().read_double(); {
double mmin = shape.shp().read_double(); double zmin = shape.shp().read_double();
double mmax = shape.shp().read_double(); double zmax = shape.shp().read_double();
double mmin = shape.shp().read_double();
double mmax = shape.shp().read_double();
std::clog << "Shape Plugin: Z min/max " << zmin << "," << zmax << std::endl; mapnik::log() << "shape_datasource: Z min/max=" << zmin << "," << zmax;
std::clog << "Shape Plugin: M min/max " << mmin << "," << mmax << "\n"; mapnik::log() << "shape_datasource: M min/max=" << mmin << "," << mmax;
}
#else #else
shape.shp().skip(4*8); shape.shp().skip(4*8);
#endif #endif
@ -213,13 +236,19 @@ void shape_datasource::init(shape_io& shape) const
//} //}
//else //else
//{ //{
// std::clog << "### Notice: no .index file found for " + shape_name_ + ".shp, use the 'shapeindex' program to build an index for faster rendering\n"; // #ifdef MAPNIK_LOG
// mapnik::log() << "shape_datasource: No .index file found for "
// << shape_name_ << ".shp, use the 'shapeindex' program to build an index for faster rendering";
// #endif
//} //}
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Shape Plugin: extent=" << extent_ << std::endl; if (log_enabled_)
std::clog << "Shape Plugin: file_length=" << file_length_ << std::endl; {
std::clog << "Shape Plugin: shape_type=" << shape_type_ << std::endl; mapnik::log() << "shape_datasource: Extent=" << extent_;
mapnik::log() << "shape_datasource: File length=" << file_length_;
mapnik::log() << "shape_datasource: Shape type=" << shape_type_;
}
#endif #endif
} }
@ -244,6 +273,10 @@ featureset_ptr shape_datasource::features(const query& q) const
{ {
if (!is_bound_) bind(); if (!is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features");
#endif
filter_in_box filter(q.get_bbox()); filter_in_box filter(q.get_bbox());
if (indexed_) if (indexed_)
{ {
@ -272,6 +305,10 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
{ {
if (!is_bound_) bind(); if (!is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::features_at_point");
#endif
filter_at_point filter(pt); filter_at_point filter(pt);
// collect all attribute names // collect all attribute names
std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors(); std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors();
@ -317,6 +354,10 @@ box2d<double> shape_datasource::envelope() const
boost::optional<mapnik::datasource::geometry_t> shape_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> shape_datasource::get_geometry_type() const
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "shape_datasource::get_geometry_type");
#endif
boost::optional<mapnik::datasource::geometry_t> result; boost::optional<mapnik::datasource::geometry_t> result;
switch (shape_type_) switch (shape_type_)
{ {

View file

@ -44,7 +44,6 @@ class shape_datasource : public datasource
public: public:
shape_datasource(const parameters &params, bool bind=true); shape_datasource(const parameters &params, bool bind=true);
virtual ~shape_datasource(); virtual ~shape_datasource();
datasource::datasource_t type() const; datasource::datasource_t type() const;
static std::string name(); static std::string name();
featureset_ptr features(const query& q) const; featureset_ptr features(const query& q) const;
@ -53,11 +52,10 @@ public:
boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const; boost::optional<mapnik::datasource::geometry_t> get_geometry_type() const;
layer_descriptor get_descriptor() const; layer_descriptor get_descriptor() const;
void bind() const; void bind() const;
private: private:
shape_datasource(const shape_datasource&);
shape_datasource& operator=(const shape_datasource&);
void init(shape_io& shape) const; void init(shape_io& shape) const;
private:
datasource::datasource_t type_; datasource::datasource_t type_;
std::string shape_name_; std::string shape_name_;
mutable boost::shared_ptr<shape_io> shape_; mutable boost::shared_ptr<shape_io> shape_;

View file

@ -24,6 +24,7 @@
#include <iostream> #include <iostream>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
#include "shape_featureset.hpp" #include "shape_featureset.hpp"
@ -145,8 +146,8 @@ feature_ptr shape_featureset<filterT>::next()
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Shape Plugin: total shapes read=" << count_ << std::endl; mapnik::log() << "shape_featureset: Total shapes read=" << count_;
#endif #endif
return feature_ptr(); return feature_ptr();
} }
@ -247,7 +248,7 @@ feature_ptr shape_featureset<filterT>::next()
} }
catch (...) catch (...)
{ {
std::clog << "Shape Plugin: error processing attributes " << std::endl; std::cerr << "Shape Plugin: error processing attributes " << std::endl;
} }
} }
@ -255,8 +256,8 @@ feature_ptr shape_featureset<filterT>::next()
} }
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Shape Plugin: total shapes read=" << count_ << std::endl; mapnik::log() << "shape_featureset: Total shapes read=" << count_;
#endif #endif
return feature_ptr(); return feature_ptr();
} }

View file

@ -24,6 +24,7 @@
#include <fstream> #include <fstream>
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
// boost // boost
@ -66,8 +67,8 @@ shape_index_featureset<filterT>::shape_index_featureset(filterT const& filter,
std::sort(ids_.begin(), ids_.end()); std::sort(ids_.begin(), ids_.end());
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Shape Plugin: query size=" << ids_.size() << std::endl; mapnik::log() << "shape_index_featureset: Query size=" << ids_.size();
#endif #endif
itr_ = ids_.begin(); itr_ = ids_.begin();
@ -202,8 +203,8 @@ feature_ptr shape_index_featureset<filterT>::next()
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Shape Plugin: " << count_ << " features" << std::endl; mapnik::log() << "shape_index_featureset: " << count_ << " features";
#endif #endif
return feature_ptr(); return feature_ptr();
} }

View file

@ -23,6 +23,7 @@
#include "shape_io.hpp" #include "shape_io.hpp"
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
// boost // boost
@ -57,8 +58,8 @@ shape_io::shape_io(const std::string& shape_name, bool open_index)
} }
catch (...) catch (...)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Shape Plugin: warning - could not open index: '" + shape_name + INDEX + "'" << std::endl; mapnik::log() << "shape_io: Could not open index=" << shape_name << INDEX;
#endif #endif
} }
} }

View file

@ -29,7 +29,7 @@
// mapnik // mapnik
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/sql_utils.hpp> #include <mapnik/sql_utils.hpp>
#include <mapnik/timer.hpp>
// boost // boost
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -120,6 +120,9 @@ public:
boost::shared_ptr<sqlite_resultset> execute_query(const std::string& sql) boost::shared_ptr<sqlite_resultset> execute_query(const std::string& sql)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, std::string("sqlite_resultset::execute_query ") + sql);
#endif
sqlite3_stmt* stmt = 0; sqlite3_stmt* stmt = 0;
const int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0); const int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0);
@ -133,6 +136,10 @@ public:
void execute(const std::string& sql) void execute(const std::string& sql)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, std::string("sqlite_resultset::execute ") + sql);
#endif
const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0); const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0);
if (rc != SQLITE_OK) if (rc != SQLITE_OK)
{ {
@ -142,6 +149,10 @@ public:
int execute_with_code(const std::string& sql) int execute_with_code(const std::string& sql)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, std::string("sqlite_resultset::execute_with_code ") + sql);
#endif
const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0); const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0);
return rc; return rc;
} }

View file

@ -26,9 +26,11 @@
#include "sqlite_utils.hpp" #include "sqlite_utils.hpp"
// mapnik // mapnik
#include <mapnik/debug.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/sql_utils.hpp> #include <mapnik/sql_utils.hpp>
#include <mapnik/util/geometry_to_ds_type.hpp> #include <mapnik/util/geometry_to_ds_type.hpp>
#include <mapnik/timer.hpp>
#include <mapnik/wkb.hpp> #include <mapnik/wkb.hpp>
// boost // boost
@ -51,23 +53,25 @@ using mapnik::parameters;
DATASOURCE_PLUGIN(sqlite_datasource) DATASOURCE_PLUGIN(sqlite_datasource)
sqlite_datasource::sqlite_datasource(parameters const& params, bool bind) sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
: datasource(params), : datasource(params),
extent_(), extent_(),
extent_initialized_(false), extent_initialized_(false),
type_(datasource::Vector), type_(datasource::Vector),
table_(*params_.get<std::string>("table", "")), table_(*params_.get<std::string>("table", "")),
fields_(*params_.get<std::string>("fields", "*")), fields_(*params_.get<std::string>("fields", "*")),
metadata_(*params_.get<std::string>("metadata", "")), metadata_(*params_.get<std::string>("metadata", "")),
geometry_table_(*params_.get<std::string>("geometry_table", "")), geometry_table_(*params_.get<std::string>("geometry_table", "")),
geometry_field_(*params_.get<std::string>("geometry_field", "")), geometry_field_(*params_.get<std::string>("geometry_field", "")),
index_table_(*params_.get<std::string>("index_table", "")), index_table_(*params_.get<std::string>("index_table", "")),
key_field_(*params_.get<std::string>("key_field", "")), key_field_(*params_.get<std::string>("key_field", "")),
row_offset_(*params_.get<int>("row_offset", 0)), row_offset_(*params_.get<int>("row_offset", 0)),
row_limit_(*params_.get<int>("row_limit", 0)), row_limit_(*params_.get<int>("row_limit", 0)),
intersects_token_("!intersects!"), intersects_token_("!intersects!"),
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")), desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
format_(mapnik::wkbAuto) format_(mapnik::wkbAuto)
{ {
log_enabled_ = *params_.get<mapnik::boolean>("log", MAPNIK_DEBUG_AS_BOOL);
/* TODO /* TODO
- throw if no primary key but spatial index is present? - throw if no primary key but spatial index is present?
- remove auto-indexing - remove auto-indexing
@ -87,6 +91,10 @@ void sqlite_datasource::bind() const
{ {
if (is_bound_) return; if (is_bound_) return;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::bind");
#endif
boost::optional<std::string> file = params_.get<std::string>("file"); boost::optional<std::string> file = params_.get<std::string>("file");
if (! file) throw datasource_exception("Sqlite Plugin: missing <file> parameter"); if (! file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");
@ -209,8 +217,8 @@ void sqlite_datasource::bind() const
for (std::vector<std::string>::const_iterator iter = init_statements_.begin(); for (std::vector<std::string>::const_iterator iter = init_statements_.begin();
iter != init_statements_.end(); ++iter) iter != init_statements_.end(); ++iter)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Sqlite Plugin: Execute init sql: " << *iter << std::endl; if (log_enabled_) mapnik::log() << "sqlite_datasource: Execute init sql=" << *iter;
#endif #endif
dataset_->execute(*iter); dataset_->execute(*iter);
} }
@ -283,6 +291,10 @@ void sqlite_datasource::bind() const
has_spatial_index_ = false; has_spatial_index_ = false;
if (use_spatial_index_) if (use_spatial_index_)
{ {
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats2__(std::clog, "sqlite_datasource::bind(use_spatial_index)");
#endif
if (boost::filesystem::exists(index_db)) if (boost::filesystem::exists(index_db))
{ {
dataset_->execute("attach database '" + index_db + "' as " + index_table_); dataset_->execute("attach database '" + index_db + "' as " + index_table_);
@ -315,8 +327,6 @@ void sqlite_datasource::bind() const
dataset_->execute("attach database '" + index_db + "' as " + index_table_); dataset_->execute("attach database '" + index_db + "' as " + index_table_);
} }
} }
*/ */
boost::shared_ptr<sqlite_resultset> rs = dataset_->execute_query(query.str()); boost::shared_ptr<sqlite_resultset> rs = dataset_->execute_query(query.str());
if (sqlite_utils::create_spatial_index(index_db,index_table_,rs)) if (sqlite_utils::create_spatial_index(index_db,index_table_,rs))
@ -343,7 +353,6 @@ void sqlite_datasource::bind() const
if (! extent_initialized_) if (! extent_initialized_)
{ {
// TODO - clean this up - reducing arguments // TODO - clean this up - reducing arguments
std::string query = populate_tokens(table_); std::string query = populate_tokens(table_);
if (!sqlite_utils::detect_extent(dataset_, if (!sqlite_utils::detect_extent(dataset_,
@ -487,8 +496,12 @@ box2d<double> sqlite_datasource::envelope() const
boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_type() const boost::optional<mapnik::datasource::geometry_t> sqlite_datasource::get_geometry_type() const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
boost::optional<mapnik::datasource::geometry_t> result;
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::get_geometry_type");
#endif
boost::optional<mapnik::datasource::geometry_t> result;
if (dataset_) if (dataset_)
{ {
// finally, get geometry type by querying first feature // finally, get geometry type by querying first feature
@ -542,6 +555,10 @@ featureset_ptr sqlite_datasource::features(query const& q) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features");
#endif
if (dataset_) if (dataset_)
{ {
mapnik::box2d<double> const& e = q.get_bbox(); mapnik::box2d<double> const& e = q.get_bbox();
@ -579,7 +596,8 @@ featureset_ptr sqlite_datasource::features(query const& q) const
key_field_, key_field_,
index_table_, index_table_,
geometry_table_, geometry_table_,
intersects_token_); } intersects_token_);
}
else else
{ {
query = populate_tokens(table_); query = populate_tokens(table_);
@ -597,9 +615,12 @@ featureset_ptr sqlite_datasource::features(query const& q) const
s << " OFFSET " << row_offset_; s << " OFFSET " << row_offset_;
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Sqlite Plugin: table: " << table_ << "\n\n"; if (log_enabled_)
std::clog << "Sqlite Plugin: query: " << s.str() << "\n\n"; {
mapnik::log() << "sqlite_datasource: Table=" << table_;
mapnik::log() << "sqlite_datasource: Query=" << s.str();
}
#endif #endif
boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str())); boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str()));
@ -618,6 +639,10 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
{ {
if (! is_bound_) bind(); if (! is_bound_) bind();
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "sqlite_datasource::features_at_point");
#endif
if (dataset_) if (dataset_)
{ {
// TODO - need tolerance // TODO - need tolerance
@ -678,8 +703,8 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
s << " OFFSET " << row_offset_; s << " OFFSET " << row_offset_;
} }
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Sqlite Plugin: " << s.str() << std::endl; if (log_enabled_) mapnik::log() << "sqlite_datasource: " << s.str();
#endif #endif
boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str())); boost::shared_ptr<sqlite_resultset> rs(dataset_->execute_query(s.str()));

View file

@ -52,11 +52,14 @@ public:
void bind() const; void bind() const;
private: private:
// Fill init_statements with any statements
// needed to attach auxillary databases
void parse_attachdb(std::string const& attachdb) const;
std::string populate_tokens(const std::string& sql) const;
// FIXME: remove mutable qualifier from data members // FIXME: remove mutable qualifier from data members
// by factoring out bind() logic out from // by factoring out bind() logic out from
// datasource impl !!! // datasource impl !!!
mutable mapnik::box2d<double> extent_; mutable mapnik::box2d<double> extent_;
mutable bool extent_initialized_; mutable bool extent_initialized_;
mapnik::datasource::datasource_t type_; mapnik::datasource::datasource_t type_;
@ -79,11 +82,6 @@ private:
mutable bool has_spatial_index_; mutable bool has_spatial_index_;
mutable bool using_subquery_; mutable bool using_subquery_;
mutable std::vector<std::string> init_statements_; mutable std::vector<std::string> init_statements_;
// Fill init_statements with any statements
// needed to attach auxillary databases
void parse_attachdb(std::string const& attachdb) const;
std::string populate_tokens(const std::string& sql) const;
}; };
#endif // MAPNIK_SQLITE_DATASOURCE_HPP #endif // MAPNIK_SQLITE_DATASOURCE_HPP

View file

@ -22,6 +22,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -124,9 +125,8 @@ feature_ptr sqlite_featureset::next()
break; break;
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "Sqlite Plugin: field " << fld_name_str mapnik::log() << "sqlite_featureset: Field=" << fld_name_str << " unhandled type_oid=" << type_oid;
<< " unhandled type_oid=" << type_oid << std::endl;
#endif #endif
break; break;
} }

View file

@ -76,7 +76,7 @@
#include <boost/math/special_functions/round.hpp> #include <boost/math/special_functions/round.hpp>
// stl // stl
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
#include <iostream> #include <iostream>
#endif #endif
@ -174,8 +174,9 @@ void agg_renderer<T>::setup(Map const &m)
} }
} }
} }
#ifdef MAPNIK_DEBUG
std::clog << "scale=" << m.scale() << "\n"; #ifdef MAPNIK_LOG
mapnik::log() << "agg_renderer: Scale=" << m.scale();
#endif #endif
} }
@ -185,9 +186,8 @@ agg_renderer<T>::~agg_renderer() {}
template <typename T> template <typename T>
void agg_renderer<T>::start_map_processing(Map const& map) void agg_renderer<T>::start_map_processing(Map const& map)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "start map processing bbox=" mapnik::log() << "agg_renderer: Start map processing bbox=" << map.get_current_extent();
<< map.get_current_extent() << "\n";
#endif #endif
ras_ptr->clip_box(0,0,width_,height_); ras_ptr->clip_box(0,0,width_,height_);
} }
@ -195,18 +195,18 @@ void agg_renderer<T>::start_map_processing(Map const& map)
template <typename T> template <typename T>
void agg_renderer<T>::end_map_processing(Map const& ) void agg_renderer<T>::end_map_processing(Map const& )
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "end map processing\n"; mapnik::log() << "agg_renderer: End map processing";
#endif #endif
} }
template <typename T> template <typename T>
void agg_renderer<T>::start_layer_processing(layer const& lay, box2d<double> const& query_extent) void agg_renderer<T>::start_layer_processing(layer const& lay, box2d<double> const& query_extent)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "start layer processing : " << lay.name() << "\n"; mapnik::log() << "agg_renderer: Start processing layer=" << lay.name();
std::clog << "datasource = " << lay.datasource().get() << "\n"; mapnik::log() << "agg_renderer: -- datasource=" << lay.datasource().get();
std::clog << "query_extent = " << query_extent << "\n"; mapnik::log() << "agg_renderer: -- query_extent=" << query_extent;
#endif #endif
if (lay.clear_label_cache()) if (lay.clear_label_cache())
{ {
@ -218,8 +218,8 @@ void agg_renderer<T>::start_layer_processing(layer const& lay, box2d<double> con
template <typename T> template <typename T>
void agg_renderer<T>::end_layer_processing(layer const&) void agg_renderer<T>::end_layer_processing(layer const&)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_LOG
std::clog << "end layer processing\n"; mapnik::log() << "agg_renderer: End layer processing";
#endif #endif
} }
@ -258,8 +258,6 @@ void agg_renderer<T>::render_marker(pixel_position const& pos, marker const& mar
(*marker.get_vector_data())->attributes()); (*marker.get_vector_data())->attributes());
svg_renderer.render(*ras_ptr, sl, renb, mtx, opacity, bbox); svg_renderer.render(*ras_ptr, sl, renb, mtx, opacity, bbox);
} }
else else
{ {

Some files were not shown because too many files have changed in this diff Show more