diff --git a/.gitignore b/.gitignore index e64ea97ea..28a67d62c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store *~ *.o *.pyc @@ -23,4 +24,13 @@ utils/shapeindex/shapeindex utils/pgsql2sqlite/pgsql2sqlite utils/svg2png/svg2png demo/python/demo* -demo/python/map.xml \ No newline at end of file +demo/python/map.xml +tests/cpp_tests/svg_renderer_tests/background_color_test +tests/cpp_tests/svg_renderer_tests/combined_test +tests/cpp_tests/svg_renderer_tests/compilation_test +tests/cpp_tests/svg_renderer_tests/file_output_test +tests/cpp_tests/svg_renderer_tests/file_output_test_case.svg +tests/cpp_tests/svg_renderer_tests/path_element_test +tests/cpp_tests/svg_renderer_tests/path_element_test_case_1.svg +tests/cpp_tests/svg_renderer_tests/root_element_test +tests/data/sqlite/*index diff --git a/CHANGELOG b/CHANGELOG index 920a5bde6..c60bcb714 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,7 @@ ---------------- Mapnik Changelog ---------------- - + A simple log of core changes affecting Mapnik usage. Developers: Please commit along with changes. @@ -18,6 +18,7 @@ Mapnik 2.1.0 - Fixed bug in shield line placement when dx/dy are used to shift the label relative to the placement point (Matt Amos) (#908) +- Added parameter in OGR plugin to select a layer by SQL query (besides name or index): see http://www.gdal.org/ogr/ogr_sql.html for specifications (kunitoki) (#472) Mapnik 2.0.0 @@ -45,7 +46,7 @@ Mapnik 2.0.0 - Added map.base parameter that can be set to control where files with relative paths should be interpreted from when a map is loaded from a string or saved to a string. It defaults to an empty string which means that the base path will be the current working directory of the mapnik process. When a stylesheet is read - from a file that files directory is used. And a custom value can still be passed as an argument to + from a file that files directory is used. And a custom value can still be passed as an argument to load_map_from_string(). - Added python function 'render_grid' to allow conversion of grid buffer to python object containing list of grid @@ -112,7 +113,7 @@ Mapnik 2.0.0 Mapnik 0.7.2 Release -------------------- - + - Added forward compatibility for Mapnik 2.0 XML syntax (https://trac.mapnik.org/wiki/Mapnik2/Changes) - Build fixes to ensure boost_threads are not used unless THREADING=multi build option is used @@ -167,9 +168,9 @@ Mapnik 0.7.0 Release * Use the gdaladdo utility to add overviews to existing GDAL datasets -- PostGIS: Added an optional 'geometry_table' parameter. The 'geometry_table' used by Mapnik to look up +- PostGIS: Added an optional 'geometry_table' parameter. The 'geometry_table' used by Mapnik to look up metadata in the geometry_columns and calculate extents (when the 'geometry_field' and 'srid' parameters - are not supplied). If 'geometry_table' is not specified Mapnik will attempt to determine the name of the + are not supplied). If 'geometry_table' is not specified Mapnik will attempt to determine the name of the table to query based on parsing the 'table' parameter, which may fail for complex queries with more than one 'from' keyword. Using this parameter should allow for existing metadata and table indexes to be used while opening the door to much more complicated subqueries being passed to the 'table' parameter without @@ -191,7 +192,7 @@ Mapnik 0.7.0 Release query to be used by indexes. (#415) * Pass the bbox token inside a subquery like: !bbox! - + * Valid Usages include: @@ -210,7 +211,7 @@ Mapnik 0.7.0 Release - PostGIS Plugin: Added support for quoted table names (r1454) (#393) -- PostGIS: Add a 'persist_connection' option (default true), that when false will release +- PostGIS: Add a 'persist_connection' option (default true), that when false will release the idle psql connection after datasource goes out of scope (r1337) (#433,#434) - PostGIS: Added support for BigInt (int8) postgres type (384) @@ -234,14 +235,14 @@ Mapnik 0.7.0 Release - PolygonSymbolizer: Added 'gamma' attribute to allow for dilation of polygon edges - a solution to gap artifacts or "ghost lines" between adjacent polygons and allows for slight sharpening of the edges of non overlapping polygons. Accepts any values but 0-1 is the recommended range. - -- TextSymbolizer: Large set of new attributes: 'text_transform', 'line_spacing', 'character_spacing', + +- TextSymbolizer: Large set of new attributes: 'text_transform', 'line_spacing', 'character_spacing', 'wrap_character', 'wrap_before', 'horizontal_alignment', 'justify_alignment', and 'opacity'. * More details at changesets: r1254 and r1341 - SheildSymbolizer: Added special new attributes: 'unlock_image', 'VERTEX' placement, 'no_text' and many - attributes previously only supported in the TextSymbolizer: 'allow_overlap', 'vertical_alignment', + attributes previously only supported in the TextSymbolizer: 'allow_overlap', 'vertical_alignment', 'horizontal_alignment', 'justify_alignment', 'wrap_width', 'wrap_character', 'wrap_before', 'text_transform', 'line_spacing', 'character_spacing', and 'opacity'. @@ -281,7 +282,7 @@ Mapnik 0.7.0 Release - Python: Ensured mapnik::config_errors now throw RuntimeError exception instead of UserWarning exception (#442) -- Filters: Added support for '!=' as an alias to '<>' for not-equals filters (avoids <>) (r1326) (#427) +- Filters: Added support for '!=' as an alias to '<>' for not-equals filters (avoids <>) (r1326) (#427) - SCons: Improved boost auto-detection (r1255,r1279) @@ -303,7 +304,7 @@ Mapnik 0.6.1 Release (Packaged from r1247) -- Plugins: expose list of registered plugins as a 'plugin_names()' method of DatasourceCache (r1180) +- Plugins: expose list of registered plugins as a 'plugin_names()' method of DatasourceCache (r1180) - XML: Fixed serialization and parsing bugs related to handling of integers and Enums (#328,#353) diff --git a/SConstruct b/SConstruct index 0d71d5457..845da73bf 100644 --- a/SConstruct +++ b/SConstruct @@ -329,7 +329,7 @@ opts.AddVariables( ('BOOST_TOOLKIT','Specify boost toolkit, e.g., gcc41.','',False), ('BOOST_ABI', 'Specify boost ABI, e.g., d.','',False), ('BOOST_VERSION','Specify boost version, e.g., 1_35.','',False), - ('BOOST_PYTHON_LIB','Specify library name or full path to boost_python lib (e.g. "boost_python-py26" or "/usr/lib/libboost_python.dylib")',''), + ('BOOST_PYTHON_LIB','Specify library name to specific Boost Python lib (e.g. "boost_python-py26")',''), # Variables for required dependencies ('FREETYPE_CONFIG', 'The path to the freetype-config executable.', 'freetype-config'), @@ -425,7 +425,6 @@ pickle_store = [# Scons internal variables 'PYTHON_INSTALL_LOCATION', 'PYTHON_SYS_PREFIX', 'COLOR_PRINT', - 'HAS_BOOST_SYSTEM', 'SVN_REVISION', 'HAS_CAIRO', 'HAS_PYCAIRO', @@ -451,6 +450,7 @@ pickle_store = [# Scons internal variables 'CAIROMM_LIBPATHS', 'CAIROMM_LINKFLAGS', 'CAIROMM_CPPPATHS', + 'SVG_RENDERER', ] # Add all other user configurable options to pickle pickle_store @@ -1070,15 +1070,17 @@ if not preconfigured: env.AppendUnique(CPPPATH = os.path.realpath(inc_path)) env.AppendUnique(LIBPATH = os.path.realpath(lib_path)) - conf.parse_config('FREETYPE_CONFIG') - - # check if freetype links to bz2 - if env['RUNTIME_LINK'] == 'static': - temp_env = env.Clone() - temp_env['LIBS'] = [] - temp_env.ParseConfig('%s --libs' % env['FREETYPE_CONFIG']) - if 'bz2' in temp_env['LIBS']: - env['EXTRA_FREETYPE_LIBS'].append('bz2') + if conf.parse_config('FREETYPE_CONFIG'): + # check if freetype links to bz2 + if env['RUNTIME_LINK'] == 'static': + temp_env = env.Clone() + temp_env['LIBS'] = [] + try: + temp_env.ParseConfig('%s --libs' % env['FREETYPE_CONFIG']) + if 'bz2' in temp_env['LIBS']: + env['EXTRA_FREETYPE_LIBS'].append('bz2') + except OSError,e: + pass # libxml2 should be optional but is currently not # https://github.com/mapnik/mapnik/issues/913 @@ -1105,14 +1107,14 @@ if not preconfigured: if env['PRIORITIZE_LINKING']: conf.prioritize_paths(silent=False) - for libinfo in LIBSHEADERS: - if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], libinfo[3]): - if libinfo[2]: - color_print(1,'Could not find required header or shared library for %s' % libinfo[0]) - env['MISSING_DEPS'].append(libinfo[0]) + for libname, headers, required, lang in LIBSHEADERS: + if not conf.CheckLibWithHeader(libname, headers, lang): + if required: + color_print(1, 'Could not find required header or shared library for %s' % libname) + env['MISSING_DEPS'].append(libname) else: - color_print(4,'Could not find optional header or shared library for %s' % libinfo[0]) - env['SKIPPED_DEPS'].append(libinfo[0]) + color_print(4, 'Could not find optional header or shared library for %s' % libname) + env['SKIPPED_DEPS'].append(libname) if env['ICU_LIB_NAME'] not in env['MISSING_DEPS']: if not conf.icu_at_least_four_two(): @@ -1126,18 +1128,14 @@ if not preconfigured: conf.FindBoost(BOOST_SEARCH_PREFIXES,thread_flag) - # boost system is used in boost 1.35 and greater - env['HAS_BOOST_SYSTEM'] = False boost_lib_version_from_header = conf.GetBoostLibVersion() if boost_lib_version_from_header: boost_version_from_header = int(boost_lib_version_from_header.split('_')[1]) - if boost_version_from_header >= 35: - env['HAS_BOOST_SYSTEM'] = True # The other required boost headers. BOOST_LIBSHEADERS = [ - ['system', 'boost/system/system_error.hpp', env['HAS_BOOST_SYSTEM']], + ['system', 'boost/system/system_error.hpp', True], ['filesystem', 'boost/filesystem/operations.hpp', True], ['regex', 'boost/regex.hpp', True], ['program_options', 'boost/program_options.hpp', False] @@ -1331,7 +1329,7 @@ if not preconfigured: if not conf.CheckHeader(header='boost/python/detail/config.hpp',language='C++'): color_print(1,'Could not find required header files for boost python') env['MISSING_DEPS'].append('boost python') - + if env['CAIRO']: if conf.CheckPKGConfig('0.15.0') and conf.CheckPKG('pycairo'): env['HAS_PYCAIRO'] = True @@ -1502,14 +1500,23 @@ if not preconfigured: if not conf.CheckHeader(header='Python.h',language='C'): color_print(1,'Could not find required header files for the Python language (version %s)' % env['PYTHON_VERSION']) env.Replace(**backup) - env['MISSING_DEPS'].append('python %s development headers' % env['PYTHON_VERSION']) + Exit(1) else: env.Replace(**backup) if (int(majver), int(minver)) < (2, 2): color_print(1,"Python version 2.2 or greater required") Exit(1) - + + if env['BOOST_PYTHON_LIB']: + env.Append(LIBS='python%s' % env['PYTHON_VERSION']) + if not conf.CheckLibWithHeader(libs=[env['BOOST_PYTHON_LIB']], header='boost/python/detail/config.hpp', language='C++'): + color_print(1, 'Could not find library %s for boost python' % env['BOOST_PYTHON_LIB']) + env.Replace(**backup) + Exit(1) + else: + env.Replace(**backup) + color_print(4,'Bindings Python version... %s' % env['PYTHON_VERSION']) color_print(4,'Python %s prefix... %s' % (env['PYTHON_VERSION'], env['PYTHON_SYS_PREFIX'])) color_print(4,'Python bindings will install in... %s' % os.path.normpath(env['PYTHON_INSTALL_LOCATION'])) diff --git a/bindings/python/build.py b/bindings/python/build.py index 52e46d464..6deed738a 100644 --- a/bindings/python/build.py +++ b/bindings/python/build.py @@ -48,13 +48,7 @@ if env['JPEG']: libraries.append('jpeg') if env['BOOST_PYTHON_LIB']: - if os.path.sep in env['BOOST_PYTHON_LIB']: - pylib_dir = os.path.dirname(env['BOOST_PYTHON_LIB']) - env.Prepend(LIBPATH = pylib_dir) - pylib_name = os.path.splitext(os.path.basename(env['BOOST_PYTHON_LIB']))[0].replace('lib','',1) - libraries.append(pylib_name) - else: - libraries.append(env['BOOST_PYTHON_LIB'].replace('lib','',1)) + libraries.append(env['BOOST_PYTHON_LIB']) else: if is_py3(): libraries.append('boost_python3%s' % env['BOOST_APPEND']) diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 6eac1d6d9..d5c2b4a0c 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -410,6 +410,13 @@ def Raster(**keywords): Optional keyword arguments: base -- path prefix (default None) + multi -- whether the image is in tiles on disk (default False) + + Multi-tiled keyword arguments: + x_width -- virtual image number of tiles in X direction (required) + y_width -- virtual image number of tiles in Y direction (required) + tile_size -- if an image is in tiles, how large are the tiles (default 256) + tile_stride -- if an image is in tiles, what's the increment between rows/cols (default 1) >>> from mapnik import Raster, Layer >>> raster = Raster(base='/home/mapnik/data',file='elevation.tif',lox=-122.8,loy=48.5,hix=-122.7,hiy=48.6) @@ -478,10 +485,11 @@ def Ogr(**keywords): Required keyword arguments: file -- path to OGR supported dataset - layer -- name of layer to use within datasource (optional if layer_by_index is used) + layer -- name of layer to use within datasource (optional if layer_by_index or layer_by_sql is used) Optional keyword arguments: - layer_by_index -- choose layer by index number instead of by layer name. + layer_by_index -- choose layer by index number instead of by layer name or sql. + layer_by_sql -- choose layer by sql query number instead of by layer name or index. base -- path prefix (default None) encoding -- file encoding (default 'utf-8') multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False) diff --git a/bindings/python/mapnik/printing.py b/bindings/python/mapnik/printing.py index 9ef4be733..db6f6a139 100644 --- a/bindings/python/mapnik/printing.py +++ b/bindings/python/mapnik/printing.py @@ -15,6 +15,7 @@ page.render_map(m,"my_output_file.pdf") see the documentation of mapnik2.printing.PDFPrinter() for options """ +from __future__ import absolute_import from . import render, Map, Box2d, MemoryDatasource, Layer, Feature, Projection, ProjTransform, Coord, Style, Rule, Geometry2d import math diff --git a/bindings/python/mapnik_geometry.cpp b/bindings/python/mapnik_geometry.cpp index c1a1c871e..611c1c580 100644 --- a/bindings/python/mapnik_geometry.cpp +++ b/bindings/python/mapnik_geometry.cpp @@ -78,7 +78,6 @@ void export_geometry() .def("envelope",&geometry_type::envelope) // .def("__str__",&geometry_type::to_string) .def("type",&geometry_type::type) - .def("area",&geometry_type::area) // TODO add other geometry_type methods ; diff --git a/bindings/python/mapnik_label_collision_detector.cpp b/bindings/python/mapnik_label_collision_detector.cpp new file mode 100644 index 000000000..c81c6191a --- /dev/null +++ b/bindings/python/mapnik_label_collision_detector.cpp @@ -0,0 +1,123 @@ +/***************************************************************************** + * + * 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 +#include +#include +#include + +#include +#include + +#include + +using mapnik::label_collision_detector4; +using mapnik::box2d; +using mapnik::Map; +using boost::make_shared; + +namespace +{ + +boost::shared_ptr +create_label_collision_detector_from_extent(box2d const &extent) +{ + return make_shared(extent); +} + +boost::shared_ptr +create_label_collision_detector_from_map(Map const &m) +{ + double buffer = m.buffer_size(); + box2d extent(-buffer, -buffer, m.width() + buffer, m.height() + buffer); + return make_shared(extent); +} + +boost::python::list +make_label_boxes(boost::shared_ptr det) +{ + boost::python::list boxes; + + for (label_collision_detector4::query_iterator jtr = det->begin(); + jtr != det->end(); ++jtr) + { + boxes.append >(jtr->box); + } + + return boxes; +} + +} + +void export_label_collision_detector() +{ + using namespace boost::python; + + // for overload resolution + void (label_collision_detector4::*insert_box)(box2d const &) = &label_collision_detector4::insert; + + class_, boost::noncopyable> + ("LabelCollisionDetector", + "Object to detect collisions between labels, used in the rendering process.", + no_init) + + .def("__init__", make_constructor(create_label_collision_detector_from_extent), + "Creates an empty collision detection object with a given extent. Note " + "that the constructor from Map objects is a sensible default and usually " + "what you want to do.\n" + "\n" + "Example:\n" + ">>> m = Map(size_x, size_y)\n" + ">>> buf_sz = m.buffer_size\n" + ">>> extent = mapnik.Box2d(-buf_sz, -buf_sz, m.width + buf_sz, m.height + buf_sz)\n" + ">>> detector = mapnik.LabelCollisionDetector(extent)") + + .def("__init__", make_constructor(create_label_collision_detector_from_map), + "Creates an empty collision detection object matching the given Map object. " + "The created detector will have the same size, including the buffer, as the " + "map object. This is usually what you want to do.\n" + "\n" + "Example:\n" + ">>> m = Map(size_x, size_y)\n" + ">>> detector = mapnik.LabelCollisionDetector(m)") + + .def("extent", &label_collision_detector4::extent, return_value_policy(), + "Returns the total extent (bounding box) of all labels inside the detector.\n" + "\n" + "Example:\n" + ">>> detector.extent()\n" + "Box2d(573.252589209,494.789179821,584.261023823,496.83610261)") + + .def("boxes", &make_label_boxes, + "Returns a list of all the label boxes inside the detector.") + + .def("insert", insert_box, + "Insert a 2d box into the collision detector. This can be used to ensure that " + "some space is left clear on the map for later overdrawing, for example by " + "non-Mapnik processes.\n" + "\n" + "Example:\n" + ">>> m = Map(size_x, size_y)\n" + ">>> detector = mapnik.LabelCollisionDetector(m)" + ">>> detector.insert(mapnik.Box2d(196, 254, 291, 389))") + ; +} diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 9d36aebc6..03c6fc75f 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -66,6 +66,7 @@ void export_view_transform(); void export_raster_colorizer(); void export_glyph_symbolizer(); void export_inmem_metawriter(); +void export_label_collision_detector(); #include #include @@ -120,6 +121,28 @@ void render(const mapnik::Map& map, Py_END_ALLOW_THREADS } +void render_with_detector( + const mapnik::Map &map, + mapnik::image_32 &image, + boost::shared_ptr detector, + double scale_factor = 1.0, + unsigned offset_x = 0u, + unsigned offset_y = 0u) +{ + Py_BEGIN_ALLOW_THREADS + try + { + mapnik::agg_renderer ren(map,image,detector); + ren.apply(); + } + catch (...) + { + Py_BLOCK_THREADS + throw; + } + Py_END_ALLOW_THREADS +} + void render_layer2(const mapnik::Map& map, mapnik::image_32& image, unsigned layer_idx) @@ -374,6 +397,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(load_map_string_overloads, load_map_string, 2, 4 BOOST_PYTHON_FUNCTION_OVERLOADS(save_map_overloads, save_map, 2, 3) BOOST_PYTHON_FUNCTION_OVERLOADS(save_map_to_string_overloads, save_map_to_string, 1, 2) BOOST_PYTHON_FUNCTION_OVERLOADS(render_overloads, render, 2, 5) +BOOST_PYTHON_FUNCTION_OVERLOADS(render_with_detector_overloads, render_with_detector, 3, 6) BOOST_PYTHON_MODULE(_mapnik2) { @@ -427,6 +451,7 @@ BOOST_PYTHON_MODULE(_mapnik2) export_raster_colorizer(); export_glyph_symbolizer(); export_inmem_metawriter(); + export_label_collision_detector(); def("render_grid",&render_grid, ( arg("map"), @@ -503,6 +528,19 @@ BOOST_PYTHON_MODULE(_mapnik2) "\n" )); + def("render_with_detector", &render_with_detector, render_with_detector_overloads( + "\n" + "Render Map to an AGG image_32 using a pre-constructed detector.\n" + "\n" + "Usage:\n" + ">>> from mapnik import Map, Image, LabelCollisionDetector, render_with_detector, load_map\n" + ">>> m = Map(256,256)\n" + ">>> load_map(m,'mapfile.xml')\n" + ">>> im = Image(m.width,m.height)\n" + ">>> detector = LabelCollisionDetector(m)\n" + ">>> render_with_detector(m, im, detector)\n" + )); + def("render_layer", &render_layer2, (arg("map"),arg("image"),args("layer")) ); diff --git a/demo/c++/rundemo.cpp b/demo/c++/rundemo.cpp index 4216dd677..8f4ba0a3a 100644 --- a/demo/c++/rundemo.cpp +++ b/demo/c++/rundemo.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/demo/viewer/about_dialog.cpp b/demo/viewer/about_dialog.cpp index 3594c63e1..5f6fa88f5 100644 --- a/demo/viewer/about_dialog.cpp +++ b/demo/viewer/about_dialog.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/demo/viewer/about_dialog.hpp b/demo/viewer/about_dialog.hpp index 13d71dda2..b70e27330 100644 --- a/demo/viewer/about_dialog.hpp +++ b/demo/viewer/about_dialog.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/demo/viewer/info_dialog.cpp b/demo/viewer/info_dialog.cpp index 89652c33e..92b3599d3 100644 --- a/demo/viewer/info_dialog.cpp +++ b/demo/viewer/info_dialog.cpp @@ -1,5 +1,6 @@ - /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko +/* This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,6 +36,6 @@ info_dialog::info_dialog(QVector > const& info, QWidget * QTableWidgetItem *keyItem = new QTableWidgetItem(info[i].first); QTableWidgetItem *valueItem = new QTableWidgetItem(info[i].second); ui.tableWidget->setItem(i,0,keyItem); - ui.tableWidget->setItem(i,1,valueItem); + ui.tableWidget->setItem(i,1,valueItem); } } diff --git a/demo/viewer/info_dialog.hpp b/demo/viewer/info_dialog.hpp index f9fda8b03..81d550c8b 100644 --- a/demo/viewer/info_dialog.hpp +++ b/demo/viewer/info_dialog.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/demo/viewer/layer_info_dialog.cpp b/demo/viewer/layer_info_dialog.cpp index ec23b1ec4..c223146b4 100644 --- a/demo/viewer/layer_info_dialog.cpp +++ b/demo/viewer/layer_info_dialog.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,15 +29,15 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent) : QDialog(parent) { ui.setupUi(this); - + ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name")); ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value")); - + // Layer name ui.layerNameEdit->setText(QString(lay.name().c_str())); // Named Styles : TODO!!! - + // Datasource mapnik::datasource_ptr ds = lay.datasource(); if (ds) @@ -57,10 +58,10 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent) QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str())); QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str())); ui.tableWidget->setItem(index,0,keyItem); - ui.tableWidget->setItem(index,1,valueItem); + ui.tableWidget->setItem(index,1,valueItem); ++index; } - } + } } } diff --git a/demo/viewer/layer_info_dialog.hpp b/demo/viewer/layer_info_dialog.hpp index d9ecb8a90..4fb8730fa 100644 --- a/demo/viewer/layer_info_dialog.hpp +++ b/demo/viewer/layer_info_dialog.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/demo/viewer/layerdelegate.cpp b/demo/viewer/layerdelegate.cpp index b06a129ef..fbaf101ed 100644 --- a/demo/viewer/layerdelegate.cpp +++ b/demo/viewer/layerdelegate.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,7 +38,7 @@ void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, else painter->setBrush(QBrush(QColor(255, 0, 0, 64))); - + painter->drawRoundRect(option.rect,4,4); if (option.state & QStyle::State_Selected) diff --git a/demo/viewer/layerdelegate.hpp b/demo/viewer/layerdelegate.hpp index d747ebe7a..a5442a6fc 100644 --- a/demo/viewer/layerdelegate.hpp +++ b/demo/viewer/layerdelegate.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,11 +33,11 @@ class QPainter; class LayerDelegate : public QAbstractItemDelegate { Q_OBJECT - + public: LayerDelegate(QObject *parent = 0); void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; + const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const; }; diff --git a/demo/viewer/layerlistmodel.cpp b/demo/viewer/layerlistmodel.cpp index b8ae00766..b6dae0d20 100644 --- a/demo/viewer/layerlistmodel.cpp +++ b/demo/viewer/layerlistmodel.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -61,7 +62,7 @@ QVariant LayerListModel::data(QModelIndex const& index,int role) const { if (map_->layers().at(index.row()).isActive()) return QVariant(Qt::Checked); - else + else return QVariant(Qt::Unchecked); } else @@ -75,7 +76,7 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, { if (role != Qt::DisplayRole) return QVariant(); - + if (orientation == Qt::Horizontal) return QString("TODO Column %1").arg(section); else @@ -86,22 +87,22 @@ bool LayerListModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!map_) return false; - + if (index.isValid() && role == Qt::CheckStateRole) { - int status = value.toInt(); + int status = value.toInt(); std::vector & layers = const_cast& >(map_->layers()); layers.at(index.row()).setActive(status); emit dataChanged(index, index); return true; - } + } return false; } Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const { Qt::ItemFlags flags = QAbstractItemModel::flags(index); - + if (index.isValid()) flags |= Qt::ItemIsUserCheckable; return flags; @@ -121,4 +122,4 @@ boost::optional LayerListModel::map_layer(int i) - + diff --git a/demo/viewer/layerlistmodel.hpp b/demo/viewer/layerlistmodel.hpp index 30f126ba5..52720a9ca 100644 --- a/demo/viewer/layerlistmodel.hpp +++ b/demo/viewer/layerlistmodel.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,10 +37,10 @@ class LayerListModel : public QAbstractListModel int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; + int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - Qt::ItemFlags flags(QModelIndex const& index) const; + Qt::ItemFlags flags(QModelIndex const& index) const; boost::optional map_layer(int i); private: diff --git a/demo/viewer/layerwidget.cpp b/demo/viewer/layerwidget.cpp index c5402b53d..4affb0a2c 100644 --- a/demo/viewer/layerwidget.cpp +++ b/demo/viewer/layerwidget.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -41,7 +42,7 @@ LayerTab::LayerTab(QWidget* parent) void LayerTab::paintEvent(QPaintEvent *e) { - QListView::paintEvent(e); + QListView::paintEvent(e); } void LayerTab::dataChanged(const QModelIndex &topLeft, @@ -55,7 +56,7 @@ void LayerTab::dataChanged(const QModelIndex &topLeft, void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &) { QModelIndexList list = selected.indexes(); - if (list.size() != 0) + if (list.size() != 0) { std::cout << "SELECTED LAYER ->" << list[0].row() << "\n"; emit layerSelected(list[0].row()); @@ -69,7 +70,7 @@ void LayerTab::layerInfo() if (indexes.size() > 0) { qDebug("id = %d",indexes[0].row()); - + } } @@ -81,7 +82,7 @@ void LayerTab::layerInfo2(QModelIndex const& index) unsigned i = index.row(); LayerListModel * model = static_cast(this->model()); boost::optional layer = model->map_layer(i); - + if (layer) { layer_info_dialog dlg(*layer,this); @@ -91,7 +92,7 @@ void LayerTab::layerInfo2(QModelIndex const& index) StyleTab::StyleTab(QWidget*) { - + } void StyleTab::contextMenuEvent(QContextMenuEvent * event ) diff --git a/demo/viewer/layerwidget.hpp b/demo/viewer/layerwidget.hpp index 38ab77e7b..a62a91e10 100644 --- a/demo/viewer/layerwidget.hpp +++ b/demo/viewer/layerwidget.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2006 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,10 +34,10 @@ class LayerTab : public QListView void paintEvent(QPaintEvent *e); signals: void update_mapwidget(); - void layerSelected(int) const; + void layerSelected(int) const; public slots: - void layerInfo(); - void layerInfo2(QModelIndex const&); + void layerInfo(); + void layerInfo2(QModelIndex const&); protected slots: void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void selectionChanged(const QItemSelection & selected, const QItemSelection &); @@ -51,4 +52,4 @@ protected: void contextMenuEvent(QContextMenuEvent * event ); }; -#endif +#endif diff --git a/demo/viewer/main.cpp b/demo/viewer/main.cpp index d4b785f7b..21f639815 100644 --- a/demo/viewer/main.cpp +++ b/demo/viewer/main.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2006 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,13 +35,13 @@ int main( int argc, char **argv ) { using mapnik::datasource_cache; using mapnik::freetype_engine; - + QCoreApplication::setOrganizationName("Mapnik"); QCoreApplication::setOrganizationDomain("mapnik.org"); QCoreApplication::setApplicationName("Viewer"); - + QSettings settings("viewer.ini",QSettings::IniFormat); - + // register input plug-ins QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik2/input/")).toString(); @@ -54,8 +55,8 @@ int main( int argc, char **argv ) freetype_engine::register_fonts(font_dir.toStdString()); } settings.endArray(); - - QApplication app( argc, argv ); + + QApplication app( argc, argv ); MainWindow window; window.show(); if (argc > 1) window.open(argv[1]); @@ -82,5 +83,5 @@ int main( int argc, char **argv ) double scaling_factor = QString(argv[3]).toDouble(&ok); if (ok) window.set_scaling_factor(scaling_factor); } - return app.exec(); + return app.exec(); } diff --git a/demo/viewer/mainwindow.cpp b/demo/viewer/mainwindow.cpp index a4da2a683..d8cda56e1 100644 --- a/demo/viewer/mainwindow.cpp +++ b/demo/viewer/mainwindow.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2006 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -47,42 +48,42 @@ MainWindow::MainWindow() : filename_(), default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428) -{ +{ mapWidget_ = new MapWidget(this); - QSplitter *splitter = new QSplitter(this); + QSplitter *splitter = new QSplitter(this); QTabWidget *tabWidget=new QTabWidget; layerTab_ = new LayerTab; layerTab_->setFocusPolicy(Qt::NoFocus); layerTab_->setIconSize(QSize(16,16)); - - //LayerDelegate *delegate = new LayerDelegate(this); + + //LayerDelegate *delegate = new LayerDelegate(this); //layerTab_->setItemDelegate(delegate); //layerTab_->setItemDelegate(new QItemDelegate(this)); //layerTab_->setViewMode(QListView::IconMode); - + layerTab_->setFlow(QListView::TopToBottom); tabWidget->addTab(layerTab_,tr("Layers")); // Styles tab styleTab_ = new StyleTab; - tabWidget->addTab(styleTab_,tr("Styles")); + tabWidget->addTab(styleTab_,tr("Styles")); splitter->addWidget(tabWidget); splitter->addWidget(mapWidget_); QList list; list.push_back(200); list.push_back(600); splitter->setSizes(list); - + mapWidget_->setFocusPolicy(Qt::StrongFocus); mapWidget_->setFocus(); - + //setCentralWidget(mapWidget_); setCentralWidget(splitter); createActions(); createMenus(); createToolBars(); createContextMenu(); - + setWindowTitle(tr("Mapnik Viewer")); status=new QStatusBar(this); status->showMessage(tr("")); @@ -91,11 +92,11 @@ MainWindow::MainWindow() //connect mapview to layerlist connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update())); - // slider + // slider connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int))); - // + // connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap())); - connect(layerTab_,SIGNAL(layerSelected(int)), + connect(layerTab_,SIGNAL(layerSelected(int)), mapWidget_,SLOT(layerSelected(int))); } @@ -128,21 +129,21 @@ void MainWindow::open(QString const& path) { filename_ = path; } - + if (!filename_.isEmpty()) { - + load_map_file(filename_); setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_)); } - + } void MainWindow::reload() { if (!filename_.isEmpty()) { - + mapnik::box2d bbox = mapWidget_->getMap()->get_current_extent(); load_map_file(filename_); mapWidget_->zoomToBox(bbox); @@ -157,7 +158,7 @@ void MainWindow::save() initialPath, tr("%1 Files (*.xml)") .arg(QString("Mapnik definition"))); - if (!filename.isEmpty()) + if (!filename.isEmpty()) { std::cout<<"saving "<< filename.toStdString() << std::endl; mapnik::save_map(*mapWidget_->getMap(),filename.toStdString()); @@ -166,16 +167,16 @@ void MainWindow::save() void MainWindow::load_map_file(QString const& filename) { - std::cout<<"loading "<< filename.toStdString() << std::endl; + std::cout<<"loading "<< filename.toStdString() << std::endl; unsigned width = mapWidget_->width(); unsigned height = mapWidget_->height(); - boost::shared_ptr map(new mapnik::Map(width,height)); + boost::shared_ptr map(new mapnik::Map(width,height)); mapWidget_->setMap(map); - try - { + try + { mapnik::load_map(*map,filename.toStdString()); } - catch (mapnik::config_error & ex) + catch (mapnik::config_error & ex) { std::cout << ex.what() << "\n"; } @@ -195,7 +196,7 @@ void MainWindow::zoom_to_box() void MainWindow::pan() { - mapWidget_->setTool(MapWidget::Pan); + mapWidget_->setTool(MapWidget::Pan); } void MainWindow::info() @@ -240,7 +241,7 @@ void MainWindow::export_as() tr("%1 Files (*.%2);;All Files (*)") .arg(QString(fileFormat.toUpper())) .arg(QString(fileFormat))); - if (!fileName.isEmpty()) + if (!fileName.isEmpty()) { QPixmap const& pix = mapWidget_->pixmap(); pix.save(fileName); @@ -248,8 +249,8 @@ void MainWindow::export_as() } void MainWindow::print() -{ - +{ + //Q_ASSERT(mapWidget_->pixmap()); //QPrintDialog dialog(&printer, this); //if (dialog.exec()) { @@ -264,31 +265,31 @@ void MainWindow::print() } void MainWindow::createActions() -{ +{ //exportAct = new QAction(tr("&Export as ..."),this); //exportAct->setShortcut(tr("Ctrl+E")); //connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as())); zoomAllAct = new QAction(QIcon(":/images/home.png"),tr("Zoom All"),this); connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all())); - + zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"),tr("Zoom To Box"),this); zoomBoxAct->setCheckable(true); connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box())); - + panAct = new QAction(QIcon(":/images/pan.png"),tr("Pan"),this); panAct->setCheckable(true); connect(panAct, SIGNAL(triggered()), this, SLOT(pan())); - + infoAct = new QAction(QIcon(":/images/info.png"),tr("Info"),this); infoAct->setCheckable(true); connect(infoAct, SIGNAL(triggered()), this, SLOT(info())); - + toolsGroup=new QActionGroup(this); toolsGroup->addAction(zoomBoxAct); toolsGroup->addAction(panAct); toolsGroup->addAction(infoAct); zoomBoxAct->setChecked(true); - + openAct=new QAction(tr("Open Map definition"),this); connect(openAct,SIGNAL(triggered()),this,SLOT(open())); saveAct=new QAction(tr("Save Map definition"),this); @@ -302,27 +303,27 @@ void MainWindow::createActions() connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up())); panDownAct = new QAction(QIcon(":/images/down.png"),tr("&Pan Down"),this); connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down())); - + reloadAct = new QAction(QIcon(":/images/reload.png"),tr("Reload"),this); connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload())); - + layerInfo = new QAction(QIcon(":/images/info.png"),tr("&Layer info"),layerTab_); connect(layerInfo, SIGNAL(triggered()), layerTab_,SLOT(layerInfo())); connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_,SLOT(layerInfo2(QModelIndex const&))); - foreach (QByteArray format, QImageWriter::supportedImageFormats()) + foreach (QByteArray format, QImageWriter::supportedImageFormats()) { QString text = tr("%1...").arg(QString(format).toUpper()); - + QAction *action = new QAction(text, this); action->setData(format); connect(action, SIGNAL(triggered()), this, SLOT(export_as())); exportAsActs.append(action); } - + printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this); printAct->setShortcut(tr("Ctrl+E")); connect(printAct, SIGNAL(triggered()), this, SLOT(print())); - + exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(tr("Ctrl+Q")); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); @@ -335,8 +336,8 @@ void MainWindow::createMenus() { exportMenu = new QMenu(tr("&Export As"), this); foreach (QAction *action, exportAsActs) - exportMenu->addAction(action); - + exportMenu->addAction(action); + fileMenu = new QMenu(tr("&File"),this); fileMenu->addAction(openAct); fileMenu->addAction(saveAct); @@ -345,7 +346,7 @@ void MainWindow::createMenus() fileMenu->addSeparator(); fileMenu->addAction(exitAct); menuBar()->addMenu(fileMenu); - + helpMenu = new QMenu(tr("&Help"), this); helpMenu->addAction(aboutAct); menuBar()->addMenu(helpMenu); @@ -377,10 +378,10 @@ void MainWindow::createToolBars() void MainWindow::set_default_extent(double x0,double y0, double x1, double y1) { - try + try { boost::shared_ptr map_ptr = mapWidget_->getMap(); - if (map_ptr) + if (map_ptr) { mapnik::projection prj(map_ptr->srs()); prj.forward(x0,y0); @@ -401,7 +402,7 @@ void MainWindow::set_scaling_factor(double scaling_factor) void MainWindow::zoom_all() { boost::shared_ptr map_ptr = mapWidget_->getMap(); - if (map_ptr) + if (map_ptr) { map_ptr->zoom_all(); mapnik::box2d const& ext = map_ptr->get_current_extent(); diff --git a/demo/viewer/mainwindow.hpp b/demo/viewer/mainwindow.hpp index 2d70210d5..64080cdd1 100644 --- a/demo/viewer/mainwindow.hpp +++ b/demo/viewer/mainwindow.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2006 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -67,7 +68,7 @@ private: void createToolBars(); void createContextMenu(); void load_map_file(QString const& filename); - + QString currentPath; QString filename_; diff --git a/demo/viewer/mapwidget.cpp b/demo/viewer/mapwidget.cpp index d9c72c043..eafdb7adc 100644 --- a/demo/viewer/mapwidget.cpp +++ b/demo/viewer/mapwidget.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2006 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -63,7 +64,7 @@ double scales [] = {279541132.014, 1066.36479192, 533.182395962}; -MapWidget::MapWidget(QWidget *parent) +MapWidget::MapWidget(QWidget *parent) : QWidget(parent), map_(), selected_(1), @@ -90,9 +91,9 @@ void MapWidget::setTool(eTool tool) } void MapWidget::paintEvent(QPaintEvent*) -{ +{ QPainter painter(this); - + if (drag_) { if (cur_tool_ == ZoomToBox) @@ -119,7 +120,7 @@ void MapWidget::paintEvent(QPaintEvent*) } painter.end(); } - + void MapWidget::resizeEvent(QResizeEvent * ev) { if (map_) @@ -128,10 +129,10 @@ void MapWidget::resizeEvent(QResizeEvent * ev) updateMap(); } } - + void MapWidget::mousePressEvent(QMouseEvent* e) { - if (e->button()==Qt::LeftButton) + if (e->button()==Qt::LeftButton) { if (cur_tool_ == ZoomToBox || cur_tool_==Pan) { @@ -142,17 +143,17 @@ void MapWidget::mousePressEvent(QMouseEvent* e) else if (cur_tool_==Info) { if (map_) - { + { QVector > info; - + projection map_proj(map_->srs()); // map projection double scale_denom = scale_denominator(*map_,map_proj.is_geographic()); CoordTransform t(map_->width(),map_->height(),map_->get_current_extent()); - + for (unsigned index = 0; index < map_->layer_count();++index) { if (int(index) != selectedLayer_) continue; - + layer & layer = map_->layers()[index]; if (!layer.isVisible(scale_denom)) continue; std::string name = layer.name(); @@ -163,11 +164,11 @@ void MapWidget::mousePressEvent(QMouseEvent* e) mapnik::proj_transform prj_trans(map_proj,layer_proj); //std::auto_ptr data(new mapnik::memory_datasource); mapnik::featureset_ptr fs = map_->query_map_point(index,x,y); - + if (fs) { feature_ptr feat = fs->next(); - if (feat) + if (feat) { std::map const& props = feat->props(); std::map::const_iterator itr=props.begin(); @@ -180,10 +181,10 @@ void MapWidget::mousePressEvent(QMouseEvent* e) } } typedef mapnik::coord_transform2 path_type; - + for (unsigned i=0; inum_geometries();++i) { - mapnik::geometry_type & geom = feat->get_geometry(i); + mapnik::geometry_type & geom = feat->get_geometry(i); path_type path(t,geom,prj_trans); if (geom.num_points() > 0) { @@ -208,7 +209,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e) } } } - + if (info.size() > 0) { info_dialog info_dlg(info,this); @@ -216,34 +217,34 @@ void MapWidget::mousePressEvent(QMouseEvent* e) break; } } - + // remove annotation layer map_->layers().erase(remove_if(map_->layers().begin(), map_->layers().end(), bind(&layer::name,_1) == "*annotations*") , map_->layers().end()); } - } + } } - else if (e->button()==Qt::RightButton) - { + else if (e->button()==Qt::RightButton) + { //updateMap(); } } - + void MapWidget::mouseMoveEvent(QMouseEvent* e) -{ +{ if (cur_tool_ == ZoomToBox || cur_tool_==Pan) { end_x_ = e->x(); end_y_ = e->y(); update(); - } + } } void MapWidget::mouseReleaseEvent(QMouseEvent* e) { - if (e->button()==Qt::LeftButton) + if (e->button()==Qt::LeftButton) { end_x_ = e->x(); end_y_ = e->y(); @@ -252,7 +253,7 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e) drag_=false; if (map_) { - CoordTransform t(map_->width(),map_->height(),map_->get_current_extent()); + CoordTransform t(map_->width(),map_->height(),map_->get_current_extent()); box2d box = t.backward(box2d(start_x_,start_y_,end_x_,end_y_)); map_->zoom_to_box(box); updateMap(); @@ -267,7 +268,7 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e) int cy = int(0.5 * map_->height()); int dx = end_x_ - start_x_; int dy = end_y_ - start_y_; - map_->pan(cx - dx ,cy - dy); + map_->pan(cx - dx ,cy - dy); updateMap(); } } @@ -275,10 +276,10 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e) } -void MapWidget::keyPressEvent(QKeyEvent *e) +void MapWidget::keyPressEvent(QKeyEvent *e) { std::cout << "key pressed:"<< e->key()<<"\n"; - switch (e->key()) { + switch (e->key()) { case Qt::Key_Minus: zoomOut(); break; @@ -294,10 +295,10 @@ void MapWidget::keyPressEvent(QKeyEvent *e) break; case Qt::Key_Down: panDown(); - break; + break; case Qt::Key_Left: panLeft(); - break; + break; case Qt::Key_Right: panRight(); break; @@ -309,7 +310,7 @@ void MapWidget::keyPressEvent(QKeyEvent *e) break; case 51: zoomToLevel(12); - break; + break; case 52: zoomToLevel(13); break; @@ -318,7 +319,7 @@ void MapWidget::keyPressEvent(QKeyEvent *e) break; case 54: zoomToLevel(15); - break; + break; case 55: zoomToLevel(16); break; @@ -327,12 +328,12 @@ void MapWidget::keyPressEvent(QKeyEvent *e) break; case 57: zoomToLevel(18); - break; + break; default: QWidget::keyPressEvent(e); } - - + + } void MapWidget::zoomToBox(mapnik::box2d const& bbox) @@ -344,7 +345,7 @@ void MapWidget::zoomToBox(mapnik::box2d const& bbox) } } -void MapWidget::defaultView() +void MapWidget::defaultView() { if (map_) { @@ -354,7 +355,7 @@ void MapWidget::defaultView() } } -void MapWidget::zoomIn() +void MapWidget::zoomIn() { if (map_) { @@ -363,7 +364,7 @@ void MapWidget::zoomIn() } } -void MapWidget::zoomOut() +void MapWidget::zoomOut() { if (map_) { @@ -406,12 +407,12 @@ void MapWidget::panLeft() } void MapWidget::panRight() -{ +{ if (map_) { double cx = 0.5*map_->width(); double cy = 0.5*map_->height(); - map_->pan(int(cx + cx * 0.25),int(cy)); + map_->pan(int(cx + cx * 0.25),int(cy)); updateMap(); } } @@ -425,11 +426,11 @@ void MapWidget::zoomToLevel(int level) std::cerr << "scale denominator = " << scale_denom << "\n"; mapnik::box2d ext = map_->get_current_extent(); double width = static_cast(map_->width()); - double height= static_cast(map_->height()); + double height= static_cast(map_->height()); mapnik::coord2d pt = ext.center(); double res = scale_denom * 0.00028; - + mapnik::box2d box(pt.x - 0.5 * width * res, pt.y - 0.5 * height*res, pt.x + 0.5 * width * res, @@ -439,37 +440,37 @@ void MapWidget::zoomToLevel(int level) } } -void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&) +void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&) { //image_32 image(width,height); //agg_renderer renderer(map,image); //renderer.apply(); //image.saveToFile(filename,type); } - + void MapWidget::set_scaling_factor(double scaling_factor) { scaling_factor_ = scaling_factor; } -void MapWidget::updateMap() -{ +void MapWidget::updateMap() +{ if (map_) { unsigned width=map_->width(); unsigned height=map_->height(); - + image_32 buf(width,height); - try + try { mapnik::agg_renderer ren(*map_,buf,scaling_factor_); ren.apply(); - + QImage image((uchar*)buf.raw_data(),width,height,QImage::Format_ARGB32); pix_=QPixmap::fromImage(image.rgbSwapped()); projection prj(map_->srs()); // map projection - + box2d ext = map_->get_current_extent(); double x0 = ext.minx(); double y0 = ext.miny(); diff --git a/demo/viewer/mapwidget.hpp b/demo/viewer/mapwidget.hpp index e2d3c13d3..92cbe7322 100644 --- a/demo/viewer/mapwidget.hpp +++ b/demo/viewer/mapwidget.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,19 +33,19 @@ #include #include -class MapWidget : public QWidget +class MapWidget : public QWidget { Q_OBJECT - - public: - enum eTool + + public: + enum eTool { ZoomToBox = 1, Pan, Info, }; - -private: + +private: boost::shared_ptr map_; int selected_; QPixmap pix_; @@ -64,7 +65,7 @@ public: void setTool(eTool tool); boost::shared_ptr getMap(); inline QPixmap const& pixmap() const { return pix_;} - void setMap(boost::shared_ptr map); + void setMap(boost::shared_ptr map); void defaultView(); void zoomToBox(mapnik::box2d const& box); void zoomIn(); @@ -80,7 +81,7 @@ public slots: void layerSelected(int); signals: void mapViewChanged(); -protected: +protected: void paintEvent(QPaintEvent* ev); void resizeEvent(QResizeEvent* ev); void mousePressEvent(QMouseEvent* e); @@ -89,8 +90,8 @@ protected: void keyPressEvent(QKeyEvent *e); void export_to_file(unsigned width, unsigned height, - std::string const& filename, - std::string const& type); + std::string const& filename, + std::string const& type); }; #endif // MAP_WIDGET_HPP diff --git a/demo/viewer/styles_model.cpp b/demo/viewer/styles_model.cpp index aae9aa9ba..4a0fd0116 100644 --- a/demo/viewer/styles_model.cpp +++ b/demo/viewer/styles_model.cpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -38,60 +39,60 @@ class node : private boost::noncopyable virtual QIcon icon() const=0; virtual ~node_base() {} }; - + template struct wrap : public node_base { wrap(T const& obj) : obj_(obj) {} - + ~wrap() {} - + QString name () const { return obj_.name(); } - + QIcon icon() const { return obj_.icon(); } - + T obj_; }; - + public: - template + template node ( T const& obj, node * parent=0) : impl_(new wrap(obj)), parent_(parent) {} - + QString name() const { return impl_->name(); } - + QIcon icon() const { return impl_->icon(); } - + unsigned num_children() const { return children_.count(); } - + node * child(unsigned row) const { return children_.value(row); } - + node * parent() const { return parent_; } - + node * add_child(node * child) { children_.push_back(child); @@ -104,12 +105,12 @@ public: else return 0; } - - ~node() + + ~node() { qDeleteAll(children_); } - + private: boost::scoped_ptr impl_; QList children_; @@ -124,7 +125,7 @@ struct symbolizer_info : public boost::static_visitor boost::ignore_unused_variable_warning(sym); return QString("PointSymbolizer"); } - + QString operator() (mapnik::line_symbolizer const& sym) const { boost::ignore_unused_variable_warning(sym); @@ -148,19 +149,19 @@ struct symbolizer_info : public boost::static_visitor boost::ignore_unused_variable_warning(sym); return QString("PolygonSymbolizer"); } - + QString operator() (mapnik::text_symbolizer const& sym) const { boost::ignore_unused_variable_warning(sym); return QString("TextSymbolizer"); } - + QString operator() (mapnik::shield_symbolizer const& sym) const { boost::ignore_unused_variable_warning(sym); return QString("ShieldSymbolizer"); } - + template QString operator() (T const& ) const { @@ -200,14 +201,14 @@ struct symbolizer_icon : public boost::static_visitor QPixmap pix(48,16); pix.fill(); QPainter painter(&pix); - mapnik::stroke const& strk = sym.get_stroke(); + mapnik::stroke const& strk = sym.get_stroke(); mapnik::color const& col = strk.get_color(); QPen pen(QColor(col.red(),col.green(),col.blue(),col.alpha())); pen.setWidth(strk.get_width()); painter.setPen(pen); painter.drawLine(0,7,47,7); //painter.drawLine(7,15,12,0); - //painter.drawLine(12,0,8,15); + //painter.drawLine(12,0,8,15); return QIcon(pix); } @@ -224,13 +225,13 @@ public: symbolizer_node(mapnik::symbolizer const & sym) : sym_(sym) {} ~symbolizer_node(){} - - QString name() const + + QString name() const { //return QString("Symbolizer:fixme"); return boost::apply_visitor(symbolizer_info(),sym_); } - + QIcon icon() const { return boost::apply_visitor(symbolizer_icon(),sym_);//QIcon(":/images/filter.png"); @@ -248,15 +249,15 @@ public: QString name() const { mapnik::expression_ptr filter = rule_.get_filter(); - + return QString(mapnik::to_expression_string(*filter).c_str()); - } - + } + QIcon icon() const { return QIcon(":/images/filter.png"); } - + private: QString name_; mapnik::rule const& rule_; @@ -268,19 +269,19 @@ public: style_node(QString name, mapnik::feature_type_style const& style) : name_(name), style_(style) {} - + ~style_node() {} - + QString name() const { return name_; } - + QIcon icon() const { return QIcon(":/images/style.png"); } - + private: QString name_; mapnik::feature_type_style const& style_; @@ -292,26 +293,26 @@ public: explicit map_node(boost::shared_ptr map) : map_(map) {} ~map_node() {} - + QString name() const { return QString("Map"); } - + QIcon icon() const { return QIcon(":/images/map.png"); } - + private: boost::shared_ptr map_; }; StyleModel::StyleModel(boost::shared_ptr map, QObject * parent) : QAbstractItemModel(parent), - root_(new node(map_node(map))) + root_(new node(map_node(map))) { - typedef std::map style_type; + typedef std::map style_type; style_type const & styles = map->styles(); style_type::const_iterator itr = styles.begin(); style_type::const_iterator end = styles.end(); @@ -329,22 +330,22 @@ StyleModel::StyleModel(boost::shared_ptr map, QObject * parent) rule_n->add_child(new node(symbolizer_node(*itr3),rule_n)); } } - } + } } StyleModel::~StyleModel() {} -// interface +// interface QModelIndex StyleModel::index (int row, int col, QModelIndex const& parent) const { // qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId()); node * parent_node; - + if (!parent.isValid()) parent_node = root_.get(); else parent_node = static_cast(parent.internalPointer()); - + node * child_node = parent_node->child(row); if (child_node) return createIndex(row,col,child_node); @@ -358,7 +359,7 @@ QModelIndex StyleModel::parent (QModelIndex const& index) const node * parent_node = child_node->parent(); if (parent_node == root_.get()) return QModelIndex(); - + return createIndex(parent_node->row(),0,parent_node); } @@ -389,7 +390,7 @@ QVariant StyleModel::data(const QModelIndex & index, int role) const { if (role == Qt::DisplayRole) { - + return QVariant(cur_node->name()); } else if ( role == Qt::DecorationRole) diff --git a/demo/viewer/styles_model.hpp b/demo/viewer/styles_model.hpp index 621a3fd33..fc7626484 100644 --- a/demo/viewer/styles_model.hpp +++ b/demo/viewer/styles_model.hpp @@ -1,5 +1,6 @@ /* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2007 Artem Pavlenko + * + * Copyright (C) 2011 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,11 +33,11 @@ class StyleModel : public QAbstractItemModel public: StyleModel(boost::shared_ptr map, QObject * parent=0); ~StyleModel(); - // interface + // interface QModelIndex index (int row, int col, QModelIndex const& parent = QModelIndex()) const; QModelIndex parent (QModelIndex const& child) const; int rowCount( QModelIndex const& parent = QModelIndex()) const; - int columnCount( QModelIndex const& parent = QModelIndex()) const; + int columnCount( QModelIndex const& parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; private: //boost::shared_ptr map_; diff --git a/deps/agg/include/agg_path_storage.h b/deps/agg/include/agg_path_storage.h index 6a238aee7..9a2fd8232 100644 --- a/deps/agg/include/agg_path_storage.h +++ b/deps/agg/include/agg_path_storage.h @@ -736,7 +736,7 @@ namespace agg template void join_path(VertexSource& vs, unsigned path_id = 0) { - double x, y; + double x=0.0, y=0.0; unsigned cmd; vs.rewind(path_id); cmd = vs.vertex(&x, &y); diff --git a/deps/agg/include/agg_rasterizer_outline_aa.h b/deps/agg/include/agg_rasterizer_outline_aa.h index a06bd1e84..538321c9d 100644 --- a/deps/agg/include/agg_rasterizer_outline_aa.h +++ b/deps/agg/include/agg_rasterizer_outline_aa.h @@ -323,68 +323,65 @@ namespace agg int y2; int lprev; - if(close_polygon) + if(close_polygon && (m_src_vertices.size() >= 3)) { - if(m_src_vertices.size() >= 3) + dv.idx = 2; + + v = &m_src_vertices[m_src_vertices.size() - 1]; + x1 = v->x; + y1 = v->y; + lprev = v->len; + + v = &m_src_vertices[0]; + x2 = v->x; + y2 = v->y; + dv.lcurr = v->len; + line_parameters prev(x1, y1, x2, y2, lprev); + + v = &m_src_vertices[1]; + dv.x1 = v->x; + dv.y1 = v->y; + dv.lnext = v->len; + dv.curr = line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr); + + v = &m_src_vertices[dv.idx]; + dv.x2 = v->x; + dv.y2 = v->y; + dv.next = line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext); + + dv.xb1 = 0; + dv.yb1 = 0; + dv.xb2 = 0; + dv.yb2 = 0; + + switch(m_line_join) { - dv.idx = 2; + case outline_no_join: + dv.flags = 3; + break; - v = &m_src_vertices[m_src_vertices.size() - 1]; - x1 = v->x; - y1 = v->y; - lprev = v->len; + case outline_miter_join: + case outline_round_join: + dv.flags = + (prev.diagonal_quadrant() == dv.curr.diagonal_quadrant()) | + ((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant()) << 1); + break; - v = &m_src_vertices[0]; - x2 = v->x; - y2 = v->y; - dv.lcurr = v->len; - line_parameters prev(x1, y1, x2, y2, lprev); - - v = &m_src_vertices[1]; - dv.x1 = v->x; - dv.y1 = v->y; - dv.lnext = v->len; - dv.curr = line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr); - - v = &m_src_vertices[dv.idx]; - dv.x2 = v->x; - dv.y2 = v->y; - dv.next = line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext); - - dv.xb1 = 0; - dv.yb1 = 0; - dv.xb2 = 0; - dv.yb2 = 0; - - switch(m_line_join) - { - case outline_no_join: - dv.flags = 3; - break; - - case outline_miter_join: - case outline_round_join: - dv.flags = - (prev.diagonal_quadrant() == dv.curr.diagonal_quadrant()) | - ((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant()) << 1); - break; - - case outline_miter_accurate_join: - dv.flags = 0; - break; - } - - if((dv.flags & 1) == 0 && m_line_join != outline_round_join) - { - bisectrix(prev, dv.curr, &dv.xb1, &dv.yb1); - } - - if((dv.flags & 2) == 0 && m_line_join != outline_round_join) - { - bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2); - } - draw(dv, 0, m_src_vertices.size()); + case outline_miter_accurate_join: + dv.flags = 0; + break; } + + if((dv.flags & 1) == 0 && m_line_join != outline_round_join) + { + bisectrix(prev, dv.curr, &dv.xb1, &dv.yb1); + } + + if((dv.flags & 2) == 0 && m_line_join != outline_round_join) + { + bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2); + } + draw(dv, 0, m_src_vertices.size()); } else { diff --git a/deps/agg/src/agg_rounded_rect.cpp b/deps/agg/src/agg_rounded_rect.cpp index bebc06362..7f68651b7 100644 --- a/deps/agg/src/agg_rounded_rect.cpp +++ b/deps/agg/src/agg_rounded_rect.cpp @@ -78,8 +78,8 @@ namespace agg //-------------------------------------------------------------------- void rounded_rect::normalize_radius() { - double dx = fabs(m_y2 - m_y1); - double dy = fabs(m_x2 - m_x1); + double dx = fabs(m_x2 - m_x1); + double dy = fabs(m_y2 - m_y1); double k = 1.0; double t; diff --git a/docs/contributing.markdown b/docs/contributing.markdown index 722841a34..b3fba320a 100644 --- a/docs/contributing.markdown +++ b/docs/contributing.markdown @@ -15,11 +15,33 @@ Look through the code to get an idea, and do not hesitate to ask questions. Also read the design philosophy page for the motivations that lead to code decisions. +Templates are good, within reason. We seek to use templates were possible for flexible code, but not in cases where functional +patterns would be just as concise and clear. + In general we use Boost, it makes more possible in C++. It is a big build time dependency (as in time to compile against and # of headers) but ultimately compiles to small object code and is very fast (particularly spirit). It also has no dependencies itself (it's really an extension to the C++ language) so requiring it is much easier than requiring a hard dependency that itself has other dependencies. This is a big reason that we prefer AGG to Cairo as our primary renderer. Also AGG, besides producing the best visual output, strikes an excellent balance between speed and thread safety by using very lightweight objects. Cairo not so much. You will also notice that we don't use many of the standard geo libraries when we could. For instance we don't use GDAL, OGR, or GEOS anywhere in core, and only leverage them in optional plugins. We feel we can often write code that is faster and more thread safe than these libraries but that still does the job. If this ever changes we can adapt and start using these libraries or others as dependencies - nothing is nicer than standing on the shoulders of giants when it makes sense. +## Code commits best practices. + +#### Big changes - awesome as pull requests + +We love big, aggressive refactoring - but ideally in branches. Even if the changes should go directly into the mainline code and are stable, very big changes are useful to see as a group and branches are cheap. So, branch and commit then create a pull request against master so that other developers can take a quick look. This is a great way for informal code review when a full issue is not warrented. + +#### Commits that fix issues should note the issue # + + git commit plugins/input/ogr/ -m "implemented sql query in OGR plugin (closes #472)" + +#### Commits that relate to issues should reference them: + + git commit tests/python_tests/sqlite_test.py -m "more robust sqlite tests - refs #928" + +#### Commits that add a new feature or fix should be added to the CHANGELOG + +Ideally the CHANGELOG can be a very concise place to look for the most important recent development and should not read like a full commit log. So, some developers may prefer to weekly or monthly look back over their commits and summarize all at once with additions to the CHANGELOG. Other developers may prefer to add as they go. + + ## License Mapnik is licensed LGPL, which means that you are a free to use the code in any of your applications whether they be open source or not. It also means that if you contribute code to Mapnik that others are free to continue using Mapnik in the same way, even with your new additions. If you choose to redistribute an application using Mapnik just make sure to provide any source code modifications you make back to the community. For the actual details see the full LGPL license in the COPYING doc. @@ -67,13 +89,19 @@ If you see bits of code around that do not follow these please don't hesitate to #### Indentation is four spaces +#### Use C++ style casts + + static_cast(value); // yes + + (int)value; // no + #### Shared pointers should be created with [boost::make_shared](http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/make_shared.html) where possible #### Function definitions should not be separated from their arguments: - void foo(int a) { ... } // please + void foo(int a) // please - void foo (int a) { ... } // no + void foo (int a) // no #### Separate arguments by a single space: @@ -87,7 +115,18 @@ If you see bits of code around that do not follow these please don't hesitate to if(a==b) // no -#### Braces should ideally be on a separate line: +#### Braces should always be used: + + if (!file) + { + throw mapnik::datasource_exception("not found"); // please + } + + if (!file) + throw mapnik::datasource_exception("not found"); // no + + +#### Braces should be on a separate line: if (a == b) { diff --git a/include/mapnik/agg_pattern_source.hpp b/include/mapnik/agg_pattern_source.hpp index 1a9046d7d..0f24ddaf4 100644 --- a/include/mapnik/agg_pattern_source.hpp +++ b/include/mapnik/agg_pattern_source.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,15 +19,16 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef MAPNIK_AGG_PATTERN_SOURCE_HPP #define MAPNIK_AGG_PATTERN_SOURCE_HPP // mapnik #include + // boost #include + // agg #include "agg_color_rgba.h" @@ -61,4 +62,4 @@ private: }; } -#endif //MAPNIK_AGG_PATTERN_SOURCE_HPP +#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP diff --git a/include/mapnik/agg_rasterizer.hpp b/include/mapnik/agg_rasterizer.hpp index 44ee4eee5..49ac23b81 100644 --- a/include/mapnik/agg_rasterizer.hpp +++ b/include/mapnik/agg_rasterizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,12 +19,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef MAPNIK_AGG_RASTERIZER_HPP #define MAPNIK_AGG_RASTERIZER_HPP +// boost #include + +// agg #include "agg_rasterizer_scanline_aa.h" namespace mapnik { @@ -33,4 +35,4 @@ struct rasterizer : agg::rasterizer_scanline_aa<>, boost::noncopyable {}; } -#endif //MAPNIK_AGG_RASTERIZER_HPP +#endif // MAPNIK_AGG_RASTERIZER_HPP diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index 08a48d44a..1a74dd461 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef AGG_RENDERER_HPP -#define AGG_RENDERER_HPP +#ifndef MAPNIK_AGG_RENDERER_HPP +#define MAPNIK_AGG_RENDERER_HPP // mapnik #include @@ -40,6 +38,7 @@ // boost #include #include +#include // FIXME // forward declare so that @@ -61,7 +60,11 @@ class MAPNIK_DECL agg_renderer : public feature_style_processor { public: + // create with default, empty placement detector agg_renderer(Map const& m, T & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); + // create with external placement detector, possibly non-empty + agg_renderer(Map const &m, T & pixmap, boost::shared_ptr detector, + double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); ~agg_renderer(); void start_map_processing(Map const& map); void end_map_processing(Map const& map); @@ -122,9 +125,11 @@ private: CoordTransform t_; freetype_engine font_engine_; face_manager font_manager_; - label_collision_detector4 detector_; + boost::shared_ptr detector_; boost::scoped_ptr ras_ptr; + + void setup(Map const &m); }; } -#endif //AGG_RENDERER_HPP +#endif // MAPNIK_AGG_RENDERER_HPP diff --git a/include/mapnik/arrow.hpp b/include/mapnik/arrow.hpp index d070427f6..93a56db67 100644 --- a/include/mapnik/arrow.hpp +++ b/include/mapnik/arrow.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef ARROW_HPP -#define ARROW_HPP +#ifndef MAPNIK_ARROW_HPP +#define MAPNIK_ARROW_HPP #include @@ -44,4 +42,4 @@ private: }; } -#endif // ARROW_HPP +#endif // MAPNIK_ARROW_HPP diff --git a/include/mapnik/attribute.hpp b/include/mapnik/attribute.hpp index 7a34c30ab..d4172ab9c 100644 --- a/include/mapnik/attribute.hpp +++ b/include/mapnik/attribute.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,15 +20,18 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_ATTRIBUTE_HPP #define MAPNIK_ATTRIBUTE_HPP +// mapnik +#include +// stl #include namespace mapnik { +static mapnik::value _null_value; + struct attribute { std::string name_; @@ -38,7 +41,13 @@ struct attribute template V value(F const& f) const { - return f[name_]; + typedef typename F::const_iterator const_iterator; + const_iterator itr = f.find(name_); + if (itr != f.end()) + { + return itr->second; + } + return _null_value; } std::string const& name() const { return name_;} }; diff --git a/include/mapnik/attribute_collector.hpp b/include/mapnik/attribute_collector.hpp index 9f386a582..b9b62a89c 100644 --- a/include/mapnik/attribute_collector.hpp +++ b/include/mapnik/attribute_collector.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,20 +20,20 @@ * *****************************************************************************/ -//$Id$ - -#ifndef ATTRIBUTE_COLLECTOR_HPP -#define ATTRIBUTE_COLLECTOR_HPP +#ifndef MAPNIK_ATTRIBUTE_COLLECTOR_HPP +#define MAPNIK_ATTRIBUTE_COLLECTOR_HPP // mapnik #include #include #include #include + // boost #include #include #include + // stl #include #include @@ -271,4 +271,4 @@ private: } // namespace mapnik -#endif //ATTRIBUTE_COLLECTOR_HPP +#endif // MAPNIK_ATTRIBUTE_COLLECTOR_HPP diff --git a/include/mapnik/attribute_descriptor.hpp b/include/mapnik/attribute_descriptor.hpp index 72e15839c..7ba2e665d 100644 --- a/include/mapnik/attribute_descriptor.hpp +++ b/include/mapnik/attribute_descriptor.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef ATTRIBUTE_DESCRIPTOR -#define ATTRIBUTE_DESCRIPTOR +#ifndef MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP +#define MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP #include @@ -118,4 +116,4 @@ operator << (std::basic_ostream& out, } -#endif // ATTRIBUTE_DESCRIPTOR_HPP +#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP diff --git a/include/mapnik/box2d.hpp b/include/mapnik/box2d.hpp index b9e21ad35..16d7f85c4 100644 --- a/include/mapnik/box2d.hpp +++ b/include/mapnik/box2d.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,16 +20,16 @@ * *****************************************************************************/ -//$Id: box2d.hpp 39 2005-04-10 20:39:53Z pavlenko $ - #ifndef MAPNIK_BOX2D_HPP #define MAPNIK_BOX2D_HPP // mapnik #include #include + // boost #include + // stl #include diff --git a/include/mapnik/cairo_renderer.hpp b/include/mapnik/cairo_renderer.hpp index 60a79b144..821ed1334 100644 --- a/include/mapnik/cairo_renderer.hpp +++ b/include/mapnik/cairo_renderer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2008 Tom Hughes + * 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 @@ -20,14 +20,10 @@ * *****************************************************************************/ -//$Id$ - #if defined(HAVE_CAIRO) -#ifndef CAIRO_RENDERER_HPP -#define CAIRO_RENDERER_HPP - - +#ifndef MAPNIK_CAIRO_RENDERER_HPP +#define MAPNIK_CAIRO_RENDERER_HPP // mapnik #include @@ -152,6 +148,6 @@ public: }; } -#endif +#endif // MAPNIK_CAIRO_RENDERER_HPP -#endif //CAIRO_RENDERER_HPP +#endif diff --git a/include/mapnik/color.hpp b/include/mapnik/color.hpp index a923d3223..37c10cc93 100644 --- a/include/mapnik/color.hpp +++ b/include/mapnik/color.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id: color.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef COLOR_HPP -#define COLOR_HPP +#ifndef MAPNIK_COLOR_HPP +#define MAPNIK_COLOR_HPP // mapnik #include @@ -32,6 +30,7 @@ //boost #include #include + // stl #include @@ -141,4 +140,4 @@ public: } -#endif //COLOR_HPP +#endif // MAPNIK_COLOR_HPP diff --git a/include/mapnik/color_factory.hpp b/include/mapnik/color_factory.hpp index 15a3e07a8..c27af5fa4 100644 --- a/include/mapnik/color_factory.hpp +++ b/include/mapnik/color_factory.hpp @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_COLOR_FACTORY_HPP #define MAPNIK_COLOR_FACTORY_HPP @@ -120,4 +118,4 @@ public: #endif -#endif //MAPNIK_COLOR_FACTORY_HPP +#endif // MAPNIK_COLOR_FACTORY_HPP diff --git a/include/mapnik/config.hpp b/include/mapnik/config.hpp index 75a96fa2e..a79ade04d 100644 --- a/include/mapnik/config.hpp +++ b/include/mapnik/config.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef CONFIG_HPP -#define CONFIG_HPP +#ifndef MAPNIK_CONFIG_HPP +#define MAPNIK_CONFIG_HPP // Windows DLL support @@ -47,4 +47,5 @@ #endif #define PROJ_ENVELOPE_POINTS 20 -#endif // CONFIG_HPP + +#endif // MAPNIK_CONFIG_HPP diff --git a/include/mapnik/config_error.hpp b/include/mapnik/config_error.hpp index 933b101ed..c43169e50 100644 --- a/include/mapnik/config_error.hpp +++ b/include/mapnik/config_error.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef MAPNIK_CONFIG_ERROR_INCLUDED -#define MAPNIK_CONFIG_ERROR_INCLUDED +#ifndef MAPNIK_CONFIG_ERROR_HPP +#define MAPNIK_CONFIG_ERROR_HPP #include #include @@ -54,4 +54,4 @@ protected: }; } -#endif // MAPNIK_CONFIG_ERROR_INCLUDED +#endif // MAPNIK_CONFIG_ERROR_HPP diff --git a/include/mapnik/coord.hpp b/include/mapnik/coord.hpp index 6a5fe529d..340929801 100644 --- a/include/mapnik/coord.hpp +++ b/include/mapnik/coord.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,12 +20,13 @@ * *****************************************************************************/ -//$Id: coord.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef COORD_HPP -#define COORD_HPP +#ifndef MAPNIK_COORD_HPP +#define MAPNIK_COORD_HPP +// boost #include + +// stl #include #include @@ -187,4 +188,4 @@ operator << (std::basic_ostream& out, } } -#endif // COORD_HPP +#endif // MAPNIK_COORD_HPP diff --git a/include/mapnik/coord_array.hpp b/include/mapnik/coord_array.hpp index 45c76cab7..410e8e5d0 100644 --- a/include/mapnik/coord_array.hpp +++ b/include/mapnik/coord_array.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,13 +20,12 @@ * *****************************************************************************/ -//$Id: coord_array.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef COORD_ARRAY_HPP -#define COORD_ARRAY_HPP +#ifndef MAPNIK_COORD_ARRAY_HPP +#define MAPNIK_COORD_ARRAY_HPP //mapnik #include + // stl #include @@ -89,4 +88,4 @@ private: } -#endif //COORD_ARRAY_HPP +#endif // MAPNIK_COORD_ARRAY_HPP diff --git a/include/mapnik/css_color_grammar.hpp b/include/mapnik/css_color_grammar.hpp index 8e04011de..28166b5fb 100644 --- a/include/mapnik/css_color_grammar.hpp +++ b/include/mapnik/css_color_grammar.hpp @@ -20,22 +20,23 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_CSS_COLOR_GRAMMAR_HPP #define MAPNIK_CSS_COLOR_GRAMMAR_HPP // mapnik #include + // spirit2 #include #include #include + // phoenix #include #include #include #include + // fusion #include #include @@ -387,4 +388,4 @@ struct css_color_grammar : qi::grammar } -#endif //MAPNIK_CSS_COLOR_GRAMMAR_HPP +#endif // MAPNIK_CSS_COLOR_GRAMMAR_HPP diff --git a/include/mapnik/css_color_grammar_deprecated.hpp b/include/mapnik/css_color_grammar_deprecated.hpp index 1fdd44fb9..336dd2f56 100644 --- a/include/mapnik/css_color_grammar_deprecated.hpp +++ b/include/mapnik/css_color_grammar_deprecated.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,22 +20,23 @@ * *****************************************************************************/ -//$Id$ - -#ifndef MAPNIK_CSS_COLOR_GRAMMAR_HPP -#define MAPNIK_CSS_COLOR_GRAMMAR_HPP +#ifndef MAPNIK_CSS_COLOR_GRAMMAR_DEPRECATED_HPP +#define MAPNIK_CSS_COLOR_GRAMMAR_DEPRECATED_HPP // mapnik #include + // spirit2 #include #include #include + // phoenix #include #include #include #include + // fusion #include @@ -45,7 +46,6 @@ // stl #include - //BOOST_FUSION_ADAPT_CLASS( // mapnik::color, // (unsigned, unsigned, obj.red(), obj.set_red(val)) @@ -417,4 +417,4 @@ struct css_color_grammar : qi::grammar } -#endif //MAPNIK_CSS_COLOR_GRAMMAR_HPP +#endif // MAPNIK_CSS_COLOR_GRAMMAR_DEPRECATED_HPP diff --git a/include/mapnik/ctrans.hpp b/include/mapnik/ctrans.hpp index e18e80fd8..6fc2297f4 100644 --- a/include/mapnik/ctrans.hpp +++ b/include/mapnik/ctrans.hpp @@ -1,8 +1,8 @@ /***************************************************************************** - * + * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,90 +20,90 @@ * *****************************************************************************/ -//$Id: ctrans.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef CTRANS_HPP -#define CTRANS_HPP - -#include +#ifndef MAPNIK_CTRANS_HPP +#define MAPNIK_CTRANS_HPP +// mapnik #include #include #include #include -namespace mapnik { +// boost +#include + +// stl +#include + +const double pi = boost::math::constants::pi(); +const double pi_by_2 = pi/2.0; + +namespace mapnik +{ + typedef coord_array CoordinateArray; - -template + + +template struct MAPNIK_DECL coord_transform { coord_transform(Transform const& t, Geometry& geom) : t_(t), geom_(geom) {} - - unsigned vertex(double *x , double *y) const + + unsigned vertex(double *x, double *y) const { - unsigned command = geom_.vertex(x,y); - t_.forward(x,y); + unsigned command = geom_.vertex(x, y); + t_.forward(x, y); return command; } - - void rewind (unsigned pos) + + void rewind(unsigned pos) { geom_.rewind(pos); } - + private: Transform const& t_; Geometry& geom_; }; -template + +template struct MAPNIK_DECL coord_transform2 { typedef std::size_t size_type; typedef typename Geometry::value_type value_type; - coord_transform2(Transform const& t, - Geometry const& geom, + coord_transform2(Transform const& t, + Geometry const& geom, proj_transform const& prj_trans) - : t_(t), - geom_(geom), + : t_(t), + geom_(geom), prj_trans_(prj_trans) {} - - unsigned vertex(double * x , double * y) const + + unsigned vertex(double *x, double *y) const { - unsigned command(SEG_MOVETO); + unsigned command = SEG_MOVETO; bool ok = false; bool skipped_points = false; - while (!ok) + double z = 0; + while (!ok && command != SEG_END) { - command = geom_.vertex(x,y); - double z=0; - ok = prj_trans_.backward(*x,*y,z); + command = geom_.vertex(x, y); + ok = prj_trans_.backward(*x, *y, z); if (!ok) { skipped_points = true; } - ok = ok || (command == SEG_END); } if (skipped_points && (command == SEG_LINETO)) { command = SEG_MOVETO; } - t_.forward(x,y); + t_.forward(x, y); return command; } - /*unsigned vertex(double * x , double * y) const - { - unsigned command = geom_.vertex(x,y); - double z=0; - prj_trans_.backward(*x,*y,z); - t_.forward(x,y); - return command; - }*/ - - void rewind (unsigned pos) + void rewind(unsigned pos) { geom_.rewind(pos); } @@ -112,42 +112,42 @@ struct MAPNIK_DECL coord_transform2 { return geom_; } - + private: Transform const& t_; Geometry const& geom_; proj_transform const& prj_trans_; }; - -template + +template struct MAPNIK_DECL coord_transform3 { - coord_transform3(Transform const& t, - Geometry const& geom, + coord_transform3(Transform const& t, + Geometry const& geom, proj_transform const& prj_trans, int dx, int dy) - : t_(t), - geom_(geom), + : t_(t), + geom_(geom), prj_trans_(prj_trans), dx_(dx), dy_(dy) {} - - unsigned vertex(double * x , double * y) const + + unsigned vertex(double *x, double *y) const { - unsigned command = geom_.vertex(x,y); - double z=0; - prj_trans_.backward(*x,*y,z); - t_.forward(x,y); - *x+=dx_; - *y+=dy_; + unsigned command = geom_.vertex(x, y); + double z = 0; + prj_trans_.backward(*x, *y, z); + t_.forward(x, y); + *x += dx_; + *y += dy_; return command; } - - void rewind (unsigned pos) + + void rewind(unsigned pos) { geom_.rewind(pos); } - + private: Transform const& t_; Geometry const& geom_; @@ -155,7 +155,226 @@ private: int dx_; int dy_; }; + + +// TODO - expose this and make chainable +template +struct MAPNIK_DECL coord_transform_parallel +{ + typedef std::size_t size_type; + typedef typename Geometry::value_type value_type; + + coord_transform_parallel(Transform const& t, + Geometry const& geom, + proj_transform const& prj_trans ) + : t_(t), + geom_(geom), + prj_trans_(prj_trans), + offset_(0.0), + threshold_(10), + m_status(initial) {} + + enum status + { + initial, + start, + first, + process, + last_vertex, + angle_joint, + end + }; + + double get_offset() const + { + return offset_; + } + + void set_offset(double offset) + { + offset_ = offset; + } + + unsigned int get_threshold() const + { + return threshold_; + } + + void set_threshold(unsigned int t) + { + threshold_ = t; + } + + unsigned vertex(double * x , double * y) + { + double z=0; + + if (offset_==0.0) + { + unsigned command = geom_.vertex(x,y); + prj_trans_.backward(*x,*y,z); + t_.forward(x,y); + return command; + } + else + { + while(true){ + switch(m_status) + { + case end: + return SEG_END; + break; + case initial: + m_pre_cmd = geom_.vertex(x,y); + prj_trans_.backward(*x,*y,z); + t_.forward(x,y); + m_pre_x = *x; + m_pre_y = *y; + //m_status = (m_pre_cmd!=SEG_END)?start:end; // + case start: + m_cur_cmd = geom_.vertex(&m_cur_x, &m_cur_y); + prj_trans_.backward(m_cur_x,m_cur_y,z); + t_.forward(&m_cur_x,&m_cur_y); + case first: + angle_a = atan2((m_pre_y-m_cur_y),(m_pre_x-m_cur_x)); + dx_pre = cos(angle_a + pi_by_2); + dy_pre = sin(angle_a + pi_by_2); + #ifdef MAPNIK_DEBUG + std::clog << "offsetting line by: " << offset_ << "\n"; + std::clog << "initial dx=" << (dx_pre * offset_) << " dy=" << (dy_pre * offset_) << "\n"; + #endif + *x = m_pre_x + (dx_pre * offset_); + *y = m_pre_y + (dy_pre * offset_); + m_status = process; + return SEG_MOVETO; + case process: + switch(m_cur_cmd) + { + case SEG_LINETO: + m_next_cmd = geom_.vertex(&m_next_x, &m_next_y); + prj_trans_.backward(m_next_x,m_next_y,z); + t_.forward(&m_next_x,&m_next_y); + switch(m_next_cmd) + { + case SEG_LINETO: + m_status = angle_joint; + break; + default: + m_status = last_vertex; + break; + } + break; + case SEG_END: + m_status = end; + return SEG_END; + } + break; + case last_vertex: + dx_curr = cos(angle_a + pi_by_2); + dy_curr = sin(angle_a + pi_by_2); + *x = m_cur_x + (dx_curr * offset_); + *y = m_cur_y + (dy_curr * offset_); + m_status = end; + return m_cur_cmd; + case angle_joint: + angle_b = atan2((m_cur_y-m_next_y),(m_cur_x-m_next_x)); + h = tan((angle_b - angle_a)/2.0); + + if (fabs(h) < threshold_) + { + dx_curr = cos(angle_a + pi_by_2); + dy_curr = sin(angle_a + pi_by_2); + *x = m_cur_x + (dx_curr * offset_) - h * (dy_curr * offset_); + *y = m_cur_y + (dy_curr * offset_) + h * (dx_curr * offset_); + } + else // skip sharp spikes + { + + #ifdef MAPNIK_DEBUG + dx_curr = cos(angle_a + pi_by_2); + dy_curr = sin(angle_a + pi_by_2); + sin_curve = dx_curr*dy_pre-dy_curr*dx_pre; + std::clog << "angle a: " << angle_a << "\n"; + std::clog << "angle b: " << angle_b << "\n"; + std::clog << "h: " << h << "\n"; + std::clog << "sin_curve: " << sin_curve << "\n"; + #endif + m_status = process; + break; + } + + // alternate sharp spike fix, but suboptimal... + + /* + sin_curve = dx_curr*dy_pre-dy_curr*dx_pre; + cos_curve = -dx_pre*dx_curr-dy_pre*dy_curr; + + #ifdef MAPNIK_DEBUG + std::clog << "sin_curve value: " << sin_curve << "\n"; + #endif + if(sin_curve > -0.3 && sin_curve < 0.3) { + angle_b = atan2((m_cur_y-m_next_y),(m_cur_x-m_next_x)); + h = tan((angle_b - angle_a)/2.0); + *x = m_cur_x + (dx_curr * offset_) - h * (dy_curr * offset_); + *y = m_cur_y + (dy_curr * offset_) + h * (dx_curr * offset_); + } else { + if (angle_b - angle_a > 0) + h = -1.0*(1.0+cos_curve)/sin_curve; + else + h = (1.0+cos_curve)/sin_curve; + *x = m_cur_x + (dx_curr + base_shift*dy_curr)*offset_; + *y = m_cur_y + (dy_curr - base_shift*dx_curr)*offset_; + } + */ + + m_pre_x = *x; + m_pre_x = *y; + m_cur_x = m_next_x; + m_cur_y = m_next_y; + angle_a = angle_b; + m_pre_cmd = m_cur_cmd; + m_cur_cmd = m_next_cmd; + m_status = process; + return m_pre_cmd; + } + } + } + } + + void rewind (unsigned pos) + { + geom_.rewind(pos); + m_status = initial; + } +private: + Transform const& t_; + Geometry const& geom_; + proj_transform const& prj_trans_; + int offset_; + unsigned int threshold_; + status m_status; + double dx_pre; + double dy_pre; + double dx_curr; + double dy_curr; + double sin_curve; + double cos_curve; + double angle_a; + double angle_b; + double h; + unsigned m_pre_cmd; + double m_pre_x; + double m_pre_y; + unsigned m_cur_cmd; + double m_cur_x; + double m_cur_y; + unsigned m_next_cmd; + double m_next_x; + double m_next_y; +}; + + class CoordTransform { private: @@ -166,71 +385,74 @@ private: box2d extent_; double offset_x_; double offset_y_; + public: - CoordTransform(int width,int height,const box2d& extent, + CoordTransform(int width, int height, const box2d& extent, double offset_x = 0, double offset_y = 0) - :width_(width),height_(height),extent_(extent),offset_x_(offset_x),offset_y_(offset_y) + : width_(width), height_(height), extent_(extent), + offset_x_(offset_x), offset_y_(offset_y) { - sx_ = (double(width_))/extent_.width(); - sy_ = (double(height_))/extent_.height(); + sx_ = static_cast(width_) / extent_.width(); + sy_ = static_cast(height_) / extent_.height(); } - + inline int width() const { return width_; } - + inline int height() const { return height_; } - + inline double scale_x() const { return sx_; } - + inline double scale_y() const { return sy_; } - - inline void forward(double * x, double * y) const + + inline void forward(double *x, double *y) const { *x = (*x - extent_.minx()) * sx_ - offset_x_; *y = (extent_.maxy() - *y) * sy_ - offset_y_; } - - inline void backward(double * x, double * y) const + + inline void backward(double *x, double *y) const { - *x = extent_.minx() + (*x + offset_x_)/sx_; - *y = extent_.maxy() - (*y + offset_y_)/sy_; + *x = extent_.minx() + (*x + offset_x_) / sx_; + *y = extent_.maxy() - (*y + offset_y_) / sy_; } - + inline coord2d& forward(coord2d& c) const { - forward(&c.x,&c.y); - return c; - } - - inline coord2d& backward(coord2d& c) const - { - backward(&c.x,&c.y); + forward(&c.x, &c.y); return c; } - inline box2d forward(const box2d& e,proj_transform const& prj_trans) const + inline coord2d& backward(coord2d& c) const + { + backward(&c.x, &c.y); + return c; + } + + inline box2d forward(const box2d& e, + proj_transform const& prj_trans) const { double x0 = e.minx(); double y0 = e.miny(); double x1 = e.maxx(); double y1 = e.maxy(); double z = 0.0; - prj_trans.backward(x0,y0,z); - forward(&x0,&y0); - prj_trans.backward(x1,y1,z); - forward(&x1,&y1); - return box2d(x0,y0,x1,y1); + prj_trans.backward(x0, y0, z); + forward(&x0, &y0); + prj_trans.backward(x1, y1, z); + forward(&x1, &y1); + return box2d(x0, y0, x1, y1); } inline box2d forward(const box2d& e) const @@ -239,23 +461,24 @@ public: double y0 = e.miny(); double x1 = e.maxx(); double y1 = e.maxy(); - forward(&x0,&y0); - forward(&x1,&y1); - return box2d(x0,y0,x1,y1); + forward(&x0, &y0); + forward(&x1, &y1); + return box2d(x0, y0, x1, y1); } - inline box2d backward(const box2d& e,proj_transform const& prj_trans) const + inline box2d backward(const box2d& e, + proj_transform const& prj_trans) const { double x0 = e.minx(); double y0 = e.miny(); double x1 = e.maxx(); double y1 = e.maxy(); double z = 0.0; - backward(&x0,&y0); - prj_trans.forward(x0,y0,z); - backward(&x1,&y1); - prj_trans.forward(x1,y1,z); - return box2d(x0,y0,x1,y1); + backward(&x0, &y0); + prj_trans.forward(x0, y0, z); + backward(&x1, &y1); + prj_trans.forward(x1, y1, z); + return box2d(x0, y0, x1, y1); } inline box2d backward(const box2d& e) const @@ -264,28 +487,29 @@ public: double y0 = e.miny(); double x1 = e.maxx(); double y1 = e.maxy(); - backward(&x0,&y0); - backward(&x1,&y1); - return box2d(x0,y0,x1,y1); + backward(&x0, &y0); + backward(&x1, &y1); + return box2d(x0, y0, x1, y1); } inline CoordinateArray& forward(CoordinateArray& coords) const { - for (unsigned i=0;i const& extent() const { return extent_; @@ -293,4 +517,4 @@ public: }; } -#endif //CTRANS_HPP +#endif // MAPNIK_CTRANS_HPP diff --git a/include/mapnik/datasource.hpp b/include/mapnik/datasource.hpp index f2d34e724..0495ab450 100644 --- a/include/mapnik/datasource.hpp +++ b/include/mapnik/datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,9 @@ * *****************************************************************************/ -//$Id: datasource.hpp 43 2005-04-22 18:52:47Z pavlenko $ +#ifndef MAPNIK_DATASOURCE_HPP +#define MAPNIK_DATASOURCE_HPP -#ifndef DATASOURCE_HPP -#define DATASOURCE_HPP // mapnik #include #include @@ -31,9 +30,11 @@ #include #include #include + // boost #include #include + // stl #include #include @@ -142,6 +143,7 @@ typedef boost::shared_ptr datasource_ptr; delete ds; \ } \ // + } -#endif //DATASOURCE_HPP +#endif // MAPNIK_DATASOURCE_HPP diff --git a/include/mapnik/datasource_cache.hpp b/include/mapnik/datasource_cache.hpp index 4a063c826..08cb18a47 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,18 +20,18 @@ * *****************************************************************************/ -//$Id: datasource_cache.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef DATASOURCE_CACHE_HPP -#define DATASOURCE_CACHE_HPP +#ifndef MAPNIK_DATASOURCE_CACHE_HPP +#define MAPNIK_DATASOURCE_CACHE_HPP // mapnik #include #include #include #include + // boost #include + // stl #include @@ -57,4 +57,4 @@ public: }; } -#endif //DATASOURCE_CACHE_HPP +#endif // MAPNIK_DATASOURCE_CACHE_HPP diff --git a/include/mapnik/distance.hpp b/include/mapnik/distance.hpp index ca1b276b7..5c1b8f7eb 100644 --- a/include/mapnik/distance.hpp +++ b/include/mapnik/distance.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef DISTANCE_HPP -#define DISTANCE_HPP +#ifndef MAPNIK_DISTANCE_HPP +#define MAPNIK_DISTANCE_HPP #include @@ -52,4 +50,4 @@ public: */ } -#endif // GEO_UTILS_HPP +#endif // MAPNIK_DISTANCE_HPP diff --git a/include/mapnik/ellipsoid.hpp b/include/mapnik/ellipsoid.hpp index 14ea28f50..82c3e7231 100644 --- a/include/mapnik/ellipsoid.hpp +++ b/include/mapnik/ellipsoid.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_ELLIPSOID_HPP #define MAPNIK_ELLIPSOID_HPP diff --git a/include/mapnik/enumeration.hpp b/include/mapnik/enumeration.hpp index f93cffc2c..19ffc2828 100644 --- a/include/mapnik/enumeration.hpp +++ b/include/mapnik/enumeration.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,13 @@ * *****************************************************************************/ -#ifndef MAPNIK_ENUMERATION_INCLUDED -#define MAPNIK_ENUMERATION_INCLUDED +#ifndef MAPNIK_ENUMERATION_HPP +#define MAPNIK_ENUMERATION_HPP +// mapnik #include +// stl #include #include #include @@ -325,4 +327,4 @@ operator>>(std::istream & is, mapnik::enumeration & e) template <> std::string name ::our_name_ = #name; \ template <> bool name ::our_verified_flag_( name ::verify(__FILE__, __LINE__)); -#endif // MAPNIK_ENUMERATION_INCLUDED +#endif // MAPNIK_ENUMERATION_HPP diff --git a/include/mapnik/expression_evaluator.hpp b/include/mapnik/expression_evaluator.hpp index ad8cfad30..ded3c7e79 100644 --- a/include/mapnik/expression_evaluator.hpp +++ b/include/mapnik/expression_evaluator.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,14 +20,11 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_EXPRESSION_EVALUATOR_HPP #define MAPNIK_EXPRESSION_EVALUATOR_HPP // boost #include -//#include #if defined(BOOST_REGEX_HAS_ICU) #include #endif @@ -43,7 +40,11 @@ struct evaluate : boost::static_visitor explicit evaluate(feature_type const& f) : feature_(f) {} - value_type operator() (value_type x) const { return x; } + value_type operator() (value_type x) const + { + return x; + } + value_type operator() (attribute const& attr) const { return attr.value(feature_); @@ -104,4 +105,4 @@ struct evaluate : boost::static_visitor } -#endif //MAPNIK_EXPRESSION_EVALUATOR_HPP +#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp index 8f6a4f1e2..469a24a09 100644 --- a/include/mapnik/expression_grammar.hpp +++ b/include/mapnik/expression_grammar.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_EXPRESSIONS_GRAMMAR_HPP #define MAPNIK_EXPRESSIONS_GRAMMAR_HPP @@ -34,12 +32,15 @@ #include #include #include -//spirit2 + +// spirit2 #include #include -//fusion + +// fusion #include -//phoenix + +// phoenix #include #include #include @@ -222,11 +223,13 @@ struct expression_grammar : qi::grammar | '(' >> expr [_val = _1 ] >> ')' ; - attr %= '[' >> +(char_ - ']') >> ']'; + #if BOOST_VERSION > 104200 ustring %= '\'' >> no_skip[*~char_('\'')] >> '\''; + attr %= '[' >> no_skip[+~char_(']')] >> ']'; #else ustring %= '\'' >> lexeme[*(char_-'\'')] >> '\''; + attr %= '[' >> lexeme[+(char_ - ']')] >> ']'; #endif } diff --git a/include/mapnik/expression_node.hpp b/include/mapnik/expression_node.hpp index e8bbda615..c83ed795d 100644 --- a/include/mapnik/expression_node.hpp +++ b/include/mapnik/expression_node.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,12 +20,13 @@ * *****************************************************************************/ -#ifndef MAPNIK_EXPRESSION_NODE_HPP -#define MAPNIK_EXPRESSION_NODE_HPP +#ifndef MAPNIK_EXPRESSION_NODE_HPP +#define MAPNIK_EXPRESSION_NODE_HPP // mapnik #include #include + // boost #include #include diff --git a/include/mapnik/expression_string.hpp b/include/mapnik/expression_string.hpp index e55ebbf53..1f8279a87 100644 --- a/include/mapnik/expression_string.hpp +++ b/include/mapnik/expression_string.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,14 +20,13 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_EXPRESSION_STRING_HPP #define MAPNIK_EXPRESSION_STRING_HPP // mapnik #include #include + // stl #include diff --git a/include/mapnik/factory.hpp b/include/mapnik/factory.hpp index 28baa9327..71d09d703 100644 --- a/include/mapnik/factory.hpp +++ b/include/mapnik/factory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,13 +20,12 @@ * *****************************************************************************/ -//$Id: factory.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef FACTORY_HPP -#define FACTORY_HPP +#ifndef MAPNIK_FACTORY_HPP +#define MAPNIK_FACTORY_HPP // mapnik #include + // stl #include #include @@ -89,4 +88,4 @@ public: }; } -#endif //FACTORY_HPP +#endif // MAPNIK_FACTORY_HPP diff --git a/include/mapnik/fastmath.hpp b/include/mapnik/fastmath.hpp index 78259e5a9..c5b086727 100644 --- a/include/mapnik/fastmath.hpp +++ b/include/mapnik/fastmath.hpp @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef FASTMATH_HPP -#define FASTMATH_HPP +#ifndef MAPNIK_FASTMATH_HPP +#define MAPNIK_FASTMATH_HPP /* Timings: * fast_sin(not inlined) 8.95s @@ -109,4 +109,4 @@ static inline double fast_atan2(double y, double x) return result; } -#endif // FASTMATH_HPP +#endif // MAPNIK_FASTMATH_HPP diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 462733e3d..fd8347a3e 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,9 @@ * *****************************************************************************/ -//$Id: feature.hpp 40 2005-04-13 20:20:46Z pavlenko $ +#ifndef MAPNIK_FEATURE_HPP +#define MAPNIK_FEATURE_HPP -#ifndef FEATURE_HPP -#define FEATURE_HPP // mapnik #include #include @@ -36,9 +35,9 @@ #else #include #endif - #include #include + // stl #include @@ -66,6 +65,7 @@ private: std::map props_; public: typedef std::map::iterator iterator; + typedef std::map::const_iterator const_iterator; explicit feature(int id) : properties(props_), id_(id), @@ -146,7 +146,7 @@ public: { return props_; } - + iterator begin() { return props_.begin(); @@ -156,12 +156,27 @@ public: { return props_.end(); } + + const_iterator begin() const + { + return props_.begin(); + } + const_iterator end() const + { + return props_.end(); + } + + const_iterator find(std::string const& key) const + { + return props_.find(key); + } + std::string to_string() const { std::stringstream ss; - ss << "feature (" << std::endl; - ss << " id:" << id_ << std::endl; + ss << "feature " + << id_ << " (" << std::endl; for (std::map::const_iterator itr=props_.begin(); itr != props_.end();++itr) { @@ -181,4 +196,4 @@ inline std::ostream& operator<< (std::ostream & out,Feature const& f) } } -#endif //FEATURE_HPP +#endif // MAPNIK_FEATURE_HPP diff --git a/include/mapnik/feature_factory.hpp b/include/mapnik/feature_factory.hpp index 2383e3b50..dd550a16d 100644 --- a/include/mapnik/feature_factory.hpp +++ b/include/mapnik/feature_factory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,12 +20,13 @@ * *****************************************************************************/ -//$Id$ - -#ifndef FEATURE_FACTORY_HPP -#define FEATURE_FACTORY_HPP +#ifndef MAPNIK_FEATURE_FACTORY_HPP +#define MAPNIK_FEATURE_FACTORY_HPP +// mapnik #include + +// boost #include //#include @@ -39,8 +40,7 @@ struct feature_factory //return boost::allocate_shared(boost::fast_pool_allocator(),fid); return boost::make_shared(fid); } - }; } -#endif //FEATURE_FACTORY_HPP +#endif // MAPNIK_FEATURE_FACTORY_HPP diff --git a/include/mapnik/feature_layer_desc.hpp b/include/mapnik/feature_layer_desc.hpp index 8ae1363f5..14adb6d4e 100644 --- a/include/mapnik/feature_layer_desc.hpp +++ b/include/mapnik/feature_layer_desc.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,14 +20,13 @@ * *****************************************************************************/ -//$Id$ - -#ifndef FEATURE_LAYER_DESC_HPP -#define FEATURE_LAYER_DESC_HPP +#ifndef MAPNIK_FEATURE_LAYER_DESC_HPP +#define MAPNIK_FEATURE_LAYER_DESC_HPP // mapnik #include +// stl #include #include #include @@ -106,4 +105,4 @@ operator << (std::basic_ostream& out, } } -#endif //FEATURE_LAYER_DESC_HPP +#endif // MAPNIK_FEATURE_LAYER_DESC_HPP diff --git a/include/mapnik/feature_style_processor.hpp b/include/mapnik/feature_style_processor.hpp index 6c944d979..d0e1b3b99 100644 --- a/include/mapnik/feature_style_processor.hpp +++ b/include/mapnik/feature_style_processor.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef FEATURE_STYLE_PROCESSOR_HPP -#define FEATURE_STYLE_PROCESSOR_HPP +#ifndef MAPNIK_FEATURE_STYLE_PROCESSOR_HPP +#define MAPNIK_FEATURE_STYLE_PROCESSOR_HPP #include #include @@ -74,4 +72,4 @@ private: }; } -#endif //FEATURE_STYLE_PROCESSOR_HPP +#endif // MAPNIK_FEATURE_STYLE_PROCESSOR_HPP diff --git a/include/mapnik/feature_type_style.hpp b/include/mapnik/feature_type_style.hpp index 63d943204..ce47a891f 100644 --- a/include/mapnik/feature_type_style.hpp +++ b/include/mapnik/feature_type_style.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,14 +20,14 @@ * *****************************************************************************/ -//$Id$ +#ifndef MAPNIK_FEATURE_TYPE_STYLE_HPP +#define MAPNIK_FEATURE_TYPE_STYLE_HPP -#ifndef FEATURE_TYPE_STYLE_HPP -#define FEATURE_TYPE_STYLE_HPP // mapnik #include #include #include + // stl #include @@ -69,4 +69,4 @@ public: }; } -#endif //FEATURE_TYPE_STYLE_HPP +#endif // MAPNIK_FEATURE_TYPE_STYLE_HPP diff --git a/include/mapnik/fill.hpp b/include/mapnik/fill.hpp index 2762e8806..a802c4925 100644 --- a/include/mapnik/fill.hpp +++ b/include/mapnik/fill.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,17 +20,16 @@ * *****************************************************************************/ -//$Id$ - -#ifndef FILL_HPP -#define FILL_HPP +#ifndef MAPNIK_FILL_HPP +#define MAPNIK_FILL_HPP namespace mapnik { + class fill { - }; + } -#endif //FILL_HPP +#endif // MAPNIK_FILL_HPP diff --git a/include/mapnik/filter_factory.hpp b/include/mapnik/filter_factory.hpp index 79709c4f6..3e25c4014 100644 --- a/include/mapnik/filter_factory.hpp +++ b/include/mapnik/filter_factory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006-2009 Artem Pavlenko + * 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 @@ -20,14 +20,13 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_FILTER_FACTORY_HPP #define MAPNIK_FILTER_FACTORY_HPP // mapnik #include #include + // stl #include @@ -41,4 +40,4 @@ MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt); } -#endif //MAPNIK_FILTER_FACTORY_HPP +#endif // MAPNIK_FILTER_FACTORY_HPP diff --git a/include/mapnik/filter_featureset.hpp b/include/mapnik/filter_featureset.hpp index 866f33583..37b57803f 100644 --- a/include/mapnik/filter_featureset.hpp +++ b/include/mapnik/filter_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,10 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_FILTER_FEATURESET_HPP #define MAPNIK_FILTER_FEATURESET_HPP +// mapnik #include namespace mapnik { @@ -54,4 +53,4 @@ private: }; } -#endif //MAPNIK_FILTER_FEATURESET_HPP +#endif // MAPNIK_FILTER_FEATURESET_HPP diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index eaa464ace..fcdbb9740 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,9 @@ * *****************************************************************************/ -//$Id$ +#ifndef MAPNIK_FONT_ENGINE_FREETYPE_HPP +#define MAPNIK_FONT_ENGINE_FREETYPE_HPP -#ifndef FONT_ENGINE_FREETYPE_HPP -#define FONT_ENGINE_FREETYPE_HPP // mapnik #include #include @@ -50,7 +49,6 @@ extern "C" #include #endif - // stl #include #include @@ -121,7 +119,13 @@ public: { if (! FT_Set_Pixel_Sizes( face_, 0, size )) return true; + return false; + } + bool set_character_sizes(float size) + { + if ( !FT_Set_Char_Size(face_,0,(FT_F26Dot6)(size * (1<<6)),0,0)) + return true; return false; } @@ -186,6 +190,14 @@ public: (*face)->set_pixel_sizes(size); } } + + void set_character_sizes(float size) + { + for (std::vector::iterator face = faces_.begin(); face != faces_.end(); ++face) + { + (*face)->set_character_sizes(size); + } + } private: std::vector faces_; std::map dimension_cache_; @@ -200,7 +212,7 @@ public: void init(double radius) { - FT_Stroker_Set(s_, (FT_Fixed) radius * (1<<6), + FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); @@ -334,11 +346,17 @@ struct text_renderer : private boost::noncopyable halo_radius_(0.0), opacity_(1.0) {} + void set_pixel_size(unsigned size) { faces_->set_pixel_sizes(size); } - + + void set_character_size(float size) + { + faces_->set_character_sizes(size); + } + void set_fill(mapnik::color const& fill) { fill_=fill; @@ -602,4 +620,4 @@ private: }; } -#endif // FONT_ENGINE_FREETYPE_HPP +#endif // MAPNIK_FONT_ENGINE_FREETYPE_HPP diff --git a/include/mapnik/font_set.hpp b/include/mapnik/font_set.hpp index 7ce08db5e..11c73a316 100644 --- a/include/mapnik/font_set.hpp +++ b/include/mapnik/font_set.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef FONT_SET_HPP -#define FONT_SET_HPP +#ifndef MAPNIK_FONT_SET_HPP +#define MAPNIK_FONT_SET_HPP // mapnik #include @@ -52,4 +50,4 @@ private: }; } -#endif //FONT_SET_HPP +#endif // MAPNIK_FONT_SET_HPP diff --git a/include/mapnik/gamma.hpp b/include/mapnik/gamma.hpp index c24dfa44a..5267c3e89 100644 --- a/include/mapnik/gamma.hpp +++ b/include/mapnik/gamma.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id: gamma.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef GAMMA_HPP -#define GAMMA_HPP +#ifndef MAPNIK_GAMMA_HPP +#define MAPNIK_GAMMA_HPP #include @@ -50,4 +48,4 @@ struct MAPNIK_DECL gamma }; } -#endif //GAMMA_HPP +#endif // MAPNIK_GAMMA_HPP diff --git a/include/mapnik/geom_util.hpp b/include/mapnik/geom_util.hpp index f01b678e8..87c91e02a 100644 --- a/include/mapnik/geom_util.hpp +++ b/include/mapnik/geom_util.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,15 +20,16 @@ * *****************************************************************************/ -//$Id: geom_util.hpp 39 2005-04-10 20:39:53Z pavlenko $ +#ifndef MAPNIK_GEOM_UTIL_HPP +#define MAPNIK_GEOM_UTIL_HPP -#ifndef GEOM_UTIL_HPP -#define GEOM_UTIL_HPP // mapnik #include #include + // boost #include + // stl #include @@ -217,4 +218,4 @@ struct filter_at_point }; } -#endif //GEOM_UTIL_HPP +#endif // MAPNIK_GEOM_UTIL_HPP diff --git a/include/mapnik/geometry.hpp b/include/mapnik/geometry.hpp index dea3125cd..f083d5102 100644 --- a/include/mapnik/geometry.hpp +++ b/include/mapnik/geometry.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,15 +20,14 @@ * *****************************************************************************/ -//$Id: geometry.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef GEOMETRY_HPP -#define GEOMETRY_HPP +#ifndef MAPNIK_GEOMETRY_HPP +#define MAPNIK_GEOMETRY_HPP // mapnik #include #include #include + // boost #include #include @@ -68,27 +67,7 @@ public: { return type_; } - - double area() const - { - double sum = 0.0; - double x(0); - double y(0); - rewind(0); - double xs = x; - double ys = y; - for (unsigned i=0;i envelope() const { box2d result; @@ -412,4 +391,4 @@ typedef boost::ptr_vector geometry_containter; } -#endif //GEOMETRY_HPP +#endif // MAPNIK_GEOMETRY_HPP diff --git a/include/mapnik/global.hpp b/include/mapnik/global.hpp index 55eb6f1b1..f834552c7 100644 --- a/include/mapnik/global.hpp +++ b/include/mapnik/global.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,14 +20,13 @@ * *****************************************************************************/ -//$Id$ - -#ifndef GLOBAL_HPP -#define GLOBAL_HPP +#ifndef MAPNIK_GLOBAL_HPP +#define MAPNIK_GLOBAL_HPP // boost #include #include + // stl #include @@ -183,4 +182,4 @@ inline double round (double val) -#endif //GLOBAL_HPP +#endif // MAPNIK_GLOBAL_HPP diff --git a/include/mapnik/glyph_symbolizer.hpp b/include/mapnik/glyph_symbolizer.hpp index a45830a08..25daf62b8 100644 --- a/include/mapnik/glyph_symbolizer.hpp +++ b/include/mapnik/glyph_symbolizer.hpp @@ -1,5 +1,27 @@ -#ifndef GLYPH_SYMBOLIZER_HPP -#define GLYPH_SYMBOLIZER_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 MAPNIK_GLYPH_SYMBOLIZER_HPP +#define MAPNIK_GLYPH_SYMBOLIZER_HPP // mapnik #include @@ -190,4 +212,4 @@ private: } // end mapnik namespace -#endif +#endif // MAPNIK_GLYPH_SYMBOLIZER_HPP diff --git a/include/mapnik/gradient.hpp b/include/mapnik/gradient.hpp index a1d029e38..896765133 100644 --- a/include/mapnik/gradient.hpp +++ b/include/mapnik/gradient.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,11 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef GRADIENT_HPP -#define GRADIENT_HPP +#ifndef MAPNIK_GRADIENT_HPP +#define MAPNIK_GRADIENT_HPP +// agg #include // mapnik @@ -104,4 +104,4 @@ private: }; } -#endif //GRADIENT_HPP +#endif // MAPNIK_GRADIENT_HPP diff --git a/include/mapnik/graphics.hpp b/include/mapnik/graphics.hpp index 421e29287..6774da392 100644 --- a/include/mapnik/graphics.hpp +++ b/include/mapnik/graphics.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id: graphics.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef GRAPHICS_HPP -#define GRAPHICS_HPP +#ifndef MAPNIK_GRAPHICS_HPP +#define MAPNIK_GRAPHICS_HPP // mapnik #include @@ -520,4 +518,5 @@ public: } }; } -#endif //GRAPHICS_HPP + +#endif // MAPNIK_GRAPHICS_HPP diff --git a/include/mapnik/grid/grid_pixfmt.hpp b/include/mapnik/grid/grid_pixfmt.hpp index 0f3978975..7ae058479 100644 --- a/include/mapnik/grid/grid_pixfmt.hpp +++ b/include/mapnik/grid/grid_pixfmt.hpp @@ -23,7 +23,7 @@ #ifndef MAPNIK_GRID_PIXFMT_HPP #define MAPNIK_GRID_PIXFMT_HPP -#include +#include #include "agg_basics.h" #include #include diff --git a/include/mapnik/grid/grid_util.hpp b/include/mapnik/grid/grid_util.hpp index 8a48f11b0..2ea1220df 100644 --- a/include/mapnik/grid/grid_util.hpp +++ b/include/mapnik/grid/grid_util.hpp @@ -50,7 +50,10 @@ static inline void scale_grid(mapnik::grid::data_type & target, int th2 = target_height/2; int offs_x = rint((source_width-target_width-x_off_f*2*source_width)/2); int offs_y = rint((source_height-target_height-y_off_f*2*source_height)/2); - unsigned yprt, yprt1, xprt, xprt1; + unsigned yprt(0); + unsigned yprt1(0); + unsigned xprt(0); + unsigned xprt1(0); //no scaling or subpixel offset if (target_height == source_height && target_width == source_width && offs_x == 0 && offs_y == 0){ diff --git a/include/mapnik/hextree.hpp b/include/mapnik/hextree.hpp index c9f1265e5..9c42d5798 100644 --- a/include/mapnik/hextree.hpp +++ b/include/mapnik/hextree.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef _HEXTREE_HPP_ -#define _HEXTREE_HPP_ +#ifndef MAPNIK_HEXTREE_HPP +#define MAPNIK_HEXTREE_HPP // mapnik #include @@ -455,4 +454,4 @@ private: }; } // namespace mapnik -#endif // _HEXTREE_HPP_ +#endif // MAPNIK_HEXTREE_HPP diff --git a/include/mapnik/hit_test_filter.hpp b/include/mapnik/hit_test_filter.hpp index 702d7d250..67c3837ca 100644 --- a/include/mapnik/hit_test_filter.hpp +++ b/include/mapnik/hit_test_filter.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,10 @@ * *****************************************************************************/ -//$Id$ - -#ifndef HIT_TEST_FILTER_HPP -#define HIT_TEST_FILTER_HPP +#ifndef MAPNIK_HIT_TEST_FILTER_HPP +#define MAPNIK_HIT_TEST_FILTER_HPP +// mapnik #include namespace mapnik { @@ -54,4 +53,4 @@ private: }; } -#endif // HIT_TEST_FILTER_HPP +#endif // MAPNIK_HIT_TEST_FILTER_HPP diff --git a/include/mapnik/image_compositing.hpp b/include/mapnik/image_compositing.hpp index adf5df9ab..dcd35676e 100644 --- a/include/mapnik/image_compositing.hpp +++ b/include/mapnik/image_compositing.hpp @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef IMAGE_COMPOSITING_HPP -#define IMAGE_COMPOSITING_HPP +#ifndef MAPNIK_IMAGE_COMPOSITING_HPP +#define MAPNIK_IMAGE_COMPOSITING_HPP // agg #include "agg_rendering_buffer.h" @@ -186,4 +184,4 @@ void composite(T1 & im, T2 & im2, composite_mode_e mode) } -#endif // IMAGE_COMPOSITING_HPP +#endif // MAPNIK_IMAGE_COMPOSITING_HPP diff --git a/include/mapnik/image_data.hpp b/include/mapnik/image_data.hpp index 3b8de2bea..d381f1393 100644 --- a/include/mapnik/image_data.hpp +++ b/include/mapnik/image_data.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,12 +20,13 @@ * *****************************************************************************/ -//$Id: image_data.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef IMAGE_DATA_HPP -#define IMAGE_DATA_HPP +#ifndef MAPNIK_IMAGE_DATA_HPP +#define MAPNIK_IMAGE_DATA_HPP +// mapnik #include + +// stl #include #include @@ -139,4 +140,4 @@ typedef ImageData image_data_32; typedef ImageData image_data_8; } -#endif //IMAGE_DATA_HPP +#endif // MAPNIK_IMAGE_DATA_HPP diff --git a/include/mapnik/image_reader.hpp b/include/mapnik/image_reader.hpp index 36074ea9f..144863c1e 100644 --- a/include/mapnik/image_reader.hpp +++ b/include/mapnik/image_reader.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,13 +20,13 @@ * *****************************************************************************/ -//$Id: image_reader.hpp 39 2005-04-10 20:39:53Z pavlenko $ +#ifndef MAPNIK_IMAGE_READER_HPP +#define MAPNIK_IMAGE_READER_HPP -#ifndef IMAGE_READER_HPP -#define IMAGE_READER_HPP // mapnik #include #include + // stl #include #include @@ -63,4 +63,4 @@ MAPNIK_DECL image_reader* get_image_reader(const std::string& file); } -#endif //IMAGE_READER_HPP +#endif // MAPNIK_IMAGE_READER_HPP diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 2f8aff77d..604b34b78 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id: image_util.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef IMAGE_UTIL_HPP -#define IMAGE_UTIL_HPP +#ifndef MAPNIK_IMAGE_UTIL_HPP +#define MAPNIK_IMAGE_UTIL_HPP // mapnik #include @@ -292,10 +290,13 @@ template MAPNIK_DECL std::string save_to_string(image_data_32 con rgba_palette const&); template MAPNIK_DECL std::string save_to_string > (image_view const&, - std::string const&, + std::string const&); + +template MAPNIK_DECL std::string save_to_string > (image_view const&, + std::string const&, rgba_palette const&); #endif } -#endif //IMAGE_UTIL_HPP +#endif // MAPNIK_IMAGE_UTIL_HPP diff --git a/include/mapnik/image_view.hpp b/include/mapnik/image_view.hpp index 45498b204..c942d17d2 100644 --- a/include/mapnik/image_view.hpp +++ b/include/mapnik/image_view.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef IMAGE_VIEW_HPP -#define IMAGE_VIEW_HPP - +#ifndef MAPNIK_IMAGE_VIEW_HPP +#define MAPNIK_IMAGE_VIEW_HPP namespace mapnik { @@ -107,5 +104,5 @@ private: }; } -#endif // IMAGE_VIEW_HPP +#endif // MAPNIK_IMAGE_VIEW_HPP diff --git a/include/mapnik/jpeg_io.hpp b/include/mapnik/jpeg_io.hpp index 33a7fba74..f5d96bc71 100644 --- a/include/mapnik/jpeg_io.hpp +++ b/include/mapnik/jpeg_io.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_JPEG_IO_HPP #define MAPNIK_JPEG_IO_HPP diff --git a/include/mapnik/label_collision_detector.hpp b/include/mapnik/label_collision_detector.hpp index f52d394e1..48de5f647 100644 --- a/include/mapnik/label_collision_detector.hpp +++ b/include/mapnik/label_collision_detector.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,13 +20,12 @@ * *****************************************************************************/ -//$Id$ - -#ifndef LABEL_COLLISION_DETECTOR_HPP -#define LABEL_COLLISION_DETECTOR_HPP +#ifndef MAPNIK_LABEL_COLLISION_DETECTOR_HPP +#define MAPNIK_LABEL_COLLISION_DETECTOR_HPP // mapnik #include + // stl #include #include @@ -69,7 +68,7 @@ class label_collision_detector2 : boost::noncopyable typedef quad_tree > tree_t; tree_t tree_; public: - + explicit label_collision_detector2(box2d const& extent) : tree_(extent) {} @@ -138,6 +137,7 @@ public: //quad tree based label collission detector so labels dont appear within a given distance class label_collision_detector4 : boost::noncopyable { +public: struct label { label(box2d const& b) : box(b) {} @@ -146,11 +146,13 @@ class label_collision_detector4 : boost::noncopyable box2d box; UnicodeString text; }; - + +private: typedef quad_tree< label > tree_t; tree_t tree_; public: + typedef tree_t::query_iterator query_iterator; explicit label_collision_detector4(box2d const& extent) : tree_(extent) {} @@ -224,7 +226,10 @@ public: { return tree_.extent(); } + + query_iterator begin() { return tree_.query_in_box(extent()); } + query_iterator end() { return tree_.query_end(); } }; } -#endif // LABEL_COLLISION_DETECTOR_HPP +#endif // MAPNIK_LABEL_COLLISION_DETECTOR_HPP diff --git a/include/mapnik/label_placement.hpp b/include/mapnik/label_placement.hpp index c1bdbad96..a667516a9 100644 --- a/include/mapnik/label_placement.hpp +++ b/include/mapnik/label_placement.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef LABEL_PLACEMENT_HPP -#define LABEL_PLACEMENT_HPP +#ifndef MAPNIK_LABEL_PLACEMENT_HPP +#define MAPNIK_LABEL_PLACEMENT_HPP namespace mapnik { @@ -51,4 +50,4 @@ public: }; } -#endif //LABEL_PLACEMENT_HPP +#endif // MAPNIK_LABEL_PLACEMENT_HPP diff --git a/include/mapnik/layer.hpp b/include/mapnik/layer.hpp index d4d4c7ea4..337bc1872 100644 --- a/include/mapnik/layer.hpp +++ b/include/mapnik/layer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: layer.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef LAYER_HPP -#define LAYER_HPP +#ifndef MAPNIK_LAYER_HPP +#define MAPNIK_LAYER_HPP + // mapnik #include #include @@ -217,4 +217,4 @@ private: }; } -#endif //LAYER_HPP +#endif // MAPNIK_LAYER_HPP diff --git a/include/mapnik/libxml2_loader.hpp b/include/mapnik/libxml2_loader.hpp index d81e14187..c4e5ca893 100644 --- a/include/mapnik/libxml2_loader.hpp +++ b/include/mapnik/libxml2_loader.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,13 @@ * *****************************************************************************/ -#ifndef LIBXML2_LOADER_INCLUDED -#define LIBXML2_LOADER_INCLUDED +#ifndef MAPNIK_LIBXML2_LOADER_HPP +#define MAPNIK_LIBXML2_LOADER_HPP +// boost #include +// stl #include namespace mapnik @@ -33,4 +35,4 @@ void read_xml2( std::string const & filename, boost::property_tree::ptree & pt); void read_xml2_string( std::string const & str, boost::property_tree::ptree & pt, std::string const & base_path=""); } -#endif // LIBXML2_LOADER_INCLUDED +#endif // MAPNIK_LIBXML2_LOADER_HPP diff --git a/include/mapnik/line_pattern_symbolizer.hpp b/include/mapnik/line_pattern_symbolizer.hpp index 88cea4082..8a65bf043 100644 --- a/include/mapnik/line_pattern_symbolizer.hpp +++ b/include/mapnik/line_pattern_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: polygon_symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef LINE_PATTERN_SYMBOLIZER_HPP -#define LINE_PATTERN_SYMBOLIZER_HPP +#ifndef MAPNIK_LINE_PATTERN_SYMBOLIZER_HPP +#define MAPNIK_LINE_PATTERN_SYMBOLIZER_HPP // mapnik #include @@ -38,4 +37,4 @@ struct MAPNIK_DECL line_pattern_symbolizer : }; } -#endif // LINE_PATTERN_SYMBOLIZER_HPP +#endif // MAPNIK_LINE_PATTERN_SYMBOLIZER_HPP diff --git a/include/mapnik/line_symbolizer.hpp b/include/mapnik/line_symbolizer.hpp index e76eccbb2..39df6685d 100644 --- a/include/mapnik/line_symbolizer.hpp +++ b/include/mapnik/line_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,11 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: line_symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef LINE_SYMBOLIZER_HPP -#define LINE_SYMBOLIZER_HPP +#ifndef MAPNIK_LINE_SYMBOLIZER_HPP +#define MAPNIK_LINE_SYMBOLIZER_HPP +// mapnik #include #include #include @@ -82,4 +82,4 @@ private: }; } -#endif //LINE_SYMBOLIZER_HPP +#endif // MAPNIK_LINE_SYMBOLIZER_HPP diff --git a/include/mapnik/load_map.hpp b/include/mapnik/load_map.hpp index 84d35a19f..2d1f23336 100644 --- a/include/mapnik/load_map.hpp +++ b/include/mapnik/load_map.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,16 +19,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -// $Id$ -#ifndef MAP_LOADER_HPP -#define MAP_LOADER_HPP +#ifndef MAPNIK_LOAD_MAP_HPP +#define MAPNIK_LOAD_MAP_HPP #ifdef HAVE_CONFIG_H -#include +#include #endif +// mapnik #include + +// stl #include namespace mapnik @@ -37,4 +39,4 @@ MAPNIK_DECL void load_map(Map & map, std::string const& filename, bool strict = MAPNIK_DECL void load_map_string(Map & map, std::string const& str, bool strict = false, std::string const& base_path=""); } -#endif // LOAD_MAP_HPP +#endif // MAPNIK_LOAD_MAP_HPP diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index 9cc58116f..152ca0181 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,13 +19,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: map.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef MAP_HPP -#define MAP_HPP +#ifndef MAPNIK_MAP_HPP +#define MAPNIK_MAP_HPP #ifdef HAVE_CONFIG_H -#include +#include #endif // mapnik @@ -461,4 +460,4 @@ private: DEFINE_ENUM(aspect_fix_mode_e,Map::aspect_fix_mode); } -#endif //MAP_HPP +#endif // MAPNIK_MAP_HPP diff --git a/include/mapnik/mapped_memory_cache.hpp b/include/mapnik/mapped_memory_cache.hpp index b143a6f30..d6bb27f5c 100644 --- a/include/mapnik/mapped_memory_cache.hpp +++ b/include/mapnik/mapped_memory_cache.hpp @@ -20,21 +20,19 @@ * *****************************************************************************/ -//$Id$ - -#ifndef MEMORY_REGION_CACHE_HPP -#define MEMORY_REGION_CACHE_HPP +#ifndef MAPNIK_MAPPED_MEMORY_CACHE_HPP +#define MAPNIK_MAPPED_MEMORY_CACHE_HPP // mapnik #include #include + // boost #include #include #include #include #include - #ifdef MAPNIK_THREADSAFE #include #endif @@ -61,5 +59,5 @@ struct MAPNIK_DECL mapped_memory_cache : } -#endif // MAPNIK_MARKER_CACHE_HPP +#endif // MAPNIK_MAPPED_MEMORY_CACHE_HPP diff --git a/include/mapnik/marker.hpp b/include/mapnik/marker.hpp index 1fd9918ca..571180ecd 100644 --- a/include/mapnik/marker.hpp +++ b/include/mapnik/marker.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,18 +20,19 @@ * *****************************************************************************/ -//$Id: image_data.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef MARKER_HPP -#define MARKER_HPP +#ifndef MAPNIK_MARKER_HPP +#define MAPNIK_MARKER_HPP +// mapnik #include #include #include #include #include +// agg #include "agg_path_storage.h" + // boost #include #include @@ -39,6 +40,7 @@ #include #include +// stl #include #include @@ -125,4 +127,4 @@ private: } -#endif //MARKER_HPP +#endif // MAPNIK_MARKER_HPP diff --git a/include/mapnik/marker_cache.hpp b/include/mapnik/marker_cache.hpp index 9c8c620fb..7595334ea 100644 --- a/include/mapnik/marker_cache.hpp +++ b/include/mapnik/marker_cache.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_MARKER_CACHE_HPP #define MAPNIK_MARKER_CACHE_HPP @@ -32,8 +30,10 @@ #include #include #include + // agg #include "agg_path_storage.h" + // boost #include #include diff --git a/include/mapnik/markers_placement.hpp b/include/mapnik/markers_placement.hpp index d2519af61..259fd4ae4 100644 --- a/include/mapnik/markers_placement.hpp +++ b/include/mapnik/markers_placement.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Hermann Kraus + * 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 @@ -20,13 +20,19 @@ * *****************************************************************************/ -#ifndef MARKERS_PLACEMENT_HPP -#define MARKERS_PLACEMENT_HPP +#ifndef MAPNIK_MARKERS_PLACEMENT_HPP +#define MAPNIK_MARKERS_PLACEMENT_HPP +// agg #include "agg_basics.h" + +// mapnik #include +// boost #include + +// stl #include namespace mapnik { @@ -242,5 +248,7 @@ template box2d markers_placement(x1_, y1_, x2_, y2_); } -} /* end namespace */ -#endif // MARKERS_PLACEMENT_HPP + +} + +#endif // MAPNIK_MARKERS_PLACEMENT_HPP diff --git a/include/mapnik/markers_symbolizer.hpp b/include/mapnik/markers_symbolizer.hpp index 507519157..09d568cca 100644 --- a/include/mapnik/markers_symbolizer.hpp +++ b/include/mapnik/markers_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef MARKERS_SYMBOLIZER_HPP -#define MARKERS_SYMBOLIZER_HPP +#ifndef MAPNIK_MARKERS_SYMBOLIZER_HPP +#define MAPNIK_MARKERS_SYMBOLIZER_HPP //mapnik #include @@ -92,4 +90,4 @@ private: } -#endif // MARKERS_SYMBOLIZER_HPP +#endif // MAPNIK_MARKERS_SYMBOLIZER_HPP diff --git a/include/mapnik/memory.hpp b/include/mapnik/memory.hpp index 71ac50d9f..ecdb05dcc 100644 --- a/include/mapnik/memory.hpp +++ b/include/mapnik/memory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,11 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: memory.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef MEMORY_HPP -#define MEMORY_HPP +#ifndef MAPNIK_MEMORY_HPP +#define MAPNIK_MEMORY_HPP +// stl #include #include @@ -85,4 +85,4 @@ public: }; } -#endif //MEMORY_HPP +#endif // MAPNIK_MEMORY_HPP diff --git a/include/mapnik/memory_datasource.hpp b/include/mapnik/memory_datasource.hpp index f344ff1d7..4a51b46a2 100644 --- a/include/mapnik/memory_datasource.hpp +++ b/include/mapnik/memory_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,13 +20,14 @@ * *****************************************************************************/ -//$Id$ - -#ifndef MEMORY_DATASOURCE_HPP -#define MEMORY_DATASOURCE_HPP +#ifndef MAPNIK_MEMORY_DATASOURCE_HPP +#define MAPNIK_MEMORY_DATASOURCE_HPP +// mapnik #include #include + +// stl #include namespace mapnik { @@ -65,4 +66,4 @@ private: }; } -#endif // MEMORY_DATASOURCE_HPP +#endif // MAPNIK_MEMORY_DATASOURCE_HPP diff --git a/include/mapnik/memory_featureset.hpp b/include/mapnik/memory_featureset.hpp index 116e1f350..2b6557521 100644 --- a/include/mapnik/memory_featureset.hpp +++ b/include/mapnik/memory_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,13 @@ * *****************************************************************************/ -//$Id$ -#ifndef MEMORY_FEATURESET_HPP -#define MEMORY_FEATURESET_HPP +#ifndef MAPNIK_MEMORY_FEATURESET_HPP +#define MAPNIK_MEMORY_FEATURESET_HPP +// mapnik #include + +// boost #include namespace mapnik { @@ -73,4 +75,4 @@ private: }; } -#endif // MEMORY_FEATURESET_HPP +#endif // MAPNIK_MEMORY_FEATURESET_HPP diff --git a/include/mapnik/metawriter.hpp b/include/mapnik/metawriter.hpp index 3549e4f8e..fa324cecf 100644 --- a/include/mapnik/metawriter.hpp +++ b/include/mapnik/metawriter.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Hermann Kraus + * 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 @@ -20,21 +20,21 @@ * *****************************************************************************/ +#ifndef MAPNIK_METAWRITER_HPP +#define MAPNIK_METAWRITER_HPP -#ifndef METAWRITER_HPP -#define METAWRITER_HPP - -// Mapnik +// mapnik #include #include #include -// Boost +// boost #include #include #include #include -// STL + +// stl #include #include @@ -47,11 +47,22 @@ struct placement; class metawriter_property_map { public: + typedef std::map property_map; + typedef property_map::const_iterator const_iterator; + metawriter_property_map() {} UnicodeString const& operator[](std::string const& key) const; UnicodeString& operator[](std::string const& key) {return m_[key];} + std::map::const_iterator find(std::string const& key) const + { + return m_.find(key); + } + std::map::const_iterator end() const + { + return m_.end(); + } private: - std::map m_; + property_map m_; UnicodeString not_found_; }; @@ -139,4 +150,4 @@ typedef std::pair metawriter_with_propert } -#endif +#endif // MAPNIK_METAWRITER_HPP diff --git a/include/mapnik/metawriter_factory.hpp b/include/mapnik/metawriter_factory.hpp index d9c4fffe0..cb0150fd4 100644 --- a/include/mapnik/metawriter_factory.hpp +++ b/include/mapnik/metawriter_factory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 MapQuest + * 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 @@ -20,9 +20,8 @@ * *****************************************************************************/ - -#ifndef METAWRITER_FACTORY_HPP -#define METAWRITER_FACTORY_HPP +#ifndef MAPNIK_METAWRITER_FACTORY_HPP +#define MAPNIK_METAWRITER_FACTORY_HPP // mapnik #include @@ -51,5 +50,5 @@ void metawriter_save( } -#endif /* METAWRITER_FACTORY_HPP */ +#endif // MAPNIK_METAWRITER_FACTORY_HPP diff --git a/include/mapnik/metawriter_inmem.hpp b/include/mapnik/metawriter_inmem.hpp index 278ffea44..5fb00d624 100644 --- a/include/mapnik/metawriter_inmem.hpp +++ b/include/mapnik/metawriter_inmem.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 MapQuest + * 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 @@ -20,9 +20,8 @@ * *****************************************************************************/ - -#ifndef METAWRITER_INMEM_HPP -#define METAWRITER_INMEM_HPP +#ifndef MAPNIK_METAWRITER_INMEM_HPP +#define MAPNIK_METAWRITER_INMEM_HPP // mapnik #include @@ -117,4 +116,4 @@ typedef boost::shared_ptr metawriter_inmem_ptr; } -#endif /* METAWRITER_INMEM_HPP */ +#endif // MAPNIK_METAWRITER_INMEM_HPP diff --git a/include/mapnik/metawriter_json.hpp b/include/mapnik/metawriter_json.hpp index f46a7393c..eb7ae8ca9 100644 --- a/include/mapnik/metawriter_json.hpp +++ b/include/mapnik/metawriter_json.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Hermann Kraus + * 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 @@ -20,9 +20,8 @@ * *****************************************************************************/ - -#ifndef METAWRITER_JSON_HPP -#define METAWRITER_JSON_HPP +#ifndef MAPNIK_METAWRITER_JSON_HPP +#define MAPNIK_METAWRITER_JSON_HPP // mapnik #include @@ -150,4 +149,4 @@ typedef boost::shared_ptr metawriter_json_ptr; } -#endif +#endif // MAPNIK_METAWRITER_JSON_HPP diff --git a/include/mapnik/octree.hpp b/include/mapnik/octree.hpp index fc08302aa..755fbb3cc 100644 --- a/include/mapnik/octree.hpp +++ b/include/mapnik/octree.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef _OCTREE_HPP_ -#define _OCTREE_HPP_ +#ifndef MAPNIK_OCTREE_HPP +#define MAPNIK_OCTREE_HPP // mapnik #include @@ -303,6 +302,7 @@ public: private: node * root_; }; + } // namespace mapnik -#endif /* _OCTREE_HPP_ */ +#endif // MAPNIK_OCTREE_HPP diff --git a/include/mapnik/palette.hpp b/include/mapnik/palette.hpp index 18b433b30..ea1f66a33 100644 --- a/include/mapnik/palette.hpp +++ b/include/mapnik/palette.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,11 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ - -#ifndef _PALETTE_HPP_ -#define _PALETTE_HPP_ +#ifndef MAPNIK_PALETTE_HPP +#define MAPNIK_PALETTE_HPP // mapnik #include @@ -164,5 +162,5 @@ private: } // namespace mapnik -#endif // _PALETTE_HPP_ +#endif // MAPNIK_PALETTE_HPP diff --git a/include/mapnik/params.hpp b/include/mapnik/params.hpp index 4590d3b38..97f4fd4f6 100644 --- a/include/mapnik/params.hpp +++ b/include/mapnik/params.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,15 +19,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: params.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef PARAMS_HPP -#define PARAMS_HPP +#ifndef MAPNIK_PARAMS_HPP +#define MAPNIK_PARAMS_HPP +// mapnik #include #include #include #include + +// stl #include #include @@ -100,4 +102,4 @@ public: }; } -#endif //PARAMS_HPP +#endif // MAPNIK_PARAMS_HPP diff --git a/include/mapnik/parse_path.hpp b/include/mapnik/parse_path.hpp index 4434ec2bf..250a175ef 100644 --- a/include/mapnik/parse_path.hpp +++ b/include/mapnik/parse_path.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -28,10 +28,12 @@ #include #include #include + // boost #include #include #include + // stl #include #include @@ -140,4 +142,4 @@ typedef mapnik::path_processor path_processor_type; } -#endif //MAPNIK_PARSE_PATH_HPP +#endif // MAPNIK_PARSE_PATH_HPP diff --git a/include/mapnik/path_expression_grammar.hpp b/include/mapnik/path_expression_grammar.hpp index eae2ed7aa..632745dad 100644 --- a/include/mapnik/path_expression_grammar.hpp +++ b/include/mapnik/path_expression_grammar.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP #define MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP @@ -29,22 +27,26 @@ #include #include #include + // boost #include #include -//spirit2 +// spirit2 #include #include -//fusion + +// fusion #include -//phoenix + +// phoenix #include #include #include #include #include #include + // stl #include #include @@ -56,11 +58,9 @@ namespace qi = boost::spirit::qi; namespace phoenix = boost::phoenix; namespace standard_wide = boost::spirit::standard_wide; -// using standard_wide::space_type; using standard_wide::space; - template struct path_expression_grammar : qi::grammar(), space_type> { @@ -92,8 +92,6 @@ struct path_expression_grammar : qi::grammar str; }; - } #endif // MAPNIK_PATH_EXPRESSIONS_GRAMMAR_HPP - diff --git a/include/mapnik/placement_finder.hpp b/include/mapnik/placement_finder.hpp index 2a605d15b..bf8869ec4 100644 --- a/include/mapnik/placement_finder.hpp +++ b/include/mapnik/placement_finder.hpp @@ -2,8 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko - * Copyright (C) 2006 10East Corp. + * 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 @@ -21,11 +20,10 @@ * *****************************************************************************/ -//$Id$ - -#ifndef __PLACEMENT_FINDER__ -#define __PLACEMENT_FINDER__ +#ifndef MAPNIK_PLACEMENT_FINDER_HPP +#define MAPNIK_PLACEMENT_FINDER_HPP +// mapnik #include #include #include @@ -34,6 +32,7 @@ #include #include +// stl #include namespace mapnik @@ -145,7 +144,7 @@ private: DetectorT & detector_; box2d const& dimensions_; }; + } -#endif - +#endif // MAPNIK_PLACEMENT_FINDER_HPP diff --git a/include/mapnik/plugin.hpp b/include/mapnik/plugin.hpp index 8d800f4a8..5ccd3ca78 100644 --- a/include/mapnik/plugin.hpp +++ b/include/mapnik/plugin.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,14 +20,15 @@ * *****************************************************************************/ -//$Id: plugin.hpp 39 2005-04-10 20:39:53Z pavlenko $ +#ifndef MAPNIK_PLUGIN_HPP +#define MAPNIK_PLUGIN_HPP -#ifndef PLUGIN_HPP -#define PLUGIN_HPP // boost #include + // stl #include + // ltdl #include @@ -46,4 +47,4 @@ public: }; } -#endif //PLUGIN_HPP +#endif // MAPNIK_PLUGIN_HPP diff --git a/include/mapnik/png_io.hpp b/include/mapnik/png_io.hpp index 5c85c1404..fd47535b3 100644 --- a/include/mapnik/png_io.hpp +++ b/include/mapnik/png_io.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,16 +20,16 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_PNG_IO_HPP #define MAPNIK_PNG_IO_HPP +// mapnik #include #include #include #include +// zlib #include extern "C" diff --git a/include/mapnik/point_symbolizer.hpp b/include/mapnik/point_symbolizer.hpp index e47ea4fc1..c1f7c1382 100644 --- a/include/mapnik/point_symbolizer.hpp +++ b/include/mapnik/point_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: image_symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ #ifndef MAPNIK_POINT_SYMBOLIZER_HPP #define MAPNIK_POINT_SYMBOLIZER_HPP diff --git a/include/mapnik/polygon_pattern_symbolizer.hpp b/include/mapnik/polygon_pattern_symbolizer.hpp index 0c389e36d..e1ffc39b9 100644 --- a/include/mapnik/polygon_pattern_symbolizer.hpp +++ b/include/mapnik/polygon_pattern_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef POLYGON_PATTERN_SYMBOLIZER_HPP -#define POLYGON_PATTERN_SYMBOLIZER_HPP +#ifndef MAPNIK_POLYGON_PATTERN_SYMBOLIZER_HPP +#define MAPNIK_POLYGON_PATTERN_SYMBOLIZER_HPP // mapnik #include @@ -57,4 +56,4 @@ private: }; } -#endif //POLYGON_PATTERN_SYMBOLIZER_HPP +#endif // MAPNIK_POLYGON_PATTERN_SYMBOLIZER_HPP diff --git a/include/mapnik/polygon_symbolizer.hpp b/include/mapnik/polygon_symbolizer.hpp index d6695ba3b..809ceced3 100644 --- a/include/mapnik/polygon_symbolizer.hpp +++ b/include/mapnik/polygon_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id: polygon_symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef POLYGON_SYMBOLIZER_HPP -#define POLYGON_SYMBOLIZER_HPP +#ifndef MAPNIK_POLYGON_SYMBOLIZER_HPP +#define MAPNIK_POLYGON_SYMBOLIZER_HPP // mapnik #include @@ -122,4 +120,4 @@ private: }; } -#endif // POLYGON_SYMBOLIZER_HPP +#endif // MAPNIK_POLYGON_SYMBOLIZER_HPP diff --git a/include/mapnik/pool.hpp b/include/mapnik/pool.hpp index 7459fd719..518744a9c 100644 --- a/include/mapnik/pool.hpp +++ b/include/mapnik/pool.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,17 +20,15 @@ * *****************************************************************************/ -//$Id: pool.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef POOL_HPP -#define POOL_HPP +#ifndef MAPNIK_POOL_HPP +#define MAPNIK_POOL_HPP // mapnik #include + // boost #include #include - #ifdef MAPNIK_THREADSAFE #include #endif @@ -164,5 +162,7 @@ public: return size; } }; + } -#endif //POOL_HPP + +#endif // MAPNIK_POOL_HPP diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp index 83430bf57..8c156a0a8 100644 --- a/include/mapnik/proj_transform.hpp +++ b/include/mapnik/proj_transform.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef PROJ_TRANSFORM_HPP -#define PROJ_TRANSFORM_HPP +#ifndef MAPNIK_PROJ_TRANSFORM_HPP +#define MAPNIK_PROJ_TRANSFORM_HPP // mapnik #include @@ -62,4 +60,4 @@ private: }; } -#endif // PROJ_TRANSFORM_HPP +#endif // MAPNIK_PROJ_TRANSFORM_HPP diff --git a/include/mapnik/projection.hpp b/include/mapnik/projection.hpp index 33a534dcd..26d64466a 100644 --- a/include/mapnik/projection.hpp +++ b/include/mapnik/projection.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef PROJECTION_HPP -#define PROJECTION_HPP +#ifndef MAPNIK_PROJECTION_HPP +#define MAPNIK_PROJECTION_HPP // mapnik #include @@ -35,8 +33,8 @@ #if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480 #include #endif - #include + // stl #include #include @@ -85,6 +83,7 @@ private: static boost::mutex mutex_; #endif }; + } -#endif //PROJECTION_HPP +#endif // MAPNIK_PROJECTION_HPP diff --git a/include/mapnik/ptree_helpers.hpp b/include/mapnik/ptree_helpers.hpp index 88a75f458..c97ce4d55 100644 --- a/include/mapnik/ptree_helpers.hpp +++ b/include/mapnik/ptree_helpers.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,17 +20,20 @@ * *****************************************************************************/ -#ifndef MAPNIK_CONFIG_HELPERS_INCLUDED -#define MAPNIK_CONFIG_HELPERS_INCLUDED +#ifndef MAPNIK_PTREE_HELPERS_HPP +#define MAPNIK_PTREE_HELPERS_HPP +// mapnik #include #include #include +// boost #include #include #include +// stl #include #include @@ -422,6 +425,7 @@ inline boost::optional get_optional(const boost::property_tree::ptree & n return result; } + } // end of namespace mapnik -#endif // MAPNIK_CONFIG_HELPERS_INCLUDED +#endif // MAPNIK_PTREE_HELPERS_HPP diff --git a/include/mapnik/quad_tree.hpp b/include/mapnik/quad_tree.hpp index 0c9af81d0..63b305c73 100644 --- a/include/mapnik/quad_tree.hpp +++ b/include/mapnik/quad_tree.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,15 +19,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef QUAD_TREE_HPP -#define QUAD_TREE_HPP +#ifndef MAPNIK_QUAD_TREE_HPP +#define MAPNIK_QUAD_TREE_HPP + // mapnik #include + // boost #include #include + // stl #include #include @@ -220,4 +222,4 @@ private: }; } -#endif +#endif // MAPNIK_QUAD_TREE_HPP diff --git a/include/mapnik/query.hpp b/include/mapnik/query.hpp index d43c8b722..db607c587 100644 --- a/include/mapnik/query.hpp +++ b/include/mapnik/query.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id$ - -#ifndef QUERY_HPP -#define QUERY_HPP +#ifndef MAPNIK_QUERY_HPP +#define MAPNIK_QUERY_HPP //mapnik #include @@ -123,7 +121,7 @@ public: return names_; } }; + } - -#endif //QUERY_HPP +#endif // MAPNIK_QUERY_HPP diff --git a/include/mapnik/raster.hpp b/include/mapnik/raster.hpp index 5449294cd..cd26af27a 100644 --- a/include/mapnik/raster.hpp +++ b/include/mapnik/raster.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,11 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: raster.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef RASTER_HPP -#define RASTER_HPP +#ifndef MAPNIK_RASTER_HPP +#define MAPNIK_RASTER_HPP +// mapnik #include namespace mapnik { @@ -37,5 +37,5 @@ struct raster }; } -#endif //RASTER_HPP +#endif // MAPNIK_RASTER_HPP diff --git a/include/mapnik/raster_colorizer.hpp b/include/mapnik/raster_colorizer.hpp index 45cb69f21..cdcf212ef 100644 --- a/include/mapnik/raster_colorizer.hpp +++ b/include/mapnik/raster_colorizer.hpp @@ -3,7 +3,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,7 +20,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ /** \brief Raster Colouriser * @@ -35,9 +34,8 @@ * */ - -#ifndef RASTER_COLORIZER_HPP -#define RASTER_COLORIZER_HPP +#ifndef MAPNIK_RASTER_COLORIZER_HPP +#define MAPNIK_RASTER_COLORIZER_HPP // mapnik #include @@ -218,14 +216,9 @@ private: }; - - - - - typedef boost::shared_ptr raster_colorizer_ptr; } // mapnik namespace -#endif //RASTER_COLORIZER_HPP +#endif // MAPNIK_RASTER_COLORIZER_HPP diff --git a/include/mapnik/raster_symbolizer.hpp b/include/mapnik/raster_symbolizer.hpp index 2bc4cad32..76366b4a8 100644 --- a/include/mapnik/raster_symbolizer.hpp +++ b/include/mapnik/raster_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef RASTER_SYMBOLIZER_HPP -#define RASTER_SYMBOLIZER_HPP +#ifndef MAPNIK_RASTER_SYMBOLIZER_HPP +#define MAPNIK_RASTER_SYMBOLIZER_HPP // mapnik #include @@ -159,4 +158,4 @@ private: }; } -#endif //RASTER_SYMBOLIZER_HPP +#endif // MAPNIK_RASTER_SYMBOLIZER_HPP diff --git a/include/mapnik/rule.hpp b/include/mapnik/rule.hpp index b4a5e3f0c..9a41bacec 100644 --- a/include/mapnik/rule.hpp +++ b/include/mapnik/rule.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef RULE_HPP -#define RULE_HPP +#ifndef MAPNIK_RULE_HPP +#define MAPNIK_RULE_HPP // mapnik #include @@ -408,4 +408,4 @@ private: } -#endif //RULE_HPP +#endif // MAPNIK_RULE_HPP diff --git a/include/mapnik/save_map.hpp b/include/mapnik/save_map.hpp index f28746dc2..65ca13dac 100644 --- a/include/mapnik/save_map.hpp +++ b/include/mapnik/save_map.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,22 +19,22 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -// $Id$ -#ifndef SAVE_MAP_HPP -#define SAVE_MAP_HPP +#ifndef MAPNIK_SAVE_MAP_HPP +#define MAPNIK_SAVE_MAP_HPP + // mapnik #include + // stl #include namespace mapnik { class Map; + MAPNIK_DECL void save_map(Map const& map, std::string const& filename, bool explicit_defaults = false); - MAPNIK_DECL std::string save_map_to_string(Map const& map, bool explicit_defaults = false); - } -#endif // SAVE_MAP_HPP +#endif // MAPNIK_SAVE_MAP_HPP diff --git a/include/mapnik/scale_denominator.hpp b/include/mapnik/scale_denominator.hpp index 31562bc9e..c42b15788 100644 --- a/include/mapnik/scale_denominator.hpp +++ b/include/mapnik/scale_denominator.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,10 @@ * *****************************************************************************/ -//$Id$ #ifndef MAPNIK_SCALE_DENOMINATOR_HPP #define MAPNIK_SCALE_DENOMINATOR_HPP +// mapnik #include namespace mapnik { diff --git a/include/mapnik/segment.hpp b/include/mapnik/segment.hpp index 1836eb69c..12fa2a74b 100644 --- a/include/mapnik/segment.hpp +++ b/include/mapnik/segment.hpp @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_SEGMENT_HPP #define MAPNIK_SEGMENT_HPP @@ -41,4 +39,4 @@ static bool y_order(segment_t const& first,segment_t const& second) } -#endif //MAPNIK_SEGMENT_HPP +#endif // MAPNIK_SEGMENT_HPP diff --git a/include/mapnik/shield_symbolizer.hpp b/include/mapnik/shield_symbolizer.hpp index b373608cb..847bff663 100644 --- a/include/mapnik/shield_symbolizer.hpp +++ b/include/mapnik/shield_symbolizer.hpp @@ -2,8 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko - * Copyright (C) 2006 10East Corp. + * 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 @@ -20,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef MAPNIK_SHIELD_SYMBOLIZER_HPP #define MAPNIK_SHIELD_SYMBOLIZER_HPP @@ -40,11 +38,11 @@ struct MAPNIK_DECL shield_symbolizer : public text_symbolizer, { shield_symbolizer(expression_ptr name, std::string const& face_name, - unsigned size, + float size, color const& fill, path_expression_ptr file); shield_symbolizer(expression_ptr name, - unsigned size, + float size, color const& fill, path_expression_ptr file); @@ -62,4 +60,4 @@ private: }; } -#endif // SHIELD_SYMBOLIZER_HPP +#endif // MAPNIK_SHIELD_SYMBOLIZER_HPP diff --git a/include/mapnik/sql_utils.hpp b/include/mapnik/sql_utils.hpp index c208d3b11..ee6805cb7 100644 --- a/include/mapnik/sql_utils.hpp +++ b/include/mapnik/sql_utils.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,26 +20,23 @@ * *****************************************************************************/ -//$Id: sql_utils.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef SQL_UTILS_HPP -#define SQL_UTILS_HPP +#ifndef MAPNIK_SQL_UTILS_HPP +#define MAPNIK_SQL_UTILS_HPP // boost #include #include -namespace mapnik -{ +namespace mapnik { namespace sql_utils { -inline std::string unquote_sql(const std::string& sql) +inline std::string unquote_double(const std::string& sql) { std::string table_name = boost::algorithm::to_lower_copy(sql); boost::algorithm::trim_if(table_name,boost::algorithm::is_any_of("\"")); return table_name; } -inline std::string unquote_sql2(const std::string& sql) +inline std::string unquote(const std::string& sql) { std::string table_name = boost::algorithm::to_lower_copy(sql); boost::algorithm::trim_if(table_name,boost::algorithm::is_any_of("\"\'")); @@ -67,7 +64,6 @@ inline std::string table_from_sql(const std::string& sql) std::string::size_type idx = table_name.rfind(" from "); if (idx!=std::string::npos) { - idx = table_name.find_first_not_of(" ",idx+5); if (idx != std::string::npos) { @@ -193,7 +189,8 @@ inline std::string numeric2string(const char* buf) } return ss.str(); } +} } -#endif //SQL_UTILS_HPP +#endif // MAPNIK_SQL_UTILS_HPP diff --git a/include/mapnik/stroke.hpp b/include/mapnik/stroke.hpp index 194878886..36b6a882c 100644 --- a/include/mapnik/stroke.hpp +++ b/include/mapnik/stroke.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,13 +19,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef STROKE_HPP -#define STROKE_HPP +#ifndef MAPNIK_STROKE_HPP +#define MAPNIK_STROKE_HPP + // mapnik #include #include + // stl #include @@ -107,4 +108,4 @@ private: }; } -#endif //STROKE_HPP +#endif // MAPNIK_STROKE_HPP diff --git a/include/mapnik/style_factory.hpp b/include/mapnik/style_factory.hpp index aa372d76a..fb0982f40 100644 --- a/include/mapnik/style_factory.hpp +++ b/include/mapnik/style_factory.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: style_factory.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef STYLE_FACTORY_HPP -#define STYLE_FACTORY_HPP +#ifndef MAPNIK_STYLE_FACTORY_HPP +#define MAPNIK_STYLE_FACTORY_HPP //#include @@ -34,4 +33,4 @@ class style_factory } -#endif //STYLE_FACTORY_HPP +#endif // MAPNIK_STYLE_FACTORY_HPP diff --git a/include/mapnik/svg/svg_converter.hpp b/include/mapnik/svg/svg_converter.hpp index a875feefc..74689971c 100644 --- a/include/mapnik/svg/svg_converter.hpp +++ b/include/mapnik/svg/svg_converter.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,15 +20,16 @@ * *****************************************************************************/ -// $Id$ - #ifndef MAPNIK_SVG_CONVERTER_HPP #define MAPNIK_SVG_CONVERTER_HPP + // mapnik #include #include + // boost #include + // agg #include "agg_path_storage.h" #include "agg_conv_transform.h" @@ -37,6 +38,7 @@ #include "agg_conv_curve.h" #include "agg_color_rgba.h" #include "agg_bounding_rect.h" + // stl #include @@ -327,5 +329,4 @@ typedef svg_converter #include +// stl #include namespace mapnik { namespace svg { diff --git a/include/mapnik/svg/svg_path_adapter.hpp b/include/mapnik/svg/svg_path_adapter.hpp index e8d9b6240..86e6f728f 100644 --- a/include/mapnik/svg/svg_path_adapter.hpp +++ b/include/mapnik/svg/svg_path_adapter.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,17 +19,18 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef MAPNIK_SVG_PATH_ADAPTER -#define MAPNIK_SVG_PATH_ADAPTER +#ifndef MAPNIK_SVG_PATH_ADAPTER_HPP +#define MAPNIK_SVG_PATH_ADAPTER_HPP // mapnik #include + // agg #include "agg_math.h" #include "agg_array.h" #include "agg_bezier_arc.h" + // stl #include #include diff --git a/include/mapnik/svg/svg_path_attributes.hpp b/include/mapnik/svg/svg_path_attributes.hpp index a1a7250b7..66df711fb 100644 --- a/include/mapnik/svg/svg_path_attributes.hpp +++ b/include/mapnik/svg/svg_path_attributes.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,16 +20,16 @@ * *****************************************************************************/ -// $Id$ - #ifndef MAPNIK_SVG_PATH_ATTRIBUTES_HPP #define MAPNIK_SVG_PATH_ATTRIBUTES_HPP +// agg #include "agg_math_stroke.h" #include "agg_color_rgba.h" #include "agg_pixfmt_rgba.h" #include "agg_trans_affine.h" +// mapnik #include namespace mapnik { diff --git a/include/mapnik/svg/svg_path_commands.hpp b/include/mapnik/svg/svg_path_commands.hpp index b5e01b5da..ab6bcee46 100644 --- a/include/mapnik/svg/svg_path_commands.hpp +++ b/include/mapnik/svg/svg_path_commands.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,12 +20,13 @@ * *****************************************************************************/ -#ifndef SVG_COMMANDS_HPP -#define SVG_COMMANDS_HPP +#ifndef MAPNIK_SVG_PATH_COMMANDS_HPP +#define MAPNIK_SVG_PATH_COMMANDS_HPP // mapnik #include -// + +// boost #include #include #include @@ -262,4 +263,4 @@ namespace mapnik { namespace svg { }} -#endif // SVG_COMMANDS_HPP +#endif // MAPNIK_SVG_COMMANDS_HPP diff --git a/include/mapnik/svg/svg_path_grammar.hpp b/include/mapnik/svg/svg_path_grammar.hpp index 3cc078d2f..5411db679 100644 --- a/include/mapnik/svg/svg_path_grammar.hpp +++ b/include/mapnik/svg/svg_path_grammar.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,11 +20,12 @@ * *****************************************************************************/ -#ifndef SVG_PATH_GRAMMAR_HPP -#define SVG_PATH_GRAMMAR_HPP +#ifndef MAPNIK_SVG_PATH_GRAMMAR_HPP +#define MAPNIK_SVG_PATH_GRAMMAR_HPP // mapnik #include + // spirit #include #include @@ -152,4 +153,4 @@ namespace mapnik { namespace svg { }} -#endif // SVG_PATH_GRAMMAR_HPP +#endif // MAPNIK_SVG_PATH_GRAMMAR_HPP diff --git a/include/mapnik/svg/svg_path_iterator.hpp b/include/mapnik/svg/svg_path_iterator.hpp index 30bb847f8..5f5ad6395 100644 --- a/include/mapnik/svg/svg_path_iterator.hpp +++ b/include/mapnik/svg/svg_path_iterator.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/include/mapnik/svg/svg_path_parser.hpp b/include/mapnik/svg/svg_path_parser.hpp index d836deffc..4d249cb9d 100644 --- a/include/mapnik/svg/svg_path_parser.hpp +++ b/include/mapnik/svg/svg_path_parser.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef SVG_PATH_PARSER_HPP -#define SVG_PATH_PARSER_HPP +#ifndef MAPNIK_SVG_PATH_PARSER_HPP +#define MAPNIK_SVG_PATH_PARSER_HPP #include #include @@ -42,5 +42,4 @@ bool MAPNIK_DECL parse_transform(const char * wkt, TransformType & tr); }} - -#endif // SVG_PATH_PARSER_HPP +#endif // MAPNIK_SVG_PATH_PARSER_HPP diff --git a/include/mapnik/svg/svg_points_grammar.hpp b/include/mapnik/svg/svg_points_grammar.hpp index 77e1a2480..e6deb843d 100644 --- a/include/mapnik/svg/svg_points_grammar.hpp +++ b/include/mapnik/svg/svg_points_grammar.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/include/mapnik/svg/svg_renderer.hpp b/include/mapnik/svg/svg_renderer.hpp index e13e36a7c..4ffe11cd3 100644 --- a/include/mapnik/svg/svg_renderer.hpp +++ b/include/mapnik/svg/svg_renderer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/include/mapnik/svg/svg_storage.hpp b/include/mapnik/svg/svg_storage.hpp index bd6df64d3..f3600646a 100644 --- a/include/mapnik/svg/svg_storage.hpp +++ b/include/mapnik/svg/svg_storage.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,12 +20,13 @@ * *****************************************************************************/ -// $Id$ - #ifndef MAPNIK_SVG_STORAGE_HPP #define MAPNIK_SVG_STORAGE_HPP +// mapnik #include + +// boost #include namespace mapnik { diff --git a/include/mapnik/svg/svg_transform_grammar.hpp b/include/mapnik/svg/svg_transform_grammar.hpp index 8f8c7f03f..9d9bab750 100644 --- a/include/mapnik/svg/svg_transform_grammar.hpp +++ b/include/mapnik/svg/svg_transform_grammar.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -20,15 +20,15 @@ * *****************************************************************************/ -//$Id$ - -#ifndef SVG_TRANSFORM_GRAMMAR_HPP -#define SVG_TRANSFORM_GRAMMAR_HPP +#ifndef MAPNIK_SVG_TRANSFORM_GRAMMAR_HPP +#define MAPNIK_SVG_TRANSFORM_GRAMMAR_HPP // mapnik #include + // agg #include + // spirit #include #include @@ -260,4 +260,4 @@ namespace mapnik { namespace svg { }} -#endif // SVG_TRANSFORM_GRAMMAR_HPP +#endif // MAPNIK_SVG_TRANSFORM_GRAMMAR_HPP diff --git a/include/mapnik/svg_renderer.hpp b/include/mapnik/svg_renderer.hpp index 15c7ebdc9..3459d0eb3 100644 --- a/include/mapnik/svg_renderer.hpp +++ b/include/mapnik/svg_renderer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,15 +20,12 @@ * *****************************************************************************/ -//$Id$ - -#ifndef SVG_RENDERER_HPP -#define SVG_RENDERER_HPP +#ifndef MAPNIK_SVG_RENDERER_HPP +#define MAPNIK_SVG_RENDERER_HPP // mapnik #include #include - #include #include @@ -150,4 +147,4 @@ namespace mapnik }; } -#endif //SVG_RENDERER_HPP +#endif // MAPNIK_SVG_RENDERER_HPP diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index c4b46cde3..546c4c1fe 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: symbolizer.hpp 39 2005-04-10 20:39:53Z pavlenko $ #ifndef MAPNIK_SYMBOLIZER_HPP #define MAPNIK_SYMBOLIZER_HPP @@ -105,4 +104,4 @@ protected: }; } -#endif //MAPNIK_SYMBOLIZER_HPP +#endif // MAPNIK_SYMBOLIZER_HPP diff --git a/include/mapnik/text_path.hpp b/include/mapnik/text_path.hpp index cd9a4c275..eeebd97c4 100644 --- a/include/mapnik/text_path.hpp +++ b/include/mapnik/text_path.hpp @@ -2,8 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko - * Copyright (C) 2006 10East Corp. + * 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 @@ -21,13 +20,14 @@ * *****************************************************************************/ -//$Id$ - -#ifndef __TEXT_PATH_H__ -#define __TEXT_PATH_H__ +#ifndef MAPNIK_TEXT_PATH_HPP +#define MAPNIK_TEXT_PATH_HPP +// boost #include #include + +// uci #include namespace mapnik @@ -180,6 +180,4 @@ struct text_path : boost::noncopyable typedef boost::shared_ptr text_path_ptr; } -#endif - - +#endif // MAPNIK_TEXT_PATH_HPP diff --git a/include/mapnik/text_placements.hpp b/include/mapnik/text_placements.hpp index 56b0c04de..383bbcb33 100644 --- a/include/mapnik/text_placements.hpp +++ b/include/mapnik/text_placements.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 Hermann Kraus + * 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 @@ -19,18 +19,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#ifndef TEXT_PLACEMENTS_HPP -#define TEXT_PLACEMENTS_HPP -//mapnik +#ifndef MAPNIK_TEXT_PLACEMENTS_HPP +#define MAPNIK_TEXT_PLACEMENTS_HPP + +// mapnik #include #include -//stl +// stl #include #include -//boost +// boost #include #include #include @@ -111,7 +112,7 @@ public: /* NOTE: Values are public and non-virtual to avoid any performance problems. */ position displacement; - unsigned text_size; + float text_size; horizontal_alignment_e halign; justify_alignment_e jalign; vertical_alignment_e valign; @@ -126,9 +127,9 @@ public: text_size_(10), halign_(H_MIDDLE), jalign_(J_MIDDLE), valign_(V_MIDDLE) {} virtual text_placement_info_ptr get_placement_info() const =0; - virtual void set_default_text_size(unsigned size) { text_size_ = size; } - unsigned get_default_text_size() const { return text_size_; } - + virtual void set_default_text_size(float size) { text_size_ = size; } + float get_default_text_size() const { return text_size_; } + virtual void set_default_displacement(position const& displacement) { displacement_ = displacement;} position const& get_default_displacement() { return displacement_; } @@ -143,7 +144,7 @@ public: virtual ~text_placements() {} protected: - unsigned text_size_; + float text_size_; position displacement_; horizontal_alignment_e halign_; justify_alignment_e jalign_; @@ -176,7 +177,6 @@ private: }; - } //namespace -#endif // TEXT_PLACEMENTS_HPP +#endif // MAPNIK_TEXT_PLACEMENTS_HPP diff --git a/include/mapnik/text_placements_simple.hpp b/include/mapnik/text_placements_simple.hpp index 9b11c6abe..fe0e541ca 100644 --- a/include/mapnik/text_placements_simple.hpp +++ b/include/mapnik/text_placements_simple.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 Hermann Kraus + * 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 @@ -19,8 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#ifndef TEXT_PLACEMENTS_SIMPLE_HPP -#define TEXT_PLACEMENTS_SIMPLE_HPP + +#ifndef MAPNIK_TEXT_PLACEMENTS_SIMPLE_HPP +#define MAPNIK_TEXT_PLACEMENTS_SIMPLE_HPP + +// mapnik #include namespace mapnik { @@ -70,6 +73,6 @@ private: text_placements_simple const* parent_; }; - } //namespace -#endif + +#endif // MAPNIK_TEXT_PLACEMENTS_SIMPLE_HPP diff --git a/include/mapnik/text_symbolizer.hpp b/include/mapnik/text_symbolizer.hpp index f61f58c23..7387eb263 100644 --- a/include/mapnik/text_symbolizer.hpp +++ b/include/mapnik/text_symbolizer.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id$ - #ifndef MAPNIK_TEXT_SYMBOLIZER_HPP #define MAPNIK_TEXT_SYMBOLIZER_HPP @@ -46,10 +44,10 @@ namespace mapnik struct MAPNIK_DECL text_symbolizer : public symbolizer_base { text_symbolizer(expression_ptr name, std::string const& face_name, - unsigned size, color const& fill, + float size, color const& fill, text_placements_ptr placements = boost::make_shared() ); - text_symbolizer(expression_ptr name, unsigned size, color const& fill, + text_symbolizer(expression_ptr name, float size, color const& fill, text_placements_ptr placements = boost::make_shared() ); text_symbolizer(text_symbolizer const& rhs); @@ -82,8 +80,8 @@ struct MAPNIK_DECL text_symbolizer : public symbolizer_base void set_force_odd_labels(bool force); double get_max_char_angle_delta() const; // maximum change in angle between adjacent characters void set_max_char_angle_delta(double angle); - unsigned get_text_size() const; - void set_text_size(unsigned size); + float get_text_size() const; + void set_text_size(float size); std::string const& get_face_name() const; void set_face_name(std::string face_name); font_set const& get_fontset() const; @@ -155,4 +153,4 @@ private: }; } -#endif //MAPNIK_TEXT_SYMBOLIZER_HPP +#endif // MAPNIK_TEXT_SYMBOLIZER_HPP diff --git a/include/mapnik/timer.hpp b/include/mapnik/timer.hpp index 4791b8772..4518159c1 100644 --- a/include/mapnik/timer.hpp +++ b/include/mapnik/timer.hpp @@ -20,14 +20,15 @@ * *****************************************************************************/ -#ifndef MAPNIK_TIMER_INCLUDED -#define MAPNIK_TIMER_INCLUDED +#ifndef MAPNIK_TIMER_HPP +#define MAPNIK_TIMER_HPP +// stl #include #include #include #include -#include +#include namespace mapnik { @@ -121,4 +122,4 @@ private: }; }; -#endif // MAPNIK_TIMER_INCLUDED +#endif // MAPNIK_TIMER_HPP diff --git a/include/mapnik/unicode.hpp b/include/mapnik/unicode.hpp index 6f79e8f38..1d9cb077d 100644 --- a/include/mapnik/unicode.hpp +++ b/include/mapnik/unicode.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,18 +20,20 @@ * *****************************************************************************/ -//$Id$ -#ifndef UNICODE_HPP -#define UNICODE_HPP +#ifndef MAPNIK_UNICODE_HPP +#define MAPNIK_UNICODE_HPP //mapnik #include + // icu #include #include + // boost #include #include + // stl #include @@ -49,4 +51,4 @@ private: }; } -#endif // UNICODE_HPP +#endif // MAPNIK_UNICODE_HPP diff --git a/include/mapnik/utils.hpp b/include/mapnik/utils.hpp index a6ec6fdb5..b6acd5e58 100644 --- a/include/mapnik/utils.hpp +++ b/include/mapnik/utils.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,8 @@ * *****************************************************************************/ -//$Id: utils.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef UTILS_HPP -#define UTILS_HPP +#ifndef MAPNIK_UTILS_HPP +#define MAPNIK_UTILS_HPP #ifdef MAPNIK_THREADSAFE #include @@ -165,9 +163,8 @@ template class CreatePolicy> T* singleton::pInstance_=0; template class CreatePolicy> bool singleton::destroyed_=false; - + template class CreatePolicy> bool singleton::destroyed_=false; + } - -#endif //UTILS_HPP +#endif // MAPNIK_UTILS_HPP diff --git a/include/mapnik/value.hpp b/include/mapnik/value.hpp index 46fb7b05f..f6ac076d0 100644 --- a/include/mapnik/value.hpp +++ b/include/mapnik/value.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef VALUE_HPP -#define VALUE_HPP +#ifndef MAPNIK_VALUE_HPP +#define MAPNIK_VALUE_HPP // mapnik #include @@ -30,17 +29,18 @@ #include // boost - #include #include #include #include + // stl #include #include #include #include #include + // uci #include #include @@ -823,4 +823,4 @@ operator << (std::basic_ostream& out, } } -#endif //VALUE_HPP +#endif // MAPNIK_VALUE_HPP diff --git a/include/mapnik/value_error.hpp b/include/mapnik/value_error.hpp index a83631f5d..22a692946 100644 --- a/include/mapnik/value_error.hpp +++ b/include/mapnik/value_error.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,8 @@ * *****************************************************************************/ -#ifndef MAPNIK_VALUE_ERROR_INCLUDED -#define MAPNIK_VALUE_ERROR_INCLUDED +#ifndef MAPNIK_VALUE_ERROR_HPP +#define MAPNIK_VALUE_ERROR_HPP #include #include @@ -54,4 +54,4 @@ protected: }; } -#endif // MAPNIK_VALUE_ERROR_INCLUDED +#endif // MAPNIK_VALUE_ERROR_HPP diff --git a/include/mapnik/version.hpp b/include/mapnik/version.hpp index defeb9da1..dd69d20bd 100644 --- a/include/mapnik/version.hpp +++ b/include/mapnik/version.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 @@ -19,14 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef MAPNIK_VERSION_HPP #define MAPNIK_VERSION_HPP #define MAPNIK_VERSION 200000 -#endif //MAPNIK_VERSION_HPP - - - +#endif // MAPNIK_VERSION_HPP diff --git a/include/mapnik/vertex.hpp b/include/mapnik/vertex.hpp index 4227cd10d..ca76b48dc 100644 --- a/include/mapnik/vertex.hpp +++ b/include/mapnik/vertex.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: vertex.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef VERTEX_HPP -#define VERTEX_HPP +#ifndef MAPNIK_VERTEX_HPP +#define MAPNIK_VERTEX_HPP #include #include @@ -109,4 +108,4 @@ operator << (std::basic_ostream& out, } -#endif // VERTEX_HPP +#endif // MAPNIK_VERTEX_HPP diff --git a/include/mapnik/vertex_transform.hpp b/include/mapnik/vertex_transform.hpp index 3a333bdfc..1f6ac72c3 100644 --- a/include/mapnik/vertex_transform.hpp +++ b/include/mapnik/vertex_transform.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: vertex_transform.hpp 39 2005-04-10 20:39:53Z pavlenko $ -#ifndef VERTEX_TRANSFORM_HPP -#define VERTEX_TRANSFORM_HPP +#ifndef MAPNIK_VERTEX_TRANSFORM_HPP +#define MAPNIK_VERTEX_TRANSFORM_HPP // mapnik #include @@ -90,4 +89,4 @@ struct view_transform,box2d,Trans> }; } -#endif //VERTEX_TRANSFORM_HPP +#endif // MAPNIK_VERTEX_TRANSFORM_HPP diff --git a/include/mapnik/vertex_vector.hpp b/include/mapnik/vertex_vector.hpp index 72f7e1d0a..b1bf1de61 100644 --- a/include/mapnik/vertex_vector.hpp +++ b/include/mapnik/vertex_vector.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -24,17 +24,16 @@ // author of Anti-Grain Geometry (http://www.antigrain.com). I have used // the datastructure from AGG as a template for my own. +#ifndef MAPNIK_VERTEX_VECTOR_HPP +#define MAPNIK_VERTEX_VECTOR_HPP -//$Id: vertex_vector.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef VERTEX_VECTOR_HPP -#define VERTEX_VECTOR_HPP // mapnik #include -#include + // boost #include #include + // stl #include #include @@ -143,4 +142,4 @@ private: } -#endif //VERTEX_VECTOR_HPP +#endif // MAPNIK_VERTEX_VECTOR_HPP diff --git a/include/mapnik/warp.hpp b/include/mapnik/warp.hpp index 32ea74445..4fc30877d 100644 --- a/include/mapnik/warp.hpp +++ b/include/mapnik/warp.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006-2011 Artem Pavlenko + * 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 @@ -19,11 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef WARP_HPP -#define WARP_HPP +#ifndef MAPNIK_WARP_HPP +#define MAPNIK_WARP_HPP +// mapnik #include #include @@ -38,4 +38,5 @@ void reproject_raster(raster &target, raster const& source, std::string scaling_method_name); } -#endif //WARP_HPP + +#endif // MAPNIK_WARP_HPP diff --git a/include/mapnik/wkb.hpp b/include/mapnik/wkb.hpp index 6b733b528..77c7c04c6 100644 --- a/include/mapnik/wkb.hpp +++ b/include/mapnik/wkb.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,10 @@ * *****************************************************************************/ -//$Id: wkb.hpp 39 2005-04-10 20:39:53Z pavlenko $ - -#ifndef WKB_HPP -#define WKB_HPP +#ifndef MAPNIK_WKB_HPP +#define MAPNIK_WKB_HPP +// mapnik #include #include #include @@ -66,4 +65,4 @@ private: }; } -#endif //WKB_HPP +#endif // MAPNIK_WKB_HPP diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 88a3cad62..f98ff2d33 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -3,7 +3,6 @@ // boost #include #include -#include #include #include #include @@ -18,13 +17,9 @@ // stl #include -#include // fstream +#include +#include #include -#include // ostream_operator - -// std lib -#include -#include using mapnik::datasource; using mapnik::parameters; @@ -53,7 +48,8 @@ csv_datasource::csv_datasource(parameters const& params, bool bind) /* TODO: general: - refactor parser into generic class - - tests + - tests of grid_renderer output + - ensure that the attribute desc_ matches the first feature added alternate large file pipeline: - stat file, detect > 15 MB - build up csv line-by-line iterator @@ -125,7 +121,7 @@ void csv_datasource::parse_csv(T& stream, std::string const& quote) const { stream.seekg (0, std::ios::end); - int file_length_ = stream.tellg(); + file_length_ = stream.tellg(); if (filesize_max_ > 0) { @@ -149,7 +145,7 @@ void csv_datasource::parse_csv(T& stream, char newline = '\n'; int newline_count = 0; int carriage_count = 0; - for(std::size_t idx = 0; idx < file_length_; idx++) + for(unsigned idx = 0; idx < file_length_; idx++) { char c = static_cast(stream.get()); if (c == '\n') @@ -189,11 +185,11 @@ void csv_datasource::parse_csv(T& stream, { // default to ',' sep = ","; + int num_commas = std::count(csv_line.begin(), csv_line.end(), ','); // detect tabs int num_tabs = std::count(csv_line.begin(), csv_line.end(), '\t'); if (num_tabs > 0) { - int num_commas = std::count(csv_line.begin(), csv_line.end(), ','); if (num_tabs > num_commas) { sep = "\t"; @@ -202,6 +198,28 @@ void csv_datasource::parse_csv(T& stream, #endif } } + else // pipes + { + int num_pipes = std::count(csv_line.begin(), csv_line.end(), '|'); + if (num_pipes > num_commas) + { + sep = "|"; +#ifdef MAPNIK_DEBUG + std::clog << "CSV Plugin: auto detected '|' separator\n"; +#endif + } + else // semicolons + { + int num_semicolons = std::count(csv_line.begin(), csv_line.end(), ';'); + if (num_semicolons > num_commas) + { + sep = ";"; + #ifdef MAPNIK_DEBUG + std::clog << "CSV Plugin: auto detected ';' separator\n"; + #endif + } + } + } } // set back to start @@ -251,7 +269,8 @@ void csv_datasource::parse_csv(T& stream, { std::string val = boost::trim_copy(*beg); std::string lower_val = boost::algorithm::to_lower_copy(val); - if (lower_val == "wkt") + if (lower_val == "wkt" + || (lower_val.find("geom") != std::string::npos)) { wkt_idx = idx; has_wkt_field = true; @@ -300,17 +319,28 @@ void csv_datasource::parse_csv(T& stream, val = boost::trim_copy(*beg); if (val.empty()) { - std::ostringstream s; - s << "CSV Plugin: expected a column header at line " - << line_number << ", column " << idx - << " - ensure this row contains valid header fields: '" - << csv_line << "'\n"; - throw mapnik::datasource_exception(s.str()); + if (strict_) + { + std::ostringstream s; + s << "CSV Plugin: expected a column header at line " + << line_number << ", column " << idx + << " - ensure this row contains valid header fields: '" + << csv_line << "'\n"; + throw mapnik::datasource_exception(s.str()); + } + else + { + // create a placeholder for the empty header + std::ostringstream s; + s << "_" << idx; + headers_.push_back(s.str()); + } } else { std::string lower_val = boost::algorithm::to_lower_copy(val); - if (lower_val == "wkt") + if (lower_val == "wkt" + || (lower_val.find("geom") != std::string::npos)) { wkt_idx = idx; has_wkt_field = true; @@ -353,9 +383,9 @@ void csv_datasource::parse_csv(T& stream, throw mapnik::datasource_exception(s.str()); } - int feature_count(0); + int feature_count(1); bool extent_initialized = false; - int num_headers = headers_.size(); + unsigned num_headers = headers_.size(); mapnik::transcoder tr(desc_.get_encoding()); while (std::getline(stream,csv_line,newline)) @@ -367,14 +397,21 @@ void csv_datasource::parse_csv(T& stream, #endif break; } + + unsigned line_length = csv_line.length(); // skip blank lines - if (csv_line.empty()){ - ++line_number; - continue; + if (line_length < 5) + { + std::string trimmed = csv_line; + boost::trim_if(trimmed,boost::algorithm::is_any_of("\",'\r\n")); + if (trimmed.empty()){ + ++line_number; + continue; #ifdef MAPNIK_DEBUG - std::clog << "CSV Plugin: empty row encountered at line: " << line_number << "\n"; + std::clog << "CSV Plugin: empty row encountered at line: " << line_number << "\n"; #endif + } } try @@ -385,7 +422,7 @@ void csv_datasource::parse_csv(T& stream, // early return for strict mode if (strict_) { - int num_fields = std::distance(beg,tok.end()); + unsigned num_fields = std::distance(beg,tok.end()); if (num_fields != num_headers) { std::ostringstream s; @@ -400,28 +437,32 @@ void csv_datasource::parse_csv(T& stream, bool parsed_x = false; bool parsed_y = false; bool parsed_wkt = false; - bool skip = false; bool null_geom = false; std::vector collected; - int i = -1; - for (;beg != tok.end(); ++beg) + for (unsigned i = 0; i < num_headers; ++i) { - ++i; - std::string value = boost::trim_copy(*beg); - - // avoid range error if trailing separator - if (i >= num_headers) - { - #ifdef MAPNIK_DEBUG - std::clog << "CSV Plugin: messed up line encountered where # values > # column headers at: " << line_number << "\n"; - #endif - skip = true; - break; - } - std::string fld_name(headers_.at(i)); collected.push_back(fld_name); + std::string value; + if (beg == tok.end()) + { + UnicodeString ustr = tr.transcode(value.c_str()); + boost::put(*feature,fld_name,ustr); + //boost::put(*feature,fld_name,mapnik::value_null()); + null_geom = true; + if (feature_count == 1) + { + desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); + } + continue; + } + else + { + value = boost::trim_copy(*beg); + ++beg; + } + int value_length = value.length(); // parse wkt @@ -450,7 +491,7 @@ void csv_datasource::parse_csv(T& stream, ), ascii::space); - if (r /*&& (str_beg != str_end)*/) + if (r && (str_beg == str_end)) { mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point); pt->move_to(x,y); @@ -572,22 +613,26 @@ void csv_datasource::parse_csv(T& stream, } // add all values as attributes + // here we detect numbers and treat everything else as pure strings + // this is intentional since boolean and null types are not common in csv editors if (value.empty()) - { - boost::put(*feature,fld_name,mapnik::value_null()); - } - // only true strings are this long - else if (value_length > 20 - // TODO - clean up this messiness which is here temporarily - // to protect against the improperly working spirit parsing below - || value.find(",") != std::string::npos - || value.find(":") != std::string::npos - || (std::count(value.begin(), value.end(), '-') > 1)) { UnicodeString ustr = tr.transcode(value.c_str()); boost::put(*feature,fld_name,ustr); - if (!feature_count) + if (feature_count == 1) + { desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); + } + } + // only true strings are this long + else if (value_length > 20) + { + UnicodeString ustr = tr.transcode(value.c_str()); + boost::put(*feature,fld_name,ustr); + if (feature_count == 1) + { + desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); + } } else if ((value[0] >= '0' && value[0] <= '9') || value[0] == '-') @@ -596,20 +641,24 @@ void csv_datasource::parse_csv(T& stream, std::string::const_iterator str_beg = value.begin(); std::string::const_iterator str_end = value.end(); bool r = qi::phrase_parse(str_beg,str_end,qi::double_,ascii::space,float_val); - if (r) + if (r && (str_beg == str_end)) { if (value.find(".") != std::string::npos) { boost::put(*feature,fld_name,float_val); - if (!feature_count) + if (feature_count == 1) + { desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::Double)); + } } else { int val = static_cast(float_val); boost::put(*feature,fld_name,val); - if (!feature_count) + if (feature_count == 1) + { desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::Integer)); + } } } else @@ -617,55 +666,25 @@ void csv_datasource::parse_csv(T& stream, // fallback to normal string UnicodeString ustr = tr.transcode(value.c_str()); boost::put(*feature,fld_name,ustr); - if (!feature_count) + if (feature_count == 1) + { desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); + } } } else { - std::string value_lower = boost::algorithm::to_lower_copy(value); - if (value_lower == "true") + // fallback to normal string + UnicodeString ustr = tr.transcode(value.c_str()); + boost::put(*feature,fld_name,ustr); + if (feature_count == 1) { - boost::put(*feature,fld_name,true); - if (!feature_count) - desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::Boolean)); - } - else if(value_lower == "false") - { - boost::put(*feature,fld_name,false); - if (!feature_count) - desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::Boolean)); - } - else - { - // fallback to normal string - UnicodeString ustr = tr.transcode(value.c_str()); - boost::put(*feature,fld_name,ustr); - if (!feature_count) - desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); + desc_.add_descriptor(mapnik::attribute_descriptor(fld_name,mapnik::String)); } } } - if (skip) - { - ++line_number; - std::ostringstream s; - s << "CSV Plugin: # values > # column headers" - << "for line " << line_number << " - found " << headers_.size() - << " with values like: " << csv_line << "\n"; - //<< "for: " << boost::algorithm::join(collected, ",") << "\n"; - if (strict_) - { - throw mapnik::datasource_exception(s.str()); - } - else - { - if (!quiet_) std::clog << s.str() << "\n"; - continue; - } - } - else if (null_geom) + if (null_geom) { ++line_number; std::ostringstream s; @@ -696,6 +715,7 @@ void csv_datasource::parse_csv(T& stream, extent_.expand_to_include(feature->envelope()); } features_.push_back(feature); + ++feature_count; } else { @@ -767,6 +787,17 @@ void csv_datasource::parse_csv(T& stream, } ++line_number; } + catch (const mapnik::datasource_exception & ex ) + { + if (strict_) + { + throw mapnik::datasource_exception(ex.what()); + } + else + { + if (!quiet_) std::clog << ex.what() << "\n"; + } + } catch (const std::exception & ex ) { std::ostringstream s; @@ -783,6 +814,10 @@ void csv_datasource::parse_csv(T& stream, } } } + if (!feature_count > 0) + { + if (!quiet_) std::clog << "CSV Plugin: could not parse any lines of data\n"; + } } std::string csv_datasource::name() diff --git a/plugins/input/csv/csv_datasource.hpp b/plugins/input/csv/csv_datasource.hpp index e3fbb1683..d2e51bf8c 100644 --- a/plugins/input/csv/csv_datasource.hpp +++ b/plugins/input/csv/csv_datasource.hpp @@ -29,7 +29,7 @@ class csv_datasource : public mapnik::datasource mutable mapnik::box2d extent_; mutable std::string filename_; mutable std::string inline_string_; - mutable int file_length_; + mutable unsigned file_length_; mutable int row_limit_; mutable std::vector features_; mutable std::string escape_; diff --git a/plugins/input/gdal/build.py b/plugins/input/gdal/build.py index 2f81d98b1..491c26d55 100644 --- a/plugins/input/gdal/build.py +++ b/plugins/input/gdal/build.py @@ -42,6 +42,7 @@ plugin_env['LIBS'].append(env['ICU_LIB_NAME']) if env['RUNTIME_LINK'] == 'static': cmd = 'gdal-config --dep-libs' plugin_env.ParseConfig(cmd) + plugin_env['LIBS'].append('proj') input_plugin = plugin_env.SharedLibrary('../gdal', source=gdal_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LINKFLAGS=env['CUSTOM_LDFLAGS']) diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index f9ec48738..b12377eee 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -45,7 +45,7 @@ using mapnik::datasource_exception; * Opens a GDALDataset and returns a pointer to it. * Caller is responsible for calling GDALClose on it */ -inline GDALDataset *gdal_datasource::open_dataset() const +inline GDALDataset* gdal_datasource::open_dataset() const { #ifdef MAPNIK_DEBUG @@ -55,21 +55,28 @@ inline GDALDataset *gdal_datasource::open_dataset() const GDALDataset *dataset; #if GDAL_VERSION_NUM >= 1600 if (shared_dataset_) - dataset = reinterpret_cast(GDALOpenShared((dataset_name_).c_str(),GA_ReadOnly)); + { + dataset = reinterpret_cast(GDALOpenShared((dataset_name_).c_str(), GA_ReadOnly)); + } else #endif - dataset = reinterpret_cast(GDALOpen((dataset_name_).c_str(),GA_ReadOnly)); + { + dataset = reinterpret_cast(GDALOpen((dataset_name_).c_str(), GA_ReadOnly)); + } + + if (! dataset) + { + throw datasource_exception(CPLGetLastErrorMsg()); + } - if (! dataset) throw datasource_exception(CPLGetLastErrorMsg()); return dataset; } - gdal_datasource::gdal_datasource(parameters const& params, bool bind) - : datasource(params), - desc_(*params.get("type"),"utf-8"), - filter_factor_(*params_.get("filter_factor",0.0)) + : datasource(params), + desc_(*params.get("type"), "utf-8"), + filter_factor_(*params_.get("filter_factor", 0.0)) { #ifdef MAPNIK_DEBUG std::clog << "GDAL Plugin: Initializing..." << std::endl; @@ -78,13 +85,17 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind) GDALAllRegister(); boost::optional file = params.get("file"); - if (!file) throw datasource_exception("missing parameter"); + if (! file) throw datasource_exception("missing parameter"); boost::optional base = params_.get("base"); if (base) + { dataset_name_ = *base + "/" + *file; + } else + { dataset_name_ = *file; + } if (bind) { @@ -96,7 +107,7 @@ void gdal_datasource::bind() const { if (is_bound_) return; - shared_dataset_ = *params_.get("shared",false); + shared_dataset_ = *params_.get("shared", false); band_ = *params_.get("band", -1); GDALDataset *dataset = open_dataset(); @@ -105,7 +116,6 @@ void gdal_datasource::bind() const width_ = dataset->GetRasterXSize(); height_ = dataset->GetRasterYSize(); - double tr[6]; bool bbox_override = false; boost::optional bbox_s = params_.get("bbox"); @@ -114,8 +124,9 @@ void gdal_datasource::bind() const #ifdef MAPNIK_DEBUG std::clog << "GDAL Plugin: bbox parameter=" << *bbox_s << std::endl; #endif + bbox_override = extent_.from_string(*bbox_s); - if (!bbox_override) + if (! bbox_override) { throw datasource_exception("GDAL Plugin: bbox parameter '" + *bbox_s + "' invalid"); } @@ -141,7 +152,7 @@ void gdal_datasource::bind() const << tr[4] << "," << tr[5] << std::endl; #endif - if (tr[2] !=0 || tr[4] != 0) + if (tr[2] != 0 || tr[4] != 0) { throw datasource_exception("GDAL Plugin: only 'north up' images are supported"); } @@ -149,7 +160,7 @@ void gdal_datasource::bind() const dx_ = tr[1]; dy_ = tr[5]; - if (!bbox_override) + if (! bbox_override) { double x0 = tr[0]; double y0 = tr[3]; @@ -164,8 +175,9 @@ void gdal_datasource::bind() const double y1 = tr[3] + (width_) * tr[4]; // maxy */ - extent_.init(x0,y0,x1,y1); + extent_.init(x0, y0, x1, y1); } + GDALClose(dataset); #ifdef MAPNIK_DEBUG @@ -192,7 +204,7 @@ std::string gdal_datasource::name() box2d gdal_datasource::envelope() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return extent_; } @@ -204,18 +216,38 @@ layer_descriptor gdal_datasource::get_descriptor() const featureset_ptr gdal_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); gdal_query gq = q; + // TODO - move to boost::make_shared, but must reduce # of args to <= 9 - return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq, extent_, width_, height_, nbands_, dx_, dy_, filter_factor_)); + return featureset_ptr(new gdal_featureset(*open_dataset(), + band_, + gq, + extent_, + width_, + height_, + nbands_, + dx_, + dy_, + filter_factor_)); } featureset_ptr gdal_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); gdal_query gq = pt; - return featureset_ptr(new gdal_featureset(*open_dataset(), band_, gq, extent_, width_, height_, nbands_, dx_, dy_, filter_factor_)); -} + // TODO - move to boost::make_shared, but must reduce # of args to <= 9 + return featureset_ptr(new gdal_featureset(*open_dataset(), + band_, + gq, + extent_, + width_, + height_, + nbands_, + dx_, + dy_, + filter_factor_)); +} diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index e3c778c5e..a352c2cd5 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef GDAL_DATASOURCE_HPP #define GDAL_DATASOURCE_HPP @@ -35,29 +34,29 @@ class gdal_datasource : public mapnik::datasource { - public: - gdal_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~gdal_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features( mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - mutable mapnik::box2d extent_; - std::string dataset_name_; - mutable int band_; - mapnik::layer_descriptor desc_; - mutable unsigned width_; - mutable unsigned height_; - mutable double dx_; - mutable double dy_; - mutable int nbands_; - mutable bool shared_dataset_; - double filter_factor_; - inline GDALDataset *open_dataset() const; +public: + gdal_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~gdal_datasource(); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; +private: + mutable mapnik::box2d extent_; + std::string dataset_name_; + mutable int band_; + mapnik::layer_descriptor desc_; + mutable unsigned width_; + mutable unsigned height_; + mutable double dx_; + mutable double dy_; + mutable int nbands_; + mutable bool shared_dataset_; + double filter_factor_; + inline GDALDataset* open_dataset() const; }; diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index 648da2ebd..1ab5c895f 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,9 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik +#include #include #include "gdal_featureset.hpp" @@ -40,21 +40,31 @@ using mapnik::geometry_type; using mapnik::datasource_exception; using mapnik::feature_factory; +#ifdef _WINDOWS +using mapnik::rint; +#endif -gdal_featureset::gdal_featureset(GDALDataset & dataset, int band, gdal_query q, - mapnik::box2d extent, double width, double height, int nbands, - double dx, double dy, double filter_factor) - : dataset_(dataset), - band_(band), - gquery_(q), - raster_extent_(extent), - raster_width_(width), - raster_height_(height), - dx_(dx), - dy_(dy), - nbands_(nbands), - filter_factor_(filter_factor), - first_(true) +gdal_featureset::gdal_featureset(GDALDataset& dataset, + int band, + gdal_query q, + mapnik::box2d extent, + double width, + double height, + int nbands, + double dx, + double dy, + double filter_factor) + : dataset_(dataset), + band_(band), + gquery_(q), + raster_extent_(extent), + raster_width_(width), + raster_height_(height), + dx_(dx), + dy_(dy), + nbands_(nbands), + filter_factor_(filter_factor), + first_(true) { } @@ -63,6 +73,7 @@ gdal_featureset::~gdal_featureset() #ifdef MAPNIK_DEBUG std::clog << "GDAL Plugin: closing dataset = " << &dataset_ << std::endl; #endif + GDALClose(&dataset_); } @@ -76,11 +87,15 @@ feature_ptr gdal_featureset::next() #endif query *q = boost::get(&gquery_); - if(q) { + if (q) + { return get_feature(*q); - } else { + } + else + { coord2d *p = boost::get(&gquery_); - if(p) { + if (p) + { return get_feature_at_point(*p); } } @@ -108,40 +123,60 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) std::clog << "dx_: " << dx_ << " dx: " << dx << " dy_: " << dy_ << "dy: " << dy << "\n"; */ - CoordTransform t(raster_width_,raster_height_,raster_extent_,0,0); + CoordTransform t(raster_width_, raster_height_, raster_extent_, 0, 0); box2d intersect = raster_extent_.intersect(q.get_bbox()); box2d box = t.forward(intersect); //size of resized output pixel in source image domain - double margin_x = 1.0/(fabs(dx_)*boost::get<0>(q.resolution())); - double margin_y = 1.0/(fabs(dy_)*boost::get<1>(q.resolution())); + double margin_x = 1.0 / (fabs(dx_) * boost::get<0>(q.resolution())); + double margin_y = 1.0 / (fabs(dy_) * boost::get<1>(q.resolution())); if (margin_x < 1) + { margin_x = 1.0; + } if (margin_y < 1) + { margin_y = 1.0; + } + //select minimum raster containing whole box int x_off = rint(box.minx() - margin_x); int y_off = rint(box.miny() - margin_y); int end_x = rint(box.maxx() + margin_x); int end_y = rint(box.maxy() + margin_y); + //clip to available data if (x_off < 0) + { x_off = 0; + } if (y_off < 0) + { y_off = 0; + } if (end_x > (int)raster_width_) + { end_x = raster_width_; + } if (end_y > (int)raster_height_) + { end_y = raster_height_; + } int width = end_x - x_off; int height = end_y - y_off; + // don't process almost invisible data if (box.width() < 0.5) + { width = 0; + } if (box.height() < 0.5) + { height = 0; + } + //calculate actual box2d of returned raster - box2d feature_raster_extent(x_off, y_off, x_off+width, y_off+height); + box2d feature_raster_extent(x_off, y_off, x_off + width, y_off + height); intersect = t.backward(feature_raster_extent); #ifdef MAPNIK_DEBUG @@ -197,9 +232,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) if (band_ > 0) // we are querying a single band { if (band_ > nbands_) + { throw datasource_exception((boost::format("GDAL Plugin: '%d' is an invalid band, dataset only has '%d' bands\n") % band_ % nbands_).str()); + } - float *imageData = (float*)image.getBytes(); + float* imageData = (float*)image.getBytes(); GDALRasterBand * band = dataset_.GetRasterBand(band_); int hasNoData; double nodata = band->GetNoDataValue(&hasNoData); @@ -209,17 +246,18 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) feature->set_raster(mapnik::raster_ptr(boost::make_shared(intersect,image))); if (hasNoData) - feature->props()["NODATA"]=nodata; + { + feature->props()["NODATA"] = nodata; + } } - else // working with all bands { for (int i = 0; i < nbands_; ++i) { - GDALRasterBand * band = dataset_.GetRasterBand(i+1); + GDALRasterBand * band = dataset_.GetRasterBand(i + 1); #ifdef MAPNIK_DEBUG - get_overview_meta(band); + get_overview_meta(band); #endif GDALColorInterp color_interp = band->GetColorInterpretation(); @@ -263,7 +301,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) #endif GDALColorTable *color_table = band->GetColorTable(); - if ( color_table) + if (color_table) { int count = color_table->GetColorEntryCount(); #ifdef MAPNIK_DEBUG @@ -303,33 +341,36 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) float nodata = red->GetNoDataValue(&hasNoData); GDALColorTable *color_table = red->GetColorTable(); - if (!alpha && hasNoData && !color_table) + if (! alpha && hasNoData && ! color_table) { // first read the data in and create an alpha channel from the nodata values - float *imageData = (float*)image.getBytes(); + float* imageData = (float*)image.getBytes(); red->RasterIO(GF_Read, x_off, y_off, width, height, - imageData, image.width(), image.height(), - GDT_Float32, 0, 0); + imageData, image.width(), image.height(), + GDT_Float32, 0, 0); int len = image.width() * image.height(); - for (int i=0; i (&imageData[i]) = 0; + { + *reinterpret_cast(&imageData[i]) = 0; + } else - *reinterpret_cast (&imageData[i]) = 0xFFFFFFFF; + { + *reinterpret_cast(&imageData[i]) = 0xFFFFFFFF; + } } } - red->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 0, - image.width(),image.height(),GDT_Byte,4,4*image.width()); - green->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 1, - image.width(),image.height(),GDT_Byte,4,4*image.width()); - blue->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 2, - image.width(),image.height(),GDT_Byte,4,4*image.width()); - + red->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 0, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); + green->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 1, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); + blue->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 2, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); } else if (grey) { @@ -338,36 +379,40 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) #endif int hasNoData; float nodata = grey->GetNoDataValue(&hasNoData); - GDALColorTable *color_table = grey->GetColorTable(); + GDALColorTable* color_table = grey->GetColorTable(); - if (hasNoData && !color_table) + if (hasNoData && ! color_table) { #ifdef MAPNIK_DEBUG std::clog << "\tno data value for layer: " << nodata << std::endl; #endif // 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, - imageData, image.width(), image.height(), - GDT_Float32, 0, 0); + imageData, image.width(), image.height(), + GDT_Float32, 0, 0); int len = image.width() * image.height(); - for (int i=0; i (&imageData[i]) = 0; + { + *reinterpret_cast(&imageData[i]) = 0; + } else + { *reinterpret_cast (&imageData[i]) = 0xFFFFFFFF; + } } } - grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 0, - image.width(),image.height(),GDT_Byte, 4, 4 * image.width()); - grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 1, - image.width(),image.height(),GDT_Byte, 4, 4 * image.width()); - grey->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 2, - image.width(),image.height(),GDT_Byte, 4, 4 * image.width()); + grey->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 0, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); + grey->RasterIO(GF_Read,x_off, y_off, width, height, image.getBytes() + 1, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); + grey->RasterIO(GF_Read,x_off, y_off, width, height, image.getBytes() + 2, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); if (color_table) { @@ -380,8 +425,9 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) for (unsigned x = 0; x < image.width(); ++x) { unsigned value = row[x] & 0xff; - const GDALColorEntry *ce = color_table->GetColorEntry ( value ); - if (ce ){ + const GDALColorEntry *ce = color_table->GetColorEntry(value); + if (ce ) + { // TODO - big endian support row[x] = (ce->c4 << 24)| (ce->c3 << 16) | (ce->c2 << 8) | (ce->c1) ; } @@ -395,11 +441,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q) #ifdef MAPNIK_DEBUG std::clog << "GDAL Plugin: processing alpha band..." << std::endl; #endif - alpha->RasterIO(GF_Read,x_off,y_off,width,height,image.getBytes() + 3, - image.width(),image.height(),GDT_Byte,4,4*image.width()); + alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 3, + image.width(), image.height(), GDT_Byte, 4, 4 * image.width()); } - feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersect,image))); + feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersect, image))); } return feature; } @@ -418,7 +464,7 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt) double gt[6]; dataset_.GetGeoTransform(gt); - double det = gt[1]*gt[5] - gt[2]*gt[4]; + double det = gt[1] * gt[5] - gt[2] * gt[4]; // subtract half a pixel width & height because gdal coord reference // is the top-left corner of a pixel, not the center. double X = pt.x - gt[0] - gt[1]/2; @@ -433,7 +479,7 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt) std::clog << boost::format("GDAL Plugin: pt.x=%f pt.y=%f") % pt.x % pt.y << std::endl; std::clog << boost::format("GDAL Plugin: x=%f y=%f") % x % y << std::endl; #endif - GDALRasterBand * band = dataset_.GetRasterBand(band_); + GDALRasterBand* band = dataset_.GetRasterBand(band_); int hasNoData; double nodata = band->GetNoDataValue(&hasNoData); double value; @@ -455,7 +501,7 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt) } #ifdef MAPNIK_DEBUG -void gdal_featureset::get_overview_meta(GDALRasterBand * band) +void gdal_featureset::get_overview_meta(GDALRasterBand* band) { int band_overviews = band->GetOverviewCount(); if (band_overviews > 0) @@ -464,7 +510,7 @@ void gdal_featureset::get_overview_meta(GDALRasterBand * band) 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") % b % overview->GetXSize() % overview->GetYSize() << std::endl; } @@ -476,7 +522,7 @@ void gdal_featureset::get_overview_meta(GDALRasterBand * band) int bsx,bsy; double scale; - band->GetBlockSize(&bsx,&bsy); + band->GetBlockSize(&bsx, &bsy); scale = band->GetScale(); std::clog << boost::format("GDAL Plugin: Block=%dx%d Scale=%f Type=%s Color=%s") % bsx % bsy % scale @@ -484,4 +530,3 @@ void gdal_featureset::get_overview_meta(GDALRasterBand * band) % GDALGetColorInterpretationName(band->GetColorInterpretation()) << std::endl; } #endif - diff --git a/plugins/input/gdal/gdal_featureset.hpp b/plugins/input/gdal/gdal_featureset.hpp index 99261773f..55cb03ec6 100644 --- a/plugins/input/gdal/gdal_featureset.hpp +++ b/plugins/input/gdal/gdal_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef GDAL_FEATURESET_HPP #define GDAL_FEATURESET_HPP @@ -33,33 +32,40 @@ class GDALDataset; class GDALRasterBand; -typedef boost::variant gdal_query; +typedef boost::variant gdal_query; class gdal_featureset : public mapnik::Featureset { - public: - gdal_featureset(GDALDataset & dataset, int band, gdal_query q, - mapnik::box2d extent, double width, double height, int nbands, - double dx, double dy, double filter_factor); - virtual ~gdal_featureset(); - mapnik::feature_ptr next(); - private: - mapnik::feature_ptr get_feature(mapnik::query const& q); - mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p); +public: + gdal_featureset(GDALDataset& dataset, + int band, + gdal_query q, + mapnik::box2d extent, + double width, + double height, + int nbands, + double dx, + double dy, + double filter_factor); + virtual ~gdal_featureset(); + mapnik::feature_ptr next(); +private: + mapnik::feature_ptr get_feature(mapnik::query const& q); + mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p); #ifdef MAPNIK_DEBUG - void get_overview_meta(GDALRasterBand * band); + void get_overview_meta(GDALRasterBand * band); #endif - GDALDataset & dataset_; - int band_; - gdal_query gquery_; - mapnik::box2d raster_extent_; - unsigned raster_width_; - unsigned raster_height_; - double dx_; - double dy_; - int nbands_; - double filter_factor_; - bool first_; + GDALDataset & dataset_; + int band_; + gdal_query gquery_; + mapnik::box2d raster_extent_; + unsigned raster_width_; + unsigned raster_height_; + double dx_; + double dy_; + int nbands_; + double filter_factor_; + bool first_; }; #endif // GDAL_FEATURESET_HPP diff --git a/plugins/input/geos/geos_datasource.cpp b/plugins/input/geos/geos_datasource.cpp index 5270ab185..e67298392 100644 --- a/plugins/input/geos/geos_datasource.cpp +++ b/plugins/input/geos/geos_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,16 +19,16 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -// $Id$ +#include "geos_datasource.hpp" +#include "geos_featureset.hpp" + +// stl #include #include #include #include -#include "geos_datasource.hpp" -#include "geos_featureset.hpp" - // mapnik #include #include @@ -44,17 +44,9 @@ // geos #include -using std::clog; -using std::endl; - using boost::lexical_cast; using boost::bad_lexical_cast; -using mapnik::datasource; -using mapnik::parameters; - -DATASOURCE_PLUGIN(geos_datasource) - using mapnik::box2d; using mapnik::coord2d; using mapnik::query; @@ -62,9 +54,12 @@ using mapnik::featureset_ptr; using mapnik::layer_descriptor; using mapnik::attribute_descriptor; using mapnik::datasource_exception; +using mapnik::datasource; +using mapnik::parameters; using mapnik::filter_in_box; using mapnik::filter_at_point; +DATASOURCE_PLUGIN(geos_datasource) void geos_notice(const char* fmt, ...) { @@ -90,17 +85,17 @@ void geos_error(const char* fmt, ...) geos_datasource::geos_datasource(parameters const& params, bool bind) - : datasource(params), - extent_(), - extent_initialized_(false), - type_(datasource::Vector), - desc_(*params.get("type"), *params.get("encoding","utf-8")), - geometry_data_(""), - geometry_data_name_("name"), - geometry_id_(1) + : datasource(params), + extent_(), + extent_initialized_(false), + type_(datasource::Vector), + desc_(*params.get("type"), *params.get("encoding", "utf-8")), + geometry_data_(""), + geometry_data_name_("name"), + geometry_id_(1) { boost::optional geometry = params.get("wkt"); - if (!geometry) throw datasource_exception("missing parameter"); + if (! geometry) throw datasource_exception("missing parameter"); geometry_string_ = *geometry; multiple_geometries_ = *params_.get("multiple_geometries",false); @@ -153,7 +148,7 @@ void geos_datasource::bind() const if (! extent_initialized_) { #ifdef MAPNIK_DEBUG - clog << "GEOS Plugin: initializing extent from geometry" << endl; + std::clog << "GEOS Plugin: initializing extent from geometry" << std::endl; #endif if (GEOSGeomTypeId(*geometry_) == GEOS_POINT) @@ -167,7 +162,7 @@ void geos_datasource::bind() const GEOSCoordSeq_getX(cs, 0, &x); GEOSCoordSeq_getY(cs, 0, &y); - extent_.init(x,y,x,y); + extent_.init(x, y, x, y); extent_initialized_ = true; } else @@ -177,7 +172,7 @@ void geos_datasource::bind() const { #ifdef MAPNIK_DEBUG char* wkt = GEOSGeomToWKT(*envelope); - clog << "GEOS Plugin: getting coord sequence from: " << wkt << endl; + std::clog << "GEOS Plugin: getting coord sequence from: " << wkt << std::endl; GEOSFree(wkt); #endif @@ -188,7 +183,7 @@ void geos_datasource::bind() const if (cs != NULL) { #ifdef MAPNIK_DEBUG - clog << "GEOS Plugin: iterating boundary points" << endl; + std::clog << "GEOS Plugin: iterating boundary points" << std::endl; #endif double x, y; @@ -196,8 +191,8 @@ void geos_datasource::bind() const miny = std::numeric_limits::max(), maxx = -std::numeric_limits::max(), maxy = -std::numeric_limits::max(); - unsigned int num_points; + unsigned int num_points; GEOSCoordSeq_getSize(cs, &num_points); for (unsigned int i = 0; i < num_points; ++i) @@ -211,7 +206,7 @@ void geos_datasource::bind() const if (y > maxy) maxy = y; } - extent_.init(minx,miny,maxx,maxy); + extent_.init(minx, miny, maxx, maxy); extent_initialized_ = true; } } @@ -220,7 +215,9 @@ void geos_datasource::bind() const } if (! extent_initialized_) + { throw datasource_exception("GEOS Plugin: cannot determine extent for geometry"); + } is_bound_ = true; } @@ -237,21 +234,21 @@ int geos_datasource::type() const box2d geos_datasource::envelope() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return extent_; } layer_descriptor geos_datasource::get_descriptor() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return desc_; } featureset_ptr geos_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); const mapnik::box2d extent = q.get_bbox(); @@ -265,7 +262,7 @@ featureset_ptr geos_datasource::features(query const& q) const << "))"; #ifdef MAPNIK_DEBUG - clog << "GEOS Plugin: using extent: " << s.str() << endl; + std::clog << "GEOS Plugin: using extent: " << s.str() << std::endl; #endif return boost::make_shared(*geometry_, @@ -279,13 +276,13 @@ featureset_ptr geos_datasource::features(query const& q) const featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); std::ostringstream s; s << "POINT(" << pt.x << " " << pt.y << ")"; #ifdef MAPNIK_DEBUG - clog << "GEOS Plugin: using point: " << s.str() << endl; + std::clog << "GEOS Plugin: using point: " << s.str() << std::endl; #endif return boost::make_shared(*geometry_, @@ -296,4 +293,3 @@ featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const desc_.get_encoding(), multiple_geometries_); } - diff --git a/plugins/input/geos/geos_datasource.hpp b/plugins/input/geos/geos_datasource.hpp index b675b8972..2ba154df0 100644 --- a/plugins/input/geos/geos_datasource.hpp +++ b/plugins/input/geos/geos_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef GEOS_DATASOURCE_HPP #define GEOS_DATASOURCE_HPP @@ -36,28 +35,28 @@ class geos_datasource : public mapnik::datasource { - public: - geos_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~geos_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - mutable mapnik::box2d extent_; - mutable bool extent_initialized_; - int type_; - mutable mapnik::layer_descriptor desc_; - mutable geos_feature_ptr geometry_; - mutable std::string geometry_data_; - mutable std::string geometry_data_name_; - mutable int geometry_id_; - std::string geometry_string_; - bool multiple_geometries_; +public: + geos_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~geos_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; + +private: + mutable mapnik::box2d extent_; + mutable bool extent_initialized_; + int type_; + mutable mapnik::layer_descriptor desc_; + mutable geos_feature_ptr geometry_; + mutable std::string geometry_data_; + mutable std::string geometry_data_name_; + mutable int geometry_id_; + std::string geometry_string_; + bool multiple_geometries_; }; - #endif // GEOS_DATASOURCE_HPP diff --git a/plugins/input/geos/geos_feature_ptr.hpp b/plugins/input/geos/geos_feature_ptr.hpp index 377436f3c..1425822d6 100644 --- a/plugins/input/geos/geos_feature_ptr.hpp +++ b/plugins/input/geos/geos_feature_ptr.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/plugins/input/geos/geos_featureset.cpp b/plugins/input/geos/geos_featureset.cpp index 4d961bc08..51335b3d5 100644 --- a/plugins/input/geos/geos_featureset.cpp +++ b/plugins/input/geos/geos_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ +// stl #include #include @@ -35,12 +35,8 @@ #include #include -// ogr #include "geos_featureset.hpp" -using std::clog; -using std::endl; - using mapnik::query; using mapnik::box2d; using mapnik::coord2d; @@ -59,14 +55,14 @@ geos_featureset::geos_featureset(GEOSGeometry* geometry, const std::string& field_name, const std::string& encoding, bool multiple_geometries) - : geometry_(geometry), - tr_(new transcoder(encoding)), - extent_(extent), - identifier_(identifier), - field_(field), - field_name_(field_name), - multiple_geometries_(multiple_geometries), - already_rendered_(false) + : geometry_(geometry), + tr_(new transcoder(encoding)), + extent_(extent), + identifier_(identifier), + field_(field), + field_name_(field_name), + multiple_geometries_(multiple_geometries), + already_rendered_(false) { } @@ -84,12 +80,12 @@ feature_ptr geos_featureset::next() { bool render_geometry = true; - if (*extent_ != NULL && GEOSisValid(*extent_) && !GEOSisEmpty(*extent_)) + if (*extent_ != NULL && GEOSisValid(*extent_) && ! GEOSisEmpty(*extent_)) { const int type = GEOSGeomTypeId(*extent_); render_geometry = false; - switch ( type ) + switch (type) { case GEOS_POINT: if (GEOSIntersects(*extent_, geometry_)) @@ -97,6 +93,7 @@ feature_ptr geos_featureset::next() render_geometry = true; } break; + case GEOS_POLYGON: if (GEOSContains(*extent_, geometry_) || GEOSWithin(geometry_, *extent_) @@ -105,9 +102,10 @@ feature_ptr geos_featureset::next() render_geometry = true; } break; - default: + + default: #ifdef MAPNIK_DEBUG - clog << "GEOS Plugin: unknown extent geometry_type=" << type << endl; + std::clog << "GEOS Plugin: unknown extent geometry_type=" << type << std::endl; #endif break; } @@ -138,4 +136,3 @@ feature_ptr geos_featureset::next() return feature_ptr(); } - diff --git a/plugins/input/geos/geos_featureset.hpp b/plugins/input/geos/geos_featureset.hpp index 3b284a92d..8a4cd1e16 100644 --- a/plugins/input/geos/geos_featureset.hpp +++ b/plugins/input/geos/geos_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef GEOS_FEATURESET_HPP #define GEOS_FEATURESET_HPP @@ -40,28 +39,28 @@ class geos_featureset : public mapnik::Featureset { public: - geos_featureset(GEOSGeometry* geometry, - GEOSGeometry* extent, - int identifier, - const std::string& field, - const std::string& field_name, - const std::string& encoding, - bool multiple_geometries); - virtual ~geos_featureset(); - mapnik::feature_ptr next(); + geos_featureset(GEOSGeometry* geometry, + GEOSGeometry* extent, + int identifier, + const std::string& field, + const std::string& field_name, + const std::string& encoding, + bool multiple_geometries); + virtual ~geos_featureset(); + mapnik::feature_ptr next(); private: - GEOSGeometry* geometry_; - boost::scoped_ptr tr_; - geos_feature_ptr extent_; - int identifier_; - std::string field_; - std::string field_name_; - bool multiple_geometries_; - bool already_rendered_; + GEOSGeometry* geometry_; + boost::scoped_ptr tr_; + geos_feature_ptr extent_; + int identifier_; + std::string field_; + std::string field_name_; + bool multiple_geometries_; + bool already_rendered_; - geos_featureset(const geos_featureset&); - const geos_featureset& operator=(const geos_featureset&); + geos_featureset(const geos_featureset&); + const geos_featureset& operator=(const geos_featureset&); }; #endif // GEOS_FEATURESET_HPP diff --git a/plugins/input/kismet/kismet_datasource.cpp b/plugins/input/kismet/kismet_datasource.cpp index 02a18d0d8..25037e014 100644 --- a/plugins/input/kismet/kismet_datasource.cpp +++ b/plugins/input/kismet/kismet_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -22,15 +22,15 @@ // $Id$ // network -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // mapnik #include @@ -72,26 +72,42 @@ std::list knd_list; const unsigned int queue_size = 20; kismet_datasource::kismet_datasource(parameters const& params, bool bind) - : datasource(params), - extent_(), - extent_initialized_(false), - type_(datasource::Vector), - desc_(*params.get("type"), *params.get("encoding","utf-8")) + : datasource(params), + extent_(), + extent_initialized_(false), + type_(datasource::Vector), + srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"), + desc_(*params.get("type"), *params.get("encoding","utf-8")) { boost::optional host = params_.get("host"); - if (host) { + if (host) + { host_ = *host; - } else { + } + else + { throw datasource_exception("Kismet Plugin: missing parameter"); } boost::optional port = params_.get("port", 2501); - if (port) port_ = *port; + if (port) + { + port_ = *port; + } + + boost::optional srs = params_.get("srs"); + if (srs) + { + srs_ = *srs; + } boost::optional ext = params_.get("extent"); - if (ext) extent_initialized_ = extent_.from_string(*ext); + if (ext) + { + extent_initialized_ = extent_.from_string(*ext); + } - kismet_thread.reset (new boost::thread (boost::bind (&kismet_datasource::run, this, host_, port_))); + kismet_thread.reset(new boost::thread(boost::bind(&kismet_datasource::run, this, host_, port_))); if (bind) { @@ -122,7 +138,7 @@ int kismet_datasource::type() const box2d kismet_datasource::envelope() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return extent_; } @@ -133,15 +149,17 @@ layer_descriptor kismet_datasource::get_descriptor() const featureset_ptr kismet_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - //cout << "kismet_datasource::features()" << endl; + // std::clog << "kismet_datasource::features()" << endl; // TODO: use box2d to filter bbox before adding to featureset_ptr - //mapnik::box2d const& e = q.get_bbox(); + // mapnik::box2d const& e = q.get_bbox(); boost::mutex::scoped_lock lock(knd_list_mutex); - return boost::make_shared(knd_list, desc_.get_encoding()); + return boost::make_shared(knd_list, + srs_, + desc_.get_encoding()); // TODO: if illegal: // return featureset_ptr(); @@ -149,14 +167,14 @@ featureset_ptr kismet_datasource::features(query const& q) const featureset_ptr kismet_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - //cout << "kismet_datasource::features_at_point()" << endl; + // std::clog << "kismet_datasource::features_at_point()" << endl; 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 std::clog << "Kismet Plugin: enter run" << std::endl; @@ -169,18 +187,18 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port char buffer[MAX_TCP_BUFFER]; // TCP data send from kismet_server std::string command; - if (inet_aton(ip_host.c_str (), &inadr)) + if (inet_aton(ip_host.c_str(), &inadr)) { - host = gethostbyaddr((char *) &inadr, sizeof(inadr), AF_INET); + host = gethostbyaddr((char*)&inadr, sizeof(inadr), AF_INET); } else { - host = gethostbyname(ip_host.c_str ()); + host = gethostbyname(ip_host.c_str()); } if (host == NULL) { - herror ("Kismet Plugin: Error while searching host"); + std::cerr << "Kismet Plugin: error while searching host" << std::endl; return; } @@ -188,13 +206,13 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port sock_addr.sin_port = htons(port); memcpy(&sock_addr.sin_addr, host->h_addr_list[0], sizeof(sock_addr.sin_addr)); - if ( (sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) + if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { std::cerr << "Kismet Plugin: error while creating socket" << std::endl; return; } - 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; return; @@ -202,9 +220,10 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port command = "!1 ENABLE NETWORK ssid,bssid,wep,bestlat,bestlon\n"; - 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; + close(sockfd); return; } @@ -219,10 +238,10 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port // assert is called. Needs to be analyzed! while ((n = read(sockfd, buffer, sizeof(buffer))) > 0) { - assert (n < MAX_TCP_BUFFER); + assert(n < MAX_TCP_BUFFER); 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 std::clog << "Kismet Plugin: buffer_obj=" << bufferObj << "[END]" << std::endl; @@ -233,10 +252,10 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port std::string kismet_line; // contains a line from kismet_server do { - found = bufferObj.find ('\n', search_start); + found = bufferObj.find('\n', search_start); if (found != std::string::npos) { - kismet_line.assign (bufferObj, search_start, found - search_start); + kismet_line.assign(bufferObj, search_start, found - search_start); #ifdef MAPNIK_DEBUG std::clog << "Kismet Plugin: line=" << kismet_line << " [ENDL]" << std::endl; @@ -245,7 +264,7 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port int param_number = 5; // the number of parameters to parse // Attention: string length specified to the constant! - if (sscanf (kismet_line.c_str (), + if (sscanf (kismet_line.c_str(), KISMET_COMMAND, ssid, bssid, @@ -255,20 +274,20 @@ void kismet_datasource::run (const std::string &ip_host, const unsigned int port { #ifdef MAPNIK_DEBUG std::clog << "Kismet Plugin: ssid=" << ssid << ", bssid=" << bssid - << ", crypt=" << crypt << ", bestlat=" << bestlat << ", bestlon=" << bestlon << std::endl; + << ", crypt=" << crypt << ", bestlat=" << bestlat << ", bestlon=" << bestlon << std::endl; #endif - kismet_network_data knd (ssid, bssid, bestlat, bestlon, crypt); + kismet_network_data knd(ssid, bssid, bestlat, bestlon, crypt); boost::mutex::scoped_lock lock(knd_list_mutex); // the queue only grows to a max size if (knd_list.size () >= queue_size) { - knd_list.pop_front (); + knd_list.pop_front(); } - knd_list.push_back (knd); + knd_list.push_back(knd); } else { diff --git a/plugins/input/kismet/kismet_datasource.hpp b/plugins/input/kismet/kismet_datasource.hpp index e5f1694f3..1f54a377b 100644 --- a/plugins/input/kismet/kismet_datasource.hpp +++ b/plugins/input/kismet/kismet_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef KISMET_DATASOURCE_HPP #define KISMET_DATASOURCE_HPP @@ -43,27 +42,28 @@ class kismet_datasource : public mapnik::datasource { - public: - kismet_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~kismet_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - void run (const std::string &host, const unsigned int port); +public: + kismet_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~kismet_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; - mapnik::box2d extent_; - bool extent_initialized_; - std::string host_; - unsigned int port_; - int type_; - mapnik::layer_descriptor desc_; - boost::shared_ptr kismet_thread; +private: + void run (const std::string& host, const unsigned int port); + + mapnik::box2d extent_; + bool extent_initialized_; + std::string host_; + unsigned int port_; + int type_; + std::string srs_; + mapnik::layer_descriptor desc_; + boost::shared_ptr kismet_thread; }; - #endif // KISMET_DATASOURCE_HPP diff --git a/plugins/input/kismet/kismet_featureset.cpp b/plugins/input/kismet/kismet_featureset.cpp index 387ec4173..08bc6b185 100644 --- a/plugins/input/kismet/kismet_featureset.cpp +++ b/plugins/input/kismet/kismet_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include @@ -41,13 +40,14 @@ using mapnik::geometry_utils; using mapnik::transcoder; using mapnik::feature_factory; -kismet_featureset::kismet_featureset(const std::list &knd_list, +kismet_featureset::kismet_featureset(const std::list& knd_list, + std::string const& srs, std::string const& encoding) : knd_list_(knd_list), tr_(new transcoder(encoding)), feature_id_(1), - knd_list_it(knd_list_.begin ()), - source_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") + knd_list_it(knd_list_.begin()), + source_(srs) { } @@ -63,11 +63,11 @@ feature_ptr kismet_featureset::next() const std::string key = "internet_access"; std::string value; - if (knd.crypt_ == crypt_none) + if (knd.crypt() == crypt_none) { value = "wlan_uncrypted"; } - else if (knd.crypt_ == crypt_wep) + else if (knd.crypt() == crypt_wep) { value = "wlan_wep"; } @@ -80,7 +80,7 @@ feature_ptr kismet_featureset::next() ++feature_id_; geometry_type* pt = new geometry_type(mapnik::Point); - pt->move_to(knd.bestlon_, knd.bestlat_); + pt->move_to(knd.bestlon(), knd.bestlat()); feature->add_geometry(pt); boost::put(*feature, key, tr_->transcode(value.c_str())); @@ -92,4 +92,3 @@ feature_ptr kismet_featureset::next() return feature_ptr(); } - diff --git a/plugins/input/kismet/kismet_featureset.hpp b/plugins/input/kismet/kismet_featureset.hpp index 8ad565919..811713020 100644 --- a/plugins/input/kismet/kismet_featureset.hpp +++ b/plugins/input/kismet/kismet_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef KISMET_FEATURESET_HPP #define KISMET_FEATURESET_HPP @@ -40,20 +39,21 @@ class kismet_featureset : public mapnik::Featureset { - public: - kismet_featureset(const std::list &knd_list, - std::string const& encoding); - virtual ~kismet_featureset(); - mapnik::feature_ptr next(); - - private: - const std::list &knd_list_; - boost::scoped_ptr tr_; - mapnik::wkbFormat format_; - bool multiple_geometries_; - int feature_id_; - std::list::const_iterator knd_list_it; - mapnik::projection source_; +public: + kismet_featureset(const std::list& knd_list, + std::string const& srs, + std::string const& encoding); + virtual ~kismet_featureset(); + mapnik::feature_ptr next(); + +private: + const std::list& knd_list_; + boost::scoped_ptr tr_; + mapnik::wkbFormat format_; + bool multiple_geometries_; + int feature_id_; + std::list::const_iterator knd_list_it; + mapnik::projection source_; }; #endif // KISMET_FEATURESET_HPP diff --git a/plugins/input/kismet/kismet_types.hpp b/plugins/input/kismet/kismet_types.hpp index f4f3da9cd..7cdb9fe92 100644 --- a/plugins/input/kismet/kismet_types.hpp +++ b/plugins/input/kismet/kismet_types.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef KISMET_TYPES_HPP #define KISMET_TYPES_HPP @@ -57,21 +56,56 @@ enum crypt_type class kismet_network_data { - public: - kismet_network_data() : bestlat_(0), bestlon_(0), crypt_ (crypt_none) {} - kismet_network_data(std::string ssid, std::string bssid, - double bestlat, double bestlon, int crypt) : - ssid_(ssid), bssid_(bssid), - bestlat_(bestlat), bestlon_(bestlon), - crypt_ (crypt) - {} - - std::string ssid_; - std::string bssid_; - double bestlat_; - double bestlon_; - int crypt_; +public: + kismet_network_data() + : bestlat_(0), bestlon_(0), crypt_(crypt_none) + { + } + + kismet_network_data(std::string ssid, + std::string bssid, + double bestlat, + double bestlon, + int crypt) + : ssid_(ssid), + bssid_(bssid), + bestlat_(bestlat), + bestlon_(bestlon), + crypt_(crypt) + { + } + + const std::string& ssid() const + { + return ssid_; + } + + const std::string& bssid() const + { + return bssid_; + } + + double bestlat() const + { + return bestlat_; + } + + double bestlon() const + { + return bestlon_; + } + + int crypt() const + { + return crypt_; + } + +protected: + std::string ssid_; + std::string bssid_; + double bestlat_; + double bestlon_; + int crypt_; }; -#endif //KISMET_TYPES_HPP - +#endif // KISMET_TYPES_HPP diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index f2609b13c..d2885e702 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -63,30 +63,29 @@ using oracle::occi::SQLException; using oracle::occi::Type; using oracle::occi::StatelessConnectionPool; -const std::string occi_datasource::METADATA_TABLE="USER_SDO_GEOM_METADATA"; +const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA"; DATASOURCE_PLUGIN(occi_datasource) - occi_datasource::occi_datasource(parameters const& params, bool bind) - : datasource (params), - type_(datasource::Vector), - fields_(*params_.get("fields","*")), - geometry_field_(*params_.get("geometry_field","")), - srid_initialized_(false), - extent_initialized_(false), - desc_(*params_.get("type"), *params_.get("encoding","utf-8")), - row_limit_(*params_.get("row_limit",0)), - row_prefetch_(*params_.get("row_prefetch",100)), - pool_(0), - conn_(0) + : datasource (params), + type_(datasource::Vector), + fields_(*params_.get("fields", "*")), + geometry_field_(*params_.get("geometry_field", "")), + srid_initialized_(false), + extent_initialized_(false), + desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + row_limit_(*params_.get("row_limit", 0)), + row_prefetch_(*params_.get("row_prefetch", 100)), + pool_(0), + conn_(0) { if (! params_.get("user")) throw datasource_exception("OCCI Plugin: no specified"); if (! params_.get("password")) throw datasource_exception("OCCI Plugin: no specified"); if (! params_.get("host")) throw datasource_exception("OCCI Plugin: no string specified"); boost::optional table = params_.get("table"); - if (!table) + if (! table) { throw datasource_exception("OCCI Plugin: no parameter specified"); } @@ -124,12 +123,16 @@ occi_datasource::~occi_datasource() if (use_connection_pool_) { if (pool_ != 0) - env->terminateStatelessConnectionPool (pool_, StatelessConnectionPool::SPD_FORCE); + { + env->terminateStatelessConnectionPool(pool_, StatelessConnectionPool::SPD_FORCE); + } } else { if (conn_ != 0) + { env->terminateConnection(conn_); + } } } } @@ -149,12 +152,12 @@ void occi_datasource::bind() const *params_.get("user"), *params_.get("password"), *params_.get("host"), - *params_.get("max_size",10), - *params_.get("initial_size",1), + *params_.get("max_size", 10), + *params_.get("initial_size", 1), 1, StatelessConnectionPool::HOMOGENEOUS); } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -170,7 +173,7 @@ void occi_datasource::bind() const *params_.get("password"), *params_.get("host")); } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -186,7 +189,9 @@ void occi_datasource::bind() const s << " LOWER(table_name) = LOWER('" << table_name << "')"; if (geometry_field_ != "") + { s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; + } #ifdef MAPNIK_DEBUG std::clog << "OCCI Plugin: " << s.str() << std::endl; @@ -198,7 +203,7 @@ void occi_datasource::bind() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); + ResultSet* rs = conn.execute_query(s.str()); if (rs && rs->next ()) { if (! srid_initialized_) @@ -213,7 +218,7 @@ void occi_datasource::bind() const } } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -234,7 +239,7 @@ void occi_datasource::bind() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); + ResultSet* rs = conn.execute_query(s.str()); if (rs) { std::vector listOfColumns = rs->getColumnListMetaData(); @@ -317,20 +322,22 @@ void occi_datasource::bind() const case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_RSET: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << std::endl; + std::clog << "OCCI Plugin: unsupported datatype " + << occi_enums::resolve_datatype(type_oid) + << " (type_oid=" << type_oid << ")" << std::endl; #endif break; default: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; + std::clog << "OCCI Plugin: unknown datatype " + << "(type_oid=" << type_oid << ")" << std::endl; #endif break; } } } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception(ex.getMessage()); } @@ -352,11 +359,12 @@ int occi_datasource::type() const box2d occi_datasource::envelope() const { if (extent_initialized_) return extent_; - if (!is_bound_) bind(); + if (! is_bound_) bind(); double lox = 0.0, loy = 0.0, hix = 0.0, hiy = 0.0; - boost::optional estimate_extent = params_.get("estimate_extent",false); + boost::optional estimate_extent = + params_.get("estimate_extent",false); if (estimate_extent && *estimate_extent) { @@ -375,8 +383,8 @@ box2d occi_datasource::envelope() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); - if (rs && rs->next ()) + ResultSet* rs = conn.execute_query(s.str()); + if (rs && rs->next()) { try { @@ -384,16 +392,16 @@ box2d occi_datasource::envelope() const loy = lexical_cast(rs->getDouble(2)); hix = lexical_cast(rs->getDouble(3)); hiy = lexical_cast(rs->getDouble(4)); - extent_.init (lox,loy,hix,hiy); + extent_.init(lox, loy, hix, hiy); extent_initialized_ = true; } - catch (bad_lexical_cast &ex) + catch (bad_lexical_cast& ex) { std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } @@ -421,63 +429,65 @@ box2d occi_datasource::envelope() const if (use_connection_pool_) conn.set_pool(pool_); else conn.set_connection(conn_, false); - ResultSet* rs = conn.execute_query (s.str()); + ResultSet* rs = conn.execute_query(s.str()); if (rs) { - if (rs->next ()) + if (rs->next()) { try { lox = lexical_cast(rs->getDouble(1)); hix = lexical_cast(rs->getDouble(2)); } - catch (bad_lexical_cast &ex) + catch (bad_lexical_cast& ex) { std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } - if (rs->next ()) + if (rs->next()) { try { loy = lexical_cast(rs->getDouble(1)); hiy = lexical_cast(rs->getDouble(2)); } - catch (bad_lexical_cast &ex) + catch (bad_lexical_cast& ex) { std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } - extent_.init (lox,loy,hix,hiy); + extent_.init(lox, loy, hix, hiy); extent_initialized_ = true; } } - catch (SQLException &ex) + catch (SQLException& ex) { throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } if (! extent_initialized_) + { throw datasource_exception("OCCI Plugin: unable to determine the extent of a table"); + } return extent_; } layer_descriptor occi_datasource::get_descriptor() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return desc_; } featureset_ptr occi_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - box2d const& box=q.get_bbox(); + box2d const& box = q.get_bbox(); std::ostringstream s; s << "SELECT " << geometry_field_; @@ -492,7 +502,7 @@ featureset_ptr occi_datasource::features(query const& q) const s << " FROM "; - std::string query (table_); + std::string query(table_); std::string table_name = mapnik::table_from_sql(query); if (use_spatial_index_) @@ -549,24 +559,24 @@ featureset_ptr occi_datasource::features(query const& q) const #endif return boost::make_shared(pool_, - conn_, - s.str(), - desc_.get_encoding(), - multiple_geometries_, - use_connection_pool_, - row_prefetch_, - props.size()); + conn_, + s.str(), + desc_.get_encoding(), + multiple_geometries_, + use_connection_pool_, + row_prefetch_, + props.size()); } featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); std::ostringstream s; s << "SELECT " << geometry_field_; std::vector::const_iterator itr = desc_.get_descriptors().begin(); std::vector::const_iterator end = desc_.get_descriptors().end(); - unsigned size=0; + unsigned size = 0; while (itr != end) { s << ", " << itr->get_name(); @@ -576,7 +586,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const s << " FROM "; - std::string query (table_); + std::string query(table_); std::string table_name = mapnik::table_from_sql(query); if (use_spatial_index_) @@ -593,7 +603,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const { boost::algorithm::ireplace_first(query, "WHERE", spatial_sql.str() + " AND "); } - else if (boost::algorithm::ifind_first(query,table_name)) + else if (boost::algorithm::ifind_first(query, table_name)) { boost::algorithm::ireplace_first(query, table_name, table_name + " " + spatial_sql.str()); } @@ -632,12 +642,11 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const #endif return boost::make_shared(pool_, - conn_, - s.str(), - desc_.get_encoding(), - multiple_geometries_, - use_connection_pool_, - row_prefetch_, - size); + conn_, + s.str(), + desc_.get_encoding(), + multiple_geometries_, + use_connection_pool_, + row_prefetch_, + size); } - diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index 53badc22d..e0d5826e4 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OCCI_DATASOURCE_HPP #define OCCI_DATASOURCE_HPP @@ -38,35 +37,35 @@ class occi_datasource : public mapnik::datasource { - public: - occi_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~occi_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - int type_; - mutable std::string table_; - mutable std::string fields_; - mutable std::string geometry_field_; - mutable int srid_; - mutable bool srid_initialized_; - mutable bool extent_initialized_; - mutable mapnik::box2d extent_; - mutable mapnik::layer_descriptor desc_; - int row_limit_; - int row_prefetch_; - mutable oracle::occi::StatelessConnectionPool* pool_; - mutable oracle::occi::Connection* conn_; - bool use_connection_pool_; - bool multiple_geometries_; - bool use_spatial_index_; - static const std::string METADATA_TABLE; +public: + occi_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~occi_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; + +private: + int type_; + mutable std::string table_; + mutable std::string fields_; + mutable std::string geometry_field_; + mutable int srid_; + mutable bool srid_initialized_; + mutable bool extent_initialized_; + mutable mapnik::box2d extent_; + mutable mapnik::layer_descriptor desc_; + int row_limit_; + int row_prefetch_; + mutable oracle::occi::StatelessConnectionPool* pool_; + mutable oracle::occi::Connection* conn_; + bool use_connection_pool_; + bool multiple_geometries_; + bool use_spatial_index_; + static const std::string METADATA_TABLE; }; - #endif // OCCI_DATASOURCE_HPP diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index 9d850b1e7..e94e990d9 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include @@ -64,19 +63,23 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool, bool use_connection_pool, unsigned prefetch_rows, unsigned num_attrs) - : tr_(new transcoder(encoding)), - multiple_geometries_(multiple_geometries), - num_attrs_(num_attrs), - feature_id_(1) + : tr_(new transcoder(encoding)), + multiple_geometries_(multiple_geometries), + num_attrs_(num_attrs), + feature_id_(1) { if (use_connection_pool) + { conn_.set_pool(pool); + } else + { conn_.set_connection(conn, false); + } try { - rs_ = conn_.execute_query (sqlstring, prefetch_rows); + rs_ = conn_.execute_query(sqlstring, prefetch_rows); } catch (SQLException &ex) { @@ -95,10 +98,10 @@ feature_ptr occi_featureset::next() feature_ptr feature(feature_factory::create(feature_id_)); ++feature_id_; - boost::scoped_ptr geom (dynamic_cast (rs_->getObject(1))); + boost::scoped_ptr geom(dynamic_cast(rs_->getObject(1))); if (geom.get()) { - convert_geometry (geom.get(), feature, multiple_geometries_); + convert_geometry(geom.get(), feature, multiple_geometries_); } std::vector listOfColumns = rs_->getColumnListMetaData(); @@ -120,75 +123,77 @@ feature_ptr occi_featureset::next() switch (type_oid) { - case oracle::occi::OCCIBOOL: - case oracle::occi::OCCIINT: - case oracle::occi::OCCIUNSIGNED_INT: - case oracle::occi::OCCIROWID: - boost::put(*feature,fld_name,rs_->getInt (i + 1)); - break; - case oracle::occi::OCCIFLOAT: - case oracle::occi::OCCIBFLOAT: - case oracle::occi::OCCIDOUBLE: - case oracle::occi::OCCIBDOUBLE: - case oracle::occi::OCCINUMBER: - case oracle::occi::OCCI_SQLT_NUM: - boost::put(*feature,fld_name,rs_->getDouble (i + 1)); - break; - case oracle::occi::OCCICHAR: - case oracle::occi::OCCISTRING: - case oracle::occi::OCCI_SQLT_AFC: - case oracle::occi::OCCI_SQLT_AVC: - case oracle::occi::OCCI_SQLT_CHR: - case oracle::occi::OCCI_SQLT_LVC: - case oracle::occi::OCCI_SQLT_RDD: - case oracle::occi::OCCI_SQLT_STR: - case oracle::occi::OCCI_SQLT_VCS: - case oracle::occi::OCCI_SQLT_VNU: - case oracle::occi::OCCI_SQLT_VBI: - case oracle::occi::OCCI_SQLT_VST: - boost::put(*feature,fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str())); - break; - case oracle::occi::OCCIDATE: - case oracle::occi::OCCITIMESTAMP: - case oracle::occi::OCCIINTERVALDS: - case oracle::occi::OCCIINTERVALYM: - case oracle::occi::OCCI_SQLT_DAT: - case oracle::occi::OCCI_SQLT_DATE: - case oracle::occi::OCCI_SQLT_TIME: - case oracle::occi::OCCI_SQLT_TIME_TZ: - case oracle::occi::OCCI_SQLT_TIMESTAMP: - case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: - case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: - case oracle::occi::OCCI_SQLT_INTERVAL_YM: - case oracle::occi::OCCI_SQLT_INTERVAL_DS: - case oracle::occi::OCCIANYDATA: - case oracle::occi::OCCIBLOB: - case oracle::occi::OCCIBFILE: - case oracle::occi::OCCIBYTES: - case oracle::occi::OCCICLOB: - case oracle::occi::OCCIVECTOR: - case oracle::occi::OCCIMETADATA: - case oracle::occi::OCCIPOBJECT: - case oracle::occi::OCCIREF: - case oracle::occi::OCCIREFANY: - case oracle::occi::OCCISTREAM: - case oracle::occi::OCCICURSOR: - case oracle::occi::OCCI_SQLT_FILE: - case oracle::occi::OCCI_SQLT_CFILE: - case oracle::occi::OCCI_SQLT_REF: - case oracle::occi::OCCI_SQLT_CLOB: - case oracle::occi::OCCI_SQLT_BLOB: - case oracle::occi::OCCI_SQLT_RSET: + case oracle::occi::OCCIBOOL: + case oracle::occi::OCCIINT: + case oracle::occi::OCCIUNSIGNED_INT: + case oracle::occi::OCCIROWID: + boost::put(*feature,fld_name,rs_->getInt (i + 1)); + break; + case oracle::occi::OCCIFLOAT: + case oracle::occi::OCCIBFLOAT: + case oracle::occi::OCCIDOUBLE: + case oracle::occi::OCCIBDOUBLE: + case oracle::occi::OCCINUMBER: + case oracle::occi::OCCI_SQLT_NUM: + boost::put(*feature,fld_name,rs_->getDouble (i + 1)); + break; + case oracle::occi::OCCICHAR: + case oracle::occi::OCCISTRING: + case oracle::occi::OCCI_SQLT_AFC: + case oracle::occi::OCCI_SQLT_AVC: + case oracle::occi::OCCI_SQLT_CHR: + case oracle::occi::OCCI_SQLT_LVC: + case oracle::occi::OCCI_SQLT_RDD: + case oracle::occi::OCCI_SQLT_STR: + case oracle::occi::OCCI_SQLT_VCS: + case oracle::occi::OCCI_SQLT_VNU: + case oracle::occi::OCCI_SQLT_VBI: + case oracle::occi::OCCI_SQLT_VST: + boost::put(*feature,fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str())); + break; + case oracle::occi::OCCIDATE: + case oracle::occi::OCCITIMESTAMP: + case oracle::occi::OCCIINTERVALDS: + case oracle::occi::OCCIINTERVALYM: + case oracle::occi::OCCI_SQLT_DAT: + case oracle::occi::OCCI_SQLT_DATE: + case oracle::occi::OCCI_SQLT_TIME: + case oracle::occi::OCCI_SQLT_TIME_TZ: + case oracle::occi::OCCI_SQLT_TIMESTAMP: + case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: + case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: + case oracle::occi::OCCI_SQLT_INTERVAL_YM: + case oracle::occi::OCCI_SQLT_INTERVAL_DS: + case oracle::occi::OCCIANYDATA: + case oracle::occi::OCCIBLOB: + case oracle::occi::OCCIBFILE: + case oracle::occi::OCCIBYTES: + case oracle::occi::OCCICLOB: + case oracle::occi::OCCIVECTOR: + case oracle::occi::OCCIMETADATA: + case oracle::occi::OCCIPOBJECT: + case oracle::occi::OCCIREF: + case oracle::occi::OCCIREFANY: + case oracle::occi::OCCISTREAM: + case oracle::occi::OCCICURSOR: + case oracle::occi::OCCI_SQLT_FILE: + case oracle::occi::OCCI_SQLT_CFILE: + case oracle::occi::OCCI_SQLT_REF: + case oracle::occi::OCCI_SQLT_CLOB: + case oracle::occi::OCCI_SQLT_BLOB: + case oracle::occi::OCCI_SQLT_RSET: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << std::endl; + std::clog << "OCCI Plugin: unsupported datatype " + << occi_enums::resolve_datatype(type_oid) + << " (type_oid=" << type_oid << ")" << std::endl; #endif - break; - default: // shouldn't get here + break; + default: // shouldn't get here #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; + std::clog << "OCCI Plugin: unknown datatype " + << "(type_oid=" << type_oid << ")" << std::endl; #endif - break; + break; } } @@ -199,30 +204,30 @@ feature_ptr occi_featureset::next() } -void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, bool multiple_geometries) +void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, bool multiple_geometries) { - int gtype = (int) geom->getSdo_gtype(); + int gtype = (int)geom->getSdo_gtype(); int dimensions = gtype / 1000; int lrsvalue = (gtype - dimensions * 1000) / 100; int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100); #if 0 - clog << "-----------Geometry Object ------------" << endl; - clog << "SDO GTYPE = " << gtype << endl; - clog << "SDO DIMENSIONS = " << dimensions << endl; - clog << "SDO LRS = " << lrsvalue << endl; - clog << "SDO GEOMETRY TYPE = " << geomtype << endl; + 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()) - clog << "SDO SRID = " << "Null" << endl; + std::clog << "SDO SRID = " << "Null" << std::endl; else - clog << "SDO SRID = " << (int) sdo_srid << endl; + std::clog << "SDO SRID = " << (int)sdo_srid << std::endl; #endif const std::vector& elem_info = geom->getSdo_elem_info(); const std::vector& ordinates = geom->getSdo_ordinates(); - const int ordinates_size = (int) ordinates.size(); + const int ordinates_size = (int)ordinates.size(); switch (geomtype) { @@ -232,8 +237,8 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, if (sdopoint && ! sdopoint->isNull()) { geometry_type* point = new geometry_type(mapnik::Point); - point->move_to (sdopoint->getX(), sdopoint->getY()); - feature->add_geometry (point); + point->move_to(sdopoint->getX(), sdopoint->getY()); + feature->add_geometry(point); } } break; @@ -245,14 +250,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_point_type = false; const bool multiple_geoms = false; - convert_ordinates (feature, - mapnik::LineString, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geoms); + convert_ordinates(feature, + mapnik::LineString, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geoms); } } break; @@ -264,14 +269,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_point_type = false; const bool multiple_geoms = false; - convert_ordinates (feature, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geoms); + convert_ordinates(feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geoms); } } break; @@ -286,14 +291,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, // Todo - force using true as multiple_geometries until we have proper multipoint handling // http://trac.mapnik.org/ticket/458 - convert_ordinates (feature, - mapnik::Point, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geoms); + convert_ordinates(feature, + mapnik::Point, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geoms); } } break; @@ -304,16 +309,15 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_single_geom = false; const bool is_point_type = false; - convert_ordinates (feature, - mapnik::LineString, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); + convert_ordinates(feature, + mapnik::LineString, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geometries); } - } break; case SDO_GTYPE_MULTIPOLYGON: @@ -323,14 +327,14 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_single_geom = false; const bool is_point_type = false; - convert_ordinates (feature, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); + convert_ordinates(feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geometries); } } @@ -342,55 +346,56 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, const bool is_single_geom = false; const bool is_point_type = false; - convert_ordinates (feature, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); + convert_ordinates(feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + is_single_geom, + is_point_type, + multiple_geometries); } } break; case SDO_GTYPE_UNKNOWN: default: #ifdef MAPNIK_DEBUG - std::clog << "OCCI Plugin: unknown " << occi_enums::resolve_gtype(geomtype) - << "(gtype=" << gtype << ")" << std::endl; + std::clog << "OCCI Plugin: unknown " + << occi_enums::resolve_gtype(geomtype) + << "(gtype=" << gtype << ")" << std::endl; #endif break; } } -void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, - const mapnik::eGeomType& geom_type, - const std::vector& elem_info, - const std::vector& ordinates, - const int dimensions, - const bool is_single_geom, - const bool is_point_geom, - const bool multiple_geometries) +void occi_featureset::convert_ordinates(mapnik::feature_ptr feature, + const mapnik::eGeomType& geom_type, + const std::vector& elem_info, + const std::vector& ordinates, + const int dimensions, + const bool is_single_geom, + const bool is_point_geom, + const bool multiple_geometries) { const int elem_size = elem_info.size(); const int ord_size = ordinates.size(); if (elem_size >= 0) { - int offset = elem_info [0]; - int etype = elem_info [1]; - int interp = elem_info [2]; + int offset = elem_info[0]; + int etype = elem_info[1]; + int interp = elem_info[2]; if (! is_single_geom && elem_size > SDO_ELEM_INFO_SIZE) { geometry_type* geom = multiple_geometries ? 0 : new geometry_type(geom_type); - if (geom) geom->set_capacity (ord_size); + if (geom) geom->set_capacity(ord_size); for (int i = SDO_ELEM_INFO_SIZE; i < elem_size; i+=3) { - int next_offset = elem_info [i]; - int next_etype = elem_info [i + 1]; - int next_interp = elem_info [i + 2]; + int next_offset = elem_info[i]; + int next_etype = elem_info[i + 1]; + int next_interp = elem_info[i + 2]; bool is_linear_element = true; bool is_unknown_etype = false; mapnik::eGeomType gtype = mapnik::Point; @@ -398,14 +403,14 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, switch (etype) { case SDO_ETYPE_POINT: - if (interp == SDO_INTERPRETATION_POINT) {} - if (interp > SDO_INTERPRETATION_POINT) {} + if (interp == SDO_INTERPRETATION_POINT) {} + if (interp > SDO_INTERPRETATION_POINT) {} gtype = mapnik::Point; break; case SDO_ETYPE_LINESTRING: - if (interp == SDO_INTERPRETATION_STRAIGHT) {} - if (interp == SDO_INTERPRETATION_CIRCULAR) {} + if (interp == SDO_INTERPRETATION_STRAIGHT) {} + if (interp == SDO_INTERPRETATION_CIRCULAR) {} gtype = mapnik::LineString; break; @@ -433,25 +438,29 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, } if (is_unknown_etype) + { break; + } if (is_linear_element) { if (multiple_geometries) { if (geom) - feature->add_geometry (geom); + { + feature->add_geometry(geom); + } geom = new geometry_type(gtype); - geom->set_capacity ((next_offset - 1) - (offset - 1 - dimensions)); + geom->set_capacity((next_offset - 1) - (offset - 1 - dimensions)); } - fill_geometry_type (geom, - offset - 1, - next_offset - 1, - ordinates, - dimensions, - is_point_geom); + fill_geometry_type(geom, + offset - 1, + next_offset - 1, + ordinates, + dimensions, + is_point_geom); } offset = next_offset; @@ -461,45 +470,48 @@ void occi_featureset::convert_ordinates (mapnik::feature_ptr feature, if (geom) { - feature->add_geometry (geom); + feature->add_geometry(geom); geom = 0; } } else { geometry_type * geom = new geometry_type(geom_type); - geom->set_capacity (ord_size); + geom->set_capacity(ord_size); - fill_geometry_type (geom, - offset - 1, - ord_size, - ordinates, - dimensions, - is_point_geom); + fill_geometry_type(geom, + offset - 1, + ord_size, + ordinates, + dimensions, + is_point_geom); - feature->add_geometry (geom); + feature->add_geometry(geom); } } } -void occi_featureset::fill_geometry_type (geometry_type * geom, - const int real_offset, - const int next_offset, - const std::vector& ordinates, - const int dimensions, - const bool is_point_geom) +void occi_featureset::fill_geometry_type(geometry_type* geom, + const int real_offset, + const int next_offset, + const std::vector& ordinates, + const int dimensions, + const bool is_point_geom) { - geom->move_to ((double) ordinates[real_offset], (double) ordinates[real_offset + 1]); + geom->move_to((double) ordinates[real_offset], (double) ordinates[real_offset + 1]); if (is_point_geom) { for (int p = real_offset + dimensions; p < next_offset; p += dimensions) - geom->move_to ((double) ordinates[p], (double) ordinates[p + 1]); + { + geom->move_to((double) ordinates[p], (double) ordinates[p + 1]); + } } else { for (int p = real_offset + dimensions; p < next_offset; p += dimensions) - geom->line_to ((double) ordinates[p], (double) ordinates[p + 1]); + { + geom->line_to((double) ordinates[p], (double) ordinates[p + 1]); + } } } - diff --git a/plugins/input/occi/occi_featureset.hpp b/plugins/input/occi/occi_featureset.hpp index 6536d934e..ab60c884f 100644 --- a/plugins/input/occi/occi_featureset.hpp +++ b/plugins/input/occi/occi_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OCCI_FEATURESET_HPP #define OCCI_FEATURESET_HPP @@ -38,40 +37,42 @@ class occi_featureset : public mapnik::Featureset { - public: - occi_featureset(oracle::occi::StatelessConnectionPool* pool, - oracle::occi::Connection* conn, - std::string const& sqlstring, - std::string const& encoding, - bool multiple_geometries, - bool use_connection_pool, - unsigned prefetch_rows, - unsigned num_attrs); - virtual ~occi_featureset(); - mapnik::feature_ptr next(); - private: - void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); - void convert_ordinates (mapnik::feature_ptr feature, - const mapnik::eGeomType& geom_type, - const std::vector& elem_info, - const std::vector& ordinates, - const int dimensions, - const bool is_single_geom, - const bool is_point_geom, - const bool multiple_geometries); - void fill_geometry_type (mapnik::geometry_type * geom, - const int real_offset, - const int next_offset, - const std::vector& ordinates, - const int dimensions, - const bool is_point_geom); - occi_connection_ptr conn_; - oracle::occi::ResultSet* rs_; - boost::scoped_ptr tr_; - const char* fidcolumn_; - bool multiple_geometries_; - unsigned num_attrs_; - mutable int feature_id_; +public: + occi_featureset(oracle::occi::StatelessConnectionPool* pool, + oracle::occi::Connection* conn, + std::string const& sqlstring, + std::string const& encoding, + bool multiple_geometries, + bool use_connection_pool, + unsigned prefetch_rows, + unsigned num_attrs); + virtual ~occi_featureset(); + mapnik::feature_ptr next(); + +private: + void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); + void convert_ordinates (mapnik::feature_ptr feature, + const mapnik::eGeomType& geom_type, + const std::vector& elem_info, + const std::vector& ordinates, + const int dimensions, + const bool is_single_geom, + const bool is_point_geom, + const bool multiple_geometries); + void fill_geometry_type (mapnik::geometry_type* geom, + const int real_offset, + const int next_offset, + const std::vector& ordinates, + const int dimensions, + const bool is_point_geom); + + occi_connection_ptr conn_; + oracle::occi::ResultSet* rs_; + boost::scoped_ptr tr_; + const char* fidcolumn_; + bool multiple_geometries_; + unsigned num_attrs_; + mutable int feature_id_; }; #endif // OCCI_FEATURESET_HPP diff --git a/plugins/input/occi/occi_types.cpp b/plugins/input/occi/occi_types.cpp index 03e205eb5..86208e7a4 100644 --- a/plugins/input/occi/occi_types.cpp +++ b/plugins/input/occi/occi_types.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,77 +19,74 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #include "occi_types.hpp" oracle::occi::Environment* occi_environment::env_ = 0; - std::string occi_enums::resolve_gtype(int gtype) { - switch(gtype) + switch (gtype) { - case SDO_GTYPE_UNKNOWN: return "SDO_GTYPE_UNKNOWN"; - case SDO_GTYPE_POINT: return "SDO_GTYPE_POINT"; - case SDO_GTYPE_LINE: return "SDO_GTYPE_LINE"; - case SDO_GTYPE_POLYGON: return "SDO_GTYPE_POLYGON"; - case SDO_GTYPE_MULTIPOINT: return "SDO_GTYPE_MULTIPOINT"; - case SDO_GTYPE_MULTILINE: return "SDO_GTYPE_MULTILINE"; - case SDO_GTYPE_MULTIPOLYGON: return "SDO_GTYPE_MULTIPOLYGON"; - case SDO_GTYPE_COLLECTION: return "SDO_GTYPE_COLLECTION"; - default: return ""; + case SDO_GTYPE_UNKNOWN: return "SDO_GTYPE_UNKNOWN"; + case SDO_GTYPE_POINT: return "SDO_GTYPE_POINT"; + case SDO_GTYPE_LINE: return "SDO_GTYPE_LINE"; + case SDO_GTYPE_POLYGON: return "SDO_GTYPE_POLYGON"; + case SDO_GTYPE_MULTIPOINT: return "SDO_GTYPE_MULTIPOINT"; + case SDO_GTYPE_MULTILINE: return "SDO_GTYPE_MULTILINE"; + case SDO_GTYPE_MULTIPOLYGON: return "SDO_GTYPE_MULTIPOLYGON"; + case SDO_GTYPE_COLLECTION: return "SDO_GTYPE_COLLECTION"; + default: return ""; } } std::string occi_enums::resolve_etype(int etype) { - switch(etype) + switch (etype) { - case SDO_ETYPE_UNKNOWN: return "SDO_ETYPE_UNKNOWN"; - case SDO_ETYPE_POINT: return "SDO_ETYPE_POINT"; - case SDO_ETYPE_LINESTRING: return "SDO_ETYPE_LINESTRING"; - case SDO_ETYPE_POLYGON: return "SDO_ETYPE_POLYGON"; - case SDO_ETYPE_POLYGON_INTERIOR: return "SDO_ETYPE_POLYGON_INTERIOR"; - case SDO_ETYPE_COMPOUND_LINESTRING: return "SDO_ETYPE_COMPOUND_LINESTRING"; - case SDO_ETYPE_COMPOUND_POLYGON: return "SDO_ETYPE_COMPOUND_POLYGON"; - case SDO_ETYPE_COMPOUND_POLYGON_INTERIOR: return "SDO_ETYPE_COMPOUND_POLYGON_INTERIOR"; - default: return ""; + case SDO_ETYPE_UNKNOWN: return "SDO_ETYPE_UNKNOWN"; + case SDO_ETYPE_POINT: return "SDO_ETYPE_POINT"; + case SDO_ETYPE_LINESTRING: return "SDO_ETYPE_LINESTRING"; + case SDO_ETYPE_POLYGON: return "SDO_ETYPE_POLYGON"; + case SDO_ETYPE_POLYGON_INTERIOR: return "SDO_ETYPE_POLYGON_INTERIOR"; + case SDO_ETYPE_COMPOUND_LINESTRING: return "SDO_ETYPE_COMPOUND_LINESTRING"; + case SDO_ETYPE_COMPOUND_POLYGON: return "SDO_ETYPE_COMPOUND_POLYGON"; + case SDO_ETYPE_COMPOUND_POLYGON_INTERIOR: return "SDO_ETYPE_COMPOUND_POLYGON_INTERIOR"; + default: return ""; } } std::string occi_enums::resolve_datatype(int type_id) { - switch(type_id) + switch (type_id) { - case oracle::occi::OCCIINT: return "OCCIINT"; - case oracle::occi::OCCIUNSIGNED_INT: return "OCCIUNSIGNED_INT"; - case oracle::occi::OCCIFLOAT: return "OCCIFLOAT"; - case oracle::occi::OCCIBFLOAT: return "OCCIBFLOAT"; - case oracle::occi::OCCIDOUBLE: return "OCCIDOUBLE"; - case oracle::occi::OCCIBDOUBLE: return "OCCIBDOUBLE"; - case oracle::occi::OCCINUMBER: return "OCCINUMBER"; - case oracle::occi::OCCI_SQLT_NUM: return "OCCI_SQLT_NUM"; - case oracle::occi::OCCICHAR: return "OCCICHAR"; - case oracle::occi::OCCISTRING: return "OCCISTRING"; - case oracle::occi::OCCI_SQLT_AFC: return "OCCI_SQLT_AFC"; - case oracle::occi::OCCI_SQLT_AVC: return "OCCI_SQLT_AVC"; - case oracle::occi::OCCI_SQLT_CHR: return "OCCI_SQLT_CHR"; - case oracle::occi::OCCI_SQLT_LVC: return "OCCI_SQLT_LVC"; - case oracle::occi::OCCI_SQLT_STR: return "OCCI_SQLT_STR"; - case oracle::occi::OCCI_SQLT_VCS: return "OCCI_SQLT_VCS"; - case oracle::occi::OCCI_SQLT_VNU: return "OCCI_SQLT_VNU"; - case oracle::occi::OCCI_SQLT_VBI: return "OCCI_SQLT_VBI"; - case oracle::occi::OCCI_SQLT_VST: return "OCCI_SQLT_VST"; - case oracle::occi::OCCI_SQLT_RDD: return "OCCI_SQLT_RDD"; - case oracle::occi::OCCIDATE: return "OCCIDATE"; - case oracle::occi::OCCITIMESTAMP: return "OCCITIMESTAMP"; - case oracle::occi::OCCI_SQLT_DAT: return "OCCI_SQLT_DAT"; - case oracle::occi::OCCI_SQLT_TIMESTAMP: return "OCCI_SQLT_TIMESTAMP"; - case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: return "OCCI_SQLT_TIMESTAMP_LTZ"; - case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: return "OCCI_SQLT_TIMESTAMP_TZ"; - case oracle::occi::OCCIPOBJECT: return "OCCIPOBJECT"; - default: return ""; + case oracle::occi::OCCIINT: return "OCCIINT"; + case oracle::occi::OCCIUNSIGNED_INT: return "OCCIUNSIGNED_INT"; + case oracle::occi::OCCIFLOAT: return "OCCIFLOAT"; + case oracle::occi::OCCIBFLOAT: return "OCCIBFLOAT"; + case oracle::occi::OCCIDOUBLE: return "OCCIDOUBLE"; + case oracle::occi::OCCIBDOUBLE: return "OCCIBDOUBLE"; + case oracle::occi::OCCINUMBER: return "OCCINUMBER"; + case oracle::occi::OCCI_SQLT_NUM: return "OCCI_SQLT_NUM"; + case oracle::occi::OCCICHAR: return "OCCICHAR"; + case oracle::occi::OCCISTRING: return "OCCISTRING"; + case oracle::occi::OCCI_SQLT_AFC: return "OCCI_SQLT_AFC"; + case oracle::occi::OCCI_SQLT_AVC: return "OCCI_SQLT_AVC"; + case oracle::occi::OCCI_SQLT_CHR: return "OCCI_SQLT_CHR"; + case oracle::occi::OCCI_SQLT_LVC: return "OCCI_SQLT_LVC"; + case oracle::occi::OCCI_SQLT_STR: return "OCCI_SQLT_STR"; + case oracle::occi::OCCI_SQLT_VCS: return "OCCI_SQLT_VCS"; + case oracle::occi::OCCI_SQLT_VNU: return "OCCI_SQLT_VNU"; + case oracle::occi::OCCI_SQLT_VBI: return "OCCI_SQLT_VBI"; + case oracle::occi::OCCI_SQLT_VST: return "OCCI_SQLT_VST"; + case oracle::occi::OCCI_SQLT_RDD: return "OCCI_SQLT_RDD"; + case oracle::occi::OCCIDATE: return "OCCIDATE"; + case oracle::occi::OCCITIMESTAMP: return "OCCITIMESTAMP"; + case oracle::occi::OCCI_SQLT_DAT: return "OCCI_SQLT_DAT"; + case oracle::occi::OCCI_SQLT_TIMESTAMP: return "OCCI_SQLT_TIMESTAMP"; + case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: return "OCCI_SQLT_TIMESTAMP_LTZ"; + case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: return "OCCI_SQLT_TIMESTAMP_TZ"; + case oracle::occi::OCCIPOBJECT: return "OCCIPOBJECT"; + default: return ""; } } - diff --git a/plugins/input/occi/occi_types.hpp b/plugins/input/occi/occi_types.hpp index 548c6321b..8c369c037 100644 --- a/plugins/input/occi/occi_types.hpp +++ b/plugins/input/occi/occi_types.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OCCI_TYPES_HPP #define OCCI_TYPES_HPP @@ -41,7 +40,6 @@ #error Only ORACLE 10g >= 10.2.0.X is supported ! #endif - // geometry types definitions enum { @@ -79,14 +77,13 @@ enum SDO_INTERPRETATION_CIRCULAR = 2 }; - -class occi_environment : public mapnik::singleton +class occi_environment : public mapnik::singleton { friend class mapnik::CreateStatic; public: - static oracle::occi::Environment* get_environment () + static oracle::occi::Environment* get_environment() { if (env_ == 0) { @@ -94,11 +91,11 @@ public: std::clog << "OCCI Plugin: occi_environment constructor" << std::endl; #endif - int mode = oracle::occi::Environment::OBJECT - | oracle::occi::Environment::THREADED_MUTEXED; + const int mode = oracle::occi::Environment::OBJECT + | oracle::occi::Environment::THREADED_MUTEXED; - env_ = oracle::occi::Environment::createEnvironment ((oracle::occi::Environment::Mode) mode); - RegisterClasses (env_); + env_ = oracle::occi::Environment::createEnvironment((oracle::occi::Environment::Mode) mode); + RegisterClasses(env_); } return env_; @@ -118,7 +115,7 @@ private: std::clog << "OCCI Plugin: occi_environment destructor" << std::endl; #endif - oracle::occi::Environment::terminateEnvironment (env_); + oracle::occi::Environment::terminateEnvironment(env_); env_ = 0; } } @@ -126,28 +123,27 @@ private: static oracle::occi::Environment* env_; }; - class occi_connection_ptr { public: - explicit occi_connection_ptr () - : env_ (occi_environment::get_environment()), - pool_ (0), - conn_ (0), - stmt_ (0), - rs_ (0), - owns_connection_ (false) + explicit occi_connection_ptr() + : env_(occi_environment::get_environment()), + pool_(0), + conn_(0), + stmt_(0), + rs_(0), + owns_connection_(false) { } - ~occi_connection_ptr () + ~occi_connection_ptr() { - close_query (true); + close_query(true); } void set_pool(oracle::occi::StatelessConnectionPool* pool) { - close_query (true); + close_query(true); pool_ = pool; conn_ = pool_->getConnection(); @@ -156,26 +152,26 @@ public: void set_connection(oracle::occi::Connection* conn, bool owns_connection) { - close_query (true); + close_query(true); pool_ = 0; conn_ = conn; owns_connection_ = owns_connection; } - oracle::occi::ResultSet* execute_query (const std::string& s, const unsigned prefetch = 0) + oracle::occi::ResultSet* execute_query(const std::string& s, const unsigned prefetch = 0) { - close_query (false); + close_query(false); - stmt_ = conn_->createStatement (s); + stmt_ = conn_->createStatement(s); if (prefetch > 0) { - stmt_->setPrefetchMemorySize (0); - stmt_->setPrefetchRowCount (prefetch); + stmt_->setPrefetchMemorySize(0); + stmt_->setPrefetchRowCount(prefetch); } - rs_ = stmt_->executeQuery (); + rs_ = stmt_->executeQuery(); return rs_; } @@ -186,8 +182,7 @@ public: } private: - - void close_query (const bool release_connection) + void close_query(const bool release_connection) { if (conn_) { @@ -195,11 +190,11 @@ private: { if (rs_) { - stmt_->closeResultSet (rs_); + stmt_->closeResultSet(rs_); rs_ = 0; } - conn_->terminateStatement (stmt_); + conn_->terminateStatement(stmt_); stmt_ = 0; } @@ -207,7 +202,7 @@ private: { if (pool_) { - pool_->releaseConnection (conn_); + pool_->releaseConnection(conn_); } else { @@ -230,7 +225,6 @@ private: bool owns_connection_; }; - class occi_enums { public: @@ -240,5 +234,4 @@ public: static std::string resolve_datatype(int type_id); }; - #endif // OCCI_TYPES_HPP diff --git a/plugins/input/ogr/build.py b/plugins/input/ogr/build.py index f07b8701e..4b3225737 100644 --- a/plugins/input/ogr/build.py +++ b/plugins/input/ogr/build.py @@ -46,6 +46,7 @@ plugin_env['LIBS'].append('boost_filesystem%s' % env['BOOST_APPEND']) if env['RUNTIME_LINK'] == 'static': cmd = 'gdal-config --dep-libs' plugin_env.ParseConfig(cmd) + plugin_env['LIBS'].append('proj') input_plugin = plugin_env.SharedLibrary('../ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LINKFLAGS=env['CUSTOM_LDFLAGS']) diff --git a/plugins/input/ogr/ogr_converter.cpp b/plugins/input/ogr/ogr_converter.cpp index e6b9f8461..5d27cb08e 100644 --- a/plugins/input/ogr/ogr_converter.cpp +++ b/plugins/input/ogr/ogr_converter.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ +// mapnik #include #include #include @@ -36,235 +36,246 @@ using mapnik::feature_ptr; using mapnik::geometry_utils; using mapnik::geometry_type; -void ogr_converter::convert_geometry (OGRGeometry* geom, feature_ptr feature, bool multiple_geometries) +void ogr_converter::convert_geometry(OGRGeometry* geom, feature_ptr feature, bool multiple_geometries) { - switch (wkbFlatten (geom->getGeometryType())) - { - case wkbPoint: - convert_point (static_cast(geom), feature); - break; - case wkbLineString: - convert_linestring (static_cast(geom), feature); - break; - case wkbPolygon: - convert_polygon (static_cast(geom), feature); - break; - case wkbMultiPoint: - if (multiple_geometries) - convert_multipoint_2 (static_cast(geom), feature); - else - // Todo - using convert_multipoint_2 until we have proper multipoint handling in convert_multipoint - // http://trac.mapnik.org/ticket/458 - //convert_multipoint (static_cast(geom), feature); - convert_multipoint_2 (static_cast(geom), feature); - break; - case wkbMultiLineString: - if (multiple_geometries) - convert_multilinestring_2 (static_cast(geom), feature); - else - convert_multilinestring (static_cast(geom), feature); - - break; - case wkbMultiPolygon: - if (multiple_geometries) - convert_multipolygon_2 (static_cast(geom), feature); - else - convert_multipolygon (static_cast(geom), feature); - break; - case wkbGeometryCollection: - convert_collection (static_cast(geom), feature, multiple_geometries); - break; - case wkbLinearRing: - convert_linestring (static_cast(geom), feature); - break; - case wkbNone: - case wkbUnknown: - default: + switch (wkbFlatten(geom->getGeometryType())) + { + case wkbPoint: + convert_point(static_cast(geom), feature); + break; + case wkbLineString: + convert_linestring(static_cast(geom), feature); + break; + case wkbPolygon: + convert_polygon(static_cast(geom), feature); + break; + case wkbMultiPoint: + if (multiple_geometries) + { + convert_multipoint_2(static_cast(geom), feature); + } + else + { + // Todo - using convert_multipoint_2 until we have proper multipoint handling in convert_multipoint + // http://trac.mapnik.org/ticket/458 + //convert_multipoint(static_cast(geom), feature); + convert_multipoint_2(static_cast(geom), feature); + } + break; + case wkbMultiLineString: + if (multiple_geometries) + { + convert_multilinestring_2(static_cast(geom), feature); + } + else + { + convert_multilinestring(static_cast(geom), feature); + } + break; + case wkbMultiPolygon: + if (multiple_geometries) + { + convert_multipolygon_2(static_cast(geom), feature); + } + else + { + convert_multipolygon(static_cast(geom), feature); + } + break; + case wkbGeometryCollection: + convert_collection(static_cast(geom), feature, multiple_geometries); + break; + case wkbLinearRing: + convert_linestring(static_cast(geom), feature); + break; + case wkbNone: + case wkbUnknown: + default: #ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unknown geometry_type=" << wkbFlatten (geom->getGeometryType()) << std::endl; + std::clog << "OGR Plugin: unknown geometry_type=" + << wkbFlatten(geom->getGeometryType()) << std::endl; #endif - break; - } + break; + } } -void ogr_converter::convert_point (OGRPoint* geom, feature_ptr feature) +void ogr_converter::convert_point(OGRPoint* geom, feature_ptr feature) { geometry_type * point = new geometry_type(mapnik::Point); - point->move_to (geom->getX(), geom->getY()); - feature->add_geometry (point); + point->move_to(geom->getX(), geom->getY()); + feature->add_geometry(point); } -void ogr_converter::convert_linestring (OGRLineString* geom, feature_ptr feature) +void ogr_converter::convert_linestring(OGRLineString* geom, feature_ptr feature) { - int num_points = geom->getNumPoints (); - geometry_type * line = new geometry_type(mapnik::LineString); - line->set_capacity (num_points); - line->move_to (geom->getX (0), geom->getY (0)); - for (int i=1;igetNumPoints(); + geometry_type* line = new geometry_type(mapnik::LineString); + line->set_capacity(num_points); + line->move_to(geom->getX(0), geom->getY(0)); + for (int i = 1; i < num_points; ++i) { - line->line_to (geom->getX (i), geom->getY (i)); + line->line_to (geom->getX(i), geom->getY(i)); } - feature->add_geometry (line); + feature->add_geometry(line); } -void ogr_converter::convert_polygon (OGRPolygon* geom, feature_ptr feature) +void ogr_converter::convert_polygon(OGRPolygon* geom, feature_ptr feature) { - OGRLinearRing* exterior = geom->getExteriorRing (); - int num_points = exterior->getNumPoints (); - int num_interior = geom->getNumInteriorRings (); + OGRLinearRing* exterior = geom->getExteriorRing(); + int num_points = exterior->getNumPoints(); + int num_interior = geom->getNumInteriorRings(); int capacity = 0; - for (int r=0;rgetInteriorRing (r); - capacity += interior->getNumPoints (); + OGRLinearRing* interior = geom->getInteriorRing(r); + capacity += interior->getNumPoints(); } - - geometry_type * poly = new geometry_type(mapnik::Polygon); - poly->set_capacity (num_points + capacity); - poly->move_to (exterior->getX (0), exterior->getY (0)); - for (int i=1;iset_capacity(num_points + capacity); + poly->move_to(exterior->getX(0), exterior->getY(0)); + for (int i = 1; i < num_points; ++i) { - poly->line_to (exterior->getX (i), exterior->getY (i)); + poly->line_to(exterior->getX(i), exterior->getY(i)); } - for (int r=0;rgetInteriorRing (r); - num_points = interior->getNumPoints (); - poly->move_to(interior->getX (0), interior->getY (0)); - for (int i=1;igetInteriorRing(r); + num_points = interior->getNumPoints(); + poly->move_to(interior->getX(0), interior->getY(0)); + for (int i = 1; i < num_points; ++i) { - poly->line_to(interior->getX (i), interior->getY (i)); + poly->line_to(interior->getX(i), interior->getY(i)); } } - feature->add_geometry (poly); + feature->add_geometry(poly); } -void ogr_converter::convert_multipoint (OGRMultiPoint* geom, feature_ptr feature) +void ogr_converter::convert_multipoint(OGRMultiPoint* geom, feature_ptr feature) { - int num_geometries = geom->getNumGeometries (); - geometry_type * point = new geometry_type(mapnik::Point); + int num_geometries = geom->getNumGeometries(); + geometry_type* point = new geometry_type(mapnik::Point); - for (int i=0;i(geom->getGeometryRef (i)); - point->move_to (ogrpoint->getX(), ogrpoint->getY()); + OGRPoint* ogrpoint = static_cast(geom->getGeometryRef(i)); + point->move_to(ogrpoint->getX(), ogrpoint->getY()); //Todo - need to accept multiple points per mapnik::Point } // Todo - this only gets last point - feature->add_geometry (point); + feature->add_geometry(point); } -void ogr_converter::convert_multipoint_2 (OGRMultiPoint* geom, feature_ptr feature) +void ogr_converter::convert_multipoint_2(OGRMultiPoint* geom, feature_ptr feature) { - int num_geometries = geom->getNumGeometries (); - for (int i=0;igetNumGeometries(); + for (int i = 0; i < num_geometries; i++) { - convert_point (static_cast(geom->getGeometryRef (i)), feature); + convert_point(static_cast(geom->getGeometryRef(i)), feature); } } -void ogr_converter::convert_multilinestring (OGRMultiLineString* geom, feature_ptr feature) +void ogr_converter::convert_multilinestring(OGRMultiLineString* geom, feature_ptr feature) { - int num_geometries = geom->getNumGeometries (); + int num_geometries = geom->getNumGeometries(); int num_points = 0; - for (int i=0;i(geom->getGeometryRef (i)); - num_points += ls->getNumPoints (); + OGRLineString* ls = static_cast(geom->getGeometryRef(i)); + num_points += ls->getNumPoints(); } - geometry_type * line = new geometry_type(mapnik::LineString); - line->set_capacity (num_points); + geometry_type* line = new geometry_type(mapnik::LineString); + line->set_capacity(num_points); - for (int i=0;i(geom->getGeometryRef (i)); - num_points = ls->getNumPoints (); - line->move_to (ls->getX (0), ls->getY (0)); - for (int i=1;i(geom->getGeometryRef(i)); + num_points = ls->getNumPoints(); + line->move_to(ls->getX(0), ls->getY(0)); + for (int i = 1; i < num_points; ++i) { - line->line_to (ls->getX (i), ls->getY (i)); + line->line_to(ls->getX(i), ls->getY(i)); } } - feature->add_geometry (line); + feature->add_geometry(line); } -void ogr_converter::convert_multilinestring_2 (OGRMultiLineString* geom, feature_ptr feature) +void ogr_converter::convert_multilinestring_2(OGRMultiLineString* geom, feature_ptr feature) { - int num_geometries = geom->getNumGeometries (); - for (int i=0;igetNumGeometries(); + for (int i = 0; i < num_geometries; i++) { - convert_linestring (static_cast(geom->getGeometryRef (i)), feature); + convert_linestring(static_cast(geom->getGeometryRef(i)), feature); } } -void ogr_converter::convert_multipolygon (OGRMultiPolygon* geom, feature_ptr feature) +void ogr_converter::convert_multipolygon(OGRMultiPolygon* geom, feature_ptr feature) { - int num_geometries = geom->getNumGeometries (); + int num_geometries = geom->getNumGeometries(); int capacity = 0; - for (int i=0;i(geom->getGeometryRef (i)); - OGRLinearRing* exterior = p->getExteriorRing (); - capacity += exterior->getNumPoints (); - for (int r=0;rgetNumInteriorRings ();r++) + OGRPolygon* p = static_cast(geom->getGeometryRef(i)); + OGRLinearRing* exterior = p->getExteriorRing(); + capacity += exterior->getNumPoints(); + for (int r = 0; r < p->getNumInteriorRings(); r++) { - OGRLinearRing* interior = p->getInteriorRing (r); - capacity += interior->getNumPoints (); + OGRLinearRing* interior = p->getInteriorRing(r); + capacity += interior->getNumPoints(); } } - geometry_type * poly = new geometry_type(mapnik::Polygon); - poly->set_capacity (capacity); + geometry_type* poly = new geometry_type(mapnik::Polygon); + poly->set_capacity(capacity); - for (int i=0;i(geom->getGeometryRef (i)); - OGRLinearRing* exterior = p->getExteriorRing (); - int num_points = exterior->getNumPoints (); - int num_interior = p->getNumInteriorRings (); - poly->move_to (exterior->getX (0), exterior->getY (0)); - for (int i=1;i(geom->getGeometryRef(i)); + OGRLinearRing* exterior = p->getExteriorRing(); + int num_points = exterior->getNumPoints(); + int num_interior = p->getNumInteriorRings(); + poly->move_to(exterior->getX(0), exterior->getY(0)); + for (int i = 1; i < num_points; ++i) { - poly->line_to (exterior->getX (i), exterior->getY (i)); + poly->line_to(exterior->getX(i), exterior->getY(i)); } - for (int r=0;rgetInteriorRing (r); - num_points = interior->getNumPoints (); - poly->move_to(interior->getX (0), interior->getY (0)); - for (int i=1;igetInteriorRing(r); + num_points = interior->getNumPoints(); + poly->move_to(interior->getX(0), interior->getY(0)); + for (int i = 1; i < num_points; ++i) { - poly->line_to(interior->getX (i), interior->getY (i)); + poly->line_to(interior->getX(i), interior->getY(i)); } } } - feature->add_geometry (poly); + feature->add_geometry(poly); } -void ogr_converter::convert_multipolygon_2 (OGRMultiPolygon* geom, feature_ptr feature) +void ogr_converter::convert_multipolygon_2(OGRMultiPolygon* geom, feature_ptr feature) { - int num_geometries = geom->getNumGeometries (); - for (int i=0;igetNumGeometries(); + for (int i = 0; i < num_geometries; i++) { - convert_polygon (static_cast(geom->getGeometryRef (i)), feature); + convert_polygon(static_cast(geom->getGeometryRef(i)), feature); } } -void ogr_converter::convert_collection (OGRGeometryCollection* geom, feature_ptr feature, bool multiple_geometries) +void ogr_converter::convert_collection(OGRGeometryCollection* geom, feature_ptr feature, bool multiple_geometries) { - int num_geometries = geom->getNumGeometries (); - for (int i=0;igetNumGeometries(); + for (int i = 0; i < num_geometries; i++) { - OGRGeometry* g = geom->getGeometryRef (i); + OGRGeometry* g = geom->getGeometryRef(i); if (g != NULL) { - convert_geometry (g, feature, multiple_geometries); + convert_geometry(g, feature, multiple_geometries); } } } diff --git a/plugins/input/ogr/ogr_converter.hpp b/plugins/input/ogr/ogr_converter.hpp index 79dfd320f..f810dff39 100644 --- a/plugins/input/ogr/ogr_converter.hpp +++ b/plugins/input/ogr/ogr_converter.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OGR_CONVERTER_HPP #define OGR_CONVERTER_HPP @@ -32,19 +31,19 @@ class ogr_converter { - public: +public: - static void convert_geometry (OGRGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); - static void convert_collection (OGRGeometryCollection* geom, mapnik::feature_ptr feature, bool multiple_geometries); - static void convert_point (OGRPoint* geom, mapnik::feature_ptr feature); - static void convert_linestring (OGRLineString* geom, mapnik::feature_ptr feature); - static void convert_polygon (OGRPolygon* geom, mapnik::feature_ptr feature); - static void convert_multipoint (OGRMultiPoint* geom, mapnik::feature_ptr feature); - static void convert_multipoint_2 (OGRMultiPoint* geom, mapnik::feature_ptr feature); - static void convert_multilinestring (OGRMultiLineString* geom, mapnik::feature_ptr feature); - static void convert_multilinestring_2 (OGRMultiLineString* geom, mapnik::feature_ptr feature); - static void convert_multipolygon (OGRMultiPolygon* geom, mapnik::feature_ptr feature); - static void convert_multipolygon_2 (OGRMultiPolygon* geom, mapnik::feature_ptr feature); + static void convert_geometry (OGRGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); + static void convert_collection (OGRGeometryCollection* geom, mapnik::feature_ptr feature, bool multiple_geometries); + static void convert_point (OGRPoint* geom, mapnik::feature_ptr feature); + static void convert_linestring (OGRLineString* geom, mapnik::feature_ptr feature); + static void convert_polygon (OGRPolygon* geom, mapnik::feature_ptr feature); + static void convert_multipoint (OGRMultiPoint* geom, mapnik::feature_ptr feature); + static void convert_multipoint_2 (OGRMultiPoint* geom, mapnik::feature_ptr feature); + static void convert_multilinestring (OGRMultiLineString* geom, mapnik::feature_ptr feature); + static void convert_multilinestring_2 (OGRMultiLineString* geom, mapnik::feature_ptr feature); + static void convert_multipolygon (OGRMultiPolygon* geom, mapnik::feature_ptr feature); + static void convert_multipolygon_2 (OGRMultiPolygon* geom, mapnik::feature_ptr feature); }; -#endif // OGR_FEATURESET_HPP +#endif // OGR_CONVERTER_HPP diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index 0380a0bcd..7186f138c 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -53,302 +53,349 @@ using mapnik::filter_at_point; ogr_datasource::ogr_datasource(parameters const& params, bool bind) - : datasource(params), - extent_(), - type_(datasource::Vector), - desc_(*params.get("type"), *params.get("encoding","utf-8")), - indexed_(false) + : datasource(params), + extent_(), + type_(datasource::Vector), + desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + indexed_(false) { - boost::optional file = params.get("file"); - boost::optional string = params.get("string"); - if (!file && !string) throw datasource_exception("missing or parameter"); + boost::optional file = params.get("file"); + boost::optional string = params.get("string"); + if (! file && ! string) + { + throw datasource_exception("missing or parameter"); + } - multiple_geometries_ = *params.get("multiple_geometries",false); + multiple_geometries_ = *params.get("multiple_geometries", false); - if (string) - { + if (string) + { dataset_name_ = *string; - } - else - { - boost::optional base = params.get("base"); - if (base) - dataset_name_ = *base + "/" + *file; - else - dataset_name_ = *file; - } - - if (bind) - { - this->bind(); - } + } + else + { + boost::optional base = params.get("base"); + if (base) + { + dataset_name_ = *base + "/" + *file; + } + else + { + dataset_name_ = *file; + } + } + + if (bind) + { + this->bind(); + } } ogr_datasource::~ogr_datasource() { if (is_bound_) { + // free layer before destroying the datasource + layer_.free_layer(); + OGRDataSource::DestroyDataSource (dataset_); } } void ogr_datasource::bind() const { - if (is_bound_) return; + if (is_bound_) return; - // initialize ogr formats - OGRRegisterAll(); + // initialize ogr formats + OGRRegisterAll(); - // open ogr driver - dataset_ = OGRSFDriverRegistrar::Open ((dataset_name_).c_str(), FALSE); - if (!dataset_) - { - std::string err = CPLGetLastErrorMsg(); - if( err.size() == 0 ) { - throw datasource_exception("OGR Plugin: connection failed: " + dataset_name_ + " was not found or is not a supported format"); - } else { - throw datasource_exception("OGR Plugin: " + err); - } - } + std::string driver = *params_.get("driver",""); - // initialize layer - - boost::optional layer_by_name = params_.get("layer"); - boost::optional layer_by_index = params_.get("layer_by_index"); - - if (layer_by_name && layer_by_index) - throw datasource_exception("OGR Plugin: you can only select an ogr layer by name ('layer' parameter) or by number ('layer_by_index' parameter), do not supply both parameters" ); + if (! driver.empty()) + { + OGRSFDriver * ogr_driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver.c_str()); + if (ogr_driver && ogr_driver != NULL) + { + dataset_ = ogr_driver->Open((dataset_name_).c_str(), FALSE); + } + + } + else + { + // open ogr driver + dataset_ = OGRSFDriverRegistrar::Open((dataset_name_).c_str(), FALSE); + } - if (layer_by_name) - { - layerName_ = *layer_by_name; - layer_ = dataset_->GetLayerByName (layerName_.c_str()); - } - else if (layer_by_index) - { - unsigned num_layers = dataset_->GetLayerCount(); - if (*layer_by_index >= num_layers) - { - std::ostringstream s; - s << "OGR Plugin: only "; - s << num_layers; - s << " layer(s) exist, cannot find layer by index '" << *layer_by_index << "'"; - - throw datasource_exception(s.str()); - } - OGRLayer *ogr_layer = dataset_->GetLayer(*layer_by_index); - if (ogr_layer) - { - OGRFeatureDefn* def = ogr_layer->GetLayerDefn(); - if (def != 0) { - layerName_ = def->GetName(); - layer_ = ogr_layer; - } - } - } - else - { - std::ostringstream s; - s << "OGR Plugin: missing or parameter, available layers are: "; - unsigned num_layers = dataset_->GetLayerCount(); - bool found = false; - for (unsigned i = 0; i < num_layers; ++i ) - { - OGRLayer *ogr_layer = dataset_->GetLayer(i); - OGRFeatureDefn* def = ogr_layer->GetLayerDefn(); - if (def != 0) { - found = true; - s << " '" << def->GetName() << "' "; - } - } - if (!found) { - s << "None (no layers were found in dataset)"; - } - throw datasource_exception(s.str()); - } + if (! dataset_) + { + const std::string err = CPLGetLastErrorMsg(); + if (err.size() == 0) + { + throw datasource_exception("OGR Plugin: connection failed: " + dataset_name_ + " was not found or is not a supported format"); + } + else + { + throw datasource_exception("OGR Plugin: " + err); + } + } - if (!layer_) - { - std::string s("OGR Plugin: "); - if (layer_by_name) s += "cannot find layer by name '" + *layer_by_name; - else if (layer_by_index) s += "cannot find layer by index number '" + *layer_by_index; - s += "' in dataset '" + dataset_name_ + "'"; - throw datasource_exception(s); - } - - // initialize envelope - OGREnvelope envelope; - layer_->GetExtent (&envelope); - extent_.init (envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY); + // initialize layer + boost::optional layer_by_name = params_.get("layer"); + boost::optional layer_by_index = params_.get("layer_by_index"); + boost::optional layer_by_sql = params_.get("layer_by_sql"); - // scan for index file - // TODO - layer names don't match dataset name, so this will break for - // any layer types of ogr than shapefiles, etc - // fix here and in ogrindex - size_t breakpoint = dataset_name_.find_last_of ("."); - if (breakpoint == std::string::npos) breakpoint = dataset_name_.length(); - index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex"; - std::ifstream index_file (index_name_.c_str(), std::ios::in | std::ios::binary); - if (index_file) - { - indexed_=true; - index_file.close(); - } - // enable this warning once the ogrindex tool is a bit more stable/mature - //else - /*{ - std::clog << "### Notice: no ogrindex file found for " + dataset_name_ + ", use the 'ogrindex' program to build an index for faster rendering\n"; - }*/ + int passed_parameters = 0; + passed_parameters += layer_by_name ? 1 : 0; + passed_parameters += layer_by_index ? 1 : 0; + passed_parameters += layer_by_sql ? 1 : 0; - // deal with attributes descriptions - OGRFeatureDefn* def = layer_->GetLayerDefn (); - if (def != 0) - { - int fld_count = def->GetFieldCount (); - for (int i = 0; i < fld_count; i++) - { - OGRFieldDefn* fld = def->GetFieldDefn (i); + if (passed_parameters > 1) + { + throw datasource_exception("OGR Plugin: you can only select an ogr layer by name " + "('layer' parameter), by number ('layer_by_index' parameter), " + "or by sql ('layer_by_sql' parameter), " + "do not supply 2 or more of them at the same time" ); + } - std::string fld_name = fld->GetNameRef (); - OGRFieldType type_oid = fld->GetType (); + if (layer_by_name) + { + layer_name_ = *layer_by_name; + layer_.layer_by_name(dataset_, layer_name_); + } + else if (layer_by_index) + { + const unsigned num_layers = dataset_->GetLayerCount(); + if (*layer_by_index >= num_layers) + { + std::ostringstream s; + s << "OGR Plugin: only "; + s << num_layers; + s << " layer(s) exist, cannot find layer by index '" << *layer_by_index << "'"; - switch (type_oid) - { - case OFTInteger: - desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer)); - break; + throw datasource_exception(s.str()); + } - case OFTReal: - desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double)); - break; - - case OFTString: - case OFTWideString: // deprecated - desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String)); - break; - - case OFTBinary: - desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object)); - break; + layer_.layer_by_index(dataset_, *layer_by_index); + layer_name_ = layer_.layer_name(); + } + else if (layer_by_sql) + { + layer_.layer_by_sql(dataset_, *layer_by_sql); + layer_name_ = layer_.layer_name(); + } + else + { + std::ostringstream s; + s << "OGR Plugin: missing or or " + << "parameter, available layers are: "; - case OFTIntegerList: - case OFTRealList: - case OFTStringList: - case OFTWideStringList: // deprecated ! -#ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; + unsigned num_layers = dataset_->GetLayerCount(); + bool layer_found = false; + for (unsigned i = 0; i < num_layers; ++i ) + { + OGRLayer* ogr_layer = dataset_->GetLayer(i); + OGRFeatureDefn* ogr_layer_def = ogr_layer->GetLayerDefn(); + if (ogr_layer_def != 0) + { + layer_found = true; + s << " '" << ogr_layer_def->GetName() << "' "; + } + } + + if (! layer_found) + { + s << "None (no layers were found in dataset)"; + } + + throw datasource_exception(s.str()); + } + + if (! layer_.is_valid()) + { + std::string s("OGR Plugin: "); + + if (layer_by_name) + { + s += "cannot find layer by name '" + *layer_by_name; + } + else if (layer_by_index) + { + s += "cannot find layer by index number '" + *layer_by_index; + } + else if (layer_by_sql) + { + s += "cannot find layer by sql query '" + *layer_by_sql; + } + + s += "' in dataset '" + dataset_name_ + "'"; + + throw datasource_exception(s); + } + + // work with real OGR layer + OGRLayer* layer = layer_.layer(); + + // initialize envelope + OGREnvelope envelope; + layer->GetExtent(&envelope); + extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY); + + // scan for index file + // TODO - layer names don't match dataset name, so this will break for + // any layer types of ogr than shapefiles, etc + // fix here and in ogrindex + size_t breakpoint = dataset_name_.find_last_of("."); + if (breakpoint == std::string::npos) + { + breakpoint = dataset_name_.length(); + } + index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex"; + + std::ifstream index_file(index_name_.c_str(), std::ios::in | std::ios::binary); + if (index_file) + { + indexed_ = true; + index_file.close(); + } +#if 0 + // TODO - enable this warning once the ogrindex tool is a bit more stable/mature + else + { + std::clog << "### Notice: no ogrindex file found for " << dataset_name_ + << ", use the 'ogrindex' program to build an index for faster rendering" + << std::endl; + } #endif - break; - case OFTDate: - case OFTTime: - case OFTDateTime: // unhandled ! -#ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; -#endif - desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object)); - break; + // deal with attributes descriptions + OGRFeatureDefn* def = layer->GetLayerDefn(); + if (def != 0) + { + const int fld_count = def->GetFieldCount(); + for (int i = 0; i < fld_count; i++) + { + OGRFieldDefn* fld = def->GetFieldDefn(i); - default: // unknown + const std::string fld_name = fld->GetNameRef(); + const OGRFieldType type_oid = fld->GetType(); + + switch (type_oid) + { + case OFTInteger: + desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Integer)); + break; + + case OFTReal: + desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Double)); + break; + + case OFTString: + case OFTWideString: // deprecated + desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); + break; + + case OFTBinary: + desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object)); + break; + + case OFTIntegerList: + case OFTRealList: + case OFTStringList: + case OFTWideStringList: // deprecated ! #ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl; + std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; #endif - break; - } - } - } - - is_bound_ = true; + break; + + case OFTDate: + case OFTTime: + case OFTDateTime: // unhandled ! +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; +#endif + desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Object)); + break; + + default: // unknown +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl; +#endif + break; + } + } + } + + is_bound_ = true; } std::string ogr_datasource::name() { - return "ogr"; + return "ogr"; } int ogr_datasource::type() const { - return type_; + return type_; } box2d ogr_datasource::envelope() const { - if (!is_bound_) bind(); - return extent_; + if (! is_bound_) bind(); + return extent_; } layer_descriptor ogr_datasource::get_descriptor() const { - if (!is_bound_) bind(); - return desc_; + if (! is_bound_) bind(); + return desc_; } featureset_ptr ogr_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - if (dataset_ && layer_) - { - - // TODO - actually filter fields! - // http://trac.osgeo.org/gdal/wiki/rfc29_desired_fields - // http://trac.osgeo.org/gdal/wiki/rfc28_sqlfunc -#if 0 - std::ostringstream s; - - s << "select "; - std::set const& props=q.property_names(); - std::set::const_iterator pos=props.begin(); - std::set::const_iterator end=props.end(); - while (pos != end) - { - s <<",\""<<*pos<<"\""; - ++pos; - } - s << " from " << layerName_ ; - - // execute existing SQL - OGRLayer* layer = dataset_->ExecuteSQL (s.str(), poly); - - // layer must be freed - dataset_->ReleaseResultSet (layer); -#endif + if (dataset_ && layer_.is_valid()) + { + OGRLayer* layer = layer_.layer(); if (indexed_) { filter_in_box filter(q.get_bbox()); - return featureset_ptr(new ogr_index_featureset (*dataset_, - *layer_, - filter, - index_name_, - desc_.get_encoding(), - multiple_geometries_)); + return featureset_ptr(new ogr_index_featureset(*dataset_, + *layer, + filter, + index_name_, + desc_.get_encoding(), + multiple_geometries_)); } else { return featureset_ptr(new ogr_featureset (*dataset_, - *layer_, + *layer, q.get_bbox(), desc_.get_encoding(), multiple_geometries_)); } - } - return featureset_ptr(); + } + + return featureset_ptr(); } featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (!is_bound_) bind(); - if (dataset_ && layer_) - { + if (dataset_ && layer_.is_valid()) + { + OGRLayer* layer = layer_.layer(); + if (indexed_) { filter_at_point filter(pt); return featureset_ptr(new ogr_index_featureset (*dataset_, - *layer_, + *layer, filter, index_name_, desc_.get_encoding(), @@ -361,12 +408,12 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const point.setY (pt.y); return featureset_ptr(new ogr_featureset (*dataset_, - *layer_, + *layer, point, desc_.get_encoding(), multiple_geometries_)); } - } - return featureset_ptr(); -} + } + return featureset_ptr(); +} diff --git a/plugins/input/ogr/ogr_datasource.hpp b/plugins/input/ogr/ogr_datasource.hpp index fee15ff9a..23228432f 100644 --- a/plugins/input/ogr/ogr_datasource.hpp +++ b/plugins/input/ogr/ogr_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OGR_DATASOURCE_HPP #define OGR_DATASOURCE_HPP @@ -35,30 +34,32 @@ // ogr #include +#include "ogr_layer_ptr.hpp" + class ogr_datasource : public mapnik::datasource { - public: - ogr_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~ogr_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - mutable mapnik::box2d extent_; - int type_; - std::string dataset_name_; - mutable std::string index_name_; - mutable OGRDataSource* dataset_; - mutable OGRLayer* layer_; - mutable std::string layerName_; - mutable mapnik::layer_descriptor desc_; - bool multiple_geometries_; - mutable bool indexed_; +public: + ogr_datasource(mapnik::parameters const& params, bool bind=true); + virtual ~ogr_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; + +private: + mutable mapnik::box2d extent_; + int type_; + std::string dataset_name_; + mutable std::string index_name_; + mutable OGRDataSource* dataset_; + mutable ogr_layer_ptr layer_; + mutable std::string layer_name_; + mutable mapnik::layer_descriptor desc_; + bool multiple_geometries_; + mutable bool indexed_; }; - #endif // OGR_DATASOURCE_HPP diff --git a/plugins/input/ogr/ogr_feature_ptr.hpp b/plugins/input/ogr/ogr_feature_ptr.hpp index 26cd4b893..ed87bb9cf 100644 --- a/plugins/input/ogr/ogr_feature_ptr.hpp +++ b/plugins/input/ogr/ogr_feature_ptr.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OGR_FEATURE_PTR_HPP #define OGR_FEATURE_PTR_HPP @@ -30,15 +29,17 @@ class ogr_feature_ptr { public: - ogr_feature_ptr (OGRFeature* const feat) - : feat_ (feat) + ogr_feature_ptr(OGRFeature* const feat) + : feat_(feat) { } - ~ogr_feature_ptr () + ~ogr_feature_ptr() { if (feat_ != NULL) - OGRFeature::DestroyFeature (feat_); + { + OGRFeature::DestroyFeature(feat_); + } } OGRFeature* operator*() @@ -51,4 +52,3 @@ private: }; #endif // OGR_FEATURE_PTR_HPP - diff --git a/plugins/input/ogr/ogr_featureset.cpp b/plugins/input/ogr/ogr_featureset.cpp index 3ea72a106..d34964cbf 100644 --- a/plugins/input/ogr/ogr_featureset.cpp +++ b/plugins/input/ogr/ogr_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ +// mapnik #include #include #include @@ -51,13 +51,13 @@ ogr_featureset::ogr_featureset(OGRDataSource & dataset, OGRGeometry & extent, const std::string& encoding, const bool multiple_geometries) - : dataset_(dataset), - layer_(layer), - layerdef_(layer.GetLayerDefn()), - tr_(new transcoder(encoding)), - fidcolumn_(layer_.GetFIDColumn ()), - multiple_geometries_(multiple_geometries), - count_(0) + : dataset_(dataset), + layer_(layer), + layerdef_(layer.GetLayerDefn()), + tr_(new transcoder(encoding)), + fidcolumn_(layer_.GetFIDColumn ()), + multiple_geometries_(multiple_geometries), + count_(0) { layer_.SetSpatialFilter (&extent); } @@ -67,13 +67,13 @@ ogr_featureset::ogr_featureset(OGRDataSource & dataset, const mapnik::box2d & extent, const std::string& encoding, const bool multiple_geometries) - : dataset_(dataset), - layer_(layer), - layerdef_(layer.GetLayerDefn()), - tr_(new transcoder(encoding)), - fidcolumn_(layer_.GetFIDColumn()), - multiple_geometries_(multiple_geometries), - count_(0) + : dataset_(dataset), + layer_(layer), + layerdef_(layer.GetLayerDefn()), + tr_(new transcoder(encoding)), + fidcolumn_(layer_.GetFIDColumn()), + multiple_geometries_(multiple_geometries), + count_(0) { layer_.SetSpatialFilterRect (extent.minx(), extent.miny(), @@ -81,27 +81,31 @@ ogr_featureset::ogr_featureset(OGRDataSource & dataset, extent.maxy()); } -ogr_featureset::~ogr_featureset() {} +ogr_featureset::~ogr_featureset() +{ +} feature_ptr ogr_featureset::next() { ogr_feature_ptr feat (layer_.GetNextFeature()); + if ((*feat) != NULL) { // ogr feature ids start at 0, so add one to stay // consistent with other mapnik datasources that start at 1 - int feature_id = ((*feat)->GetFID() + 1); + const int feature_id = ((*feat)->GetFID() + 1); feature_ptr feature(feature_factory::create(feature_id)); - OGRGeometry* geom=(*feat)->GetGeometryRef(); - if (geom && !geom->IsEmpty()) + OGRGeometry* geom = (*feat)->GetGeometryRef(); + if (geom && ! geom->IsEmpty()) { - ogr_converter::convert_geometry (geom, feature, multiple_geometries_); + ogr_converter::convert_geometry(geom, feature, multiple_geometries_); } #ifdef MAPNIK_DEBUG else { - std::clog << "### Warning: feature with null geometry: " << (*feat)->GetFID() << "\n"; + std::clog << "OGR Plugin: feature with null geometry: " + << (*feat)->GetFID() << std::endl; } #endif ++count_; @@ -109,30 +113,30 @@ feature_ptr ogr_featureset::next() int fld_count = layerdef_->GetFieldCount(); for (int i = 0; i < fld_count; i++) { - OGRFieldDefn* fld = layerdef_->GetFieldDefn (i); - OGRFieldType type_oid = fld->GetType (); - std::string fld_name = fld->GetNameRef (); + OGRFieldDefn* fld = layerdef_->GetFieldDefn(i); + const OGRFieldType type_oid = fld->GetType(); + const std::string fld_name = fld->GetNameRef(); switch (type_oid) { case OFTInteger: { - boost::put(*feature,fld_name,(*feat)->GetFieldAsInteger (i)); - break; + boost::put(*feature, fld_name, (*feat)->GetFieldAsInteger(i)); + break; } case OFTReal: { - boost::put(*feature,fld_name,(*feat)->GetFieldAsDouble (i)); - break; + boost::put(*feature, fld_name, (*feat)->GetFieldAsDouble(i)); + break; } case OFTString: case OFTWideString: // deprecated ! { - UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString (i)); - boost::put(*feature,fld_name,ustr); - break; + UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString(i)); + boost::put(*feature, fld_name, ustr); + break; } case OFTIntegerList: @@ -140,37 +144,37 @@ feature_ptr ogr_featureset::next() case OFTStringList: case OFTWideStringList: // deprecated ! { - #ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; - #endif - break; +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; +#endif + break; } case OFTBinary: { - #ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; - #endif - //boost::put(*feature,name,feat->GetFieldAsBinary (i, size)); - break; +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; +#endif + //boost::put(*feature,name,feat->GetFieldAsBinary (i, size)); + break; } case OFTDate: case OFTTime: case OFTDateTime: // unhandled ! { - #ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; - #endif - break; +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl; +#endif + break; } default: // unknown { - #ifdef MAPNIK_DEBUG - std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl; - #endif - break; +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl; +#endif + break; } } } @@ -182,4 +186,3 @@ feature_ptr ogr_featureset::next() #endif return feature_ptr(); } - diff --git a/plugins/input/ogr/ogr_featureset.hpp b/plugins/input/ogr/ogr_featureset.hpp index f28a3e6ca..9cf7bb067 100644 --- a/plugins/input/ogr/ogr_featureset.hpp +++ b/plugins/input/ogr/ogr_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OGR_FEATURESET_HPP #define OGR_FEATURESET_HPP @@ -37,30 +36,32 @@ class ogr_featureset : public mapnik::Featureset { - OGRDataSource & dataset_; - OGRLayer & layer_; - OGRFeatureDefn * layerdef_; - boost::scoped_ptr tr_; - const char* fidcolumn_; - bool multiple_geometries_; - mutable int count_; - public: - ogr_featureset(OGRDataSource & dataset, - OGRLayer & layer, - OGRGeometry & extent, - const std::string& encoding, - const bool multiple_geometries); +public: + ogr_featureset(OGRDataSource & dataset, + OGRLayer & layer, + OGRGeometry & extent, + const std::string& encoding, + const bool multiple_geometries); - ogr_featureset(OGRDataSource & dataset, - OGRLayer & layer, - const mapnik::box2d & extent, - const std::string& encoding, - const bool multiple_geometries); - virtual ~ogr_featureset(); - mapnik::feature_ptr next(); - private: - ogr_featureset(const ogr_featureset&); - const ogr_featureset& operator=(const ogr_featureset&); + ogr_featureset(OGRDataSource & dataset, + OGRLayer & layer, + const mapnik::box2d & extent, + const std::string& encoding, + const bool multiple_geometries); + virtual ~ogr_featureset(); + mapnik::feature_ptr next(); + +private: + ogr_featureset(const ogr_featureset&); + const ogr_featureset& operator=(const ogr_featureset&); + + OGRDataSource& dataset_; + OGRLayer& layer_; + OGRFeatureDefn* layerdef_; + boost::scoped_ptr tr_; + const char* fidcolumn_; + bool multiple_geometries_; + mutable int count_; }; #endif // OGR_FEATURESET_HPP diff --git a/plugins/input/ogr/ogr_index.hpp b/plugins/input/ogr/ogr_index.hpp index bebcbd804..c4fc9627c 100644 --- a/plugins/input/ogr/ogr_index.hpp +++ b/plugins/input/ogr/ogr_index.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -37,18 +37,18 @@ template class ogr_index { public: - static void query(const filterT& filter, IStream& file,std::vector& pos); + static void query(const filterT& filter, IStream& file, std::vector& pos); private: ogr_index(); ~ogr_index(); ogr_index(const ogr_index&); ogr_index& operator=(const ogr_index&); - static int read_ndr_integer(IStream & in); - static void read_envelope(IStream & in,box2d &envelope); - static void query_node(const filterT& filter,IStream & in,std::vector& pos); + static int read_ndr_integer(IStream& in); + static void read_envelope(IStream& in, box2d& envelope); + static void query_node(const filterT& filter, IStream& in, std::vector& pos); }; -template +template void ogr_index::query(const filterT& filter,IStream & file,std::vector& pos) { file.seekg(16,std::ios::beg); @@ -56,50 +56,49 @@ void ogr_index::query(const filterT& filter,IStream & file,std } template -void ogr_index::query_node(const filterT& filter,IStream & file,std::vector& ids) +void ogr_index::query_node(const filterT& filter, IStream& file, std::vector& ids) { - int offset=read_ndr_integer(file); + const int offset = read_ndr_integer(file); box2d node_ext; - read_envelope(file,node_ext); + read_envelope(file, node_ext); - int num_shapes=read_ndr_integer(file); + const int num_shapes = read_ndr_integer(file); - if (!filter.pass(node_ext)) + if (! filter.pass(node_ext)) { - file.seekg(offset+num_shapes*4+4,std::ios::cur); + file.seekg(offset + num_shapes * 4 + 4, std::ios::cur); return; } - for (int i=0;i -int ogr_index::read_ndr_integer(IStream & file) +template +int ogr_index::read_ndr_integer(IStream& file) { char b[4]; - file.read(b,4); - return (b[0]&0xff) | (b[1]&0xff)<<8 | (b[2]&0xff)<<16 | (b[3]&0xff)<<24; + file.read(b, 4); + return (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24; } -template -void ogr_index::read_envelope(IStream & file,box2d& envelope) +template +void ogr_index::read_envelope(IStream& file, box2d& envelope) { - file.read(reinterpret_cast(&envelope),sizeof(envelope)); + file.read(reinterpret_cast(&envelope), sizeof(envelope)); } - -#endif //SHP_INDEX_HH +#endif // OGR_INDEX_HH diff --git a/plugins/input/ogr/ogr_index_featureset.cpp b/plugins/input/ogr/ogr_index_featureset.cpp index 407578ad4..a67881b9c 100644 --- a/plugins/input/ogr/ogr_index_featureset.cpp +++ b/plugins/input/ogr/ogr_index_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 diff --git a/plugins/input/ogr/ogr_index_featureset.hpp b/plugins/input/ogr/ogr_index_featureset.hpp index 74ee29706..39b90598a 100644 --- a/plugins/input/ogr/ogr_index_featureset.hpp +++ b/plugins/input/ogr/ogr_index_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef OGR_INDEX_FEATURESET_HPP #define OGR_INDEX_FEATURESET_HPP @@ -32,29 +31,29 @@ template class ogr_index_featureset : public mapnik::Featureset { - OGRDataSource & dataset_; - OGRLayer & layer_; - OGRFeatureDefn * layerdef_; - filterT filter_; - std::vector ids_; - std::vector::iterator itr_; - boost::scoped_ptr tr_; - const char* fidcolumn_; - bool multiple_geometries_; +public: + ogr_index_featureset(OGRDataSource& dataset, + OGRLayer& layer, + const filterT& filter, + const std::string& index_file, + const std::string& encoding, + const bool multiple_geometries); + virtual ~ogr_index_featureset(); + mapnik::feature_ptr next(); - public: - ogr_index_featureset(OGRDataSource & dataset, - OGRLayer & layer, - const filterT& filter, - const std::string& index_file, - const std::string& encoding, - const bool multiple_geometries); - virtual ~ogr_index_featureset(); - mapnik::feature_ptr next(); - private: - //no copying - ogr_index_featureset(const ogr_index_featureset&); - ogr_index_featureset& operator=(const ogr_index_featureset&); +private: + ogr_index_featureset(const ogr_index_featureset&); + ogr_index_featureset& operator=(const ogr_index_featureset&); + + OGRDataSource& dataset_; + OGRLayer& layer_; + OGRFeatureDefn* layerdef_; + filterT filter_; + std::vector ids_; + std::vector::iterator itr_; + boost::scoped_ptr tr_; + const char* fidcolumn_; + bool multiple_geometries_; }; -#endif // OGR_FEATURESET_HPP +#endif // OGR_INDEX_FEATURESET_HPP diff --git a/plugins/input/ogr/ogr_layer_ptr.hpp b/plugins/input/ogr/ogr_layer_ptr.hpp new file mode 100644 index 000000000..8fdc85971 --- /dev/null +++ b/plugins/input/ogr/ogr_layer_ptr.hpp @@ -0,0 +1,194 @@ +/***************************************************************************** + * + * 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 OGR_LAYER_PTR_HPP +#define OGR_LAYER_PTR_HPP + +// stl +#include +#include +#include + +// ogr +#include + +class ogr_layer_ptr +{ +public: + ogr_layer_ptr() + : datasource_(NULL), + layer_(NULL), + owns_layer_(false), + is_valid_(false) + { + } + + ~ogr_layer_ptr() + { + free_layer(); + } + + void free_layer() + { + if (owns_layer_ && layer_ != NULL && datasource_ != NULL) + { + datasource_->ReleaseResultSet(layer_); + } + + datasource_ = NULL; + layer_ = NULL; + layer_name_ = ""; + owns_layer_ = false; + is_valid_ = false; + } + + void layer_by_name(OGRDataSource* const datasource, + const std::string& layer_name) + { + free_layer(); + + datasource_ = datasource; + + OGRLayer* ogr_layer = datasource_->GetLayerByName(layer_name.c_str()); + if (ogr_layer) + { + layer_name_ = layer_name; + layer_ = ogr_layer; + is_valid_ = true; + +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: layer_from_name layer is " << layer_name_ << std::endl; +#endif + } + +#ifdef MAPNIK_DEBUG + debug_print_last_error(); +#endif + } + + void layer_by_index(OGRDataSource* const datasource, + int layer_index) + { + free_layer(); + + datasource_ = datasource; + + OGRLayer* ogr_layer = datasource_->GetLayer(layer_index); + if (ogr_layer) + { + OGRFeatureDefn* def = ogr_layer->GetLayerDefn(); + if (def != 0) + { + layer_ = ogr_layer; + layer_name_ = def->GetName(); + is_valid_ = true; + +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: layer_from_index layer is " << layer_name_ << std::endl; +#endif + } + } + +#ifdef MAPNIK_DEBUG + debug_print_last_error(); +#endif + } + + void layer_by_sql(OGRDataSource* const datasource, + const std::string& layer_sql) + { + free_layer(); + + datasource_ = datasource; + owns_layer_ = true; + + // TODO - actually filter fields! + // http://trac.osgeo.org/gdal/wiki/rfc29_desired_fields + // http://trac.osgeo.org/gdal/wiki/rfc28_sqlfunc + + OGRGeometry* spatial_filter = NULL; + const char* sql_dialect = NULL; + OGRLayer* ogr_layer = datasource_->ExecuteSQL(layer_sql.c_str(), spatial_filter, sql_dialect); + + if (ogr_layer) + { + OGRFeatureDefn* def = ogr_layer->GetLayerDefn(); + if (def != 0) + { + layer_ = ogr_layer; + layer_name_ = def->GetName(); + is_valid_ = true; + +#ifdef MAPNIK_DEBUG + std::clog << "OGR Plugin: layer_from_sql layer is " << layer_name_ << std::endl; +#endif + } + } + +#ifdef MAPNIK_DEBUG + debug_print_last_error(); +#endif + } + + const std::string& layer_name() const + { + return layer_name_; + } + + OGRLayer* layer() const + { + return layer_; + } + + bool is_valid() const + { + return is_valid_; + } + +private: + +#ifdef MAPNIK_DEBUG + void debug_print_last_error() + { + if (! is_valid_) + { + const std::string err = CPLGetLastErrorMsg(); + if (err.size() == 0) + { + std::clog << "OGR Plugin: error getting layer" << std::endl; + } + else + { + std::clog << "OGR Plugin: " << err << std::endl; + } + } + } +#endif + + OGRDataSource* datasource_; + OGRLayer* layer_; + std::string layer_name_; + bool owns_layer_; + bool is_valid_; +}; + +#endif // OGR_LAYER_PTR_HPP diff --git a/plugins/input/osm/basiccurl.cpp b/plugins/input/osm/basiccurl.cpp index 74d6c9880..d0d1fd725 100755 --- a/plugins/input/osm/basiccurl.cpp +++ b/plugins/input/osm/basiccurl.cpp @@ -1,45 +1,70 @@ +/***************************************************************************** + * + * 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 "basiccurl.h" -CURL_LOAD_DATA *grab_http_response(const char *url) +CURL_LOAD_DATA* grab_http_response(const char* url) { - CURL_LOAD_DATA *data; + CURL_LOAD_DATA* data; - CURL *curl = curl_easy_init(); + CURL* curl = curl_easy_init(); - if(curl) - { - data = do_grab(curl,url); - curl_easy_cleanup(curl); - return data; - } - return NULL; + if(curl) + { + data = do_grab(curl, url); + curl_easy_cleanup(curl); + return data; + } + return NULL; } -CURL_LOAD_DATA *do_grab(CURL *curl,const char *url) +CURL_LOAD_DATA* do_grab(CURL* curl,const char* url) { - CURLcode res; - CURL_LOAD_DATA *data = (CURL_LOAD_DATA *)malloc(sizeof(CURL_LOAD_DATA)); - data->data = NULL; - data->nbytes = 0; + CURLcode res; + CURL_LOAD_DATA* data = (CURL_LOAD_DATA*)malloc(sizeof(CURL_LOAD_DATA)); + data->data = NULL; + data->nbytes = 0; - curl_easy_setopt(curl,CURLOPT_URL,url); - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,response_callback); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,data); + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, response_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, data); - res=curl_easy_perform(curl); + res = curl_easy_perform(curl); - return data; + return data; } -size_t response_callback(void *ptr,size_t size,size_t nmemb, void *d) +size_t response_callback(void* ptr, size_t size, size_t nmemb, void* d) { - size_t rsize=size*nmemb; - CURL_LOAD_DATA *data=(CURL_LOAD_DATA *)d; -// fprintf(stderr,"rsize is %d\n", rsize); - data->data=(char *)realloc(data->data,(data->nbytes+rsize) - *sizeof(char)); - memcpy(&(data->data[data->nbytes]),ptr,rsize); - data->nbytes += rsize; -// fprintf(stderr,"data->nbytes is %d\n", data->nbytes); - return rsize; + size_t rsize = size * nmemb; + CURL_LOAD_DATA* data = (CURL_LOAD_DATA*)d; + + // fprintf(stderr,"rsize is %d\n", rsize); + + data->data = (char*)realloc(data->data, (data->nbytes + rsize) * sizeof(char)); + memcpy(&(data->data[data->nbytes]), ptr, rsize); + data->nbytes += rsize; + + // fprintf(stderr,"data->nbytes is %d\n", data->nbytes); + + return rsize; } diff --git a/plugins/input/osm/basiccurl.h b/plugins/input/osm/basiccurl.h index 8981c773a..7ab529783 100755 --- a/plugins/input/osm/basiccurl.h +++ b/plugins/input/osm/basiccurl.h @@ -1,9 +1,31 @@ +/***************************************************************************** + * + * 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 BASICCURL_H #define BASICCURL_H #include -#include -#include +#include +#include typedef struct { @@ -12,7 +34,7 @@ typedef struct } CURL_LOAD_DATA; CURL_LOAD_DATA *grab_http_response(const char *url); -CURL_LOAD_DATA *do_grab(CURL *curl,const char *url); -size_t response_callback(void *ptr,size_t size,size_t nmemb, void *data); +CURL_LOAD_DATA *do_grab(CURL *curl, const char *url); +size_t response_callback(void *ptr ,size_t size, size_t nmemb, void *data); -#endif +#endif // BASICCURL_H diff --git a/plugins/input/osm/dataset_deliverer.cpp b/plugins/input/osm/dataset_deliverer.cpp index 1e2b11d8c..e56a52a38 100644 --- a/plugins/input/osm/dataset_deliverer.cpp +++ b/plugins/input/osm/dataset_deliverer.cpp @@ -1,56 +1,86 @@ +/***************************************************************************** + * + * 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 "dataset_deliverer.h" #include "basiccurl.h" #include -osm_dataset * dataset_deliverer::dataset=NULL; +osm_dataset * dataset_deliverer::dataset = NULL; std::string dataset_deliverer::last_bbox = ""; std::string dataset_deliverer::last_filename = ""; -osm_dataset* dataset_deliverer::load_from_file(const string& file, - const string& parser) +osm_dataset* dataset_deliverer::load_from_file(const string& file, const string& parser) { - // Only actually load from file if we haven't done so already - if(dataset == NULL) - { - dataset = new osm_dataset; - if(dataset->load(file.c_str(),parser)==false) - return NULL; - atexit(dataset_deliverer::release); - last_filename = file; - } - else if(file != last_filename) - { - dataset = new osm_dataset; - if(dataset->load(file.c_str(),parser)==false) - return NULL; - last_filename = file; - } - return dataset; + // Only actually load from file if we haven't done so already + if (dataset == NULL) + { + dataset = new osm_dataset; + if (dataset->load(file.c_str(), parser) == false) + { + return NULL; + } + + atexit(dataset_deliverer::release); + last_filename = file; + } + else if(file != last_filename) + { + dataset = new osm_dataset; + if (dataset->load(file.c_str(), parser) == false) + { + return NULL; + } + last_filename = file; + } + return dataset; } -osm_dataset* dataset_deliverer::load_from_url - (const string& url,const string& bbox,const string& parser) +osm_dataset* dataset_deliverer::load_from_url(const string& url, const string& bbox, const string& parser) { - - if(dataset==NULL) - { - dataset = new osm_dataset; - if(dataset->load_from_url(url.c_str(),bbox,parser)==false) - return NULL; - atexit(dataset_deliverer::release); - last_bbox = bbox; - } - else if (bbox != last_bbox) - { + if (dataset == NULL) + { + dataset = new osm_dataset; + if (dataset->load_from_url(url.c_str(), bbox, parser) == false) + { + return NULL; + } + + atexit(dataset_deliverer::release); + last_bbox = bbox; + } + else if (bbox != last_bbox) + { #ifdef MAPNIK_DEBUG - cerr<<"BBOXES ARE DIFFERENT: " << last_bbox<<","<clear(); - if(dataset->load_from_url(url.c_str(),bbox,parser)==false) - return NULL; - last_bbox = bbox; - } - return dataset; + // Reload the dataset + dataset->clear(); + if (dataset->load_from_url(url.c_str(), bbox, parser) == false) + { + return NULL; + } + + last_bbox = bbox; + } + return dataset; } diff --git a/plugins/input/osm/dataset_deliverer.h b/plugins/input/osm/dataset_deliverer.h index cdcbdee43..82ea029cf 100644 --- a/plugins/input/osm/dataset_deliverer.h +++ b/plugins/input/osm/dataset_deliverer.h @@ -1,3 +1,28 @@ +/***************************************************************************** + * + * 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 DATASET_DELIVERER_H +#define DATASET_DELIVERER_H + #include "osm.h" #include #include @@ -12,13 +37,13 @@ private: static std::string last_filename; public: - static osm_dataset *load_from_file(const string&,const string&); - static osm_dataset *load_from_url - (const string&,const string&,const string&); + static osm_dataset *load_from_file(const string&, const string&); + static osm_dataset *load_from_url(const string&, const string&, const string&); static void release() { - delete dataset; + delete dataset; } }; +#endif // DATASET_DELIVERER_H diff --git a/plugins/input/osm/osm.cpp b/plugins/input/osm/osm.cpp index b15ca98b2..e93b5b128 100644 --- a/plugins/input/osm/osm.cpp +++ b/plugins/input/osm/osm.cpp @@ -1,263 +1,280 @@ +/***************************************************************************** + * + * 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 "osm.h" #include "osmparser.h" +#include "basiccurl.h" + #include #include #include #include #include -#include "basiccurl.h" - - -#include -using namespace std; polygon_types osm_way::ptypes; bool osm_dataset::load(const char* filename,const std::string& parser) { - if (parser=="libxml2") - { - return osmparser::parse(this,filename); - } - return false; + if (parser == "libxml2") + { + return osmparser::parse(this, filename); + } + return false; } bool osm_dataset::load_from_url(const std::string& url, - const std::string& bbox, - const std::string& parser) + const std::string& bbox, + const std::string& parser) { - if(parser=="libxml2") - { + if (parser == "libxml2") + { #ifdef MAPNIK_DEBUG - cerr<<"osm_dataset::load_from_url: url=" << url << - " bbox="<nbytes+1]; - memcpy(blx,resp->data,resp->nbytes); - blx[resp->nbytes] = '\0'; + CURL_LOAD_DATA* resp = grab_http_response(str.str().c_str()); + + if (resp != NULL) + { + char *blx = new char[resp->nbytes + 1]; + memcpy(blx, resp->data, resp->nbytes); + blx[resp->nbytes] = '\0'; #ifdef MAPNIK_DEBUG - cerr<< " CURL RESPONSE: " << blx << endl; + std::clog << "Osm Plugin: CURL RESPONSE: " << blx << std::endl; #endif - delete[] blx; - bool success= osmparser::parse(this,resp->data,resp->nbytes); - return success; + delete[] blx; + bool success = osmparser::parse(this, resp->data, resp->nbytes); + return success; + } } - } - return false; + return false; } osm_dataset::~osm_dataset() { - clear(); + clear(); } void osm_dataset::clear() { #ifdef MAPNIK_DEBUG - cerr<<"osm_dataset::clear()"<to_string(); - } - for(unsigned int count=0; countto_string(); - } - return result; + for (unsigned int count = 0; count < nodes.size(); ++count) + { + result += nodes[count]->to_string(); + } + + for (unsigned int count = 0; count < ways.size(); ++count) + { + result += ways[count]->to_string(); + } + + return result; } bounds osm_dataset::get_bounds() { - bounds b (-180,-90,180,90); - for(unsigned int count=0; countlon > b.w) - b.w=nodes[count]->lon; - if(nodes[count]->lon < b.e) - b.e=nodes[count]->lon; - if(nodes[count]->lat > b.s) - b.s=nodes[count]->lat; - if(nodes[count]->lat < b.n) - b.n=nodes[count]->lat; - } - return b; + bounds b (-180, -90, 180, 90); + for (unsigned int count = 0; count < nodes.size(); ++count) + { + if(nodes[count]->lon > b.w) b.w = nodes[count]->lon; + if(nodes[count]->lon < b.e) b.e = nodes[count]->lon; + if(nodes[count]->lat > b.s) b.s = nodes[count]->lat; + if(nodes[count]->lat < b.n) b.n = nodes[count]->lat; + } + return b; } -osm_node *osm_dataset::next_node() +osm_node* osm_dataset::next_node() { - if(node_i!=nodes.end()) - { - return *(node_i++); - } - return NULL; - + if (node_i != nodes.end()) + { + return *(node_i++); + } + return NULL; } -osm_way *osm_dataset::next_way() + +osm_way* osm_dataset::next_way() { - if(way_i!=ways.end()) - { - return *(way_i++); - } - return NULL; + if (way_i != ways.end()) + { + return *(way_i++); + } + return NULL; } -osm_item *osm_dataset::next_item() +osm_item* osm_dataset::next_item() { - osm_item *item=NULL; - if(next_item_mode==Node) - { - item = next_node(); - if(item==NULL) + osm_item* item = NULL; + if (next_item_mode == Node) { - next_item_mode=Way; - rewind_ways(); - item = next_way(); + item = next_node(); + if (item == NULL) + { + next_item_mode = Way; + rewind_ways(); + item = next_way(); + } } - } - else - { - item = next_way(); - } - return item; + else + { + item = next_way(); + } + return item; } std::set osm_dataset::get_keys() { - std::set keys; - for(unsigned int count=0; count::iterator i= - nodes[count]->keyvals.begin(); i!=nodes[count]->keyvals.end(); i++) + std::set keys; + for (unsigned int count = 0; count < nodes.size(); ++count) { - keys.insert(i->first); + for (std::map::iterator i = nodes[count]->keyvals.begin(); + i != nodes[count]->keyvals.end(); i++) + { + keys.insert(i->first); + } } - } - for(unsigned int count=0; count::iterator i= - ways[count]->keyvals.begin(); i!=ways[count]->keyvals.end(); i++) + + for (unsigned int count = 0; count < ways.size(); ++count) { - keys.insert(i->first); + for (std::map::iterator i = ways[count]->keyvals.begin(); + i != ways[count]->keyvals.end(); i++) + { + keys.insert(i->first); + } } - } - return keys; + return keys; } - - std::string osm_item::to_string() { - std::ostringstream strm; - strm << "id=" << id << std::endl << "Keyvals: " << std::endl; - for(std::map::iterator i=keyvals.begin(); - i!=keyvals.end(); i++) - { - strm << "Key " << i->first << " Value " << i->second << std::endl; - } - return strm.str(); + std::ostringstream strm; + strm << "id=" << id << std::endl << "Keyvals: " << std::endl; + + for (std::map::iterator i = keyvals.begin(); + i != keyvals.end(); i++) + { + strm << "Key " << i->first << " Value " << i->second << std::endl; + } + + return strm.str(); } std::string osm_node::to_string() { - std::ostringstream strm; - strm << "Node: "<< osm_item::to_string() << - " Lat=" << lat <<" lon=" <id << " "; + if (nodes[count] != NULL) + { + strm << nodes[count]->id << " "; + } } - } - strm << std::endl; - return strm.str(); + + strm << std::endl; + return strm.str(); } bounds osm_way::get_bounds() { - bounds b (-180,-90,180,90); - for(unsigned int count=0; countlon > b.w) - b.w=nodes[count]->lon; - if(nodes[count]->lon < b.e) - b.e=nodes[count]->lon; - if(nodes[count]->lat > b.s) - b.s=nodes[count]->lat; - if(nodes[count]->lat < b.n) - b.n=nodes[count]->lat; - } - return b; + bounds b (-180, -90, 180, 90); + + for (unsigned int count = 0; count < nodes.size(); ++count) + { + if(nodes[count]->lon > b.w) b.w = nodes[count]->lon; + if(nodes[count]->lon < b.e) b.e = nodes[count]->lon; + if(nodes[count]->lat > b.s) b.s = nodes[count]->lat; + if(nodes[count]->lat < b.n) b.n = nodes[count]->lat; + } + return b; } bool osm_way::is_polygon() { - for(unsigned int count=0; countw = w; this->s = s; @@ -23,39 +45,35 @@ struct bounds class polygon_types { public: - std::vector > ptypes; + std::vector > ptypes; polygon_types() { - ptypes.push_back(std::pair("natural","wood")); - ptypes.push_back(std::pair("natural","water")); - ptypes.push_back(std::pair("natural","heath")); - ptypes.push_back(std::pair("natural","marsh")); - ptypes.push_back(std::pair("military", - "danger_area")); - ptypes.push_back(std::pair - ("landuse","forest")); - ptypes.push_back(std::pair - ("landuse","industrial")); + ptypes.push_back(std::pair("natural", "wood")); + ptypes.push_back(std::pair("natural", "water")); + ptypes.push_back(std::pair("natural", "heath")); + ptypes.push_back(std::pair("natural", "marsh")); + ptypes.push_back(std::pair("military", "danger_area")); + ptypes.push_back(std::pair("landuse","forest")); + ptypes.push_back(std::pair("landuse","industrial")); } }; struct osm_item { long id; - std::map keyvals; + std::map keyvals; virtual std::string to_string(); - virtual ~osm_item() { } + virtual ~osm_item() {} }; - -struct osm_node: public osm_item +struct osm_node : public osm_item { double lat, lon; std::string to_string(); }; -struct osm_way: public osm_item +struct osm_way : public osm_item { std::vector nodes; std::string to_string(); @@ -68,36 +86,48 @@ class osm_dataset { private: int next_item_mode; - enum {Node, Way }; + enum { Node, Way }; std::vector::iterator node_i; std::vector::iterator way_i; std::vector nodes; std::vector ways; public: - osm_dataset() { node_i=nodes.begin(); way_i=ways.begin(); - next_item_mode=Node; } - osm_dataset(const char* name) - { node_i=nodes.begin(); way_i=ways.begin(); - next_item_mode=Node; load(name); } - bool load(const char* name,const std::string& parser="libxml2"); - bool load_from_url(const std::string&,const std::string&, - const std::string& parser="libxml2"); + osm_dataset() + { + node_i = nodes.begin(); + way_i = ways.begin(); + next_item_mode = Node; + } + + osm_dataset(const char* name) + { + node_i = nodes.begin(); + way_i = ways.begin(); + next_item_mode = Node; + load(name); + } + ~osm_dataset(); + + bool load(const char* name, const std::string& parser = "libxml2"); + bool load_from_url(const std::string&, + const std::string&, + const std::string& parser = "libxml2"); void clear(); void add_node(osm_node* n) { nodes.push_back(n); } void add_way(osm_way* w) { ways.push_back(w); } std::string to_string(); bounds get_bounds(); std::set get_keys(); - void rewind_nodes() { node_i=nodes.begin(); } - void rewind_ways() { way_i=ways.begin(); } - void rewind() { rewind_nodes(); rewind_ways(); next_item_mode=Node; } + void rewind_nodes() { node_i = nodes.begin(); } + void rewind_ways() { way_i = ways.begin(); } + void rewind() { rewind_nodes(); rewind_ways(); next_item_mode = Node; } osm_node * next_node(); osm_way * next_way(); osm_item * next_item(); - bool current_item_is_node() { return next_item_mode==Node; } - bool current_item_is_way() { return next_item_mode==Way; } + bool current_item_is_node() { return next_item_mode == Node; } + bool current_item_is_way() { return next_item_mode == Way; } }; #endif // OSM_H diff --git a/plugins/input/osm/osm_datasource.cpp b/plugins/input/osm/osm_datasource.cpp index f286c1f55..f2f64b545 100644 --- a/plugins/input/osm/osm_datasource.cpp +++ b/plugins/input/osm/osm_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,6 +20,12 @@ * *****************************************************************************/ +// stl +#include +#include +#include +#include + // mapnik #include #include @@ -27,20 +33,12 @@ // boost #include -// stl -#include -#include -#include -#include - #include "osm_datasource.hpp" #include "osm_featureset.hpp" #include "dataset_deliverer.h" #include "osmtagtypes.h" #include "osmparser.h" -DATASOURCE_PLUGIN(osm_datasource) - using mapnik::String; using mapnik::Double; using mapnik::Integer; @@ -49,10 +47,12 @@ using mapnik::filter_in_box; using mapnik::filter_at_point; using mapnik::attribute_descriptor; -osm_datasource::osm_datasource(const parameters ¶ms, bool bind) - : datasource (params), - type_(datasource::Vector), - desc_(*params_.get("type"), *params_.get("encoding","utf-8")) +DATASOURCE_PLUGIN(osm_datasource) + +osm_datasource::osm_datasource(const parameters& params, bool bind) + : datasource (params), + type_(datasource::Vector), + desc_(*params_.get("type"), *params_.get("encoding", "utf-8")) { if (bind) { @@ -65,62 +65,64 @@ void osm_datasource::bind() const if (is_bound_) return; osm_data_ = NULL; - std::string osm_filename= *params_.get("file",""); - std::string parser = *params_.get("parser","libxml2"); - std::string url = *params_.get("url",""); - std::string bbox = *params_.get("bbox",""); + std::string osm_filename = *params_.get("file", ""); + std::string parser = *params_.get("parser", "libxml2"); + std::string url = *params_.get("url", ""); + std::string bbox = *params_.get("bbox", ""); - bool do_process=false; + bool do_process = false; // load the data // if we supplied a filename, load from file - if (url!="" && bbox!="") + if (url != "" && bbox != "") { // otherwise if we supplied a url and a bounding box, load from the url #ifdef MAPNIK_DEBUG - cerr<<"loading_from_url: url="<rewind(); + // Need code to get the attributes of all the data - std::set keys= osm_data_->get_keys(); + std::set keys = osm_data_->get_keys(); // Add the attributes to the datasource descriptor - assume they are // all of type String - for(std::set::iterator i=keys.begin(); i!=keys.end(); i++) - desc_.add_descriptor(attribute_descriptor(*i,tagtypes.get_type(*i))); + for (std::set::iterator i = keys.begin(); i != keys.end(); i++) + { + desc_.add_descriptor(attribute_descriptor(*i, tagtypes.get_type(*i))); + } // Get the bounds of the data and set extent_ accordingly bounds b = osm_data_->get_bounds(); - extent_ = box2d(b.w,b.s,b.e,b.n); + extent_ = box2d(b.w, b.s, b.e, b.n); } is_bound_ = true; } - osm_datasource::~osm_datasource() { // Do not do as is now static variable and cleaned up at exit @@ -129,59 +131,58 @@ osm_datasource::~osm_datasource() std::string osm_datasource::name() { - return "osm"; + return "osm"; } int osm_datasource::type() const { - return type_; + return type_; } layer_descriptor osm_datasource::get_descriptor() const { - return desc_; + return desc_; } featureset_ptr osm_datasource::features(const query& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); filter_in_box filter(q.get_bbox()); // so we need to filter osm features by bbox here... return boost::make_shared >(filter, - osm_data_, - q.property_names(), - desc_.get_encoding()); + osm_data_, + q.property_names(), + desc_.get_encoding()); } featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - filter_at_point filter(pt); - // collect all attribute names - std::vector const& desc_vector = - desc_.get_descriptors(); - std::vector::const_iterator itr = desc_vector.begin(); - std::vector::const_iterator end = desc_vector.end(); - std::set names; + filter_at_point filter(pt); + // collect all attribute names + std::vector const& desc_vector = desc_.get_descriptors(); + std::vector::const_iterator itr = desc_vector.begin(); + std::vector::const_iterator end = desc_vector.end(); + std::set names; - while (itr != end) - { - names.insert(itr->get_name()); - ++itr; - } + while (itr != end) + { + names.insert(itr->get_name()); + ++itr; + } return boost::make_shared >(filter, - osm_data_, - names, - desc_.get_encoding()); + osm_data_, + names, + desc_.get_encoding()); } box2d osm_datasource::envelope() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return extent_; } diff --git a/plugins/input/osm/osm_datasource.hpp b/plugins/input/osm/osm_datasource.hpp index 44b826870..600ccf406 100644 --- a/plugins/input/osm/osm_datasource.hpp +++ b/plugins/input/osm/osm_datasource.hpp @@ -1,8 +1,8 @@ /***************************************************************************** - * + * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,17 +20,15 @@ * *****************************************************************************/ -// $Id$ - #ifndef OSM_DATASOURCE_HPP #define OSM_DATASOURCE_HPP +// mapnik #include #include #include "osm.h" - using mapnik::datasource; using mapnik::parameters; using mapnik::query; @@ -41,26 +39,24 @@ using mapnik::box2d; class osm_datasource : public datasource { - public: - osm_datasource(const parameters ¶ms, bool bind=true); - virtual ~osm_datasource(); - - // these must be overridden - int type() const; - featureset_ptr features(const query& q) const; - featureset_ptr features_at_point(coord2d const& pt) const; - box2d envelope() const; - layer_descriptor get_descriptor() const; +public: + osm_datasource(const parameters& params, bool bind = true); + virtual ~osm_datasource(); + int type() const; + featureset_ptr features(const query& q) const; + featureset_ptr features_at_point(coord2d const& pt) const; + box2d envelope() const; + layer_descriptor get_descriptor() const; static std::string name(); void bind() const; - private: - osm_datasource(const osm_datasource&); - osm_datasource& operator=(const osm_datasource&); - private: - mutable box2d extent_; - mutable osm_dataset * osm_data_; +private: + mutable box2d extent_; + mutable osm_dataset* osm_data_; int type_; 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 diff --git a/plugins/input/osm/osm_featureset.cpp b/plugins/input/osm/osm_featureset.cpp index 3cf7b7b58..e16202046 100644 --- a/plugins/input/osm/osm_featureset.cpp +++ b/plugins/input/osm/osm_featureset.cpp @@ -3,7 +3,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -21,55 +21,53 @@ * *****************************************************************************/ +// stl +#include + // mapnik #include #include #include "osm_featureset.hpp" -// stl -#include - using mapnik::Feature; using mapnik::feature_ptr; using mapnik::geometry_type; using mapnik::feature_factory; -using std::cerr; -using std::endl; template osm_featureset::osm_featureset(const filterT& filter, - osm_dataset * dataset, + osm_dataset* dataset, const std::set& attribute_names, std::string const& encoding) - : filter_(filter), - query_ext_(), - tr_(new transcoder(encoding)), - feature_id_(1), - dataset_ (dataset), - attribute_names_ (attribute_names) + : filter_(filter), + query_ext_(), + tr_(new transcoder(encoding)), + feature_id_(1), + dataset_ (dataset), + attribute_names_ (attribute_names) { dataset_->rewind(); } - template feature_ptr osm_featureset::next() { - osm_item * cur_item = dataset_->next_item(); feature_ptr feature; - bool success=false; - if(cur_item != NULL) + bool success = false; + + osm_item* cur_item = dataset_->next_item(); + if (cur_item != NULL) { - if(dataset_->current_item_is_node()) + if (dataset_->current_item_is_node()) { feature = feature_factory::create(feature_id_); ++feature_id_; double lat = static_cast(cur_item)->lat; double lon = static_cast(cur_item)->lon; - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(lon,lat); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(lon, lat); feature->add_geometry(point); success = true; } @@ -78,40 +76,42 @@ feature_ptr osm_featureset::next() bounds b = static_cast(cur_item)->get_bounds(); // Loop until we find a feature which passes the filter - while(cur_item != NULL && - !filter_.pass(box2d(b.w,b.s,b.e,b.n))) + while (cur_item != NULL && + ! filter_.pass(box2d(b.w, b.s, b.e, b.n))) { cur_item = dataset_->next_item(); - if(cur_item!=NULL) + if (cur_item != NULL) + { b = static_cast(cur_item)->get_bounds(); + } } - if(cur_item != NULL) + if (cur_item != NULL) { - if(static_cast(cur_item)->nodes.size()) + if (static_cast(cur_item)->nodes.size()) { feature = feature_factory::create(feature_id_); ++feature_id_; - geometry_type *geom; - if(static_cast(cur_item)->is_polygon()) - geom = new geometry_type(mapnik::Polygon); - else - geom = new geometry_type(mapnik::LineString); - - geom->set_capacity(static_cast(cur_item)-> - nodes.size()); - geom->move_to(static_cast(cur_item)-> - nodes[0]->lon, - static_cast(cur_item)-> - nodes[0]->lat); - - for(unsigned int count=1; count(cur_item) - ->nodes.size(); count++) + geometry_type* geom; + if (static_cast(cur_item)->is_polygon()) { - geom->line_to(static_cast(cur_item) - ->nodes[count]->lon, - static_cast(cur_item) - ->nodes[count]->lat); + geom = new geometry_type(mapnik::Polygon); + } + else + { + geom = new geometry_type(mapnik::LineString); + } + + geom->set_capacity(static_cast(cur_item)->nodes.size()); + geom->move_to(static_cast(cur_item)->nodes[0]->lon, + static_cast(cur_item)->nodes[0]->lat); + + for (unsigned int count = 1; + count < static_cast(cur_item)->nodes.size(); + count++) + { + geom->line_to(static_cast(cur_item)->nodes[count]->lon, + static_cast(cur_item)->nodes[count]->lat); } feature->add_geometry(geom); success = true; @@ -120,31 +120,31 @@ feature_ptr osm_featureset::next() } // can feature_ptr be compared to NULL? - no - if(success) + if (success) { - std::map::iterator i= - cur_item->keyvals.begin(); + std::map::iterator i = cur_item->keyvals.begin(); // add the keyvals to the feature. the feature seems to be a map // of some sort so this should work - see dbf_file::add_attribute() - while(i != cur_item->keyvals.end()) + while (i != cur_item->keyvals.end()) { - //only add if in the specified set of attribute names - if(attribute_names_.find(i->first) != attribute_names_.end()) + // only add if in the specified set of attribute names + if (attribute_names_.find(i->first) != attribute_names_.end()) + { (*feature)[i->first] = tr_->transcode(i->second.c_str()); + } + i++; } + return feature; } } return feature_ptr(); } - template osm_featureset::~osm_featureset() {} template class osm_featureset; template class osm_featureset; - - diff --git a/plugins/input/osm/osm_featureset.hpp b/plugins/input/osm/osm_featureset.hpp index a1251e221..cefd63e7d 100644 --- a/plugins/input/osm/osm_featureset.hpp +++ b/plugins/input/osm/osm_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -23,14 +23,20 @@ #ifndef OSM_FS_HH #define OSM_FS_HH +// stl +#include + +// boost #include + +// mapnik #include -#include "osm.h" #include #include #include #include -#include + +#include "osm.h" using mapnik::Featureset; using mapnik::box2d; @@ -40,27 +46,26 @@ using mapnik::transcoder; template class osm_featureset : public Featureset { - filterT filter_; - box2d query_ext_; - boost::scoped_ptr tr_; - std::vector attr_ids_; - mutable box2d feature_ext_; - mutable int total_geom_size; - mutable int feature_id_; - osm_dataset *dataset_; - std::set attribute_names_; - - public: - osm_featureset(const filterT& filter, - osm_dataset *dataset, - const std::set& attribute_names, - std::string const& encoding); - virtual ~osm_featureset(); - feature_ptr next(); - private: - osm_featureset(const osm_featureset&); - const osm_featureset& operator=(const osm_featureset&); - +public: + osm_featureset(const filterT& filter, + osm_dataset* dataset, + const std::set& attribute_names, + std::string const& encoding); + virtual ~osm_featureset(); + feature_ptr next(); +private: + filterT filter_; + box2d query_ext_; + boost::scoped_ptr tr_; + std::vector attr_ids_; + mutable box2d feature_ext_; + mutable int total_geom_size; + mutable int feature_id_; + osm_dataset *dataset_; + std::set attribute_names_; + // no copying + osm_featureset(const osm_featureset&); + const osm_featureset& operator=(const osm_featureset&); }; -#endif //OSM_FS_HH +#endif // OSM_FS_HH diff --git a/plugins/input/osm/osmparser.h b/plugins/input/osm/osmparser.h index 5ffa0477f..5cc00e24a 100644 --- a/plugins/input/osm/osmparser.h +++ b/plugins/input/osm/osmparser.h @@ -1,3 +1,28 @@ +/***************************************************************************** + * + * 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 OSMPARSER_H +#define OSMPARSER_H + #include #include #include @@ -6,24 +31,24 @@ #include "osm.h" #include - class osmparser { +public: + static void processNode(xmlTextReaderPtr reader); + static void startElement(xmlTextReaderPtr reader, const xmlChar* name); + static void endElement(const xmlChar* name); + static bool parse(osm_dataset* ds, const char* filename); + static bool parse(osm_dataset* ds, char* data, int nbytes); + private: static osm_item *cur_item; static long curID; - static bool in_node, in_way; + static bool in_node, in_way; static osm_dataset* components; static std::string error; - static std::map tmp_node_store; + static std::map tmp_node_store; - static int do_parse(xmlTextReaderPtr); - -public: - static void processNode(xmlTextReaderPtr reader); - static void startElement(xmlTextReaderPtr reader, const xmlChar *name); - static void endElement(const xmlChar* name); - static bool parse(osm_dataset *ds, const char* filename); - static bool parse(osm_dataset *ds, char* data,int nbytes); + static int do_parse(xmlTextReaderPtr); }; +#endif // OSMPARSER_H diff --git a/plugins/input/osm/osmtagtypes.h b/plugins/input/osm/osmtagtypes.h index d486946a8..191514757 100644 --- a/plugins/input/osm/osmtagtypes.h +++ b/plugins/input/osm/osmtagtypes.h @@ -1,28 +1,50 @@ +/***************************************************************************** + * + * 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 OSMTAGTYPES_H #define OSMTAGTYPES_H // osmtagtypes.h // for finding the types of particular tags +// mapnik #include class osm_tag_types { -private: - std::map types; - public: - void add_type(std::string tag, mapnik::eAttributeType type) - { - types[tag]=type; - } + void add_type(std::string tag, mapnik::eAttributeType type) + { + types[tag] = type; + } - mapnik::eAttributeType get_type(std::string tag) - { - std::map::iterator i = - types.find(tag); - return (i==types.end()) ? mapnik::String: i->second; - } + mapnik::eAttributeType get_type(std::string tag) + { + std::map::iterator i = types.find(tag); + return (i == types.end()) ? mapnik::String : i->second; + } + +private: + std::map types; }; #endif // OSMTAGTYPES_H diff --git a/plugins/input/osm/render.cpp b/plugins/input/osm/render.cpp index b55e8dd53..30583346a 100644 --- a/plugins/input/osm/render.cpp +++ b/plugins/input/osm/render.cpp @@ -1,3 +1,30 @@ +/***************************************************************************** + * + * 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 + * + *****************************************************************************/ + +// stl +#include +#include + +// mapnik #include #include #include @@ -8,52 +35,41 @@ #include #include -using namespace mapnik; - -#include -#include -using namespace std; - - int main(int argc,char *argv[]) { - if(argc < 6) - { - std::cerr<<"Usage: render XMLfile w s e n [OSMfile]" << std::endl; - exit(0); - } - - datasource_cache::instance()->register_datasources - ("/usr/local/lib/mapnik/input"); - freetype_engine::register_font - ("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf"); - - Map m (800,800); - load_map(m,argv[1]); - - if(argc>6) - { - parameters p; - p["type"] = "osm"; - p["file"] = argv[6]; - for(int count=0; countparams(); - m.getLayer(count).set_datasource(datasource_cache::instance()-> - create(p)); + std::cerr << "Usage: render XMLfile w s e n [OSMfile]" << std::endl; + exit(0); } - } - box2d bbox (atof(argv[2]),atof(argv[3]), - atof(argv[4]),atof(argv[5])); + mapnik::datasource_cache::instance()->register_datasources("/usr/local/lib/mapnik/input"); + mapnik::freetype_engine::register_font("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf"); + + mapnik::Map m(800, 800); + mapnik::load_map(m, argv[1]); + + if (argc > 6) + { + mapnik::parameters p; + p["type"] = "osm"; + p["file"] = argv[6]; + for (int count = 0; count < m.layer_count(); count++) + { + mapnik::parameters q = m.getLayer(count).datasource()->params(); + m.getLayer(count).set_datasource(mapnik::datasource_cache::instance()->create(p)); + } + } + + mapnik::box2d bbox (atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5])); - m.zoom_to_box(bbox); + m.zoom_to_box(bbox); - image_32 buf (m.width(), m.height()); - agg_renderer r(m,buf); - r.apply(); + mapnik::image_32 buf (m.width(), m.height()); + mapnik::agg_renderer r(m, buf); + r.apply(); - save_to_file(buf.data(),"blah.png","png"); + mapnik::save_to_file(buf.data(), "blah.png", "png"); - return 0; + return 0; } diff --git a/plugins/input/postgis/connection.hpp b/plugins/input/postgis/connection.hpp index 6a8239cbe..1a056dfa4 100644 --- a/plugins/input/postgis/connection.hpp +++ b/plugins/input/postgis/connection.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,17 +20,14 @@ * *****************************************************************************/ -//$Id: connection.hpp 17 2005-03-08 23:58:43Z pavlenko $ - #ifndef CONNECTION_HPP #define CONNECTION_HPP #include #include -extern "C" -{ -#include "libpq-fe.h" +extern "C" { + #include "libpq-fe.h" } #include "resultset.hpp" diff --git a/plugins/input/postgis/connection_manager.hpp b/plugins/input/postgis/connection_manager.hpp index 35bba4f2a..9ec259495 100644 --- a/plugins/input/postgis/connection_manager.hpp +++ b/plugins/input/postgis/connection_manager.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,8 +20,6 @@ * *****************************************************************************/ -//$Id: connection_manager.hpp 17 2005-03-08 23:58:43Z pavlenko $ - #ifndef CONNECTION_MANAGER_HPP #define CONNECTION_MANAGER_HPP diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index b02dc9c17..3af5a8eda 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,17 +20,15 @@ * *****************************************************************************/ -//$Id: postgis.cc 44 2005-04-22 18:53:54Z pavlenko $ +#include "connection_manager.hpp" +#include "postgis_datasource.hpp" +#include "postgis_featureset.hpp" // mapnik #include #include #include -#include "connection_manager.hpp" -#include "postgis_datasource.hpp" -#include "postgis_featureset.hpp" - // boost #include #include @@ -128,7 +126,7 @@ void postgis_datasource::bind() const if(geometry_table_.empty()) { - geometry_table_ = mapnik::table_from_sql(table_); + geometry_table_ = mapnik::sql_utils::table_from_sql(table_); } std::string::size_type idx = geometry_table_.find_last_of('.'); if (idx!=std::string::npos) @@ -152,13 +150,13 @@ void postgis_datasource::bind() const { std::ostringstream s; s << "SELECT f_geometry_column, srid FROM "; - s << GEOMETRY_COLUMNS <<" WHERE f_table_name='" << mapnik::unquote_sql(geometry_table_) <<"'"; + s << GEOMETRY_COLUMNS <<" WHERE f_table_name='" << mapnik::sql_utils::unquote_double(geometry_table_) <<"'"; if (schema_.length() > 0) - s << " AND f_table_schema='" << mapnik::unquote_sql(schema_) << "'"; + s << " AND f_table_schema='" << mapnik::sql_utils::unquote_double(schema_) << "'"; if (geometry_field_.length() > 0) - s << " AND f_geometry_column='" << mapnik::unquote_sql(geometry_field_) << "'"; + s << " AND f_geometry_column='" << mapnik::sql_utils::unquote_double(geometry_field_) << "'"; /* if (show_queries_) @@ -504,14 +502,14 @@ featureset_ptr postgis_datasource::features(const query& q) const s << "AsBinary(\"" << geometryColumn_ << "\") AS geom"; if (!key_field_.empty()) - mapnik::quote_attr(s,key_field_); + mapnik::sql_utils::quote_attr(s,key_field_); std::set const& props=q.property_names(); std::set::const_iterator pos=props.begin(); std::set::const_iterator end=props.end(); while (pos != end) { - mapnik::quote_attr(s,*pos); + mapnik::sql_utils::quote_attr(s,*pos); ++pos; } @@ -580,14 +578,14 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const s << "AsBinary(\"" << geometryColumn_ << "\") AS geom"; if (!key_field_.empty()) - mapnik::quote_attr(s,key_field_); + mapnik::sql_utils::quote_attr(s,key_field_); std::vector::const_iterator itr = desc_.get_descriptors().begin(); std::vector::const_iterator end = desc_.get_descriptors().end(); unsigned size=0; while (itr != end) { - mapnik::quote_attr(s,itr->get_name()); + mapnik::sql_utils::quote_attr(s,itr->get_name()); ++itr; ++size; } @@ -646,11 +644,11 @@ box2d postgis_datasource::envelope() const if (schema_.length() > 0) { - s << mapnik::unquote_sql(schema_) << "','"; + s << mapnik::sql_utils::unquote_double(schema_) << "','"; } - s << mapnik::unquote_sql(geometry_table_) << "','" - << mapnik::unquote_sql(geometryColumn_) << "') as ext) as tmp"; + s << mapnik::sql_utils::unquote_double(geometry_table_) << "','" + << mapnik::sql_utils::unquote_double(geometryColumn_) << "') as ext) as tmp"; } else { diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index eade5781f..f371f86a1 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/postgis/postgis_featureset.cpp b/plugins/input/postgis/postgis_featureset.cpp index 98dc8c928..4129ef147 100644 --- a/plugins/input/postgis/postgis_featureset.cpp +++ b/plugins/input/postgis/postgis_featureset.cpp @@ -20,7 +20,9 @@ * *****************************************************************************/ -//$Id$ +#include "postgis_featureset.hpp" +#include "resultset.hpp" +#include "cursorresultset.hpp" // mapnik #include @@ -29,10 +31,6 @@ #include #include -#include "postgis_featureset.hpp" -#include "resultset.hpp" -#include "cursorresultset.hpp" - // boost #include #include @@ -164,7 +162,7 @@ feature_ptr postgis_featureset::next() } else if (oid == 1700) // numeric { - std::string str = mapnik::numeric2string(buf); + std::string str = mapnik::sql_utils::numeric2string(buf); try { double val = boost::lexical_cast(str); diff --git a/plugins/input/postgis/resultset.hpp b/plugins/input/postgis/resultset.hpp index 25cc20148..340258e9e 100644 --- a/plugins/input/postgis/resultset.hpp +++ b/plugins/input/postgis/resultset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,15 +20,11 @@ * *****************************************************************************/ -//$Id: resultset.hpp 17 2005-03-08 23:58:43Z pavlenko $ - - #ifndef RESULTSET_HPP #define RESULTSET_HPP -extern "C" -{ -#include "libpq-fe.h" +extern "C" { + #include "libpq-fe.h" } class IResultSet diff --git a/plugins/input/raster/raster_datasource.cpp b/plugins/input/raster/raster_datasource.cpp index e7bf0b445..421f63fb8 100644 --- a/plugins/input/raster/raster_datasource.cpp +++ b/plugins/input/raster/raster_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: raster_datasource.cc 44 2005-04-22 18:53:54Z pavlenko $ // boost #include @@ -33,12 +32,6 @@ #include "raster_info.hpp" #include "raster_datasource.hpp" -using mapnik::datasource; -using mapnik::parameters; -using mapnik::image_reader; - -DATASOURCE_PLUGIN(raster_datasource) - using boost::lexical_cast; using boost::bad_lexical_cast; using mapnik::layer_descriptor; @@ -46,11 +39,16 @@ using mapnik::featureset_ptr; using mapnik::query; using mapnik::coord2d; using mapnik::datasource_exception; +using mapnik::datasource; +using mapnik::parameters; +using mapnik::image_reader; + +DATASOURCE_PLUGIN(raster_datasource) raster_datasource::raster_datasource(const parameters& params, bool bind) - : datasource(params), - desc_(*params.get("type"),"utf-8"), - extent_initialized_(false) + : datasource(params), + desc_(*params.get("type"), "utf-8"), + extent_initialized_(false) { #ifdef MAPNIK_DEBUG std::clog << "Raster Plugin: Initializing..." << std::endl; @@ -65,7 +63,11 @@ raster_datasource::raster_datasource(const parameters& params, bool bind) else filename_ = *file; - format_=*params_.get("format","tiff"); + multi_tiles_ = *params_.get("multi", false); + tile_size_ = *params_.get("tile_size", 256); + tile_stride_ = *params_.get("tile_stride", 1); + + format_ = *params_.get("format","tiff"); boost::optional lox = params_.get("lox"); boost::optional loy = params_.get("loy"); @@ -84,7 +86,9 @@ raster_datasource::raster_datasource(const parameters& params, bool bind) } if (! extent_initialized_) + { throw datasource_exception("Raster Plugin: valid or are required"); + } if (bind) { @@ -96,33 +100,58 @@ void raster_datasource::bind() const { if (is_bound_) return; - if (! boost::filesystem::exists(filename_)) - throw datasource_exception("Raster Plugin: " + filename_ + " does not exist"); - - try - { - std::auto_ptr reader(mapnik::get_image_reader(filename_, format_)); - if (reader.get()) - { - width_ = reader->width(); - height_ = reader->height(); + if (multi_tiles_) + { + boost::optional x_width = params_.get("x_width"); + boost::optional y_width = params_.get("y_width"); -#ifdef MAPNIK_DEBUG - std::clog << "Raster Plugin: RASTER SIZE(" << width_ << "," << height_ << ")" << std::endl; -#endif + if (! x_width) + { + throw datasource_exception("Raster Plugin: x-width parameter not supplied for multi-tiled data source."); + } + + if (! y_width) + { + throw datasource_exception("Raster Plugin: y-width parameter not supplied for multi-tiled data source."); + } + + width_ = x_width.get() * tile_size_; + height_ = y_width.get() * tile_size_; + } + else + { + if (! boost::filesystem::exists(filename_)) + { + throw datasource_exception("Raster Plugin: " + filename_ + " does not exist"); + } + + try + { + std::auto_ptr reader(mapnik::get_image_reader(filename_, format_)); + if (reader.get()) + { + width_ = reader->width(); + height_ = reader->height(); + } + } + catch (mapnik::image_reader_exception const& ex) + { + throw datasource_exception("Raster Plugin: image reader exception: " + std::string(ex.what())); + } + catch (std::exception const& ex) + { + throw datasource_exception("Raster Plugin: " + std::string(ex.what())); + } + catch (...) + { + throw datasource_exception("Raster Plugin: image reader unknown exception caught"); } } - catch (mapnik::image_reader_exception const& ex) - { - std::cerr << "Raster Plugin: image reader exception caught: " << ex.what() << std::endl; - throw; - } - catch (...) - { - std::cerr << "Raster Plugin: exception caught" << std::endl; - throw; - } +#ifdef MAPNIK_DEBUG + std::clog << "Raster Plugin: RASTER SIZE(" << width_ << "," << height_ << ")" << std::endl; +#endif + is_bound_ = true; } @@ -165,13 +194,24 @@ featureset_ptr raster_datasource::features(query const& q) const std::clog << "Raster Plugin: BOX SIZE(" << width << " " << height << ")" << std::endl; #endif - if (width * height > 512*512) + if (multi_tiles_) + { +#ifdef MAPNIK_DEBUG + std::clog << "Raster Plugin: MULTI-TILED policy" << std::endl; +#endif + + tiled_multi_file_policy policy(filename_, format_, tile_size_, extent_, q.get_bbox(), width_, height_, tile_stride_); + + return boost::make_shared >(policy, extent_, q); + } + else if (width * height > 512*512) { #ifdef MAPNIK_DEBUG std::clog << "Raster Plugin: TILED policy" << std::endl; #endif tiled_file_policy policy(filename_, format_, 256, extent_, q.get_bbox(), width_, height_); + return boost::make_shared >(policy, extent_, q); } else @@ -182,13 +222,16 @@ featureset_ptr raster_datasource::features(query const& q) const raster_info info(filename_, format_, extent_, width_, height_); single_file_policy policy(info); + return boost::make_shared >(policy, extent_, q); } } featureset_ptr raster_datasource::features_at_point(coord2d const&) const { - std::clog << "Raster Plugin: ##WARNING: feature_at_point not supported for raster.input" << std::endl; +#ifdef MAPNIK_DEBUG + std::clog << "Raster Plugin: feature_at_point not supported for raster.input" << std::endl; +#endif + return featureset_ptr(); } - diff --git a/plugins/input/raster/raster_datasource.hpp b/plugins/input/raster/raster_datasource.hpp index c8f5f4745..51c723ffe 100644 --- a/plugins/input/raster/raster_datasource.hpp +++ b/plugins/input/raster/raster_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: raster_datasource.hh 44 2005-04-22 18:53:54Z pavlenko $ #ifndef RASTER_DATASOURCE_HPP #define RASTER_DATASOURCE_HPP @@ -31,28 +30,30 @@ class raster_datasource : public mapnik::datasource { - private: - mapnik::layer_descriptor desc_; - std::string filename_; - std::string format_; - mapnik::box2d extent_; - bool extent_initialized_; - mutable unsigned width_; - mutable unsigned height_; - public: - raster_datasource(const mapnik::parameters& params, bool bind=true); - virtual ~raster_datasource(); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(const mapnik::query& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - //no copying - raster_datasource(const raster_datasource&); - raster_datasource& operator=(const raster_datasource&); +public: + raster_datasource(const mapnik::parameters& params, bool bind=true); + virtual ~raster_datasource(); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(const mapnik::query& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; +private: + mapnik::layer_descriptor desc_; + std::string filename_; + std::string format_; + mapnik::box2d extent_; + bool extent_initialized_; + bool multi_tiles_; + unsigned tile_size_; + unsigned tile_stride_; + mutable unsigned width_; + mutable unsigned height_; + //no copying + raster_datasource(const raster_datasource&); + raster_datasource& operator=(const raster_datasource&); }; -#endif //RASTER_DATASOURCE_HPP +#endif // RASTER_DATASOURCE_HPP diff --git a/plugins/input/raster/raster_featureset.cpp b/plugins/input/raster/raster_featureset.cpp index 57a797f50..ace1c3975 100644 --- a/plugins/input/raster/raster_featureset.cpp +++ b/plugins/input/raster/raster_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -25,8 +25,10 @@ #include #include -#include "raster_featureset.hpp" +// boost +#include +#include "raster_featureset.hpp" using mapnik::query; using mapnik::CoordTransform; @@ -41,85 +43,114 @@ template raster_featureset::raster_featureset(LookupPolicy const& policy, box2d const& extent, query const& q) - : policy_(policy), - feature_id_(1), - extent_(extent), - bbox_(q.get_bbox()), - curIter_(policy_.begin()), - endIter_(policy_.end()) -{} + : policy_(policy), + feature_id_(1), + extent_(extent), + bbox_(q.get_bbox()), + curIter_(policy_.begin()), + endIter_(policy_.end()) +{ +} template -raster_featureset::~raster_featureset() {} +raster_featureset::~raster_featureset() +{ +} template feature_ptr raster_featureset::next() { - if (curIter_!=endIter_) - { - feature_ptr feature(feature_factory::create(feature_id_)); - ++feature_id_; - try - { - std::auto_ptr reader(mapnik::get_image_reader(curIter_->file(),curIter_->format())); + if (curIter_ != endIter_) + { + feature_ptr feature(feature_factory::create(feature_id_)); + ++feature_id_; + + try + { + std::auto_ptr reader(mapnik::get_image_reader(curIter_->file(),curIter_->format())); #ifdef MAPNIK_DEBUG - std::clog << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file() - << " size(" << curIter_->width() << "," << curIter_->height() << ")" << std::endl; + std::clog << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file() + << " size(" << curIter_->width() << "," << curIter_->height() << ")" << std::endl; #endif - if (reader.get()) - { - int image_width=reader->width(); - int image_height=reader->height(); - - if (image_width>0 && image_height>0) - { - CoordTransform t(image_width,image_height,extent_,0,0); - box2d intersect=bbox_.intersect(curIter_->envelope()); - box2d ext=t.forward(intersect); - if ( ext.width()>0.5 && ext.height()>0.5 ) - { - //select minimum raster containing whole ext - int x_off = static_cast(floor(ext.minx())); - int y_off = static_cast(floor(ext.miny())); - int end_x = static_cast(ceil(ext.maxx())); - int end_y = static_cast(ceil(ext.maxy())); - //clip to available data - if (x_off < 0) - x_off = 0; - if (y_off < 0) - y_off = 0; - if (end_x > image_width) - end_x = image_width; - if (end_y > image_height) - end_y = image_height; - int width = end_x - x_off; - int height = end_y - y_off; - //calculate actual box2d of returned raster - box2d feature_raster_extent(x_off, y_off, x_off+width, y_off+height); - intersect = t.backward(feature_raster_extent); - image_data_32 image(width,height); - reader->read(x_off,y_off,image); - feature->set_raster(boost::make_shared(intersect,image)); - } + if (reader.get()) + { + int image_width = policy_.img_width(reader->width()); + int image_height = policy_.img_height(reader->height()); + + if (image_width > 0 && image_height > 0) + { + CoordTransform t(image_width, image_height, extent_, 0, 0); + box2d intersect = bbox_.intersect(curIter_->envelope()); + box2d ext = t.forward(intersect); + box2d rem = policy_.transform(ext); + if (ext.width() > 0.5 && ext.height() > 0.5 ) + { + // select minimum raster containing whole ext + int x_off = static_cast(floor(ext.minx())); + int y_off = static_cast(floor(ext.miny())); + int end_x = static_cast(ceil(ext.maxx())); + int end_y = static_cast(ceil(ext.maxy())); + + // clip to available data + if (x_off < 0) + x_off = 0; + if (y_off < 0) + y_off = 0; + if (end_x > image_width) + end_x = image_width; + if (end_y > image_height) + end_y = image_height; + int width = end_x - x_off; + int height = end_y - y_off; + + // calculate actual box2d of returned raster + box2d feature_raster_extent(rem.minx() + x_off, + rem.miny() + y_off, + rem.maxx() + x_off + width, + rem.maxy() + y_off + height); + intersect = t.backward(feature_raster_extent); + + image_data_32 image(width,height); + reader->read(x_off, y_off, image); + feature->set_raster(boost::make_shared(intersect, image)); + } + } } - } - } - catch (mapnik::image_reader_exception const& ex) - { - std::cerr << "Raster Plugin: image reader exception caught:" << ex.what() << std::endl; - } - catch (...) - { - std::cerr << "Raster Plugin: exception caught" << std::endl; - } + } + catch (mapnik::image_reader_exception const& ex) + { + std::cerr << "Raster Plugin: image reader exception caught: " << ex.what() << std::endl; + } + catch (std::exception const& ex) + { + std::cerr << "Raster Plugin: " << ex.what() << std::endl; + } + catch (...) + { + std::cerr << "Raster Plugin: exception caught" << std::endl; + } - ++curIter_; - return feature; - } - return feature_ptr(); + ++curIter_; + return feature; + } + return feature_ptr(); +} + +std::string tiled_multi_file_policy::interpolate(std::string const& pattern, int x, int y) const +{ + // TODO: make from some sort of configurable interpolation + int tms_y = tile_stride_ * ((image_height_ / tile_size_) - y - 1); + int tms_x = tile_stride_ * x; + std::string xs = (boost::format("%03d/%03d/%03d") % (tms_x / 1000000) % ((tms_x / 1000) % 1000) % (tms_x % 1000)).str(); + std::string ys = (boost::format("%03d/%03d/%03d") % (tms_y / 1000000) % ((tms_y / 1000) % 1000) % (tms_y % 1000)).str(); + std::string rv(pattern); + boost::algorithm::replace_all(rv, "${x}", xs); + boost::algorithm::replace_all(rv, "${y}", ys); + return rv; } template class raster_featureset; template class raster_featureset; +template class raster_featureset; diff --git a/plugins/input/raster/raster_featureset.hpp b/plugins/input/raster/raster_featureset.hpp index 879b2e848..7936edc4e 100644 --- a/plugins/input/raster/raster_featureset.hpp +++ b/plugins/input/raster/raster_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,17 +19,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ + #ifndef RASTER_FEATURESET_HPP #define RASTER_FEATURESET_HPP -#include - #include "raster_datasource.hpp" #include "raster_info.hpp" +// stl +#include + // boost #include - +#include class single_file_policy { @@ -42,19 +44,19 @@ public: const single_file_policy* p_; public: explicit const_iterator(const single_file_policy* p) - :status_(start), - p_(p) {} + : status_(start), + p_(p) {} const_iterator() - :status_(end){} + : status_(end) {} const_iterator(const const_iterator& other) - :status_(other.status_), - p_(other.p_) {} + : status_(other.status_), + p_(other.p_) {} const_iterator& operator++() { - status_=end; + status_ = end; return *this; } @@ -70,12 +72,12 @@ public: bool operator!=(const const_iterator& itr) { - return status_!=itr.status_; + return status_ != itr.status_; } }; explicit single_file_policy(const raster_info& info) - :info_(info) {} + : info_(info) {} const_iterator begin() { @@ -95,85 +97,227 @@ public: { return const_iterator(); } + + inline int img_width(int reader_width) const + { + return reader_width; + } + + inline int img_height(int reader_height) const + { + return reader_height; + } + + inline box2d transform(box2d &) const + { + return box2d(0, 0, 0, 0); + } }; class tiled_file_policy { public: - typedef std::vector::const_iterator const_iterator; + typedef std::vector::const_iterator const_iterator; - tiled_file_policy(std::string const& file, std::string const& format, unsigned tile_size, - box2d extent, box2d bbox,unsigned width, unsigned height) - { - - double lox = extent.minx(); - double loy = extent.miny(); + tiled_file_policy(std::string const& file, + std::string const& format, + unsigned tile_size, + box2d extent, + box2d bbox, + unsigned width, + unsigned height) + { + double lox = extent.minx(); + double loy = extent.miny(); - int max_x = int(std::ceil(double(width)/double(tile_size))); - int max_y = int(std::ceil(double(height)/double(tile_size))); + int max_x = int(std::ceil(double(width) / double(tile_size))); + int max_y = int(std::ceil(double(height) / double(tile_size))); - double pixel_x = extent.width()/double(width); - double pixel_y = extent.height()/double(height); + double pixel_x = extent.width() / double(width); + double pixel_y = extent.height() / double(height); #ifdef MAPNIK_DEBUG - std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl; + std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl; #endif - box2d e = bbox.intersect(extent); + box2d e = bbox.intersect(extent); - for (int x = 0 ; x < max_x ; ++x) - { - for (int y = 0 ; y < max_y ; ++y) - { - double x0 = lox + x*tile_size*pixel_x; - double y0 = loy + y*tile_size*pixel_y; - double x1 = x0 + tile_size*pixel_x; - double y1 = y0 + tile_size*pixel_y; - - if (e.intersects(box2d(x0,y0,x1,y1))) + for (int x = 0; x < max_x; ++x) + { + for (int y = 0; y < max_y; ++y) { - box2d tile_box = e.intersect(box2d(x0,y0,x1,y1)); - raster_info info(file,format,tile_box,tile_size,tile_size); - infos_.push_back(info); + double x0 = lox + x * tile_size * pixel_x; + double y0 = loy + y * tile_size * pixel_y; + double x1 = x0 + tile_size * pixel_x; + double y1 = y0 + tile_size * pixel_y; + + if (e.intersects(box2d(x0, y0, x1, y1))) + { + box2d tile_box = e.intersect(box2d(x0,y0,x1,y1)); + raster_info info(file,format,tile_box,tile_size,tile_size); + infos_.push_back(info); + } } - } - } + } #ifdef MAPNIK_DEBUG - std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl; + std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl; #endif - } + } - const_iterator begin() - { - return infos_.begin(); - } + const_iterator begin() + { + return infos_.begin(); + } - const_iterator end() - { - return infos_.end(); - } + const_iterator end() + { + return infos_.end(); + } + inline int img_width(int reader_width) const + { + return reader_width; + } + + inline int img_height(int reader_height) const + { + return reader_height; + } + + inline box2d transform(box2d&) const + { + return box2d(0, 0, 0, 0); + } + private: - std::vector infos_; + std::vector infos_; }; +class tiled_multi_file_policy +{ +public: + + typedef std::vector::const_iterator const_iterator; + + tiled_multi_file_policy(std::string const& file_pattern, + std::string const& format, + unsigned tile_size, + box2d extent, + box2d bbox, + unsigned width, + unsigned height, + unsigned tile_stride) + : image_width_(width), + image_height_(height), + tile_size_(tile_size), + tile_stride_(tile_stride) + { + double lox = extent.minx(); + double loy = extent.miny(); + + //int max_x = int(std::ceil(double(width) / double(tile_size))); + //int max_y = int(std::ceil(double(height) / double(tile_size))); + + double pixel_x = extent.width() / double(width); + double pixel_y = extent.height() / double(height); + +#ifdef MAPNIK_DEBUG + std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl; +#endif + + // intersection of query with extent => new query + box2d e = bbox.intersect(extent); + + const int x_min = int(std::floor((e.minx() - lox) / (tile_size * pixel_x))); + const int y_min = int(std::floor((e.miny() - loy) / (tile_size * pixel_y))); + const int x_max = int(std::ceil((e.maxx() - lox) / (tile_size * pixel_x))); + const int y_max = int(std::ceil((e.maxy() - loy) / (tile_size * pixel_y))); + + for (int x = x_min; x < x_max; ++x) + { + for (int y = y_min; y < y_max; ++y) + { + // x0, y0, x1, y1 => projection-space image coordinates. + double x0 = lox + x*tile_size*pixel_x; + double y0 = loy + y*tile_size*pixel_y; + double x1 = x0 + tile_size*pixel_x; + double y1 = y0 + tile_size*pixel_y; + + // check if it intersects the query + if (e.intersects(box2d(x0,y0,x1,y1))) + { + // tile_box => intersection of tile with query in projection-space. + box2d tile_box = e.intersect(box2d(x0,y0,x1,y1)); + std::string file = interpolate(file_pattern, x, y); + raster_info info(file,format,tile_box,tile_size,tile_size); + infos_.push_back(info); + } + } + } +#ifdef MAPNIK_DEBUG + std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file_pattern << std::endl; +#endif + } + + const_iterator begin() + { + return infos_.begin(); + } + + const_iterator end() + { + return infos_.end(); + } + + inline int img_width(int) const + { + return image_width_; + } + + inline int img_height(int) const + { + return image_height_; + } + + inline box2d transform(box2d& box) const + { + int x_offset = int(std::floor(box.minx() / tile_size_)); + int y_offset = int(std::floor(box.miny() / tile_size_)); + box2d rem(x_offset * tile_size_, + y_offset * tile_size_, + x_offset * tile_size_, + y_offset * tile_size_); + box.init(box.minx() - rem.minx(), + box.miny() - rem.miny(), + box.maxx() - rem.maxx(), + box.maxy() - rem.maxy()); + return rem; + } + +private: + + std::string interpolate(std::string const& pattern, int x, int y) const; + + unsigned int image_width_, image_height_, tile_size_, tile_stride_; + std::vector infos_; +}; template class raster_featureset : public mapnik::Featureset { - typedef typename LookupPolicy::const_iterator iterator_type; - LookupPolicy policy_; - int feature_id_; - mapnik::box2d extent_; - mapnik::box2d bbox_; - iterator_type curIter_; - iterator_type endIter_; + typedef typename LookupPolicy::const_iterator iterator_type; + LookupPolicy policy_; + int feature_id_; + mapnik::box2d extent_; + mapnik::box2d bbox_; + iterator_type curIter_; + iterator_type endIter_; public: - raster_featureset(LookupPolicy const& policy,box2d const& exttent, mapnik::query const& q); - virtual ~raster_featureset(); - mapnik::feature_ptr next(); + raster_featureset(LookupPolicy const& policy,box2d const& exttent, mapnik::query const& q); + virtual ~raster_featureset(); + mapnik::feature_ptr next(); }; -#endif //RASTER_FEATURESET_HPP +#endif // RASTER_FEATURESET_HPP diff --git a/plugins/input/raster/raster_info.cpp b/plugins/input/raster/raster_info.cpp index 72ec49a59..ea3d219ab 100644 --- a/plugins/input/raster/raster_info.cpp +++ b/plugins/input/raster/raster_info.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,32 +19,38 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: raster_info.cc 17 2005-03-08 23:58:43Z pavlenko $ #include "raster_info.hpp" -raster_info::raster_info(std::string const& file, std::string const& format, - mapnik::box2d const& extent, unsigned width, unsigned height) - :file_(file), - format_(format), - extent_(extent), - width_(width), - height_(height) {} +raster_info::raster_info(std::string const& file, + std::string const& format, + mapnik::box2d const& extent, + unsigned width, + unsigned height) + : file_(file), + format_(format), + extent_(extent), + width_(width), + height_(height) +{ +} raster_info::raster_info(const raster_info& rhs) - :file_(rhs.file_), - format_(rhs.format_), - extent_(rhs.extent_), - width_(rhs.width_), - height_(rhs.height_) {} + : file_(rhs.file_), + format_(rhs.format_), + extent_(rhs.extent_), + width_(rhs.width_), + height_(rhs.height_) +{ +} void raster_info::swap(raster_info& other) throw() { - file_=other.file_; - format_=other.format_; - extent_=other.extent_; - width_=other.width_; - height_=other.height_; + file_ = other.file_; + format_ = other.format_; + extent_ = other.extent_; + width_ = other.width_; + height_ = other.height_; } @@ -54,6 +60,3 @@ raster_info& raster_info::operator=(const raster_info& rhs) swap(tmp); return *this; } - - - diff --git a/plugins/input/raster/raster_info.hpp b/plugins/input/raster/raster_info.hpp index 63ff43e18..40a650e83 100644 --- a/plugins/input/raster/raster_info.hpp +++ b/plugins/input/raster/raster_info.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -19,25 +19,25 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id: raster_info.hh 17 2005-03-08 23:58:43Z pavlenko $ #ifndef RASTER_INFO_HPP #define RASTER_INFO_HPP #include "raster_datasource.hpp" + +// stl #include using mapnik::box2d; class raster_info { - std::string file_; - std::string format_; - box2d extent_; - unsigned width_; - unsigned height_; public: - raster_info(const std::string& file,const std::string& format, const box2d& extent, unsigned width, unsigned height); + raster_info(const std::string& file, + const std::string& format, + const box2d& extent, + unsigned width, + unsigned height); raster_info(const raster_info& rhs); raster_info& operator=(const raster_info& rhs); inline box2d const& envelope() const {return extent_;} @@ -48,6 +48,12 @@ public: private: void swap(raster_info& other) throw(); + + std::string file_; + std::string format_; + box2d extent_; + unsigned width_; + unsigned height_; }; -#endif //RASTER_INFO_HPP +#endif // RASTER_INFO_HPP diff --git a/plugins/input/rasterlite/rasterlite_datasource.cpp b/plugins/input/rasterlite/rasterlite_datasource.cpp index 8fadb4e0b..eb68c2680 100644 --- a/plugins/input/rasterlite/rasterlite_datasource.cpp +++ b/plugins/input/rasterlite/rasterlite_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 diff --git a/plugins/input/rasterlite/rasterlite_datasource.hpp b/plugins/input/rasterlite/rasterlite_datasource.hpp index b3acd0117..85b0d6b9e 100644 --- a/plugins/input/rasterlite/rasterlite_datasource.hpp +++ b/plugins/input/rasterlite/rasterlite_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,36 +19,39 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef RASTERLITE_DATASOURCE_HPP #define RASTERLITE_DATASOURCE_HPP +// mapnik #include + +// boost #include #include "rasterlite_include.hpp" class rasterlite_datasource : public mapnik::datasource { - public: - rasterlite_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~rasterlite_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - inline void *open_dataset() const; - mutable mapnik::box2d extent_; - std::string dataset_name_; - std::string table_name_; - mapnik::layer_descriptor desc_; - unsigned width_; - unsigned height_; +public: + rasterlite_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~rasterlite_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; + +private: + inline void* open_dataset() const; + mutable mapnik::box2d extent_; + std::string dataset_name_; + std::string table_name_; + mapnik::layer_descriptor desc_; + unsigned width_; + unsigned height_; }; #endif // RASTERLITE_DATASOURCE_HPP diff --git a/plugins/input/rasterlite/rasterlite_featureset.cpp b/plugins/input/rasterlite/rasterlite_featureset.cpp index 69b11c964..8feb925ca 100644 --- a/plugins/input/rasterlite/rasterlite_featureset.cpp +++ b/plugins/input/rasterlite/rasterlite_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #include "rasterlite_featureset.hpp" @@ -43,9 +42,9 @@ using mapnik::feature_factory; rasterlite_featureset::rasterlite_featureset(void* dataset, rasterlite_query q) - : dataset_(dataset), - gquery_(q), - first_(true) + : dataset_(dataset), + gquery_(q), + first_(true) { rasterliteSetBackgroundColor(dataset_, 255, 0, 255); rasterliteSetTransparentColor(dataset_, 255, 0, 255); @@ -67,11 +66,15 @@ feature_ptr rasterlite_featureset::next() first_ = false; query *q = boost::get(&gquery_); - if(q) { + if (q) + { return get_feature(*q); - } else { + } + else + { coord2d *p = boost::get(&gquery_); - if(p) { + if (p) + { return get_feature_at_point(*p); } } @@ -91,7 +94,7 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q) double x0, y0, x1, y1; rasterliteGetExtent (dataset_, &x0, &y0, &x1, &y1); - box2d raster_extent(x0,y0,x1,y1); + box2d raster_extent(x0, y0, x1, y1); box2d intersect = raster_extent.intersect(q.get_bbox()); const int width = static_cast(boost::get<0>(q.resolution()) * intersect.width() + 0.5); @@ -104,8 +107,8 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q) std::clog << "Rasterlite Plugin: Raster extent=" << raster_extent << std::endl; std::clog << "Rasterlite Plugin: View extent=" << q.get_bbox() << std::endl; std::clog << "Rasterlite Plugin: Intersect extent=" << intersect << std::endl; - std::clog << "Rasterlite Plugin: Query resolution=" << boost::get<0>(q.resolution()) - << "," << boost::get<1>(q.resolution()) << std::endl; + std::clog << "Rasterlite Plugin: Query resolution=" + << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution()) << std::endl; std::clog << "Rasterlite Plugin: Size=" << width << " " << height << std::endl; std::clog << "Rasterlite Plugin: Pixel Size=" << pixel_size << std::endl; #endif @@ -113,11 +116,19 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q) if (width > 0 && height > 0) { int size = 0; - void *raster = 0; + void* raster = 0; if (rasterliteGetRawImageByRect(dataset_, - intersect.minx(), intersect.miny(), intersect.maxx(), intersect.maxy(), - pixel_size, width, height, GAIA_RGBA_ARRAY, &raster, &size) == RASTERLITE_OK) + intersect.minx(), + intersect.miny(), + intersect.maxx(), + intersect.maxy(), + pixel_size, + width, + height, + GAIA_RGBA_ARRAY, + &raster, + &size) == RASTERLITE_OK) { if (size > 0) { @@ -150,9 +161,7 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q) return feature_ptr(); } - feature_ptr rasterlite_featureset::get_feature_at_point(mapnik::coord2d const& pt) { return feature_ptr(); } - diff --git a/plugins/input/rasterlite/rasterlite_featureset.hpp b/plugins/input/rasterlite/rasterlite_featureset.hpp index 0db77cce2..9b83c1fa2 100644 --- a/plugins/input/rasterlite/rasterlite_featureset.hpp +++ b/plugins/input/rasterlite/rasterlite_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,12 +19,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef RASTERLITE_FEATURESET_HPP #define RASTERLITE_FEATURESET_HPP +// mapnik #include + +// boost #include #include "rasterlite_include.hpp" @@ -33,16 +35,17 @@ typedef boost::variant rasterlite_query; class rasterlite_featureset : public mapnik::Featureset { - public: - rasterlite_featureset(void* dataset, rasterlite_query q); - virtual ~rasterlite_featureset(); - mapnik::feature_ptr next(); - private: - mapnik::feature_ptr get_feature(mapnik::query const& q); - mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p); - void* dataset_; - rasterlite_query gquery_; - bool first_; +public: + rasterlite_featureset(void* dataset, rasterlite_query q); + virtual ~rasterlite_featureset(); + mapnik::feature_ptr next(); + +private: + mapnik::feature_ptr get_feature(mapnik::query const& q); + mapnik::feature_ptr get_feature_at_point(mapnik::coord2d const& p); + void* dataset_; + rasterlite_query gquery_; + bool first_; }; #endif // RASTERLITE_FEATURESET_HPP diff --git a/plugins/input/rasterlite/rasterlite_include.hpp b/plugins/input/rasterlite/rasterlite_include.hpp index c1c953768..843d01ca2 100644 --- a/plugins/input/rasterlite/rasterlite_include.hpp +++ b/plugins/input/rasterlite/rasterlite_include.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,14 +19,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef RASTERLITE_INCLUDE_HPP #define RASTERLITE_INCLUDE_HPP extern "C" { - #include - #include + #include + #include } -#endif // RASTERLITE_FEATURESET_HPP +#endif // RASTERLITE_INCLUDE_HPP diff --git a/plugins/input/shape/dbf_test.cpp b/plugins/input/shape/dbf_test.cpp index c59a4d064..5a5d48fbf 100644 --- a/plugins/input/shape/dbf_test.cpp +++ b/plugins/input/shape/dbf_test.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/shape/dbfile.cpp b/plugins/input/shape/dbfile.cpp index 63b390637..47a67d8e7 100644 --- a/plugins/input/shape/dbfile.cpp +++ b/plugins/input/shape/dbfile.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/shape/dbfile.hpp b/plugins/input/shape/dbfile.hpp index f2e4e3dab..f855c9a1e 100644 --- a/plugins/input/shape/dbfile.hpp +++ b/plugins/input/shape/dbfile.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/shape/shape_datasource.cpp b/plugins/input/shape/shape_datasource.cpp index f6ca9abfb..45f2b3158 100644 --- a/plugins/input/shape/shape_datasource.cpp +++ b/plugins/input/shape/shape_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/shape/shape_datasource.hpp b/plugins/input/shape/shape_datasource.hpp index 5fc85d0ed..477b8035b 100644 --- a/plugins/input/shape/shape_datasource.hpp +++ b/plugins/input/shape/shape_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/shape/shape_featureset.cpp b/plugins/input/shape/shape_featureset.cpp index efb95aec5..6fbcf5820 100644 --- a/plugins/input/shape/shape_featureset.cpp +++ b/plugins/input/shape/shape_featureset.cpp @@ -3,7 +3,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -21,15 +21,15 @@ * *****************************************************************************/ +// stl +#include + // mapnik #include // boost #include -// stl -#include - #include "shape_featureset.hpp" using mapnik::geometry_type; @@ -42,22 +42,23 @@ shape_featureset::shape_featureset(const filterT& filter, std::string const& encoding, long file_length, int row_limit) - : filter_(filter), - //shape_type_(shape_io::shape_null), - shape_(shape_name, false), - query_ext_(), - tr_(new transcoder(encoding)), - file_length_(file_length), - count_(0), - row_limit_(row_limit) + : filter_(filter), + //shape_type_(shape_io::shape_null), + shape_(shape_name, false), + query_ext_(), + tr_(new transcoder(encoding)), + file_length_(file_length), + count_(0), + row_limit_(row_limit) { shape_.shp().skip(100); + //attributes - typename std::set::const_iterator pos=attribute_names.begin(); - while (pos!=attribute_names.end()) + typename std::set::const_iterator pos = attribute_names.begin(); + while (pos != attribute_names.end()) { bool found_name = false; - for (int i=0;i::shape_featureset(const filterT& filter, break; } } - if (!found_name) + + if (! found_name) { std::ostringstream s; s << "no attribute '" << *pos << "' in '" << shape_name << "'. Valid attributes are: "; + std::vector list; - for (int i=0;i feature_ptr shape_featureset::next() { if (row_limit_ && count_ > row_limit_) + { return feature_ptr(); + } + + std::streampos pos = shape_.shp().pos(); - std::streampos pos=shape_.shp().pos(); // skip null shapes while (pos > 0 && pos < std::streampos(file_length_ * 2)) { shape_.move_to(pos); - if (shape_.type() == shape_io::shape_null) + if (shape_.type() == shape_io::shape_null) { pos += std::streampos(12); } - else break; + else + { + break; + } } if (pos < std::streampos(file_length_ * 2)) { - int type=shape_.type(); + int type = shape_.type(); feature_ptr feature(feature_factory::create(shape_.id_)); if (type == shape_io::shape_point) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); ++count_; } else if (type == shape_io::shape_pointm) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - shape_.shp().skip(8); //m - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + // skip m + shape_.shp().skip(8); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); ++count_; } else if (type == shape_io::shape_pointz) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); // skip z shape_.shp().skip(8); - - //skip m if exists - if ( shape_.reclength_ == 8 + 36) + // skip m if exists + if (shape_.reclength_ == 8 + 36) { shape_.shp().skip(8); } - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); ++count_; } @@ -153,11 +161,19 @@ feature_ptr shape_featureset::next() std::streampos pos = shape_.shp().pos(); if (shape_.type() == shape_io::shape_null) { - pos += std::streampos(12); + pos += std::streampos(12); + // TODO handle the shapes std::cerr << "NULL SHAPE len=" << shape_.reclength_ << std::endl; - } - else if (filter_.pass(shape_.current_extent())) break; - else pos += std::streampos(2 * shape_.reclength_ - 36); + } + else if (filter_.pass(shape_.current_extent())) + { + break; + } + else + { + pos += std::streampos(2 * shape_.reclength_ - 36); + } + if (pos > 0 && pos < std::streampos(file_length_ * 2)) { shape_.move_to(pos); @@ -176,97 +192,104 @@ feature_ptr shape_featureset::next() case shape_io::shape_multipoint: { int num_points = shape_.shp().read_ndr_integer(); - for (int i=0; i< num_points;++i) + for (int i = 0; i < num_points; ++i) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); } ++count_; break; } + case shape_io::shape_multipointm: { int num_points = shape_.shp().read_ndr_integer(); - for (int i=0; i< num_points;++i) + for (int i = 0; i < num_points; ++i) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); } - - // skip m - shape_.shp().skip(2*8 + 8*num_points); + + // skip m + shape_.shp().skip(2 * 8 + 8 * num_points); ++count_; break; } + case shape_io::shape_multipointz: { - unsigned num_points = shape_.shp().read_ndr_integer(); - for (unsigned i=0; i< num_points;++i) + int num_points = shape_.shp().read_ndr_integer(); + for (int i = 0; i < num_points; ++i) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); } - + // skip z - shape_.shp().skip(2*8 + 8*num_points); + shape_.shp().skip(2 * 8 + 8 * num_points); // check if we have measure data - - if ( shape_.reclength_ == num_points * 16 + 36) + if (shape_.reclength_ == (unsigned)(num_points * 16 + 36)) { // skip m - shape_.shp().skip(2*8 + 8*num_points); + shape_.shp().skip(2 * 8 + 8 * num_points); } ++count_; break; } + case shape_io::shape_polyline: { - geometry_type * line = shape_.read_polyline(); + geometry_type* line = shape_.read_polyline(); feature->add_geometry(line); ++count_; break; } + case shape_io::shape_polylinem: { - geometry_type * line = shape_.read_polylinem(); + geometry_type* line = shape_.read_polylinem(); feature->add_geometry(line); ++count_; break; } + case shape_io::shape_polylinez: { - geometry_type * line = shape_.read_polylinez(); + geometry_type* line = shape_.read_polylinez(); feature->add_geometry(line); ++count_; break; } + case shape_io::shape_polygon: { - geometry_type * poly = shape_.read_polygon(); + geometry_type* poly = shape_.read_polygon(); feature->add_geometry(poly); ++count_; break; } + case shape_io::shape_polygonm: { - geometry_type * poly = shape_.read_polygonm(); + geometry_type* poly = shape_.read_polygonm(); feature->add_geometry(poly); ++count_; break; } + case shape_io::shape_polygonz: { - geometry_type * poly = shape_.read_polygonz(); + geometry_type* poly = shape_.read_polygonz(); feature->add_geometry(poly); ++count_; break; @@ -278,13 +301,13 @@ feature_ptr shape_featureset::next() if (attr_ids_.size()) { shape_.dbf().move_to(shape_.id_); - std::vector::const_iterator itr=attr_ids_.begin(); - std::vector::const_iterator end=attr_ids_.end(); + std::vector::const_iterator itr = attr_ids_.begin(); + std::vector::const_iterator end = attr_ids_.end(); try { - for (;itr!=end;++itr) + for (; itr != end; ++itr) { - shape_.dbf().add_attribute(*itr,*tr_,*feature);//TODO optimize!!! + shape_.dbf().add_attribute(*itr, *tr_, *feature); //TODO optimize!!! } } catch (...) @@ -292,6 +315,7 @@ feature_ptr shape_featureset::next() std::clog << "Shape Plugin: error processing attributes " << std::endl; } } + return feature; } else @@ -308,5 +332,3 @@ shape_featureset::~shape_featureset() {} template class shape_featureset; template class shape_featureset; - - diff --git a/plugins/input/shape/shape_featureset.hpp b/plugins/input/shape/shape_featureset.hpp index 285e74fa7..ec8e6d0c5 100644 --- a/plugins/input/shape/shape_featureset.hpp +++ b/plugins/input/shape/shape_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/plugins/input/shape/shape_index_featureset.cpp b/plugins/input/shape/shape_index_featureset.cpp index 20a0b2e7c..c14f04d6c 100644 --- a/plugins/input/shape/shape_index_featureset.cpp +++ b/plugins/input/shape/shape_index_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,7 +20,8 @@ * *****************************************************************************/ -//$Id: shape_index_featureset.cc 36 2005-04-05 14:32:18Z pavlenko $ +// stl +#include // mapnik #include @@ -29,9 +30,6 @@ #include #include -// stl -#include - #include "shape_index_featureset.hpp" using mapnik::feature_factory; @@ -44,26 +42,27 @@ shape_index_featureset::shape_index_featureset(const filterT& filter, std::string const& encoding, std::string const& shape_name, int row_limit) - : filter_(filter), - //shape_type_(0), - shape_(shape), - tr_(new transcoder(encoding)), - count_(0), - row_limit_(row_limit) - + : filter_(filter), + //shape_type_(0), + shape_(shape), + tr_(new transcoder(encoding)), + count_(0), + row_limit_(row_limit) { shape_.shp().skip(100); + boost::shared_ptr index = shape_.index(); if (index) { #ifdef SHAPE_MEMORY_MAPPED_FILE - //shp_index >::query(filter,index->file(),ids_); - shp_index::query(filter,index->file(),ids_); + //shp_index >::query(filter, index->file(), ids_); + shp_index::query(filter, index->file(), ids_); #else - shp_index::query(filter,index->file(),ids_); + shp_index::query(filter, index->file(), ids_); #endif } - std::sort(ids_.begin(),ids_.end()); + + std::sort(ids_.begin(), ids_.end()); #ifdef MAPNIK_DEBUG std::clog << "Shape Plugin: query size=" << ids_.size() << std::endl; @@ -72,11 +71,11 @@ shape_index_featureset::shape_index_featureset(const filterT& filter, itr_ = ids_.begin(); // deal with attributes - std::set::const_iterator pos=attribute_names.begin(); - while (pos!=attribute_names.end()) + std::set::const_iterator pos = attribute_names.begin(); + while (pos != attribute_names.end()) { bool found_name = false; - for (int i=0;i::shape_index_featureset(const filterT& filter, break; } } - if (!found_name) + + if (! found_name) { std::ostringstream s; + s << "no attribute '" << *pos << "' in '" << shape_name << "'. Valid attributes are: "; - s << "no attribute '" << *pos << "' in '" - << shape_name << "'. Valid attributes are: "; std::vector list; - for (int i=0;i feature_ptr shape_index_featureset::next() { if (row_limit_ && count_ > row_limit_) - return feature_ptr(); - - if (itr_!=ids_.end()) { - int pos=*itr_++; + return feature_ptr(); + } + + if (itr_ != ids_.end()) + { + int pos = *itr_++; shape_.move_to(pos); - int type=shape_.type(); + + int type = shape_.type(); feature_ptr feature(feature_factory::create(shape_.id_)); if (type == shape_io::shape_point) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); ++count_; } - else if (type == shape_io::shape_pointm) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - shape_.shp().skip(8);// skip m - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + // skip m + shape_.shp().skip(8); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); ++count_; } else if (type == shape_io::shape_pointz) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); // skip z shape_.shp().skip(8); - - //skip m if exists - if ( shape_.reclength_ == 8 + 36) + // skip m if exists + if (shape_.reclength_ == 8 + 36) { shape_.shp().skip(8); } - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); ++count_; } else { - while(!filter_.pass(shape_.current_extent()) && - itr_!=ids_.end()) + while(! filter_.pass(shape_.current_extent()) && + itr_ != ids_.end()) { if (shape_.type() != shape_io::shape_null) { - pos=*itr_++; + pos = *itr_++; shape_.move_to(pos); } else @@ -176,56 +179,62 @@ feature_ptr shape_index_featureset::next() case shape_io::shape_multipointz: { int num_points = shape_.shp().read_ndr_integer(); - for (int i=0; i< num_points;++i) + for (int i = 0; i < num_points; ++i) { - double x=shape_.shp().read_double(); - double y=shape_.shp().read_double(); - geometry_type * point = new geometry_type(mapnik::Point); - point->move_to(x,y); + double x = shape_.shp().read_double(); + double y = shape_.shp().read_double(); + geometry_type* point = new geometry_type(mapnik::Point); + point->move_to(x, y); feature->add_geometry(point); } // ignore m and z for now ++count_; break; } + case shape_io::shape_polyline: { - geometry_type * line = shape_.read_polyline(); + geometry_type* line = shape_.read_polyline(); feature->add_geometry(line); ++count_; break; } + case shape_io::shape_polylinem: { - geometry_type * line = shape_.read_polylinem(); + geometry_type* line = shape_.read_polylinem(); feature->add_geometry(line); ++count_; break; } + case shape_io::shape_polylinez: { - geometry_type * line = shape_.read_polylinez(); + geometry_type* line = shape_.read_polylinez(); feature->add_geometry(line); ++count_; break; } + case shape_io::shape_polygon: { - geometry_type * poly = shape_.read_polygon(); + geometry_type* poly = shape_.read_polygon(); feature->add_geometry(poly); ++count_; break; } + case shape_io::shape_polygonm: { - geometry_type * poly = shape_.read_polygonm(); + geometry_type* poly = shape_.read_polygonm(); feature->add_geometry(poly); ++count_; break; } + case shape_io::shape_polygonz: { - geometry_type * poly = shape_.read_polygonz(); + geometry_type* poly = shape_.read_polygonz(); feature->add_geometry(poly); ++count_; break; @@ -237,18 +246,18 @@ feature_ptr shape_index_featureset::next() if (attr_ids_.size()) { shape_.dbf().move_to(shape_.id_); - std::set::const_iterator itr=attr_ids_.begin(); - std::set::const_iterator end=attr_ids_.end(); + std::set::const_iterator itr = attr_ids_.begin(); + std::set::const_iterator end = attr_ids_.end(); try { - for ( ; itr!=end; ++itr) + for (; itr!=end; ++itr) { - shape_.dbf().add_attribute(*itr,*tr_,*feature); + shape_.dbf().add_attribute(*itr, *tr_, *feature); } } catch (...) { - std::clog << "Shape Plugin: error processing attributes" << std::endl; + std::cerr << "Shape Plugin: error processing attributes" << std::endl; } } return feature; @@ -269,4 +278,3 @@ shape_index_featureset::~shape_index_featureset() {} template class shape_index_featureset; template class shape_index_featureset; - diff --git a/plugins/input/shape/shape_index_featureset.hpp b/plugins/input/shape/shape_index_featureset.hpp index c73fdd1cb..abc889075 100644 --- a/plugins/input/shape/shape_index_featureset.hpp +++ b/plugins/input/shape/shape_index_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -23,13 +23,18 @@ #ifndef SHAPE_INDEX_FEATURESET_HPP #define SHAPE_INDEX_FEATURESET_HPP +// stl +#include +#include + +// mapnik #include + +// boost #include #include "shape_datasource.hpp" #include "shape_io.hpp" -#include -#include using mapnik::Featureset; using mapnik::box2d; @@ -38,32 +43,31 @@ using mapnik::feature_ptr; template class shape_index_featureset : public Featureset { - filterT filter_; - //int shape_type_; - shape_io & shape_; - boost::scoped_ptr tr_; - std::vector ids_; - std::vector::iterator itr_; - std::set attr_ids_; - mutable box2d feature_ext_; - mutable int total_geom_size; - mutable int count_; - const int row_limit_; +public: + shape_index_featureset(const filterT& filter, + shape_io& shape, + const std::set& attribute_names, + std::string const& encoding, + std::string const& shape_name, + int row_limit); + virtual ~shape_index_featureset(); + feature_ptr next(); - public: - shape_index_featureset(const filterT& filter, - shape_io& shape, - const std::set& attribute_names, - std::string const& encoding, - std::string const& shape_name, - int row_limit); - virtual ~shape_index_featureset(); - feature_ptr next(); - - private: - //no copying - shape_index_featureset(const shape_index_featureset&); - shape_index_featureset& operator=(const shape_index_featureset&); +private: + filterT filter_; + //int shape_type_; + shape_io & shape_; + boost::scoped_ptr tr_; + std::vector ids_; + std::vector::iterator itr_; + std::set attr_ids_; + mutable box2d feature_ext_; + mutable int total_geom_size; + mutable int count_; + const int row_limit_; + //no copying + shape_index_featureset(const shape_index_featureset&); + shape_index_featureset& operator=(const shape_index_featureset&); }; -#endif //SHAPE_INDEX_FEATURESET_HPP +#endif // SHAPE_INDEX_FEATURESET_HPP diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index a6251733c..d219c8b78 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,10 +20,9 @@ * *****************************************************************************/ -//$Id: shape_io.cc 26 2005-03-29 19:18:59Z pavlenko $ - #include "shape_io.hpp" +// mapnik #include // boost @@ -38,22 +37,22 @@ const std::string shape_io::DBF = ".dbf"; const std::string shape_io::INDEX = ".index"; shape_io::shape_io(const std::string& shape_name, bool open_index) - : type_(shape_null), - shp_(shape_name + SHP), - dbf_(shape_name + DBF), - reclength_(0), - id_(0) + : type_(shape_null), + shp_(shape_name + SHP), + dbf_(shape_name + DBF), + reclength_(0), + id_(0) { bool ok = (shp_.is_open() && dbf_.is_open()); - if (!ok) + if (! ok) { throw datasource_exception("Shape Plugin: cannot read shape file '" + shape_name + "'"); } + if (open_index) { try { - index_= boost::make_shared(shape_name + INDEX); } catch (...) @@ -67,370 +66,398 @@ shape_io::shape_io(const std::string& shape_name, bool open_index) shape_io::~shape_io() {} -void shape_io::move_to (int pos) +void shape_io::move_to(int pos) { - shp_.seek(pos); - id_ = shp_.read_xdr_integer(); - reclength_ = shp_.read_xdr_integer(); - type_ = shp_.read_ndr_integer(); + shp_.seek(pos); + id_ = shp_.read_xdr_integer(); + reclength_ = shp_.read_xdr_integer(); + type_ = shp_.read_ndr_integer(); - if (type_!= shape_null && type_ != shape_point && type_ != shape_pointm && type_ != shape_pointz) - { - shp_.read_envelope(cur_extent_); - } + if (type_ != shape_null && type_ != shape_point && type_ != shape_pointm && type_ != shape_pointz) + { + shp_.read_envelope(cur_extent_); + } } int shape_io::type() const { - return type_; + return type_; } const box2d& shape_io::current_extent() const { - return cur_extent_; + return cur_extent_; } shape_file& shape_io::shp() { - return shp_; + return shp_; } -/*shape_file& shape_io::shx() +#if 0 +shape_file& shape_io::shx() { - return shx_; -}*/ - + return shx_; +} +#endif dbf_file& shape_io::dbf() { - return dbf_; + return dbf_; } -geometry_type * shape_io::read_polyline() +geometry_type* shape_io::read_polyline() { - shape_file::record_type record(reclength_*2-36); - shp_.read_record(record); - int num_parts=record.read_ndr_integer(); - int num_points=record.read_ndr_integer(); - geometry_type * line = new geometry_type(mapnik::LineString); - line->set_capacity(num_points + num_parts); - if (num_parts == 1) - { - line->set_capacity(num_points + 1); - record.skip(4); - double x=record.read_double(); - double y=record.read_double(); - line->move_to(x,y); - for (int i=1;iline_to(x,y); - } - } - else - { - std::vector parts(num_parts); - for (int i=0;iset_capacity(num_points + num_parts); + if (num_parts == 1) + { + line->set_capacity(num_points + 1); + record.skip(4); + double x = record.read_double(); + double y = record.read_double(); + line->move_to(x, y); + for (int i = 1; i < num_points; ++i) + { + x = record.read_double(); + y = record.read_double(); + line->line_to(x, y); + } + } + else + { + std::vector parts(num_parts); + for (int i = 0; i < num_parts; ++i) + { + parts[i] = record.read_ndr_integer(); + } + + int start, end; + for (int k = 0; k < num_parts; ++k) + { + start = parts[k]; + if (k == num_parts - 1) + { + end = num_points; + } + else + { + end = parts[k + 1]; + } - double x=record.read_double(); - double y=record.read_double(); - line->move_to(x,y); + double x = record.read_double(); + double y = record.read_double(); + line->move_to(x, y); - for (int j=start+1;jline_to(x,y); - } - } - } - return line; + for (int j = start + 1; j < end; ++j) + { + x = record.read_double(); + y = record.read_double(); + line->line_to(x, y); + } + } + } + return line; } -geometry_type * shape_io::read_polylinem() +geometry_type* shape_io::read_polylinem() { - shape_file::record_type record(reclength_*2-36); + shape_file::record_type record(reclength_ * 2 - 36); + shp_.read_record(record); + + int num_parts = record.read_ndr_integer(); + int num_points = record.read_ndr_integer(); + geometry_type* line = new geometry_type(mapnik::LineString); + line->set_capacity(num_points + num_parts); + if (num_parts == 1) + { + record.skip(4); + double x = record.read_double(); + double y = record.read_double(); + line->move_to(x, y); + for (int i = 1; i < num_points; ++i) + { + x = record.read_double(); + y = record.read_double(); + line->line_to(x, y); + } + } + else + { + std::vector parts(num_parts); + for (int i = 0; i < num_parts; ++i) + { + parts[i] = record.read_ndr_integer(); + } + + int start, end; + for (int k = 0; k < num_parts; ++k) + { + start = parts[k]; + if (k == num_parts - 1) + { + end = num_points; + } + else + { + end = parts[k + 1]; + } + + double x = record.read_double(); + double y = record.read_double(); + line->move_to(x, y); + + for (int j = start + 1; j < end; ++j) + { + x = record.read_double(); + y = record.read_double(); + line->line_to(x, y); + } + } + } + + // m-range + //double m0=record.read_double(); + //double m1=record.read_double(); + + //for (int i=0;iset_capacity(num_points + num_parts); if (num_parts == 1) { record.skip(4); - double x=record.read_double(); - double y=record.read_double(); - line->move_to(x,y); - for (int i=1;imove_to(x, y); + for (int i = 1; i < num_points; ++i) { - x=record.read_double(); - y=record.read_double(); - line->line_to(x,y); + x = record.read_double(); + y = record.read_double(); + line->line_to(x, y); } } else { std::vector parts(num_parts); - for (int i=0;imove_to(x,y); - - for (int j=start+1;jline_to(x,y); - } - } - } - // m-range - //double m0=record.read_double(); - //double m1=record.read_double(); - - //for (int i=0;iset_capacity(num_points + num_parts); - if (num_parts == 1) - { - record.skip(4); - double x=record.read_double(); - double y=record.read_double(); - line->move_to(x,y); - for (int i=1;iline_to(x,y); - } - } - else - { - std::vector parts(num_parts); - for (int i=0;imove_to(x,y); + double x = record.read_double(); + double y = record.read_double(); + line->move_to(x, y); - for (int j=start+1;jline_to(x,y); - } - } - } - // z-range - //double z0=record.read_double(); - //double z1=record.read_double(); - //for (int i=0;iline_to(x, y); + } + } + } + + // z-range + //double z0=record.read_double(); + //double z1=record.read_double(); + //for (int i=0;i parts(num_parts); - geometry_type * poly = new geometry_type(mapnik::Polygon); - poly->set_capacity(num_points + num_parts); - for (int i=0;imove_to(x,y); + int num_parts = record.read_ndr_integer(); + int num_points = record.read_ndr_integer(); + std::vector parts(num_parts); + geometry_type* poly = new geometry_type(mapnik::Polygon); + poly->set_capacity(num_points + num_parts); + for (int i = 0; i < num_parts; ++i) + { + parts[i] = record.read_ndr_integer(); + } + + for (int k = 0; k < num_parts; k++) + { + int start = parts[k]; + int end; + if (k == num_parts - 1) + { + end = num_points; + } + else + { + end = parts[k + 1]; + } + + double x = record.read_double(); + double y = record.read_double(); + poly->move_to(x, y); - for (int j=start+1;jline_to(x,y); - } - } - return poly; + for (int j=start+1;jline_to(x, y); + } + } + return poly; } -geometry_type * shape_io::read_polygonm() +geometry_type* shape_io::read_polygonm() { - shape_file::record_type record(reclength_*2-36); - shp_.read_record(record); - int num_parts=record.read_ndr_integer(); - int num_points=record.read_ndr_integer(); - std::vector parts(num_parts); - geometry_type * poly = new geometry_type(mapnik::Polygon); - poly->set_capacity(num_points + num_parts); - for (int i=0;i parts(num_parts); + geometry_type* poly = new geometry_type(mapnik::Polygon); + poly->set_capacity(num_points + num_parts); + for (int i = 0; i < num_parts; ++i) + { + parts[i] = record.read_ndr_integer(); + } - for (int k=0;kmove_to(x,y); + for (int k = 0; k < num_parts; k++) + { + int start = parts[k]; + int end; + if (k == num_parts - 1) + { + end = num_points; + } + else + { + end = parts[k + 1]; + } + + double x = record.read_double(); + double y = record.read_double(); + poly->move_to(x, y); - for (int j=start+1;jline_to(x,y); - } - } - // m-range - //double m0=record.read_double(); - //double m1=record.read_double(); - - //for (int i=0;iline_to(x, y); + } + } + + // m-range + //double m0=record.read_double(); + //double m1=record.read_double(); + + //for (int i=0;i parts(num_parts); - geometry_type * poly = new geometry_type(mapnik::Polygon); - poly->set_capacity(num_points + num_parts); - for (int i=0;i parts(num_parts); + geometry_type* poly = new geometry_type(mapnik::Polygon); + poly->set_capacity(num_points + num_parts); + for (int i = 0; i < num_parts; ++i) + { + parts[i] = record.read_ndr_integer(); + } - for (int k=0;kmove_to(x,y); + for (int k = 0; k < num_parts; k++) + { + int start = parts[k]; + int end; + if (k == num_parts - 1) + { + end = num_points; + } + else + { + end = parts[k + 1]; + } + + double x = record.read_double(); + double y = record.read_double(); + poly->move_to(x, y); - for (int j=start+1;jline_to(x,y); - } - } - // z-range - //double z0=record.read_double(); - //double z1=record.read_double(); - //for (int i=0;iline_to(x, y); + } + } + + // z-range + //double z0=record.read_double(); + //double z1=record.read_double(); + //for (int i=0;i #include +#include "dbfile.hpp" +#include "shapefile.hpp" +#include "shp_index.hpp" + struct shape_io : boost::noncopyable { - static const std::string SHP; - //static const std::string SHX; - static const std::string DBF; - static const std::string INDEX; - unsigned type_; - shape_file shp_; - //shape_file shx_; - dbf_file dbf_; - boost::shared_ptr index_; - unsigned reclength_; - unsigned id_; - box2d cur_extent_; - public: enum shapeType { @@ -67,6 +54,7 @@ public: shape_io(const std::string& shape_name, bool open_index=true); ~shape_io(); + shape_file& shp(); //shape_file& shx(); dbf_file& dbf(); @@ -84,12 +72,26 @@ public: void move_to(int id); int type() const; const box2d& current_extent() const; - mapnik::geometry_type * read_polyline(); - mapnik::geometry_type * read_polylinem(); - mapnik::geometry_type * read_polylinez(); - mapnik::geometry_type * read_polygon(); - mapnik::geometry_type * read_polygonm(); - mapnik::geometry_type * read_polygonz(); + mapnik::geometry_type* read_polyline(); + mapnik::geometry_type* read_polylinem(); + mapnik::geometry_type* read_polylinez(); + mapnik::geometry_type* read_polygon(); + mapnik::geometry_type* read_polygonm(); + mapnik::geometry_type* read_polygonz(); + + unsigned type_; + shape_file shp_; + //shape_file shx_; + dbf_file dbf_; + boost::shared_ptr index_; + unsigned reclength_; + unsigned id_; + box2d cur_extent_; + + static const std::string SHP; + //static const std::string SHX; + static const std::string DBF; + static const std::string INDEX; }; #endif //SHAPE_IO_HPP diff --git a/plugins/input/shape/shapefile.hpp b/plugins/input/shape/shapefile.hpp index fba659982..4626952b2 100644 --- a/plugins/input/shape/shapefile.hpp +++ b/plugins/input/shape/shapefile.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -20,11 +20,13 @@ * *****************************************************************************/ -//$Id: shapefile.hpp 33 2005-04-04 13:01:03Z pavlenko $ - #ifndef SHAPEFILE_HPP #define SHAPEFILE_HPP +// stl +#include +#include + // mapnik #include #include @@ -35,10 +37,6 @@ #include #include -// stl -#include -#include - using mapnik::box2d; using mapnik::read_int32_ndr; using mapnik::read_int32_xdr; @@ -63,7 +61,7 @@ struct RecordTag struct MappedRecordTag { typedef const char* data_type; - static data_type alloc(unsigned) { return 0;} + static data_type alloc(unsigned) { return 0; } static void dealloc(data_type ) {} }; @@ -73,12 +71,18 @@ struct shape_record typename Tag::data_type data; size_t size; mutable size_t pos; + explicit shape_record(size_t size) - : - data(Tag::alloc(size)), + : data(Tag::alloc(size)), size(size), - pos(0) {} - + pos(0) + {} + + ~shape_record() + { + Tag::dealloc(data); + } + void set_data(typename Tag::data_type data_) { data = data_; @@ -91,42 +95,37 @@ struct shape_record void skip(unsigned n) { - pos+=n; + pos += n; } int read_ndr_integer() { boost::int32_t val; - read_int32_ndr(&data[pos],val); - pos+=4; + read_int32_ndr(&data[pos], val); + pos += 4; return val; } int read_xdr_integer() { boost::int32_t val; - read_int32_xdr(&data[pos],val); - pos+=4; + read_int32_xdr(&data[pos], val); + pos += 4; return val; } double read_double() { double val; - read_double_ndr(&data[pos],val); - pos+=8; + read_double_ndr(&data[pos], val); + pos += 8; return val; } + long remains() { - return (size-pos); - } - - ~shape_record() - { - Tag::dealloc(data); - } - + return (size - pos); + } }; using namespace boost::interprocess; @@ -144,10 +143,10 @@ public: #endif file_source_type file_; + shape_file() {} - shape_file(std::string const& file_name) - : + shape_file(std::string const& file_name) : #ifdef SHAPE_MEMORY_MAPPED_FILE file_() #else @@ -155,18 +154,19 @@ public: #endif { #ifdef SHAPE_MEMORY_MAPPED_FILE - - boost::optional memory = mapnik::mapped_memory_cache::find(file_name.c_str(),true); + boost::optional memory = + mapnik::mapped_memory_cache::find(file_name.c_str(),true); + if (memory) { - file_.buffer(static_cast((*memory)->get_address()),(*memory)->get_size()); + file_.buffer(static_cast((*memory)->get_address()), (*memory)->get_size()); } #endif } ~shape_file() {} - inline file_source_type & file() + inline file_source_type& file() { return file_; } @@ -184,9 +184,9 @@ public: { #ifdef SHAPE_MEMORY_MAPPED_FILE rec.set_data(file_.buffer().first + file_.tellg()); - file_.seekg(rec.size,std::ios::cur); + file_.seekg(rec.size, std::ios::cur); #else - file_.read(rec.get_data(),rec.size); + file_.read(rec.get_data(), rec.size); #endif } @@ -195,16 +195,16 @@ public: char b[4]; file_.read(b, 4); boost::int32_t val; - read_int32_xdr(b,val); + read_int32_xdr(b, val); return val; } inline int read_ndr_integer() { char b[4]; - file_.read(b,4); + file_.read(b, 4); boost::int32_t val; - read_int32_ndr(b,val); + read_int32_ndr(b, val); return val; } @@ -212,11 +212,11 @@ public: { double val; #ifndef MAPNIK_BIG_ENDIAN - file_.read(reinterpret_cast(&val),8); + file_.read(reinterpret_cast(&val), 8); #else char b[8]; - file_.read(b,8); - read_double_ndr(b,val); + file_.read(b, 8); + read_double_ndr(b, val); #endif return val; } @@ -224,22 +224,22 @@ public: inline void read_envelope(box2d& envelope) { #ifndef MAPNIK_BIG_ENDIAN - file_.read(reinterpret_cast(&envelope),sizeof(envelope)); + file_.read(reinterpret_cast(&envelope), sizeof(envelope)); #else - char data[4*8]; - file_.read(data,4*8); - double minx,miny,maxx,maxy; - read_double_ndr(data + 0*8,minx); - read_double_ndr(data + 1*8,miny); - read_double_ndr(data + 2*8,maxx); - read_double_ndr(data + 3*8,maxy); - envelope.init(minx,miny,maxx,maxy); + char data[4 * 8]; + file_.read(data,4 * 8); + double minx, miny, maxx, maxy; + read_double_ndr(data + 0 * 8, minx); + read_double_ndr(data + 1 * 8, miny); + read_double_ndr(data + 2 * 8, maxx); + read_double_ndr(data + 3 * 8, maxy); + envelope.init(minx, miny, maxx, maxy); #endif } inline void skip(std::streampos bytes) { - file_.seekg(bytes,std::ios::cur); + file_.seekg(bytes, std::ios::cur); } inline void rewind() @@ -249,7 +249,7 @@ public: inline void seek(std::streampos pos) { - file_.seekg(pos,std::ios::beg); + file_.seekg(pos, std::ios::beg); } inline std::streampos pos() @@ -263,4 +263,4 @@ public: } }; -#endif //SHAPEFILE_HPP +#endif // SHAPEFILE_HPP diff --git a/plugins/input/shape/shp_index.hpp b/plugins/input/shape/shp_index.hpp index 37661dd12..ebd424103 100644 --- a/plugins/input/shape/shp_index.hpp +++ b/plugins/input/shape/shp_index.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -23,9 +23,10 @@ #ifndef SHP_INDEX_HH #define SHP_INDEX_HH -// st +// stl #include #include + // mapnik #include #include @@ -43,63 +44,60 @@ private: ~shp_index(); shp_index(const shp_index&); shp_index& operator=(const shp_index&); - static int read_ndr_integer(IStream & in); - static void read_envelope(IStream & in,box2d &envelope); - static void query_node(const filterT& filter,IStream & in,std::vector& pos); + static int read_ndr_integer(IStream& in); + static void read_envelope(IStream& in, box2d& envelope); + static void query_node(const filterT& filter, IStream& in, std::vector& pos); }; -template -void shp_index::query(const filterT& filter,IStream & file,std::vector& pos) +template +void shp_index::query(const filterT& filter, IStream& file, std::vector& pos) { - file.seekg(16,std::ios::beg); - query_node(filter,file,pos); + file.seekg(16, std::ios::beg); + query_node(filter, file, pos); } template -void shp_index::query_node(const filterT& filter,IStream & file,std::vector& ids) +void shp_index::query_node(const filterT& filter, IStream& file, std::vector& ids) { - int offset=read_ndr_integer(file); + int offset = read_ndr_integer(file); box2d node_ext; - read_envelope(file,node_ext); + read_envelope(file, node_ext); - int num_shapes=read_ndr_integer(file); + int num_shapes = read_ndr_integer(file); - if (!filter.pass(node_ext)) + if (! filter.pass(node_ext)) { - file.seekg(offset+num_shapes*4+4,std::ios::cur); + file.seekg(offset + num_shapes * 4 + 4, std::ios::cur); return; } - for (int i=0;i -int shp_index::read_ndr_integer(IStream & file) +template +int shp_index::read_ndr_integer(IStream& file) { char b[4]; - file.read(b,4); - return (b[0]&0xff) | (b[1]&0xff)<<8 | (b[2]&0xff)<<16 | (b[3]&0xff)<<24; + file.read(b, 4); + return (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24; } - -template -void shp_index::read_envelope(IStream & file,box2d& envelope) +template +void shp_index::read_envelope(IStream& file, box2d& envelope) { - file.read(reinterpret_cast(&envelope),sizeof(envelope)); + file.read(reinterpret_cast(&envelope), sizeof(envelope)); } - -#endif //SHP_INDEX_HH +#endif // SHP_INDEX_HH diff --git a/plugins/input/sqlite/sqlite_connection.hpp b/plugins/input/sqlite/sqlite_connection.hpp new file mode 100644 index 000000000..0eb0bfdba --- /dev/null +++ b/plugins/input/sqlite/sqlite_connection.hpp @@ -0,0 +1,161 @@ +/***************************************************************************** + * + * 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_SQLITE_CONNECTION_HPP +#define MAPNIK_SQLITE_CONNECTION_HPP + +// stl +#include + +// mapnik +#include +#include + + +// boost +#include +#include +#include + +// sqlite +extern "C" { + #include +} + +#include "sqlite_resultset.hpp" + + +//============================================================================== + +class sqlite_connection +{ +public: + + sqlite_connection (const std::string& file) + : db_(0), + file_(file) + { +#if SQLITE_VERSION_NUMBER >= 3005000 + int mode = SQLITE_OPEN_READWRITE; + #if SQLITE_VERSION_NUMBER >= 3006018 + // shared cache flag not available until >= 3.6.18 + mode |= SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE; + #endif + const int rc = sqlite3_open_v2 (file_.c_str(), &db_, mode, 0); +#else + #warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.5.x which may make rendering slow..." + const int rc = sqlite3_open (file_.c_str(), &db_); +#endif + if (rc != SQLITE_OK) + { + std::ostringstream s; + s << "Sqlite Plugin: " << sqlite3_errmsg (db_); + + throw mapnik::datasource_exception (s.str()); + } + + sqlite3_busy_timeout(db_,5000); + } + + sqlite_connection (const std::string& file, int flags) + : db_(0), + file_(file) + { +#if SQLITE_VERSION_NUMBER >= 3005000 + const int rc = sqlite3_open_v2 (file_.c_str(), &db_, flags, 0); +#else + #warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.5.x which may make rendering slow..." + const int rc = sqlite3_open (file_.c_str(), &db_); +#endif + if (rc != SQLITE_OK) + { + std::ostringstream s; + s << "Sqlite Plugin: " << sqlite3_errmsg (db_); + + throw mapnik::datasource_exception (s.str()); + } + } + + virtual ~sqlite_connection () + { + if (db_) + { + sqlite3_close (db_); + } + } + + void throw_sqlite_error(const std::string& sql) + { + std::ostringstream s; + s << "Sqlite Plugin: "; + if (db_) + s << "'" << sqlite3_errmsg(db_) << "'"; + else + s << "unknown error, lost connection"; + s << " (" << file_ << ")" + << "\nFull sql was: '" + << sql << "'"; + + throw mapnik::datasource_exception (s.str()); + } + + boost::shared_ptr execute_query(const std::string& sql) + { + sqlite3_stmt* stmt = 0; + + const int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0); + if (rc != SQLITE_OK) + { + throw_sqlite_error(sql); + } + + return boost::make_shared(stmt); + } + + void execute(const std::string& sql) + { + const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0); + if (rc != SQLITE_OK) + { + throw_sqlite_error(sql); + } + } + + int execute_with_code(const std::string& sql) + { + const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0); + return rc; + } + + sqlite3* operator*() + { + return db_; + } + + +private: + + sqlite3* db_; + std::string file_; +}; + +#endif // MAPNIK_SQLITE_CONNECTION_HPP diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index c36767cf7..990d583ca 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -19,34 +19,22 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -// $Id$ #include "sqlite_datasource.hpp" #include "sqlite_featureset.hpp" +#include "sqlite_resultset.hpp" +#include "sqlite_utils.hpp" // mapnik #include #include -// to enable extent fallback hack -#include - // boost #include -#include -#include #include #include #include - - -using boost::lexical_cast; -using boost::bad_lexical_cast; - -using mapnik::datasource; -using mapnik::parameters; - -DATASOURCE_PLUGIN(sqlite_datasource) +#include using mapnik::box2d; using mapnik::coord2d; @@ -55,31 +43,35 @@ using mapnik::featureset_ptr; using mapnik::layer_descriptor; using mapnik::attribute_descriptor; using mapnik::datasource_exception; +using mapnik::datasource; +using mapnik::parameters; +DATASOURCE_PLUGIN(sqlite_datasource) sqlite_datasource::sqlite_datasource(parameters const& params, bool bind) - : datasource(params), - extent_(), - extent_initialized_(false), - type_(datasource::Vector), - table_(*params_.get("table","")), - fields_(*params_.get("fields","*")), - metadata_(*params_.get("metadata","")), - geometry_table_(*params_.get("geometry_table","")), - geometry_field_(*params_.get("geometry_field","")), - index_table_(*params_.get("index_table","")), - key_field_(*params_.get("key_field","")), - row_offset_(*params_.get("row_offset",0)), - row_limit_(*params_.get("row_limit",0)), - desc_(*params_.get("type"), *params_.get("encoding","utf-8")), - format_(mapnik::wkbAuto) + : datasource(params), + extent_(), + extent_initialized_(false), + type_(datasource::Vector), + table_(*params_.get("table", "")), + fields_(*params_.get("fields", "*")), + metadata_(*params_.get("metadata", "")), + geometry_table_(*params_.get("geometry_table", "")), + geometry_field_(*params_.get("geometry_field", "")), + index_table_(*params_.get("index_table", "")), + key_field_(*params_.get("key_field", "")), + row_offset_(*params_.get("row_offset", 0)), + row_limit_(*params_.get("row_limit", 0)), + desc_(*params_.get("type"), *params_.get("encoding", "utf-8")), + format_(mapnik::wkbAuto) { - // TODO - // - change param from 'file' to 'dbname' - // - ensure that the supplied key_field is a valid "integer primary key" + /* TODO + - throw if no primary key but spatial index is present? + - remove auto-indexing + */ boost::optional file = params_.get("file"); - if (!file) throw datasource_exception("Sqlite Plugin: missing parameter"); + if (! file) throw datasource_exception("Sqlite Plugin: missing parameter"); if (table_.empty()) { @@ -98,35 +90,6 @@ void sqlite_datasource::bind() const boost::optional file = params_.get("file"); if (! file) throw datasource_exception("Sqlite Plugin: missing parameter"); - - // Be careful, automatically using rowid as key field of the table can lead - // to misleading results http://www.gaia-gis.it/spatialite-2.4.0-5/SpatialIndex-Update.pdf - // TODO - We should try to avoid this and eventually force to specify a valid table primary key - - boost::optional key_field_name = params_.get("key_field"); - if (key_field_name) - { - key_field_ = *key_field_name; - } - - boost::optional wkb = params_.get("wkb_format"); - if (wkb) - { - if (*wkb == "spatialite") - format_ = mapnik::wkbSpatiaLite; - else if (*wkb == "generic") - format_ = mapnik::wkbGeneric; - else - format_ = mapnik::wkbAuto; - } - - multiple_geometries_ = *params_.get("multiple_geometries", false); - use_spatial_index_ = *params_.get("use_spatial_index", true); - has_spatial_index_ = false; - using_subquery_ = false; - - boost::optional ext = params_.get("extent"); - if (ext) extent_initialized_ = extent_.from_string(*ext); boost::optional base = params_.get("base"); if (base) @@ -134,6 +97,37 @@ void sqlite_datasource::bind() const else dataset_name_ = *file; + if ((dataset_name_.compare(":memory:") != 0) && (!boost::filesystem::exists(dataset_name_))) + { + throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist"); + } + + multiple_geometries_ = *params_.get("multiple_geometries", false); + use_spatial_index_ = *params_.get("use_spatial_index", true); + + // TODO - remove this option once all datasources have an indexing api + bool auto_index = *params_.get("auto_index", true); + + boost::optional ext = params_.get("extent"); + if (ext) extent_initialized_ = extent_.from_string(*ext); + + boost::optional wkb = params_.get("wkb_format"); + if (wkb) + { + if (*wkb == "spatialite") + { + format_ = mapnik::wkbSpatiaLite; + } + else if (*wkb == "generic") + { + format_ = mapnik::wkbGeneric; + } + else + { + format_ = mapnik::wkbAuto; + } + } + // Populate init_statements_ // 1. Build attach database statements from the "attachdb" parameter // 2. Add explicit init statements from "initdb" parameter @@ -144,215 +138,73 @@ void sqlite_datasource::bind() const boost::optional attachdb = params_.get("attachdb"); if (attachdb) { - parse_attachdb(*attachdb); + parse_attachdb(*attachdb); } boost::optional initdb = params_.get("initdb"); if (initdb) { - init_statements_.push_back(*initdb); + init_statements_.push_back(*initdb); } - if (!boost::filesystem::exists(dataset_name_)) - throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist"); - - dataset_ = new sqlite_connection (dataset_name_); + if (geometry_table_.empty()) + { + geometry_table_ = mapnik::sql_utils::table_from_sql(table_); + } + + // if 'table_' is a subquery then we try to deduce names + // and types from the first row returned from that query + using_subquery_ = false; + if (table_ != geometry_table_) + { + using_subquery_ = true; + } + + // now actually create the connection and start executing setup sql + dataset_ = boost::make_shared(dataset_name_); // Execute init_statements_ for (std::vector::const_iterator iter = init_statements_.begin(); iter != init_statements_.end(); ++iter) { - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG std::clog << "Sqlite Plugin: Execute init sql: " << *iter << std::endl; - #endif +#endif dataset_->execute(*iter); } - if (geometry_table_.empty()) - { - geometry_table_ = mapnik::table_from_sql(table_); - } - - // should we deduce column names and types using PRAGMA? - bool use_pragma_table_info = true; - - if (table_ != geometry_table_) - { - // if 'table_' is a subquery then we try to deduce names - // and types from the first row returned from that query - using_subquery_ = true; - use_pragma_table_info = false; - - if (key_field_.empty()) - { - key_field_ = "rowid"; - } - } - - if (! use_pragma_table_info) + bool found_types_via_subquery = false; + if (using_subquery_) { std::ostringstream s; s << "SELECT " << fields_ << " FROM (" << table_ << ") LIMIT 1"; - - boost::scoped_ptr rs(dataset_->execute_query(s.str())); - if (rs->is_valid() && rs->step_next()) - { - for (int i = 0; i < rs->column_count (); ++i) - { - const int type_oid = rs->column_type (i); - const char* fld_name = rs->column_name (i); - switch (type_oid) - { - case SQLITE_INTEGER: - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Integer)); - break; - - case SQLITE_FLOAT: - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Double)); - break; - - case SQLITE_TEXT: - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); - break; - - case SQLITE_NULL: - // sqlite reports based on value, not actual column type unless - // PRAGMA table_info is used so here we assume the column is a string - // which is a lesser evil than altogether dropping the column - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); - - case SQLITE_BLOB: - if (geometry_field_.empty() - && (boost::algorithm::icontains(fld_name, "geom") || - boost::algorithm::icontains(fld_name, "point") || - boost::algorithm::icontains(fld_name, "linestring") || - boost::algorithm::icontains(fld_name, "polygon"))) - { - geometry_field_ = std::string(fld_name); - } - break; - - default: - #ifdef MAPNIK_DEBUG - std::clog << "Sqlite Plugin: unknown type_oid=" << type_oid << std::endl; - #endif - break; - } - } - } - else - { - // if we do not have at least a row and - // we cannot determine the right columns types and names - // as all column_type are SQLITE_NULL - // so we fallback to using PRAGMA table_info - use_pragma_table_info = true; - } + found_types_via_subquery = sqlite_utils::detect_types_from_subquery(s.str(),geometry_field_,desc_,dataset_); } - if (key_field_.empty()) + // TODO - consider removing this + if (key_field_ == "rowid") { - use_pragma_table_info = true; - } - else - { - // TODO - we can't trust so much the rowid here - if (key_field_ == "rowid") - desc_.add_descriptor(attribute_descriptor("rowid", mapnik::Integer)); + desc_.add_descriptor(attribute_descriptor("rowid", mapnik::Integer)); } - if (use_pragma_table_info) + bool found_table = sqlite_utils::table_info(key_field_, + found_types_via_subquery, + geometry_field_, + geometry_table_, + desc_, + dataset_); + + if (! found_table) { std::ostringstream s; - s << "PRAGMA table_info(" << geometry_table_ << ")"; + s << "Sqlite Plugin: could not query table '" << geometry_table_ << "' "; + if (using_subquery_) s << " from subquery '" << table_ << "' "; + s << "using 'PRAGMA table_info(" << geometry_table_ << ")' "; - boost::scoped_ptr rs(dataset_->execute_query(s.str())); - bool found_table = false; - bool found_pk = false; - while (rs->is_valid() && rs->step_next()) - { - found_table = true; + std::string sq_err = std::string(sqlite3_errmsg(*(*dataset_))); + if (sq_err != "unknown error") s << ": " << sq_err; - // TODO - support unicode strings - const char* fld_name = rs->column_text(1); - std::string fld_type(rs->column_text(2)); - int fld_pk = rs->column_integer(5); - boost::algorithm::to_lower(fld_type); - - // TODO - how to handle primary keys on multiple columns ? - if (key_field_.empty() && ! found_pk && fld_pk != 0) - { - key_field_ = fld_name; - found_pk = true; - } - - // see 2.1 "Column Affinity" at http://www.sqlite.org/datatype3.html - // TODO - refactor this somehow ? - if (geometry_field_.empty() - && ((boost::algorithm::contains(fld_type, "geom") || - boost::algorithm::contains(fld_type, "point") || - boost::algorithm::contains(fld_type, "linestring") || - boost::algorithm::contains(fld_type, "polygon")) - || - (boost::algorithm::icontains(fld_name, "geom") || - boost::algorithm::icontains(fld_name, "point") || - boost::algorithm::icontains(fld_name, "linestring") || - boost::algorithm::icontains(fld_name, "polygon"))) - ) - { - geometry_field_ = std::string(fld_name); - } - else if (boost::algorithm::contains(fld_type, "int")) - { - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Integer)); - } - else if (boost::algorithm::contains(fld_type, "text") || - boost::algorithm::contains(fld_type, "char") || - boost::algorithm::contains(fld_type, "clob")) - { - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); - } - else if (boost::algorithm::contains(fld_type, "real") || - boost::algorithm::contains(fld_type, "float") || - boost::algorithm::contains(fld_type, "double")) - { - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::Double)); - } - else if (boost::algorithm::contains(fld_type, "blob")) - { - if (! geometry_field_.empty()) - { - desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); - } - } - #ifdef MAPNIK_DEBUG - else - { - // "Column Affinity" says default to "Numeric" but for now we pass.. - //desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double)); - - // TODO - this should not fail when we specify geometry_field in XML file - - std::clog << "Sqlite Plugin: column '" - << std::string(fld_name) - << "' unhandled due to unknown type: " - << fld_type << std::endl; - } - #endif - } - - if (! found_table) - { - std::ostringstream s; - s << "Sqlite Plugin: could not query table '" << geometry_table_ << "' "; - if (using_subquery_) s << " from subquery '" << table_ << "' "; - s << "using 'PRAGMA table_info(" << geometry_table_ << ")' "; - - std::string sq_err = std::string(sqlite3_errmsg(*(*dataset_))); - if (sq_err != "unknown error") s << ": " << sq_err; - - throw datasource_exception(s.str()); - } + throw datasource_exception(s.str()); } if (geometry_field_.empty()) @@ -364,251 +216,112 @@ void sqlite_datasource::bind() const { // Generate implicit index_table name - need to do this after // we have discovered meta-data or else we don't know the column name - index_table_ = "\"idx_" + mapnik::unquote_sql2(geometry_table_) + "_" + geometry_field_ + "\""; + index_table_ = sqlite_utils::index_for_table(geometry_table_,geometry_field_); } - + + std::string index_db = sqlite_utils::index_for_db(dataset_name_); + + has_spatial_index_ = false; if (use_spatial_index_) { - std::ostringstream s; - s << "SELECT pkid,xmin,xmax,ymin,ymax FROM " << index_table_; - s << " LIMIT 0"; - - if (dataset_->execute_with_code(s.str()) == SQLITE_OK) + if (boost::filesystem::exists(index_db)) { - has_spatial_index_ = true; - } - #ifdef MAPNIK_DEBUG - else - { - std::clog << "SQLite Plugin: rtree index lookup did not succeed: '" << sqlite3_errmsg(*(*dataset_)) << "'\n"; - } - #endif - } - - if (! metadata_.empty() && ! extent_initialized_) - { - std::ostringstream s; - s << "SELECT xmin, ymin, xmax, ymax FROM " << metadata_; - s << " WHERE LOWER(f_table_name) = LOWER('" << geometry_table_ << "')"; - - boost::scoped_ptr rs(dataset_->execute_query(s.str())); - if (rs->is_valid() && rs->step_next()) - { - double xmin = rs->column_double (0); - double ymin = rs->column_double (1); - double xmax = rs->column_double (2); - double ymax = rs->column_double (3); - - extent_.init (xmin,ymin,xmax,ymax); - extent_initialized_ = true; - } - } - - if (! extent_initialized_ && has_spatial_index_) - { - std::ostringstream s; - s << "SELECT MIN(xmin), MIN(ymin), MAX(xmax), MAX(ymax) FROM " - << index_table_; - - boost::scoped_ptr rs(dataset_->execute_query(s.str())); - if (rs->is_valid() && rs->step_next()) - { - if (! rs->column_isnull(0)) - { - try - { - double xmin = lexical_cast(rs->column_double(0)); - double ymin = lexical_cast(rs->column_double(1)); - double xmax = lexical_cast(rs->column_double(2)); - double ymax = lexical_cast(rs->column_double(3)); - extent_.init (xmin,ymin,xmax,ymax); - extent_initialized_ = true; - } - catch (bad_lexical_cast &ex) - { - std::clog << boost::format("SQLite Plugin: warning: could not determine extent from query: %s\nError was: '%s'\n") % s.str() % ex.what() << std::endl; - } - } - } - } - -#ifdef MAPNIK_DEBUG - if (! has_spatial_index_ && use_spatial_index_ && using_subquery_ - && key_field_ == "rowid" && ! boost::algorithm::icontains(table_, "rowid")) - { - // this is an impossible situation because rowid will be null via a subquery - std::clog << "Sqlite Plugin: WARNING: spatial index usage will fail because rowid " - << "is not present in your subquery. You have 4 options: " - << "1) Add rowid into your select statement, " - << "2) alias your primary key as rowid, " - << "3) supply a 'key_field' value that references the primary key of your spatial table, or " - << "4) avoid using a spatial index by setting 'use_spatial_index'=false" << std::endl; - } -#endif - - // final fallback to gather extent - if (! extent_initialized_ || ! has_spatial_index_) - { - std::ostringstream s; - s << "SELECT " << geometry_field_ << "," << key_field_ - << " FROM " << geometry_table_; - - if (row_limit_ > 0) - { - s << " LIMIT " << row_limit_; - } - - if (row_offset_ > 0) - { - s << " OFFSET " << row_offset_; - } - -#ifdef MAPNIK_DEBUG - std::clog << "Sqlite Plugin: " << s.str() << std::endl; -#endif - - boost::shared_ptr rs(dataset_->execute_query(s.str())); - - // spatial index sql - std::ostringstream spatial_index_sql; - spatial_index_sql << "create virtual table " << index_table_ - << " using rtree(pkid, xmin, xmax, ymin, ymax)"; - - std::ostringstream spatial_index_insert_sql; - spatial_index_insert_sql << "insert into " << index_table_ - << " values (?,?,?,?,?)"; - - sqlite3_stmt* stmt = 0; - if (use_spatial_index_) - { - dataset_->execute(spatial_index_sql.str()); - - const int rc = sqlite3_prepare_v2 (*(*dataset_), - spatial_index_insert_sql.str().c_str(), - -1, - &stmt, - 0); - if (rc != SQLITE_OK) - { - std::ostringstream index_error; - index_error << "Sqlite Plugin: auto-index table creation failed: '" - << sqlite3_errmsg(*(*dataset_)) << "' query was: " - << spatial_index_insert_sql; - - throw datasource_exception(index_error.str()); - } - } - - bool first = true; - while (rs->is_valid() && rs->step_next()) - { - int size; - const char* data = (const char *) rs->column_blob (0, size); - if (data) - { - // create a tmp feature to be able to parse geometry - // ideally we would not have to do this. - // see: http://trac.mapnik.org/ticket/745 - mapnik::feature_ptr feature(mapnik::feature_factory::create(0)); - mapnik::geometry_utils::from_wkb(feature->paths(), data, size, multiple_geometries_, format_); - mapnik::box2d const& bbox = feature->envelope(); - - if (bbox.valid()) - { - extent_initialized_ = true; - if (first) - { - first = false; - extent_ = bbox; - } - else - { - extent_.expand_to_include(bbox); - } - - // index creation - if (use_spatial_index_) - { - const int type_oid = rs->column_type(1); - if (type_oid != SQLITE_INTEGER) - { - std::ostringstream type_error; - type_error << "Sqlite Plugin: invalid type for key field '" - << key_field_ << "' when creating index '" << index_table_ - << "' type was: " << type_oid << ""; - - throw datasource_exception(type_error.str()); - } - - const sqlite_int64 pkid = rs->column_integer64(1); - if (sqlite3_bind_int64(stmt, 1, pkid) != SQLITE_OK) - { - throw datasource_exception("invalid value for for key field while generating index"); - } - - if ((sqlite3_bind_double(stmt, 2, bbox.minx()) != SQLITE_OK) || - (sqlite3_bind_double(stmt, 3, bbox.maxx()) != SQLITE_OK) || - (sqlite3_bind_double(stmt, 4, bbox.miny()) != SQLITE_OK) || - (sqlite3_bind_double(stmt, 5, bbox.maxy()) != SQLITE_OK)) - { - throw datasource_exception("invalid value for for extent while generating index"); - } - - const int res = sqlite3_step(stmt); - if (res != SQLITE_DONE) - { - std::ostringstream s; - s << "SQLite Plugin: inserting bbox into rtree index failed: " - << "error code " << sqlite3_errcode(*(*dataset_)) << ": '" - << sqlite3_errmsg(*(*dataset_)) << "' query was: " - << spatial_index_insert_sql; - - throw datasource_exception(s.str()); - } - - sqlite3_reset(stmt); - } - } - else - { - std::ostringstream index_error; - index_error << "SQLite Plugin: encountered invalid bbox at '" - << key_field_ << "' == " << rs->column_integer64(1); - - throw datasource_exception(index_error.str()); - } - } + dataset_->execute("attach database '" + index_db + "' as " + index_table_); } - const int res = sqlite3_finalize(stmt); - if (res != SQLITE_OK) - { - throw datasource_exception("auto-indexing failed: set use_spatial_index=false to disable auto-indexing and avoid this error"); - } + has_spatial_index_ = sqlite_utils::has_rtree(index_table_,dataset_); + } + + + if (! extent_initialized_ + && !has_spatial_index_ + && auto_index) + { + if (! key_field_.empty()) + { + std::ostringstream query; + query << "SELECT " + << geometry_field_ + << "," << key_field_ + << " FROM (" + << geometry_table_ << ")"; + boost::shared_ptr rs = dataset_->execute_query(query.str()); + sqlite_utils::create_spatial_index(index_db,index_table_,rs,extent_); + extent_initialized_ = true; + } + else + { + std::ostringstream s; + s << "Sqlite Plugin: key_field is empty for " + << geometry_field_ + << " and " + << geometry_table_; + throw datasource_exception(s.str()); + } } if (! extent_initialized_) { - std::ostringstream s; - s << "Sqlite Plugin: extent could not be determined for table '" - << geometry_table_ << "' and geometry field '" << geometry_field_ << "'" - << " because an rtree spatial index is missing or empty." - << " - either set the table 'extent' or create an rtree spatial index"; - throw datasource_exception(s.str()); - } + // TODO - clean this up - reducing arguments + if (!sqlite_utils::detect_extent(dataset_, + has_spatial_index_, + extent_, + index_table_, + metadata_, + geometry_field_, + geometry_table_, + key_field_, + table_)) + { + std::ostringstream s; + s << "Sqlite Plugin: extent could not be determined for table '" + << geometry_table_ << "' and geometry field '" << geometry_field_ << "'" + << " because an rtree spatial index is missing or empty." + << " - either set the table 'extent' or create an rtree spatial index"; + throw datasource_exception(s.str()); + } + } is_bound_ = true; } sqlite_datasource::~sqlite_datasource() { - if (is_bound_) - { - delete dataset_; - } } +#if (BOOST_FILESYSTEM_VERSION <= 2) +namespace boost { +namespace filesystem { + path read_symlink(const path& p) + { + path symlink_path; + +#ifdef BOOST_POSIX_API + for (std::size_t path_max = 64;; path_max *= 2)// loop 'til buffer is large enough + { + boost::scoped_array buf(new char[path_max]); + ssize_t result; + if ((result=::readlink(p.string().c_str(), buf.get(), path_max))== -1) + { + throw std::runtime_error("could not read symlink"); + } + else + { + if(result != static_cast(path_max)) + { + symlink_path.assign(buf.get(), buf.get() + result); + break; + } + } + } +#endif + return symlink_path; + } +} +} +#endif + void sqlite_datasource::parse_attachdb(std::string const& attachdb) const { boost::char_separator sep(","); @@ -642,23 +355,15 @@ void sqlite_datasource::parse_attachdb(std::string const& attachdb) const boost::filesystem::path absolute_path(dataset_name_); // support symlinks - #if (BOOST_FILESYSTEM_VERSION == 3) if (boost::filesystem::is_symlink(absolute_path)) { absolute_path = boost::filesystem::read_symlink(absolute_path); } + #if (BOOST_FILESYSTEM_VERSION == 3) filename = boost::filesystem::absolute(absolute_path.parent_path() / filename).string(); - #else - if (boost::filesystem::is_symlink(absolute_path)) - { - //cannot figure out how to resolve on in v2 so just print a warning - std::clog << "###Warning: '" << absolute_path.string() << "' is a symlink which is not supported in attachdb\n"; - } - filename = boost::filesystem::complete(absolute_path.branch_path() / filename).normalize().string(); - #endif } } @@ -680,29 +385,31 @@ int sqlite_datasource::type() const box2d sqlite_datasource::envelope() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return extent_; } layer_descriptor sqlite_datasource::get_descriptor() const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); return desc_; } featureset_ptr sqlite_datasource::features(query const& q) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - if (dataset_) - { + if (dataset_) + { mapnik::box2d const& e = q.get_bbox(); std::ostringstream s; - s << "SELECT " << geometry_field_ << "," << key_field_; + s << "SELECT " << geometry_field_; + if (!key_field_.empty()) + s << "," << key_field_; std::set const& props = q.property_names(); std::set::const_iterator pos = props.begin(); std::set::const_iterator end = props.end(); @@ -716,15 +423,8 @@ featureset_ptr sqlite_datasource::features(query const& q) const std::string query (table_); - // TODO - // throw if select * and key_field == rowid? - // or add schema support so sqlite throws - - if (has_spatial_index_) + if (! key_field_.empty() && has_spatial_index_) { - // Use rtree to limit record id's to a given bbox - // then a btree to pull the records for those ids. - std::ostringstream spatial_sql; spatial_sql << std::setprecision(16); spatial_sql << " WHERE " << key_field_ << " IN (SELECT pkid FROM " << index_table_; @@ -752,10 +452,10 @@ featureset_ptr sqlite_datasource::features(query const& q) const s << " OFFSET " << row_offset_; } - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG std::clog << "Sqlite Plugin: table: " << table_ << "\n\n"; std::clog << "Sqlite Plugin: query:" << s.str() << "\n\n"; - #endif +#endif boost::shared_ptr rs(dataset_->execute_query(s.str())); @@ -771,15 +471,17 @@ featureset_ptr sqlite_datasource::features(query const& q) const featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const { - if (!is_bound_) bind(); + if (! is_bound_) bind(); - if (dataset_) - { + if (dataset_) + { // TODO - need tolerance - mapnik::box2d const e(pt.x,pt.y,pt.x,pt.y); + mapnik::box2d const e(pt.x, pt.y, pt.x, pt.y); std::ostringstream s; - s << "SELECT " << geometry_field_ << "," << key_field_; + s << "SELECT " << geometry_field_; + if (!key_field_.empty()) + s << "," << key_field_; std::vector::const_iterator itr = desc_.get_descriptors().begin(); std::vector::const_iterator end = desc_.get_descriptors().end(); while (itr != end) @@ -795,9 +497,9 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const s << " FROM "; - std::string query (table_); + std::string query(table_); - if (has_spatial_index_) + if (! key_field_.empty() && has_spatial_index_) { std::ostringstream spatial_sql; spatial_sql << std::setprecision(16); @@ -826,9 +528,9 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const s << " OFFSET " << row_offset_; } - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG std::clog << "Sqlite Plugin: " << s.str() << std::endl; - #endif +#endif boost::shared_ptr rs(dataset_->execute_query(s.str())); diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index 6f20ef943..0a964e61d 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef SQLITE_DATASOURCE_HPP -#define SQLITE_DATASOURCE_HPP +#ifndef MAPNIK_SQLITE_DATASOURCE_HPP +#define MAPNIK_SQLITE_DATASOURCE_HPP // mapnik #include @@ -35,50 +34,48 @@ #include // sqlite -#include "sqlite_types.hpp" +#include "sqlite_connection.hpp" -//============================================================================== - class sqlite_datasource : public mapnik::datasource { - public: - sqlite_datasource(mapnik::parameters const& params, bool bind=true); - virtual ~sqlite_datasource (); - int type() const; - static std::string name(); - mapnik::featureset_ptr features(mapnik::query const& q) const; - mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; - mapnik::box2d envelope() const; - mapnik::layer_descriptor get_descriptor() const; - void bind() const; - private: - mutable mapnik::box2d extent_; - mutable bool extent_initialized_; - int type_; - mutable std::string dataset_name_; - mutable sqlite_connection* dataset_; - std::string table_; - std::string fields_; - std::string metadata_; - mutable std::string geometry_table_; - mutable std::string geometry_field_; - mutable std::string index_table_; - mutable std::string key_field_; - mutable int row_offset_; - mutable int row_limit_; - mutable mapnik::layer_descriptor desc_; - mutable mapnik::wkbFormat format_; - mutable bool multiple_geometries_; - mutable bool use_spatial_index_; - mutable bool has_spatial_index_; - mutable bool using_subquery_; - mutable std::vector init_statements_; - - // Fill init_statements with any statements - // needed to attach auxillary databases - void parse_attachdb(std::string const& attachdb) const; +public: + sqlite_datasource(mapnik::parameters const& params, bool bind = true); + virtual ~sqlite_datasource (); + int type() const; + static std::string name(); + mapnik::featureset_ptr features(mapnik::query const& q) const; + mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; + mapnik::box2d envelope() const; + mapnik::layer_descriptor get_descriptor() const; + void bind() const; + +private: + mutable mapnik::box2d extent_; + mutable bool extent_initialized_; + int type_; + mutable std::string dataset_name_; + mutable boost::shared_ptr dataset_; + std::string table_; + std::string fields_; + std::string metadata_; + mutable std::string geometry_table_; + mutable std::string geometry_field_; + mutable std::string index_table_; + mutable std::string key_field_; + mutable int row_offset_; + mutable int row_limit_; + mutable mapnik::layer_descriptor desc_; + mutable mapnik::wkbFormat format_; + mutable bool multiple_geometries_; + mutable bool use_spatial_index_; + mutable bool has_spatial_index_; + mutable bool using_subquery_; + mutable std::vector init_statements_; + + // Fill init_statements with any statements + // needed to attach auxillary databases + void parse_attachdb(std::string const& attachdb) const; }; - -#endif // SQLITE_DATASOURCE_HPP +#endif // MAPNIK_SQLITE_DATASOURCE_HPP diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 4ca836722..9d53f0fe3 100644 --- a/plugins/input/sqlite/sqlite_featureset.cpp +++ b/plugins/input/sqlite/sqlite_featureset.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include @@ -34,6 +33,7 @@ // ogr #include "sqlite_featureset.hpp" +#include "sqlite_utils.hpp" using mapnik::query; using mapnik::box2d; @@ -49,35 +49,37 @@ sqlite_featureset::sqlite_featureset(boost::shared_ptr rs, mapnik::wkbFormat format, bool multiple_geometries, bool using_subquery) - : rs_(rs), - tr_(new transcoder(encoding)), - format_(format), - multiple_geometries_(multiple_geometries), - using_subquery_(using_subquery) + : rs_(rs), + tr_(new transcoder(encoding)), + format_(format), + multiple_geometries_(multiple_geometries), + using_subquery_(using_subquery) { } -sqlite_featureset::~sqlite_featureset() {} +sqlite_featureset::~sqlite_featureset() +{ +} feature_ptr sqlite_featureset::next() { if (rs_->is_valid () && rs_->step_next ()) { int size; - const char* data = (const char *) rs_->column_blob (0, size); + const char* data = (const char*) rs_->column_blob(0, size); if (! data) { return feature_ptr(); } - int feature_id = rs_->column_integer (1); + int feature_id = rs_->column_integer(1); feature_ptr feature(feature_factory::create(feature_id)); geometry_utils::from_wkb(feature->paths(), data, size, multiple_geometries_, format_); - for (int i = 2; i < rs_->column_count (); ++i) + for (int i = 2; i < rs_->column_count(); ++i) { - const int type_oid = rs_->column_type (i); + const int type_oid = rs_->column_type(i); const char* fld_name = rs_->column_name(i); if (! fld_name) @@ -95,13 +97,13 @@ feature_ptr sqlite_featureset::next() { case SQLITE_INTEGER: { - boost::put(*feature, fld_name_str, rs_->column_integer (i)); + boost::put(*feature, fld_name_str, rs_->column_integer(i)); break; } case SQLITE_FLOAT: { - boost::put(*feature, fld_name_str, rs_->column_double (i)); + boost::put(*feature, fld_name_str, rs_->column_double(i)); break; } diff --git a/plugins/input/sqlite/sqlite_featureset.hpp b/plugins/input/sqlite/sqlite_featureset.hpp index fced45801..819050c60 100644 --- a/plugins/input/sqlite/sqlite_featureset.hpp +++ b/plugins/input/sqlite/sqlite_featureset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,10 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef SQLITE_FEATURESET_HPP -#define SQLITE_FEATURESET_HPP +#ifndef MAPNIK_SQLITE_FEATURESET_HPP +#define MAPNIK_SQLITE_FEATURESET_HPP // mapnik #include @@ -34,28 +33,26 @@ #include // sqlite -#include "sqlite_types.hpp" +#include "sqlite_resultset.hpp" - -//============================================================================== class sqlite_featureset : public mapnik::Featureset { - public: - sqlite_featureset(boost::shared_ptr rs, - std::string const& encoding, - mapnik::wkbFormat format, - bool multiple_geometries, - bool using_subquery); - virtual ~sqlite_featureset(); - mapnik::feature_ptr next(); - private: - boost::shared_ptr rs_; - boost::scoped_ptr tr_; - mapnik::wkbFormat format_; - bool multiple_geometries_; - bool using_subquery_; +public: + sqlite_featureset(boost::shared_ptr rs, + std::string const& encoding, + mapnik::wkbFormat format, + bool multiple_geometries, + bool using_subquery); + virtual ~sqlite_featureset(); + mapnik::feature_ptr next(); + +private: + boost::shared_ptr rs_; + boost::scoped_ptr tr_; + mapnik::wkbFormat format_; + bool multiple_geometries_; + bool using_subquery_; }; - -#endif // SQLITE_FEATURESET_HPP +#endif // MAPNIK_SQLITE_FEATURESET_HPP diff --git a/plugins/input/sqlite/sqlite_prepared.hpp b/plugins/input/sqlite/sqlite_prepared.hpp new file mode 100644 index 000000000..4ad5271f2 --- /dev/null +++ b/plugins/input/sqlite/sqlite_prepared.hpp @@ -0,0 +1,132 @@ +/***************************************************************************** + * + * 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_SQLITE_PREPARED_HPP +#define MAPNIK_SQLITE_PREPARED_HPP + +// mapnik +#include +#include + +// boost +#include +#include + +// stl +#include + +#include "sqlite_connection.hpp" + +// sqlite +extern "C" { + #include +} + +class prepared_index_statement : boost::noncopyable +{ + +public: + prepared_index_statement(boost::shared_ptr ds, std::string const& sql) + : ds_(ds), + stmt_(0) + { + + const int rc = sqlite3_prepare_v2(*(*ds_), + sql.c_str(), + -1, + &stmt_, + 0); + + if (rc != SQLITE_OK) + { + std::ostringstream index_error; + index_error << "Sqlite Plugin: auto-index table creation failed: '" + << sqlite3_errmsg(*(*ds_)) << "' query was: " + << sql; + + throw mapnik::datasource_exception(index_error.str()); + } + } + + ~prepared_index_statement() + { + if (stmt_) + { + int res = sqlite3_finalize(stmt_); + if (res != SQLITE_OK) + { + if (*(*ds_)) + { + std::cerr << "ERR:" << sqlite3_errmsg(*(*ds_)) << "\n"; + } + else + { + std::cerr << "SQLite Plugin: " << res << "\n"; + } + } + } + } + + void bind(sqlite_int64 const pkid) + { + if (sqlite3_bind_int64(stmt_, 1, pkid) != SQLITE_OK) + { + throw mapnik::datasource_exception("SQLite Plugin: invalid value for for key field while generating index"); + } + + } + + void bind(mapnik::box2d const& bbox) + { + if ((sqlite3_bind_double(stmt_, 2, bbox.minx()) != SQLITE_OK) || + (sqlite3_bind_double(stmt_, 3, bbox.maxx()) != SQLITE_OK) || + (sqlite3_bind_double(stmt_, 4, bbox.miny()) != SQLITE_OK) || + (sqlite3_bind_double(stmt_, 5, bbox.maxy()) != SQLITE_OK)) + { + throw mapnik::datasource_exception("SQLite Plugin: invalid value for for extent while generating index"); + } + } + + bool step_next () + { + const int status = sqlite3_step(stmt_); + if (status != SQLITE_ROW && status != SQLITE_DONE) + { + std::ostringstream s; + s << "SQLite Plugin: inserting bbox into rtree index failed"; + std::string msg(sqlite3_errmsg(sqlite3_db_handle(stmt_))); + if (msg != "unknown error") + { + s << ": " << msg; + } + throw mapnik::datasource_exception(s.str()); + } + sqlite3_reset(stmt_); + return status == SQLITE_ROW; + } + +private: + boost::shared_ptr ds_; + sqlite3_stmt * stmt_; +}; + +#endif // MAPNIK_SQLITE_PREPARED_HPP diff --git a/plugins/input/sqlite/sqlite_types.hpp b/plugins/input/sqlite/sqlite_resultset.hpp similarity index 53% rename from plugins/input/sqlite/sqlite_types.hpp rename to plugins/input/sqlite/sqlite_resultset.hpp index 49ae59f1e..3123af9f8 100644 --- a/plugins/input/sqlite/sqlite_types.hpp +++ b/plugins/input/sqlite/sqlite_resultset.hpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 @@ -19,19 +19,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ -#ifndef SQLITE_TYPES_HPP -#define SQLITE_TYPES_HPP - -// stdc++ -#include +#ifndef MAPNIK_SQLITE_RESULTSET_HPP +#define MAPNIK_SQLITE_RESULTSET_HPP // mapnik #include -// boost -#include +// stl +#include // sqlite extern "C" { @@ -39,21 +35,6 @@ extern "C" { } -//============================================================================== - -class sqlite_utils -{ -public: - - static void dequote(std::string& s) - { - if (s[0] == '[' || s[0] == '\'' || s[0] == '"' || s[0] == '`') - { - s = s.substr(1, s.length() - 1); - } - } -}; - //============================================================================== @@ -86,7 +67,6 @@ public: { std::ostringstream s; s << "SQLite Plugin: retrieving next row failed"; - std::string msg(sqlite3_errmsg(sqlite3_db_handle(stmt_))); if (msg != "unknown error") { @@ -160,97 +140,4 @@ private: sqlite3_stmt* stmt_; }; - -//============================================================================== - -class sqlite_connection -{ -public: - - sqlite_connection (const std::string& file) - : db_(0) - { - // sqlite3_open_v2 is available earlier but - // shared cache not available until >= 3.6.18 - #if SQLITE_VERSION_NUMBER >= 3006018 - const int rc = sqlite3_enable_shared_cache(1); - if (rc != SQLITE_OK) - { - throw mapnik::datasource_exception (sqlite3_errmsg (db_)); - } - - int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE; - if (sqlite3_open_v2 (file.c_str(), &db_, mode, NULL)) - #else - #warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.6.18 which may make rendering slow..." - if (sqlite3_open (file.c_str(), &db_)) - #endif - { - std::ostringstream s; - s << "Sqlite Plugin: " << sqlite3_errmsg (db_); - - throw mapnik::datasource_exception (s.str()); - } - } - - virtual ~sqlite_connection () - { - if (db_) - { - sqlite3_close (db_); - } - } - - void throw_sqlite_error(const std::string& sql) - { - std::ostringstream s; - s << "Sqlite Plugin: "; - if (db_) - s << "'" << sqlite3_errmsg(db_) << "'"; - else - s << "unknown error, lost connection"; - s << "\nFull sql was: '" << sql << "'\n"; - - throw mapnik::datasource_exception (s.str()); - } - - sqlite_resultset* execute_query(const std::string& sql) - { - sqlite3_stmt* stmt = 0; - - const int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0); - if (rc != SQLITE_OK) - { - throw_sqlite_error(sql); - } - - return new sqlite_resultset (stmt); - } - - void execute(const std::string& sql) - { - const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0); - if (rc != SQLITE_OK) - { - throw_sqlite_error(sql); - } - } - - int execute_with_code(const std::string& sql) - { - const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0); - return rc; - } - - sqlite3* operator*() - { - return db_; - } - -private: - - sqlite3* db_; -}; - - -#endif //SQLITE_TYPES_HPP +#endif // MAPNIK_SQLITE_RESULTSET_HPP diff --git a/plugins/input/sqlite/sqlite_utils.hpp b/plugins/input/sqlite/sqlite_utils.hpp new file mode 100644 index 000000000..87c5a593c --- /dev/null +++ b/plugins/input/sqlite/sqlite_utils.hpp @@ -0,0 +1,453 @@ +/***************************************************************************** + * + * 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_SQLITE_UTILS_HPP +#define MAPNIK_SQLITE_UTILS_HPP + +// stl +#include + +// mapnik +#include +#include +#include + + +// boost +#include +#include +#include +#include + +// sqlite +extern "C" { + #include +} + +#include "sqlite_resultset.hpp" +#include "sqlite_prepared.hpp" +#include "sqlite_connection.hpp" + + +//============================================================================== + +class sqlite_utils +{ +public: + + static void dequote(std::string & z) + { + boost::algorithm::trim_if(z,boost::algorithm::is_any_of("[]'\"`")); + } + + static std::string index_for_table(std::string const& table, std::string const& field) + { + return "\"idx_" + mapnik::sql_utils::unquote(table) + "_" + field + "\""; + } + + static std::string index_for_db(std::string const& file) + { + //std::size_t idx = file.find_last_of("."); + //if(idx != std::string::npos) { + // return file.substr(0,idx) + ".index" + file.substr(idx); + //} + //else + //{ + return file + ".index"; + //} + } + + static void query_extent(boost::shared_ptr rs, + mapnik::box2d& extent) + { + + bool first = true; + while (rs->is_valid() && rs->step_next()) + { + int size; + const char* data = (const char*) rs->column_blob(0, size); + if (data) + { + boost::ptr_vector paths; + mapnik::geometry_utils::from_wkb(paths, data, size, false, mapnik::wkbAuto); + for (unsigned i=0; i const& bbox = paths[i].envelope(); + + if (bbox.valid()) + { + if (first) + { + first = false; + extent = bbox; + } + else + { + extent.expand_to_include(bbox); + } + } + } + } + } + } + + static void create_spatial_index(std::string const& index_db, + std::string const& index_table, + boost::shared_ptr rs, + mapnik::box2d& extent) + { + /* TODO + - speedups + - return early/recover from failure + - allow either in db or in separate + */ + + if (!rs->is_valid()) + return; + +#if SQLITE_VERSION_NUMBER >= 3005000 + int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX; +#else + int flags; +#endif + + boost::shared_ptr ds = boost::make_shared(index_db,flags); + + // first drop the index if it already exists + std::ostringstream spatial_index_drop_sql; + spatial_index_drop_sql << "DROP TABLE IF EXISTS " << index_table; + ds->execute(spatial_index_drop_sql.str()); + + ds->execute("PRAGMA synchronous=OFF"); + ds->execute("BEGIN TRANSACTION"); + + // create the spatial index + std::ostringstream create_idx; + create_idx << "create virtual table " + << index_table + << " using rtree(pkid, xmin, xmax, ymin, ymax)"; + + // insert for prepared statement + std::ostringstream insert_idx; + insert_idx << "insert into " + << index_table + << " values (?,?,?,?,?)"; + + ds->execute(create_idx.str()); + + prepared_index_statement ps(ds,insert_idx.str()); + + bool first = true; + while (rs->is_valid() && rs->step_next()) + { + int size; + const char* data = (const char*) rs->column_blob(0, size); + if (data) + { + boost::ptr_vector paths; + // TODO - contraint fails if multiple_geometries = true + bool multiple_geometries = false; + mapnik::geometry_utils::from_wkb(paths, data, size, multiple_geometries, mapnik::wkbAuto); + for (unsigned i=0; i const& bbox = paths[i].envelope(); + if (bbox.valid()) + { + if (first) + { + first = false; + extent = bbox; + } + else + { + extent.expand_to_include(bbox); + } + + ps.bind(bbox); + + const int type_oid = rs->column_type(1); + if (type_oid != SQLITE_INTEGER) + { + std::ostringstream error_msg; + error_msg << "Sqlite Plugin: invalid type for key field '" + << rs->column_name(1) << "' when creating index '" << index_table + << "' type was: " << type_oid << ""; + throw mapnik::datasource_exception(error_msg.str()); + } + + const sqlite_int64 pkid = rs->column_integer64(1); + ps.bind(pkid); + } + else + { + std::ostringstream error_msg; + error_msg << "SQLite Plugin: encountered invalid bbox at '" + << rs->column_name(1) << "' == " << rs->column_integer64(1); + throw mapnik::datasource_exception(error_msg.str()); + } + + ps.step_next(); + } + } + } + ds->execute("COMMIT"); + } + + static bool detect_extent(boost::shared_ptr ds, + bool has_spatial_index, + mapnik::box2d & extent, + std::string const& index_table, + std::string const& metadata, + std::string const& geometry_field, + std::string const& geometry_table, + std::string const& key_field, + std::string const& table + ) + { + if (has_spatial_index) + { + std::ostringstream s; + s << "SELECT MIN(xmin), MIN(ymin), MAX(xmax), MAX(ymax) FROM " + << index_table; + + boost::shared_ptr rs(ds->execute_query(s.str())); + if (rs->is_valid() && rs->step_next()) + { + if (! rs->column_isnull(0)) + { + try + { + double xmin = boost::lexical_cast(rs->column_double(0)); + double ymin = boost::lexical_cast(rs->column_double(1)); + double xmax = boost::lexical_cast(rs->column_double(2)); + double ymax = boost::lexical_cast(rs->column_double(3)); + extent.init(xmin, ymin, xmax, ymax); + return true; + } + catch (boost::bad_lexical_cast& ex) + { + std::ostringstream ss; + ss << "SQLite Plugin: warning: could not determine extent from query: " + << "'" << s.str() << "' \n problem was: " << ex.what() << std::endl; + std::clog << ss.str(); + } + } + } + } + else if (! metadata.empty()) + { + std::ostringstream s; + s << "SELECT xmin, ymin, xmax, ymax FROM " << metadata; + s << " WHERE LOWER(f_table_name) = LOWER('" << geometry_table << "')"; + boost::shared_ptr rs(ds->execute_query(s.str())); + if (rs->is_valid() && rs->step_next()) + { + double xmin = rs->column_double (0); + double ymin = rs->column_double (1); + double xmax = rs->column_double (2); + double ymax = rs->column_double (3); + extent.init (xmin, ymin, xmax, ymax); + return true; + } + } + else if (! key_field.empty()) + { + std::ostringstream s; + s << "SELECT " << geometry_field << "," << key_field + << " FROM (" << table << ")"; + boost::shared_ptr rs(ds->execute_query(s.str())); + sqlite_utils::query_extent(rs,extent); + return true; + } + return false; + } + + static bool has_rtree(std::string const& index_table,boost::shared_ptr ds) + { + try + { + std::ostringstream s; + s << "SELECT pkid,xmin,xmax,ymin,ymax FROM " << index_table << " LIMIT 1"; + boost::shared_ptr rs = ds->execute_query(s.str()); + if (rs->is_valid() && rs->step_next()) + { + return true; + } + } + catch (...) + { + return false; + } + return false; + } + + static bool detect_types_from_subquery(std::string const& query, + std::string & geometry_field, + mapnik::layer_descriptor & desc, + boost::shared_ptr ds) + { + bool found = false; + boost::shared_ptr rs(ds->execute_query(query)); + if (rs->is_valid() && rs->step_next()) + { + for (int i = 0; i < rs->column_count(); ++i) + { + found = true; + const int type_oid = rs->column_type(i); + const char* fld_name = rs->column_name(i); + switch (type_oid) + { + case SQLITE_INTEGER: + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Integer)); + break; + + case SQLITE_FLOAT: + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Double)); + break; + + case SQLITE_TEXT: + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String)); + break; + + case SQLITE_NULL: + // sqlite reports based on value, not actual column type unless + // PRAGMA table_info is used so here we assume the column is a string + // which is a lesser evil than altogether dropping the column + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String)); + + case SQLITE_BLOB: + if (geometry_field.empty() + && (boost::algorithm::icontains(fld_name, "geom") || + boost::algorithm::icontains(fld_name, "point") || + boost::algorithm::icontains(fld_name, "linestring") || + boost::algorithm::icontains(fld_name, "polygon"))) + { + geometry_field = std::string(fld_name); + } + break; + + default: +#ifdef MAPNIK_DEBUG + std::clog << "Sqlite Plugin: unknown type_oid=" << type_oid << std::endl; +#endif + break; + } + } + } + + return found; + } + + static bool table_info(std::string & key_field, + bool detected_types, + std::string & field, + std::string & table, + mapnik::layer_descriptor & desc, + boost::shared_ptr ds) + { + + // http://www.sqlite.org/pragma.html#pragma_table_info + // use pragma table_info to detect primary key + // and to detect types if no subquery is used or + // if the subquery-based type detection failed + std::ostringstream s; + s << "PRAGMA table_info(" << table << ")"; + boost::shared_ptr rs(ds->execute_query(s.str())); + bool found_table = false; + bool found_pk = false; + while (rs->is_valid() && rs->step_next()) + { + found_table = true; + const char* fld_name = rs->column_text(1); + std::string fld_type(rs->column_text(2)); + int fld_pk = rs->column_integer(5); + boost::algorithm::to_lower(fld_type); + + // TODO - how to handle primary keys on multiple columns ? + if (key_field.empty() && ! found_pk && fld_pk != 0) + { + key_field = fld_name; + found_pk = true; + } + if (! detected_types) + { + // see 2.1 "Column Affinity" at http://www.sqlite.org/datatype3.html + // TODO - refactor this somehow ? + if (field.empty() + && ((boost::algorithm::contains(fld_type, "geom") || + boost::algorithm::contains(fld_type, "point") || + boost::algorithm::contains(fld_type, "linestring") || + boost::algorithm::contains(fld_type, "polygon")) + || + (boost::algorithm::icontains(fld_name, "geom") || + boost::algorithm::icontains(fld_name, "point") || + boost::algorithm::icontains(fld_name, "linestring") || + boost::algorithm::icontains(fld_name, "polygon"))) + ) + { + field = std::string(fld_name); + } + else if (boost::algorithm::contains(fld_type, "int")) + { + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Integer)); + } + else if (boost::algorithm::contains(fld_type, "text") || + boost::algorithm::contains(fld_type, "char") || + boost::algorithm::contains(fld_type, "clob")) + { + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String)); + } + else if (boost::algorithm::contains(fld_type, "real") || + boost::algorithm::contains(fld_type, "float") || + boost::algorithm::contains(fld_type, "double")) + { + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Double)); + } + else if (boost::algorithm::contains(fld_type, "blob")) + { + if (! field.empty()) + { + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String)); + } + } + #ifdef MAPNIK_DEBUG + else + { + // "Column Affinity" says default to "Numeric" but for now we pass.. + //desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double)); + + // TODO - this should not fail when we specify geometry_field in XML file + + std::clog << "Sqlite Plugin: column '" + << std::string(fld_name) + << "' unhandled due to unknown type: " + << fld_type << std::endl; + } + #endif + } + } + + return found_table; + } +}; + +#endif // MAPNIK_SQLITE_UTILS_HPP diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index 42793cf49..9275c0d76 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -73,7 +73,7 @@ // boost #include - +#include // stl #ifdef MAPNIK_DEBUG @@ -121,8 +121,31 @@ agg_renderer::agg_renderer(Map const& m, T & pixmap, double scale_factor, uns t_(m.width(),m.height(),m.get_current_extent(),offset_x,offset_y), font_engine_(), font_manager_(font_engine_), - detector_(box2d(-m.buffer_size(), -m.buffer_size(), m.width() + m.buffer_size() ,m.height() + m.buffer_size())), + detector_(boost::make_shared(box2d(-m.buffer_size(), -m.buffer_size(), m.width() + m.buffer_size() ,m.height() + m.buffer_size()))), ras_ptr(new rasterizer) +{ + setup(m); +} + +template +agg_renderer::agg_renderer(Map const& m, T & pixmap, boost::shared_ptr detector, + double scale_factor, unsigned offset_x, unsigned offset_y) + : feature_style_processor(m, scale_factor), + pixmap_(pixmap), + width_(pixmap_.width()), + height_(pixmap_.height()), + scale_factor_(scale_factor), + t_(m.width(),m.height(),m.get_current_extent(),offset_x,offset_y), + font_engine_(), + font_manager_(font_engine_), + detector_(detector), + ras_ptr(new rasterizer) +{ + setup(m); +} + +template +void agg_renderer::setup(Map const &m) { boost::optional const& bg = m.background(); if (bg) pixmap_.set_background(*bg); @@ -189,7 +212,7 @@ void agg_renderer::start_layer_processing(layer const& lay) #endif if (lay.clear_label_cache()) { - detector_.clear(); + detector_->clear(); } } diff --git a/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index dda8090d8..a9b8b0dbd 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/agg/process_glyph_symbolizer.cpp b/src/agg/process_glyph_symbolizer.cpp index e3b31b3cb..4a82cdb4b 100644 --- a/src/agg/process_glyph_symbolizer.cpp +++ b/src/agg/process_glyph_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -59,9 +59,9 @@ void agg_renderer::process(glyph_symbolizer const& sym, } // set font size - unsigned size = sym.eval_size(feature); - ren.set_pixel_size(size * scale_factor_); - faces->set_pixel_sizes(size * scale_factor_); + float size = sym.eval_size(feature); + ren.set_character_size(size * scale_factor_); + faces->set_character_sizes(size * scale_factor_); // Get and render text path // @@ -77,12 +77,12 @@ void agg_renderer::process(glyph_symbolizer const& sym, // final box so we can check for a valid placement box2d dim = ren.prepare_glyphs(path.get()); box2d ext(x-dim.width()/2, y-dim.height()/2, x+dim.width()/2, y+dim.height()/2); - if ((sym.get_allow_overlap() || detector_.has_placement(ext)) && - (!sym.get_avoid_edges() || detector_.extent().contains(ext))) + if ((sym.get_allow_overlap() || detector_->has_placement(ext)) && + (!sym.get_avoid_edges() || detector_->extent().contains(ext))) { // Placement is valid, render glyph and update detector. ren.render(x, y); - detector_.insert(ext); + detector_->insert(ext); metawriter_with_properties writer = sym.get_metawriter(); if (writer.first) writer.first->add_box(ext, feature, t_, writer.second); } diff --git a/src/agg/process_line_pattern_symbolizer.cpp b/src/agg/process_line_pattern_symbolizer.cpp index 99559f167..17f9cd191 100644 --- a/src/agg/process_line_pattern_symbolizer.cpp +++ b/src/agg/process_line_pattern_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/agg/process_line_symbolizer.cpp b/src/agg/process_line_symbolizer.cpp index a4de58dd8..c44cb273c 100644 --- a/src/agg/process_line_symbolizer.cpp +++ b/src/agg/process_line_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index d40b02ee7..0765bcf6f 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -109,7 +109,7 @@ void agg_renderer::process(markers_symbolizer const& sym, } path_type path(t_,geom,prj_trans); - markers_placement placement(path, extent, detector_, + markers_placement placement(path, extent, *detector_, sym.get_spacing() * scale_factor_, sym.get_max_error(), sym.get_allow_overlap()); @@ -194,7 +194,7 @@ void agg_renderer::process(markers_symbolizer const& sym, box2d label_ext (px, py, px + dx +1, py + dy +1); if (sym.get_allow_overlap() || - detector_.has_placement(label_ext)) + detector_->has_placement(label_ext)) { agg::ellipse c(x, y, w, h); marker.concat_path(c); @@ -215,7 +215,7 @@ void agg_renderer::process(markers_symbolizer const& sym, ren.color(agg::rgba8(s_r, s_g, s_b, int(s_a*stroke_.get_opacity()))); agg::render_scanlines(*ras_ptr, sl_line, ren); } - detector_.insert(label_ext); + detector_->insert(label_ext); if (writer.first) writer.first->add_box(label_ext, feature, t_, writer.second); } } @@ -226,7 +226,7 @@ void agg_renderer::process(markers_symbolizer const& sym, marker.concat_path(arrow_); path_type path(t_,geom,prj_trans); - markers_placement placement(path, extent, detector_, + markers_placement placement(path, extent, *detector_, sym.get_spacing() * scale_factor_, sym.get_max_error(), sym.get_allow_overlap()); diff --git a/src/agg/process_point_symbolizer.cpp b/src/agg/process_point_symbolizer.cpp index fd57ec1d5..fb3035d8e 100644 --- a/src/agg/process_point_symbolizer.cpp +++ b/src/agg/process_point_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -99,13 +99,13 @@ void agg_renderer::process(point_symbolizer const& sym, label_ext.re_center(x,y); if (sym.get_allow_overlap() || - detector_.has_placement(label_ext)) + detector_->has_placement(label_ext)) { render_marker(floor(x - 0.5 * w),floor(y - 0.5 * h) ,**marker,tr, sym.get_opacity()); if (!sym.get_ignore_placement()) - detector_.insert(label_ext); + detector_->insert(label_ext); metawriter_with_properties writer = sym.get_metawriter(); if (writer.first) writer.first->add_box(label_ext, feature, t_, writer.second); } diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index 23ea90043..a9a036ae5 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index e284a5c32..c376d9544 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/agg/process_raster_symbolizer.cpp b/src/agg/process_raster_symbolizer.cpp index af1329b96..0f3e062f0 100644 --- a/src/agg/process_raster_symbolizer.cpp +++ b/src/agg/process_raster_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/agg/process_shield_symbolizer.cpp b/src/agg/process_shield_symbolizer.cpp index 2008939f0..7d2c02741 100644 --- a/src/agg/process_shield_symbolizer.cpp +++ b/src/agg/process_shield_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -129,13 +129,13 @@ void agg_renderer::process(shield_symbolizer const& sym, { text_renderer ren(pixmap_, faces, *strk); - ren.set_pixel_size(sym.get_text_size() * scale_factor_); + ren.set_character_size(sym.get_text_size() * scale_factor_); ren.set_fill(sym.get_fill()); ren.set_halo_fill(sym.get_halo_fill()); ren.set_halo_radius(sym.get_halo_radius() * scale_factor_); ren.set_opacity(sym.get_text_opacity()); - placement_finder finder(detector_); + placement_finder finder(*detector_); string_info info(text); @@ -210,13 +210,13 @@ void agg_renderer::process(shield_symbolizer const& sym, label_ext.re_center(label_x,label_y); } - if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) ) + if ( sym.get_allow_overlap() || detector_->has_placement(label_ext) ) { render_marker(px,py,**marker,tr,sym.get_opacity()); box2d dim = ren.prepare_glyphs(&text_placement.placements[0]); ren.render(x,y); - detector_.insert(label_ext); + detector_->insert(label_ext); finder.update_detector(text_placement); if (writer.first) { writer.first->add_box(label_ext, feature, t_, writer.second); diff --git a/src/agg/process_text_symbolizer.cpp b/src/agg/process_text_symbolizer.cpp index 58b00a4d6..a127a19ee 100644 --- a/src/agg/process_text_symbolizer.cpp +++ b/src/agg/process_text_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -35,6 +35,7 @@ void agg_renderer::process(text_symbolizer const& sym, { + // Use a boost::ptr_vector here instread of std::vector? std::vector geometries_to_process; unsigned num_geom = feature.num_geometries(); for (unsigned i=0; i::process(text_symbolizer const& sym, throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'"); } text_renderer ren(pixmap_, faces, *strk); - ren.set_pixel_size(placement_options->text_size * scale_factor_); + + ren.set_character_size(placement_options->text_size * scale_factor_); ren.set_fill(fill); ren.set_halo_fill(sym.get_halo_fill()); ren.set_halo_radius(sym.get_halo_radius() * scale_factor_); ren.set_opacity(sym.get_text_opacity()); - + box2d dims(0,0,width_,height_); - placement_finder finder(detector_,dims); + placement_finder finder(*detector_,dims); string_info info(text); diff --git a/src/arrow.cpp b/src/arrow.cpp index bf577da22..593452e4b 100644 --- a/src/arrow.cpp +++ b/src/arrow.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/box2d.cpp b/src/box2d.cpp index 4998994cc..16fe3148b 100644 --- a/src/box2d.cpp +++ b/src/box2d.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/build.py b/src/build.py index b5e0bd834..d519c8d72 100644 --- a/src/build.py +++ b/src/build.py @@ -53,9 +53,11 @@ ABI_VERSION = env['ABI_VERSION'] filesystem = 'boost_filesystem%s' % env['BOOST_APPEND'] regex = 'boost_regex%s' % env['BOOST_APPEND'] +system = 'boost_system%s' % env['BOOST_APPEND'] # clear out and re-set libs for this env -lib_env['LIBS'] = ['freetype','ltdl','png','tiff','z','jpeg','proj',env['ICU_LIB_NAME'],filesystem,regex] +lib_env['LIBS'] = ['freetype','ltdl','png','tiff','z','jpeg','proj',env['ICU_LIB_NAME'],filesystem,system,regex] + if len(env['EXTRA_FREETYPE_LIBS']): lib_env['LIBS'].extend(copy(env['EXTRA_FREETYPE_LIBS'])) @@ -67,11 +69,11 @@ lib_env['LIBS'].append('xml2') if env['THREADING'] == 'multi': lib_env['LIBS'].append('boost_thread%s' % env['BOOST_APPEND']) -if env['HAS_BOOST_SYSTEM']: - lib_env['LIBS'].append('boost_system%s' % env['BOOST_APPEND']) - -if not env['RUNTIME_LINK'] == 'static': +if env['RUNTIME_LINK'] == 'static': + if 'icuuc' in env['ICU_LIB_NAME']: + lib_env['LIBS'].append('icudata') +else: if env['INTERNAL_LIBAGG']: lib_env['LIBS'].insert(0, 'agg') else: diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index e1976f547..668c8ebbd 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2008 Tom Hughes + * 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 @@ -1138,7 +1138,7 @@ void cairo_renderer_base::process(shield_symbolizer const& sym, placement_finder finder(detector_); - faces->set_pixel_sizes(placement_options->text_size); + faces->set_character_sizes(placement_options->text_size); faces->get_string_info(info); int w = (*marker)->width(); @@ -1466,7 +1466,7 @@ void cairo_renderer_base::process(glyph_symbolizer const& sym, // set font size unsigned size = sym.eval_size(feature); - faces->set_pixel_sizes(size); + faces->set_character_sizes(size); // Get and render text path // @@ -1563,7 +1563,7 @@ void cairo_renderer_base::process(text_symbolizer const& sym, cairo_context context(context_); string_info info(text); - faces->set_pixel_sizes(placement_options->text_size); + faces->set_character_sizes(placement_options->text_size); faces->get_string_info(info); placement_finder finder(detector_); diff --git a/src/color.cpp b/src/color.cpp index 368d50d14..dde0575c5 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 5c0b8620b..a3847ee2f 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/distance.cpp b/src/distance.cpp index 1fff44143..683c69230 100644 --- a/src/distance.cpp +++ b/src/distance.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/expression_string.cpp b/src/expression_string.cpp index b3d5dcc0b..78932bdf0 100644 --- a/src/expression_string.cpp +++ b/src/expression_string.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2009 Artem Pavlenko + * 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 diff --git a/src/feature_type_style.cpp b/src/feature_type_style.cpp index c2afba08d..e0a7a8336 100644 --- a/src/feature_type_style.cpp +++ b/src/feature_type_style.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/filter_factory.cpp b/src/filter_factory.cpp index 97e7e6129..f55cd096c 100644 --- a/src/filter_factory.cpp +++ b/src/filter_factory.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index a1b586192..769abcbe7 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/font_set.cpp b/src/font_set.cpp index f1a975ba4..df24f4c37 100644 --- a/src/font_set.cpp +++ b/src/font_set.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/glyph_symbolizer.cpp b/src/glyph_symbolizer.cpp index b94bb7766..8ef41c638 100644 --- a/src/glyph_symbolizer.cpp +++ b/src/glyph_symbolizer.cpp @@ -97,7 +97,7 @@ unsigned glyph_symbolizer::eval_size(Feature const& feature) const #ifdef MAPNIK_DEBUG std::clog << "size_result=" << result.to_string() << "\n"; #endif - unsigned size = static_cast(result.to_int()); + float size = static_cast(result.to_double()); #ifdef MAPNIK_DEBUG std::clog << "size=" << size << "\n"; #endif diff --git a/src/gradient.cpp b/src/gradient.cpp index 35dc2ccc5..8e9c7278c 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavelenko + * 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 diff --git a/src/graphics.cpp b/src/graphics.cpp index 46f30d3c7..90099da1b 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/grid/process_markers_symbolizer.cpp b/src/grid/process_markers_symbolizer.cpp index 84b2da613..347324326 100644 --- a/src/grid/process_markers_symbolizer.cpp +++ b/src/grid/process_markers_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/grid/process_shield_symbolizer.cpp b/src/grid/process_shield_symbolizer.cpp index 182412f22..d0f61cd67 100644 --- a/src/grid/process_shield_symbolizer.cpp +++ b/src/grid/process_shield_symbolizer.cpp @@ -110,7 +110,7 @@ void grid_renderer::process(shield_symbolizer const& sym, { text_renderer ren(pixmap_, faces, *strk); - ren.set_pixel_size(sym.get_text_size() * scale_factor_ * (1.0/pixmap_.get_resolution())); + ren.set_character_size(sym.get_text_size() * scale_factor_ * (1.0/pixmap_.get_resolution())); ren.set_fill(sym.get_fill()); ren.set_halo_fill(sym.get_halo_fill()); ren.set_halo_radius(sym.get_halo_radius() * scale_factor_); diff --git a/src/grid/process_text_symbolizer.cpp b/src/grid/process_text_symbolizer.cpp index 6e3c1b5dc..e88aed6c5 100644 --- a/src/grid/process_text_symbolizer.cpp +++ b/src/grid/process_text_symbolizer.cpp @@ -77,7 +77,7 @@ void grid_renderer::process(text_symbolizer const& sym, throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'"); } text_renderer ren(pixmap_, faces, *strk); - ren.set_pixel_size(placement_options->text_size * (scale_factor_ * (1.0/pixmap_.get_resolution()))); + ren.set_character_size(placement_options->text_size * (scale_factor_ * (1.0/pixmap_.get_resolution()))); ren.set_fill(fill); ren.set_halo_fill(sym.get_halo_fill()); ren.set_halo_radius(sym.get_halo_radius() * scale_factor_); diff --git a/src/image_reader.cpp b/src/image_reader.cpp index 504538096..75f98d881 100644 --- a/src/image_reader.cpp +++ b/src/image_reader.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/image_util.cpp b/src/image_util.cpp index dc1fbbebe..39ffa9163 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/jpeg_reader.cpp b/src/jpeg_reader.cpp index 6f665daa8..aac35b24c 100644 --- a/src/jpeg_reader.cpp +++ b/src/jpeg_reader.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -36,8 +36,8 @@ extern "C" #include #include -// stl -#include +// std +#include #ifdef MAPNIK_DEBUG #include diff --git a/src/layer.cpp b/src/layer.cpp index ba40a85f6..1700dec9f 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/libxml2_loader.cpp b/src/libxml2_loader.cpp index ec9392c33..f935243ce 100644 --- a/src/libxml2_loader.cpp +++ b/src/libxml2_loader.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2007 Artem Pavlenko + * 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 diff --git a/src/line_pattern_symbolizer.cpp b/src/line_pattern_symbolizer.cpp index 4703f98d5..f03cc90ae 100644 --- a/src/line_pattern_symbolizer.cpp +++ b/src/line_pattern_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/line_symbolizer.cpp b/src/line_symbolizer.cpp index d6ae7e08f..ccece0f8a 100644 --- a/src/line_symbolizer.cpp +++ b/src/line_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/load_map.cpp b/src/load_map.cpp index f31767583..9b25dec5f 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 @@ -1244,10 +1244,10 @@ void map_parser::parse_text_symbolizer( rule & rule, ptree const & sym ) optional fontset_name = get_opt_attr(sym, "fontset-name"); - unsigned size = get_attr(sym, "size", 10U); - + float size = get_attr(sym, "size", 10.0f); + color c = get_attr(sym, "fill", color(0,0,0)); - + text_symbolizer text_symbol = text_symbolizer(parse_expression(name, "utf8"), size, c, placement_finder); optional orientation = get_opt_attr(sym, "orientation"); @@ -1486,7 +1486,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym ) optional fontset_name = get_opt_attr(sym, "fontset-name"); - unsigned size = get_attr(sym, "size", 10U); + float size = get_attr(sym, "size", 10.0f); color fill = get_attr(sym, "fill", color(0,0,0)); std::string image_file = get_attr(sym, "file"); diff --git a/src/map.cpp b/src/map.cpp index 951b76a90..2f6e7af43 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/marker_cache.cpp b/src/marker_cache.cpp index 16a1d1e63..b93ce663c 100644 --- a/src/marker_cache.cpp +++ b/src/marker_cache.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/markers_symbolizer.cpp b/src/markers_symbolizer.cpp index 7588d66e9..bd30cf47e 100644 --- a/src/markers_symbolizer.cpp +++ b/src/markers_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/memory.cpp b/src/memory.cpp index 92a5c14ad..7869a0fe6 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/memory_datasource.cpp b/src/memory_datasource.cpp index d22bcbd8a..bc60255cd 100644 --- a/src/memory_datasource.cpp +++ b/src/memory_datasource.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/metawriter.cpp b/src/metawriter.cpp index 25022b507..51a56b247 100644 --- a/src/metawriter.cpp +++ b/src/metawriter.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Hermann Kraus + * 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 diff --git a/src/metawriter_factory.cpp b/src/metawriter_factory.cpp index fc4ebbc26..fbb33afc3 100644 --- a/src/metawriter_factory.cpp +++ b/src/metawriter_factory.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 MapQuest + * 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 diff --git a/src/metawriter_inmem.cpp b/src/metawriter_inmem.cpp index b0ca16d1f..27025cde0 100644 --- a/src/metawriter_inmem.cpp +++ b/src/metawriter_inmem.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 MapQuest + * 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 diff --git a/src/palette.cpp b/src/palette.cpp index 8ef8018fc..0dccde3b7 100644 --- a/src/palette.cpp +++ b/src/palette.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -110,7 +110,9 @@ unsigned rgba_palette::quantize(rgba const& c) const da = sorted_pal_[i].a - c.a; // stop criteria based on properties of used sorting if ((dr+db+dg+da) * (dr+db+dg+da) / 4 > dist) + { break; + } newdist = dr*dr + dg*dg + db*db + da*da; if (newdist < dist) { @@ -118,6 +120,7 @@ unsigned rgba_palette::quantize(rgba const& c) const dist = newdist; } } + for (unsigned i = poz + 1; i < sorted_pal_.size(); i++) { dr = sorted_pal_[i].r - c.r; @@ -126,7 +129,9 @@ unsigned rgba_palette::quantize(rgba const& c) const da = sorted_pal_[i].a - c.a; // stop criteria based on properties of used sorting if ((dr+db+dg+da) * (dr+db+dg+da) / 4 > dist) + { break; + } newdist = dr*dr + dg*dg + db*db + da*da; if (newdist < dist) { @@ -144,7 +149,7 @@ unsigned rgba_palette::quantize(rgba const& c) const void rgba_palette::parse(std::string const& pal, palette_type type) { - int length = pal.length(); + unsigned length = pal.length(); if ((type == PALETTE_RGBA && length % 4 > 0) || (type == PALETTE_RGB && length % 3 > 0) || @@ -163,18 +168,26 @@ void rgba_palette::parse(std::string const& pal, palette_type type) rgb_pal_.clear(); alpha_pal_.clear(); - if (type == PALETTE_RGBA) for (unsigned i = 0; i < length; i += 4) + if (type == PALETTE_RGBA) { - sorted_pal_.push_back(rgba(pal[i], pal[i + 1], pal[i + 2], pal[i + 3])); + for (unsigned i = 0; i < length; i += 4) + { + sorted_pal_.push_back(rgba(pal[i], pal[i + 1], pal[i + 2], pal[i + 3])); + } } - else for (unsigned i = 0; i < length; i += 3) + else { - sorted_pal_.push_back(rgba(pal[i], pal[i + 1], pal[i + 2], 0xFF)); + for (unsigned i = 0; i < length; i += 3) + { + sorted_pal_.push_back(rgba(pal[i], pal[i + 1], pal[i + 2], 0xFF)); + } } // Make sure we have at least one entry in the palette. if (sorted_pal_.size() == 0) + { sorted_pal_.push_back(rgba(0, 0, 0, 0)); + } colors_ = sorted_pal_.size(); @@ -187,7 +200,10 @@ void rgba_palette::parse(std::string const& pal, palette_type type) rgba c = sorted_pal_[i]; color_hashmap_[c] = i; rgb_pal_.push_back(rgb(c)); - if (c.a < 0xFF) alpha_pal_.push_back(c.a); + if (c.a < 0xFF) + { + alpha_pal_.push_back(c.a); + } } } diff --git a/src/parse_path.cpp b/src/parse_path.cpp index d5ac0a9e4..aa7e1f9fe 100644 --- a/src/parse_path.cpp +++ b/src/parse_path.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index 9813dab04..b0dafd56b 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -2,8 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko - * Copyright (C) 2006 10East Corp. + * 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 diff --git a/src/plugin.cpp b/src/plugin.cpp index 7e5aa9445..e96d71b52 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/png_reader.cpp b/src/png_reader.cpp index 3dfaab3ea..9e642a91b 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/point_symbolizer.cpp b/src/point_symbolizer.cpp index c7d62645d..221f922cd 100644 --- a/src/point_symbolizer.cpp +++ b/src/point_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/polygon_pattern_symbolizer.cpp b/src/polygon_pattern_symbolizer.cpp index 4519670b6..234fc000b 100644 --- a/src/polygon_pattern_symbolizer.cpp +++ b/src/polygon_pattern_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 462453deb..e835adf4c 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/projection.cpp b/src/projection.cpp index c6a74f32a..ca0344cba 100644 --- a/src/projection.cpp +++ b/src/projection.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/raster_colorizer.cpp b/src/raster_colorizer.cpp index 603273b1f..03f2968f5 100644 --- a/src/raster_colorizer.cpp +++ b/src/raster_colorizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/save_map.cpp b/src/save_map.cpp index 0e885c9ce..2a9e8368e 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/scale_denominator.cpp b/src/scale_denominator.cpp index e9cff6dc6..f79a964a8 100644 --- a/src/scale_denominator.cpp +++ b/src/scale_denominator.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/shield_symbolizer.cpp b/src/shield_symbolizer.cpp index c8102448c..fcf54a73e 100644 --- a/src/shield_symbolizer.cpp +++ b/src/shield_symbolizer.cpp @@ -2,8 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko - * Copyright (C) 2006 10East Corp. + * 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 @@ -38,7 +37,7 @@ namespace mapnik shield_symbolizer::shield_symbolizer( expression_ptr name, std::string const& face_name, - unsigned size, + float size, color const& fill, path_expression_ptr file) : text_symbolizer(name, face_name, size, fill), @@ -51,7 +50,7 @@ shield_symbolizer::shield_symbolizer( shield_symbolizer::shield_symbolizer( expression_ptr name, - unsigned size, + float size, color const& fill, path_expression_ptr file) : text_symbolizer(name, size, fill), diff --git a/src/stroke.cpp b/src/stroke.cpp index 0a9ecb40f..fbce4542d 100644 --- a/src/stroke.cpp +++ b/src/stroke.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/svg/process_building_symbolizer.cpp b/src/svg/process_building_symbolizer.cpp index e35bd7384..da56146b6 100644 --- a/src/svg/process_building_symbolizer.cpp +++ b/src/svg/process_building_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/svg/process_glyph_symbolizer.cpp b/src/svg/process_glyph_symbolizer.cpp index cfcea7ed7..7ac35bb4d 100644 --- a/src/svg/process_glyph_symbolizer.cpp +++ b/src/svg/process_glyph_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_line_pattern_symbolizer.cpp b/src/svg/process_line_pattern_symbolizer.cpp index a72bd59d9..8a2274284 100644 --- a/src/svg/process_line_pattern_symbolizer.cpp +++ b/src/svg/process_line_pattern_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_line_symbolizer.cpp b/src/svg/process_line_symbolizer.cpp index 0e99eb681..825b08d0b 100644 --- a/src/svg/process_line_symbolizer.cpp +++ b/src/svg/process_line_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_markers_symbolizer.cpp b/src/svg/process_markers_symbolizer.cpp index c6e88f091..a4bba39bd 100644 --- a/src/svg/process_markers_symbolizer.cpp +++ b/src/svg/process_markers_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_point_symbolizer.cpp b/src/svg/process_point_symbolizer.cpp index 0d586e2ea..bc6ab1a9c 100644 --- a/src/svg/process_point_symbolizer.cpp +++ b/src/svg/process_point_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_polygon_pattern_symbolizer.cpp b/src/svg/process_polygon_pattern_symbolizer.cpp index 8ff791a81..b3639b193 100644 --- a/src/svg/process_polygon_pattern_symbolizer.cpp +++ b/src/svg/process_polygon_pattern_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_polygon_symbolizer.cpp b/src/svg/process_polygon_symbolizer.cpp index d6a65aef9..0c787d407 100644 --- a/src/svg/process_polygon_symbolizer.cpp +++ b/src/svg/process_polygon_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_raster_symbolizer.cpp b/src/svg/process_raster_symbolizer.cpp index d68be6793..ee7e0ab27 100644 --- a/src/svg/process_raster_symbolizer.cpp +++ b/src/svg/process_raster_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_shield_symbolizer.cpp b/src/svg/process_shield_symbolizer.cpp index b342b321e..7b9ae0311 100644 --- a/src/svg/process_shield_symbolizer.cpp +++ b/src/svg/process_shield_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/process_symbolizers.cpp b/src/svg/process_symbolizers.cpp index 16adc8b28..afa582e52 100644 --- a/src/svg/process_symbolizers.cpp +++ b/src/svg/process_symbolizers.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/svg/process_text_symbolizer.cpp b/src/svg/process_text_symbolizer.cpp index 1b3549c34..5440b1b01 100644 --- a/src/svg/process_text_symbolizer.cpp +++ b/src/svg/process_text_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/svg_generator.cpp b/src/svg/svg_generator.cpp index f2fe7fbfb..8e626eeea 100644 --- a/src/svg/svg_generator.cpp +++ b/src/svg/svg_generator.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/svg_output_attributes.cpp b/src/svg/svg_output_attributes.cpp index a9b209dde..eac93a891 100644 --- a/src/svg/svg_output_attributes.cpp +++ b/src/svg/svg_output_attributes.cpp @@ -3,7 +3,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg/svg_renderer.cpp b/src/svg/svg_renderer.cpp index b38644e89..8834644c4 100644 --- a/src/svg/svg_renderer.cpp +++ b/src/svg/svg_renderer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/svg_parser.cpp b/src/svg_parser.cpp index 3bd614392..73c693eb1 100644 --- a/src/svg_parser.cpp +++ b/src/svg_parser.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg_path_parser.cpp b/src/svg_path_parser.cpp index 2949ff34b..18539f42f 100644 --- a/src/svg_path_parser.cpp +++ b/src/svg_path_parser.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg_points_parser.cpp b/src/svg_points_parser.cpp index c4d410d4b..d7c6fdbb8 100644 --- a/src/svg_points_parser.cpp +++ b/src/svg_points_parser.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/svg_transform_parser.cpp b/src/svg_transform_parser.cpp index ffe11f575..ea3b9bb4d 100644 --- a/src/svg_transform_parser.cpp +++ b/src/svg_transform_parser.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2010 Artem Pavlenko + * 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 diff --git a/src/symbolizer.cpp b/src/symbolizer.cpp index 240c1b5db..4eba20036 100644 --- a/src/symbolizer.cpp +++ b/src/symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/text_placements.cpp b/src/text_placements.cpp index a8eb3574e..e0c0bc80a 100644 --- a/src/text_placements.cpp +++ b/src/text_placements.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2011 Hermann Kraus + * 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 diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index f077f303a..db0e86261 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -87,7 +87,7 @@ IMPLEMENT_ENUM( text_transform_e, text_transform_strings ) text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_name, - unsigned size, color const& fill, + float size, color const& fill, text_placements_ptr placements) : symbolizer_base(), name_(name), @@ -120,7 +120,7 @@ text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_na set_text_size(size); } -text_symbolizer::text_symbolizer(expression_ptr name, unsigned size, color const& fill, +text_symbolizer::text_symbolizer(expression_ptr name, float size, color const& fill, text_placements_ptr placements) : symbolizer_base(), name_(name), @@ -378,12 +378,12 @@ void text_symbolizer::set_max_char_angle_delta(double angle) max_char_angle_delta_ = angle; } -void text_symbolizer::set_text_size(unsigned size) +void text_symbolizer::set_text_size(float size) { placement_options_->set_default_text_size(size); } -unsigned text_symbolizer::get_text_size() const +float text_symbolizer::get_text_size() const { return placement_options_->get_default_text_size(); } diff --git a/src/tiff_reader.cpp b/src/tiff_reader.cpp index 6c000a023..25a5d5724 100644 --- a/src/tiff_reader.cpp +++ b/src/tiff_reader.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 diff --git a/src/unicode.cpp b/src/unicode.cpp index a768705c3..5665ded5d 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006,2009 Artem Pavlenko + * 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 diff --git a/src/wkb.cpp b/src/wkb.cpp index 2e434f990..f704971b7 100644 --- a/src/wkb.cpp +++ b/src/wkb.cpp @@ -2,7 +2,7 @@ * * This file is part of Mapnik (c++ mapping toolkit) * - * Copyright (C) 2006 Artem Pavlenko + * 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 @@ -67,7 +67,7 @@ public: wkbGeometryCollectionZ=1007 }; - wkb_reader(const char* wkb,unsigned size, wkbFormat format) + wkb_reader(const char* wkb, unsigned size, wkbFormat format) : wkb_(wkb), size_(size), pos_(0), @@ -76,16 +76,16 @@ public: // try to determine WKB format automatically if (format_ == wkbAuto) { - if (size >= 44 - && (unsigned char)(wkb_[0]) == (unsigned char)(0x00) - && (unsigned char)(wkb_[38]) == (unsigned char)(0x7C)) - { - format_ = wkbSpatiaLite; - } - else - { - format_ = wkbGeneric; - } + if (size >= 44 + && (unsigned char)(wkb_[0]) == (unsigned char)(0x00) + && (unsigned char)(wkb_[38]) == (unsigned char)(0x7C)) + { + format_ = wkbSpatiaLite; + } + else + { + format_ = wkbGeneric; + } } switch (format_) diff --git a/tests/cpp_tests/svg_renderer_tests/build.py b/tests/cpp_tests/svg_renderer_tests/build.py index 8a1f52f4f..e6b2d13ee 100644 --- a/tests/cpp_tests/svg_renderer_tests/build.py +++ b/tests/cpp_tests/svg_renderer_tests/build.py @@ -1,5 +1,6 @@ import os import glob +from copy import copy Import ('env') @@ -9,14 +10,9 @@ filesystem = 'boost_filesystem%s' % env['BOOST_APPEND'] system = 'boost_system%s' % env['BOOST_APPEND'] regex = 'boost_regex%s' % env['BOOST_APPEND'] -libraries = [filesystem, 'mapnik2'] +libraries = copy(env['LIBMAPNIK_LIBS']) +libraries.append('mapnik2') -if env['PLATFORM'] == 'Darwin': - libraries.append(env['ICU_LIB_NAME']) - libraries.append(regex) - -if env['HAS_BOOST_SYSTEM']: - libraries.append(system) - -for cpp_test in glob.glob('path_element_test.cpp'): - env.Program(cpp_test.replace('.cpp',''), [cpp_test], CPPPATH=headers, LIBS=libraries) \ No newline at end of file +for cpp_test in glob.glob('*_test.cpp'): + test_program = env.Program(cpp_test.replace('.cpp',''), [cpp_test], CPPPATH=headers, LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS']) + Depends(test_program, env.subst('../../../src/%s' % env['MAPNIK_LIB_NAME'])) \ No newline at end of file diff --git a/tests/cpp_tests/svg_renderer_tests/combined_test.cpp b/tests/cpp_tests/svg_renderer_tests/combined_test.cpp index ffd1730b5..d4e250f75 100644 --- a/tests/cpp_tests/svg_renderer_tests/combined_test.cpp +++ b/tests/cpp_tests/svg_renderer_tests/combined_test.cpp @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(combined_test_case) svg_ren renderer(map, output_stream_iterator); renderer.apply(); - std::string expected_output = + /*std::string expected_output = svg_ren::XML_DECLARATION + "\n" + svg_ren::SVG_DTD @@ -52,5 +52,6 @@ BOOST_AUTO_TEST_CASE(combined_test_case) std::string actual_output = output_stream.str(); BOOST_CHECK_EQUAL(actual_output, expected_output); + */ } diff --git a/tests/cpp_tests/svg_renderer_tests/path_element_test.cpp b/tests/cpp_tests/svg_renderer_tests/path_element_test.cpp index 3a1d79f68..91bc4e5b8 100644 --- a/tests/cpp_tests/svg_renderer_tests/path_element_test.cpp +++ b/tests/cpp_tests/svg_renderer_tests/path_element_test.cpp @@ -26,9 +26,9 @@ using namespace mapnik; void prepare_map(Map& m) { - const std::string mapnik_dir("../../.."); - std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/plugins/input/" << "\n"; - datasource_cache::instance()->register_datasources(mapnik_dir + "/plugins/input/"); + const std::string mapnik_dir("/usr/local/lib/mapnik2/"); + std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "input/" << "\n"; + datasource_cache::instance()->register_datasources(mapnik_dir + "input/"); // create styles @@ -132,7 +132,7 @@ void prepare_map(Map& m) { parameters p; p["type"]="shape"; - p["file"]=mapnik_dir+"/demo/data/boundaries"; + p["file"]="../../../demo/data/boundaries"; layer lyr("Provinces"); lyr.set_datasource(datasource_cache::instance()->create(p)); @@ -144,7 +144,7 @@ void prepare_map(Map& m) { parameters p; p["type"]="shape"; - p["file"]=mapnik_dir+"/demo/data/qcdrainage"; + p["file"]="../../../demo/data/qcdrainage"; layer lyr("Quebec Hydrography"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("drainage"); @@ -154,7 +154,7 @@ void prepare_map(Map& m) { parameters p; p["type"]="shape"; - p["file"]=mapnik_dir+"/demo/data/ontdrainage"; + p["file"]="../../../demo/data/ontdrainage"; layer lyr("Ontario Hydrography"); lyr.set_datasource(datasource_cache::instance()->create(p)); @@ -166,7 +166,7 @@ void prepare_map(Map& m) { parameters p; p["type"]="shape"; - p["file"]=mapnik_dir+"/demo/data/boundaries_l"; + p["file"]="../../../demo/data/boundaries_l"; layer lyr("Provincial borders"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("provlines"); @@ -177,7 +177,7 @@ void prepare_map(Map& m) { parameters p; p["type"]="shape"; - p["file"]=mapnik_dir+"/demo/data/roads"; + p["file"]="../../../demo/data/roads"; layer lyr("Roads"); lyr.set_datasource(datasource_cache::instance()->create(p)); lyr.add_style("smallroads"); diff --git a/tests/data/csv/empty_rows.csv b/tests/data/csv/empty_rows.csv index d1d0cd26e..f9c860b41 100644 --- a/tests/data/csv/empty_rows.csv +++ b/tests/data/csv/empty_rows.csv @@ -1,4 +1,4 @@ -x,y,text,date,integer,boolean,float,time,datetime,empty_column +"x","y","text","date","integer","boolean","float","time","datetime","empty_column" 0,0,a b,1971-01-01,40,True,1.0,04:14:00,1971-01-01T04:14:00, 0,0,c d,1948-01-01,63,True,1.27,14:57:13,1948-01-01T14:57:13, 0,0,e f,1920-01-01,164,False,41800000.01,00:00:00,1920-01-01T00:00:00, diff --git a/tests/data/csv/fails/datacouch_dc8364385fc612b847d66ca7886519749c.csv b/tests/data/csv/fails/datacouch_dc8364385fc612b847d66ca7886519749c.csv new file mode 100644 index 000000000..778505418 --- /dev/null +++ b/tests/data/csv/fails/datacouch_dc8364385fc612b847d66ca7886519749c.csv @@ -0,0 +1,39 @@ +"_id","_rev","city","cross_street","geometry","gpsID","heading","moving","stopped_for","street","time","truck" +"013013bd7417fc4eb1d70053370d698d","1-cc614ed8a795b24945508435763def31","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.09611556,42.33877667]}","10300B7B","382","OTHER","5350","230 FENWAY","2011-10-21T22:56:32.000Z","CheeseForceOne" +"013013bd7417fc4eb1d70053370da624","1-303e3d47832991f13115f1f8fbf7aa30","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.09611556,42.33877667]}","10300B7B","382","OTHER","5400","230 FENWAY","2011-10-21T22:57:23.000Z","CheeseForceOne" +"013013bd7417fc4eb1d700533725c9e7","1-aa06630c2060997cca42d5e5491cec00","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11798667,42.29640194]}","10300295","382","OTHER","490","WASHINGTON ST","2011-10-21T23:01:06.000Z","Cupcakory" +"013013bd7417fc4eb1d70053372c06c4","1-e5f72c7a5a71e490319257e7bafffe3d","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11798667,42.29640194]}","10300295","39","MOVING","530","WASHINGTON ST","2011-10-21T23:01:47.000Z","Cupcakory" +"013013bd7417fc4eb1d70053372c2274","1-2680de3cb56db7a8a4a603b9e49a19c6","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11749917,42.29632694]}","10300295","39","MOVING CONFIRMATION",,"WASHINGTON ST","2011-10-21T23:01:48.000Z","Cupcakory" +"013013bd7417fc4eb1d700533761e1a7","1-cef095aee70aad4819490934450c3328","BOSTON","PORTER ST","{\"type\":\"Point\",\"coordinates\":[-71.10327194,42.31483667]}","10300D5F","382","OTHER","5400","BISMARCK ST","2011-10-21T23:05:56.000Z","StaffMeal" +"013013bd7417fc4eb1d700533762cf34","1-c22129144816e3dcd1190f77bbc5fe31","BOSTON","PORTER ST","{\"type\":\"Point\",\"coordinates\":[-71.1029475,42.31493028]}","10300D5F","84","MOVING CONFIRMATION",,"BISMARCK ST","2011-10-21T23:06:12.000Z","StaffMeal" +"013013bd7417fc4eb1d700533762ed4e","1-4d5403a6228c84fed13ca94fb759eed1","BOSTON","EDINBORO ST","{\"type\":\"Point\",\"coordinates\":[-71.05961167,42.35137889]}","10300B7C","382","OTHER","6430","KINGSTON ST","2011-10-21T23:05:25.000Z","BBQSmith" +"013013bd7417fc4eb1d7005337630613","1-94299d448735b989083f44cf34e98a3d","BOSTON","EDINBORO ST","{\"type\":\"Point\",\"coordinates\":[-71.05961167,42.35137889]}","10300B7C","382","OTHER","6480","KINGSTON ST","2011-10-21T23:06:15.000Z","BBQSmith" +"013013bd7417fc4eb1d7005337631d4c","1-b8b6103d2be1fd64e38b1d6f5d0e76d2","BOSTON","PORTER ST","{\"type\":\"Point\",\"coordinates\":[-71.10327194,42.31483667]}","10300D5F","84","MOVING","5410","BISMARCK ST","2011-10-21T23:06:11.000Z","StaffMeal" +"013013bd7417fc4eb1d7005337650fe7","1-ce161a29970409d24f5a02b7ccf4b615","BOSTON","ELIOT ST","{\"type\":\"Point\",\"coordinates\":[-71.11908333,42.31402278]}","10300295","54","MOVING UPDATE",,"JAMAICAWAY","2011-10-21T23:06:47.000Z","Cupcakory" +"013013bd7417fc4eb1d70053377d841a","1-e0d814cb12f221e43385c16f212fcf20","BOSTON","COLUMBUS AVE","{\"type\":\"Point\",\"coordinates\":[-71.0980425,42.31647306]}","10300D5F","382","STOP",,"W WALNUT PARK","2011-10-21T23:09:49.000Z","StaffMeal" +"013013bd7417fc4eb1d70053377db30b","1-17556dc5b906755396440419b665834d","BOSTON","COLUMBUS AVE","{\"type\":\"Point\",\"coordinates\":[-71.0980425,42.31647306]}","10300D5F","382","OTHER",,"W WALNUT PARK","2011-10-21T23:09:50.000Z","StaffMeal" +"013013bd7417fc4eb1d70053377f3ac7","1-9d1ad161d60eef01ecf1344bad7e14c1","BOSTON","COLUMBUS AVE","{\"type\":\"Point\",\"coordinates\":[-71.09804222,42.31647306]}","10300D5F","382","OTHER","10","W WALNUT PARK","2011-10-21T23:10:00.000Z","StaffMeal" +"013013bd7417fc4eb1d70053377fbf2c","1-c19c6c9e2dc5eb43d4be22144269a598","BOSTON","COLUMBUS AVE","{\"type\":\"Point\",\"coordinates\":[-71.09804222,42.31647306]}","10300D5F","382","OTHER","20","W WALNUT PARK","2011-10-21T23:10:09.000Z","StaffMeal" +"013013bd7417fc4eb1d7005337898fa8","1-7c06e21f544ab04b87c8fbe6d5938e40","BOSTON","CRAFTSON WAY","{\"type\":\"Point\",\"coordinates\":[-71.11125444,42.32992222]}","10300295","342","MOVING UPDATE",,"S HUNTINGTON AVE","2011-10-21T23:11:47.000Z","Cupcakory" +"013013bd7417fc4eb1d700533799de4a","1-e3927379e1939732bc56607a95af7b5b","BOSTON","COLUMBUS AVE","{\"type\":\"Point\",\"coordinates\":[-71.09804222,42.31647306]}","10300D5F","382","OTHER","280","W WALNUT PARK","2011-10-21T23:14:32.000Z","StaffMeal" +"013013bd7417fc4eb1d70053379b4a53","1-3bc9cbe689e9b7b6dc912ff507c9e05d","BOSTON","W WALNUT PARK","{\"type\":\"Point\",\"coordinates\":[-71.09804222,42.31647306]}","10300D5F","213","MOVING","300","COLUMBUS AVE","2011-10-21T23:14:58.000Z","StaffMeal" +"013013bd7417fc4eb1d70053379b5e34","1-c7a60abddc8ce7942f1b6420fa5868a1","BOSTON","WALNUT PARK","{\"type\":\"Point\",\"coordinates\":[-71.09785167,42.31621194]}","10300D5F","213","MOVING CONFIRMATION",,"WASHINGTON ST","2011-10-21T23:14:59.000Z","StaffMeal" +"013013bd7417fc4eb1d70053379cbf2e","1-365e1b480d6ca3e541e758ffa3e3ad11","BOSTON","ST ALBANS RD","{\"type\":\"Point\",\"coordinates\":[-71.10669694,42.3333975]}","10300295","382","STOP",,"HUNTINGTON AVE","2011-10-21T23:15:05.000Z","Cupcakory" +"013013bd7417fc4eb1d70053379cc7cf","1-87e5e6c65f7d214f222ab82a9e8089f0","BOSTON","ST ALBANS RD","{\"type\":\"Point\",\"coordinates\":[-71.10669694,42.3333975]}","10300295","382","OTHER",,"HUNTINGTON AVE","2011-10-21T23:15:06.000Z","Cupcakory" +"02e859331414cf4c7a1081a9fe44fd7c","1-da4c76998ab374a0481a0d38cd61ca01","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.1181225,42.29648722]}","10300B7C","382","STOP","37850","LANESVILLE TER","2011-10-23T12:44:16.000Z","BBQSmith" +"02e859331414cf4c7a1081a9fe954679","1-01e3b255f529757df01e7338f6c4fa9e","BOSTON","PAUL GORE ST","{\"type\":\"Point\",\"coordinates\":[-71.10521278,42.31762583]}","10300D5F","382","STOP","21630","DANFORTH ST","2011-10-23T13:10:19.000Z","StaffMeal" +"02e859331414cf4c7a1081a9feb822e6","1-144266972310f28e6684e24676e9d861","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11804111,42.29645]}","10300B7B","382","OTHER","20910","LANESVILLE TER","2011-10-23T13:26:35.000Z","CheeseForceOne" +"02e859331414cf4c7a1081a9feb82ab9","1-d49ed0ae34db4aa289b995e71b9d796a","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11804111,42.29645]}","10300B7B","382","OTHER","20860","LANESVILLE TER","2011-10-23T13:25:43.000Z","CheeseForceOne" +"02e859331414cf4c7a1081a9febd22bc","1-efa9ad2005d635fb90c03ab3d656aa4d","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.1181175,42.29649972]}","10300B5F","382","OTHER","27100","LANESVILLE TER","2011-10-23T13:31:52.000Z","MobileHome" +"02e859331414cf4c7a1081a9febd390f","1-d89b8b61be772c3d0f241ef2dedf5c30","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.1181175,42.29649972]}","10300B5F","382","OTHER","27160","LANESVILLE TER","2011-10-23T13:32:44.000Z","MobileHome" +"02e859331414cf4c7a1081a9fece0a4b","1-721a504bd3368e6f147fe2da0992d88f","BOSTON","PORTER ST","{\"type\":\"Point\",\"coordinates\":[-71.10327,42.31494694]}","10300CE1","382","OTHER","22210","BISMARCK ST","2011-10-23T13:41:51.000Z","RoxysGrilledCheese" +"02e859331414cf4c7a1081a9fece362f","1-cc8ee7a4465a9643ab405f39e1a71979","BOSTON","PORTER ST","{\"type\":\"Point\",\"coordinates\":[-71.10327,42.31494694]}","10300CE1","382","OTHER","22260","BISMARCK ST","2011-10-23T13:42:42.000Z","RoxysGrilledCheese" +"02e859331414cf4c7a1081a9fecec292","1-6611b641ab70e0c9748cda5f14bbf6e0","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11803111,42.29643222]}","10301014","382","OTHER","27820","LANESVILLE TER","2011-10-23T13:43:11.000Z","10301014" +"02e859331414cf4c7a1081a9fecee8d4","1-733bcff28703a6afd8b9bb6b248436aa","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11803111,42.29643222]}","10301014","382","OTHER","27870","LANESVILLE TER","2011-10-23T13:44:02.000Z","10301014" +"02e859331414cf4c7a1081a9fed0f4d9","1-37b0856455fc52f71e8062652eb93e9c","BOSTON","PORTER ST","{\"type\":\"Point\",\"coordinates\":[-71.10327,42.31494694]}","10300CE1","382","STOP","22530","BISMARCK ST","2011-10-23T13:47:09.000Z","RoxysGrilledCheese" +"0591b9ad844abb7316785a5f87a07574","1-d9d000a2e997d0b3506ec736f672c126","BOSTON","PAUL GORE ST","{\"type\":\"Point\",\"coordinates\":[-71.1051475,42.31760139]}","10300D5F","382","OTHER","11740","DANFORTH ST","2011-10-21T11:41:07.000Z","StaffMeal" +"0591b9ad844abb7316785a5f87a4ba6e","1-111484ca06567b1cfa59d3bc13565f13","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11817417,42.29650278]}","10300B7B","382","OTHER","27880","LANESVILLE TER","2011-10-21T11:44:49.000Z","CheeseForceOne" +"0591b9ad844abb7316785a5f87a4d0ad","1-df94632b6a1ee63a6b4d5d356ab178fc","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11817417,42.29650278]}","10300B7B","382","OTHER","27940","LANESVILLE TER","2011-10-21T11:45:40.000Z","CheeseForceOne" +"0591b9ad844abb7316785a5f87ae8917","1-8601864a7e94c403c87a4a28c03c8978","BOSTON","HIGHLAND ST","{\"type\":\"Point\",\"coordinates\":[-71.11447306,42.253]}","10300295","382","HEALTH","6330","ALBION ST","2011-10-21T11:55:01.000Z","Cupcakory" +"0591b9ad844abb7316785a5f87aea259","1-b17b9ccbcad8a02c20f73ed070521fb4","BOSTON","HIGHLAND ST","{\"type\":\"Point\",\"coordinates\":[-71.11447306,42.253]}","10300295","382","HEALTH","6330","ALBION ST","2011-10-21T11:55:00.000Z","Cupcakory" +"0591b9ad844abb7316785a5f87b4daac","1-2dad5fa38c0332cf0b80e6ee784e9e98","BOSTON",,"{\"type\":\"Point\",\"coordinates\":[-71.11822694,42.29641556]}","10300B5F","382","OTHER","34950","LANESVILLE TER","2011-10-21T12:01:48.000Z","MobileHome" \ No newline at end of file diff --git a/tests/data/csv/mac_newlines.csv b/tests/data/csv/mac_newlines.csv index f18abbd0b..34c817967 100644 --- a/tests/data/csv/mac_newlines.csv +++ b/tests/data/csv/mac_newlines.csv @@ -1 +1 @@ -x,y,z 1,10,0 \ No newline at end of file +x,y,z 1,10,9999.9999 \ No newline at end of file diff --git a/tests/data/csv/missing_header.csv b/tests/data/csv/missing_header.csv new file mode 100644 index 000000000..d7a11b925 --- /dev/null +++ b/tests/data/csv/missing_header.csv @@ -0,0 +1,2 @@ +one,two,x,y,,aftermissing +one,two,0,0,missing,aftermissing \ No newline at end of file diff --git a/tests/data/csv/nulls_and_booleans_as_strings.csv b/tests/data/csv/nulls_and_booleans_as_strings.csv new file mode 100644 index 000000000..e77a2f070 --- /dev/null +++ b/tests/data/csv/nulls_and_booleans_as_strings.csv @@ -0,0 +1,3 @@ +x,y,null,boolean +0,0,null,true +0,0,,false \ No newline at end of file diff --git a/tests/data/csv/numbers_for_headers.csv b/tests/data/csv/numbers_for_headers.csv new file mode 100644 index 000000000..e2144a79a --- /dev/null +++ b/tests/data/csv/numbers_for_headers.csv @@ -0,0 +1,2 @@ +x,y,1990,1991,1992 +0,0,1,2,3 \ No newline at end of file diff --git a/tests/data/csv/nypd.csv b/tests/data/csv/nypd.csv new file mode 100644 index 000000000..acd2c1a38 --- /dev/null +++ b/tests/data/csv/nypd.csv @@ -0,0 +1,3 @@ +Precinct,Phone,Address,City,geo_longitude,geo_latitude,geo_accuracy +5th Precinct,(212) 334-0711,19 Elizabeth Street,"New York, NY",-70.0,40.0,house +9th Precinct,(212) 477-7811,130 Avenue C,"New York, NY",-73.0,41.0,house \ No newline at end of file diff --git a/tests/data/csv/pipe_delimiters.csv b/tests/data/csv/pipe_delimiters.csv new file mode 100644 index 000000000..4d1d2af59 --- /dev/null +++ b/tests/data/csv/pipe_delimiters.csv @@ -0,0 +1,2 @@ +x|y|z +0|0|hello \ No newline at end of file diff --git a/tests/data/csv/semicolon_delimiters.csv b/tests/data/csv/semicolon_delimiters.csv new file mode 100644 index 000000000..ba61faed5 --- /dev/null +++ b/tests/data/csv/semicolon_delimiters.csv @@ -0,0 +1,2 @@ +x;y;z +0;0;hello \ No newline at end of file diff --git a/tests/data/csv/tabs_in_csv.csv b/tests/data/csv/tabs_in_csv.csv index 1137f4ae7..3718126c6 100644 --- a/tests/data/csv/tabs_in_csv.csv +++ b/tests/data/csv/tabs_in_csv.csv @@ -1,2 +1,2 @@ -x, y,z +x, y,z -122 , 48,0 \ No newline at end of file diff --git a/tests/data/csv/trailing_newline_mac.csv b/tests/data/csv/trailing_newline_mac.csv new file mode 100644 index 000000000..5a7051dd9 --- /dev/null +++ b/tests/data/csv/trailing_newline_mac.csv @@ -0,0 +1 @@ +x,y,z 0,0,0 1,2,3 diff --git a/tests/data/csv/trailing_newline_win.csv b/tests/data/csv/trailing_newline_win.csv new file mode 100644 index 000000000..289bb9514 --- /dev/null +++ b/tests/data/csv/trailing_newline_win.csv @@ -0,0 +1,12 @@ +FID,wkt,REGIONNAME,RID +Eth_Region_Boundary.1,"POINT (0 0)",Addis Ababa,14 +Eth_Region_Boundary.2,"POINT (0 0)",Tigray,01 +Eth_Region_Boundary.3,"POINT (0 0)",Somali,05 +Eth_Region_Boundary.4,"POINT (0 0)",Dire Dawa,15 +Eth_Region_Boundary.5,"POINT (0 0)",Hareri,13 +Eth_Region_Boundary.6,"POINT (0 0)",SNNPR,07 +Eth_Region_Boundary.7,"POINT (0 0)",Gambela,12 +Eth_Region_Boundary.8,"POINT (0 0)",Beneshangul Gumu,06 +Eth_Region_Boundary.9,"POINT (0 0)",Amhara,03 +Eth_Region_Boundary.10,"POINT (0 0)",Afar,02 +Eth_Region_Boundary.11,"POINT (0 0)",Oromia,04 diff --git a/tests/data/csv/untitled file b/tests/data/csv/untitled file deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/data/csv/windows_newlines.csv b/tests/data/csv/windows_newlines.csv index 3a6e88b89..07c0dc450 100644 --- a/tests/data/csv/windows_newlines.csv +++ b/tests/data/csv/windows_newlines.csv @@ -1,2 +1,2 @@ x,y,z -0,0,0 \ No newline at end of file +1,10,9999.9999 \ No newline at end of file diff --git a/tests/data/good_maps/interior_point.xml b/tests/data/good_maps/interior_point.xml index 332a1fa03..98613e023 100644 --- a/tests/data/good_maps/interior_point.xml +++ b/tests/data/good_maps/interior_point.xml @@ -25,7 +25,6 @@ sqlite ../sqlite/qgis_spatiallite.sqlite multipolygon - spatialite \ No newline at end of file diff --git a/tests/data/good_maps/line_symbolizer2.xml b/tests/data/good_maps/line_symbolizer2.xml index 5de4241bf..1f0430aa5 100644 --- a/tests/data/good_maps/line_symbolizer2.xml +++ b/tests/data/good_maps/line_symbolizer2.xml @@ -3,7 +3,6 @@ sqlite ../sqlite/qgis_spatiallite.sqlite - spatialite true diff --git a/tests/data/good_maps/markers_symbolizer_lines.xml b/tests/data/good_maps/markers_symbolizer_lines.xml index 8eece458c..d3adaefb6 100644 --- a/tests/data/good_maps/markers_symbolizer_lines.xml +++ b/tests/data/good_maps/markers_symbolizer_lines.xml @@ -13,7 +13,6 @@ sqlite ../sqlite/qgis_spatiallite.sqlite lines - spatialite diff --git a/tests/data/good_maps/markers_symbolizer_points.xml b/tests/data/good_maps/markers_symbolizer_points.xml index 75a13db1f..14c53a285 100644 --- a/tests/data/good_maps/markers_symbolizer_points.xml +++ b/tests/data/good_maps/markers_symbolizer_points.xml @@ -37,7 +37,6 @@ sqlite ../sqlite/qgis_spatiallite.sqlite point - spatialite