From abea816e42edf51d888794d50848d4ad65c7562f Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 14:27:21 +0200 Subject: [PATCH 01/64] - removed a refuse of the past in gdal plugin --- plugins/input/gdal/gdal_datasource.hpp | 1 - plugins/input/gdal/gdal_featureset.cpp | 1 - plugins/input/gdal/gdal_featureset.hpp | 1 - 3 files changed, 3 deletions(-) diff --git a/plugins/input/gdal/gdal_datasource.hpp b/plugins/input/gdal/gdal_datasource.hpp index d3e8c12c8..a352c2cd5 100644 --- a/plugins/input/gdal/gdal_datasource.hpp +++ b/plugins/input/gdal/gdal_datasource.hpp @@ -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 diff --git a/plugins/input/gdal/gdal_featureset.cpp b/plugins/input/gdal/gdal_featureset.cpp index 1c489f240..fd8969b4f 100644 --- a/plugins/input/gdal/gdal_featureset.cpp +++ b/plugins/input/gdal/gdal_featureset.cpp @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include diff --git a/plugins/input/gdal/gdal_featureset.hpp b/plugins/input/gdal/gdal_featureset.hpp index 3ae0d6716..55cb03ec6 100644 --- a/plugins/input/gdal/gdal_featureset.hpp +++ b/plugins/input/gdal/gdal_featureset.hpp @@ -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 From 2045506a3d6df20bf763c3096920b2d68ed1a734 Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 14:28:07 +0200 Subject: [PATCH 02/64] - removed a refuse of the past in kismet plugin --- plugins/input/kismet/kismet_datasource.hpp | 1 - plugins/input/kismet/kismet_featureset.cpp | 1 - plugins/input/kismet/kismet_featureset.hpp | 1 - plugins/input/kismet/kismet_types.hpp | 1 - 4 files changed, 4 deletions(-) diff --git a/plugins/input/kismet/kismet_datasource.hpp b/plugins/input/kismet/kismet_datasource.hpp index c269b387e..1f54a377b 100644 --- a/plugins/input/kismet/kismet_datasource.hpp +++ b/plugins/input/kismet/kismet_datasource.hpp @@ -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 diff --git a/plugins/input/kismet/kismet_featureset.cpp b/plugins/input/kismet/kismet_featureset.cpp index 360d3eaa4..08bc6b185 100644 --- a/plugins/input/kismet/kismet_featureset.cpp +++ b/plugins/input/kismet/kismet_featureset.cpp @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include diff --git a/plugins/input/kismet/kismet_featureset.hpp b/plugins/input/kismet/kismet_featureset.hpp index 098241379..811713020 100644 --- a/plugins/input/kismet/kismet_featureset.hpp +++ b/plugins/input/kismet/kismet_featureset.hpp @@ -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 diff --git a/plugins/input/kismet/kismet_types.hpp b/plugins/input/kismet/kismet_types.hpp index 4465f5e2f..7cdb9fe92 100644 --- a/plugins/input/kismet/kismet_types.hpp +++ b/plugins/input/kismet/kismet_types.hpp @@ -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 From 8333b51439df1fb7a86f4428f312dd1d6055becf Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 14:28:41 +0200 Subject: [PATCH 03/64] - removed a refuse of the past in occi plugin --- plugins/input/occi/occi_datasource.hpp | 1 - plugins/input/occi/occi_featureset.cpp | 1 - plugins/input/occi/occi_featureset.hpp | 1 - plugins/input/occi/occi_types.cpp | 1 - plugins/input/occi/occi_types.hpp | 1 - 5 files changed, 5 deletions(-) diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index cc7bad223..e0d5826e4 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -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 diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index c9fe9dae9..e94e990d9 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include diff --git a/plugins/input/occi/occi_featureset.hpp b/plugins/input/occi/occi_featureset.hpp index 1d5987dfa..ab60c884f 100644 --- a/plugins/input/occi/occi_featureset.hpp +++ b/plugins/input/occi/occi_featureset.hpp @@ -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 diff --git a/plugins/input/occi/occi_types.cpp b/plugins/input/occi/occi_types.cpp index 18d33c467..86208e7a4 100644 --- a/plugins/input/occi/occi_types.cpp +++ b/plugins/input/occi/occi_types.cpp @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #include "occi_types.hpp" diff --git a/plugins/input/occi/occi_types.hpp b/plugins/input/occi/occi_types.hpp index 64b382ebb..8c369c037 100644 --- a/plugins/input/occi/occi_types.hpp +++ b/plugins/input/occi/occi_types.hpp @@ -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 From 86d2f9ef1920bc2a8cc0995dc383e140c073c0f5 Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 14:29:08 +0200 Subject: [PATCH 04/64] - removed a refuse of the past in ogr plugin --- plugins/input/ogr/ogr_converter.cpp | 2 +- plugins/input/ogr/ogr_converter.hpp | 1 - plugins/input/ogr/ogr_datasource.hpp | 1 - plugins/input/ogr/ogr_feature_ptr.hpp | 1 - plugins/input/ogr/ogr_featureset.cpp | 2 +- plugins/input/ogr/ogr_featureset.hpp | 1 - plugins/input/ogr/ogr_index_featureset.hpp | 1 - 7 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/input/ogr/ogr_converter.cpp b/plugins/input/ogr/ogr_converter.cpp index 0198a2cbc..5d27cb08e 100644 --- a/plugins/input/ogr/ogr_converter.cpp +++ b/plugins/input/ogr/ogr_converter.cpp @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ +// mapnik #include #include #include diff --git a/plugins/input/ogr/ogr_converter.hpp b/plugins/input/ogr/ogr_converter.hpp index 70dff71b2..f810dff39 100644 --- a/plugins/input/ogr/ogr_converter.hpp +++ b/plugins/input/ogr/ogr_converter.hpp @@ -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 diff --git a/plugins/input/ogr/ogr_datasource.hpp b/plugins/input/ogr/ogr_datasource.hpp index a52f5c112..28552873b 100644 --- a/plugins/input/ogr/ogr_datasource.hpp +++ b/plugins/input/ogr/ogr_datasource.hpp @@ -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 diff --git a/plugins/input/ogr/ogr_feature_ptr.hpp b/plugins/input/ogr/ogr_feature_ptr.hpp index 7125986cc..2dc9c7309 100644 --- a/plugins/input/ogr/ogr_feature_ptr.hpp +++ b/plugins/input/ogr/ogr_feature_ptr.hpp @@ -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 diff --git a/plugins/input/ogr/ogr_featureset.cpp b/plugins/input/ogr/ogr_featureset.cpp index 13baf9bdb..d34964cbf 100644 --- a/plugins/input/ogr/ogr_featureset.cpp +++ b/plugins/input/ogr/ogr_featureset.cpp @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ +// mapnik #include #include #include diff --git a/plugins/input/ogr/ogr_featureset.hpp b/plugins/input/ogr/ogr_featureset.hpp index 65c8e5fcb..9cf7bb067 100644 --- a/plugins/input/ogr/ogr_featureset.hpp +++ b/plugins/input/ogr/ogr_featureset.hpp @@ -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 diff --git a/plugins/input/ogr/ogr_index_featureset.hpp b/plugins/input/ogr/ogr_index_featureset.hpp index 38bfff21f..39b90598a 100644 --- a/plugins/input/ogr/ogr_index_featureset.hpp +++ b/plugins/input/ogr/ogr_index_featureset.hpp @@ -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 From f1460b78cd65ad640bcea9d75795c0c2d3c41bcd Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 14:29:54 +0200 Subject: [PATCH 05/64] - fix indentation and trailing spaces (generally coding style) in rasterlite plugin partially related to #911 --- .../rasterlite/rasterlite_datasource.hpp | 43 ++++++++++--------- .../rasterlite/rasterlite_featureset.cpp | 41 +++++++++++------- .../rasterlite/rasterlite_featureset.hpp | 27 ++++++------ .../input/rasterlite/rasterlite_include.hpp | 5 +-- 4 files changed, 65 insertions(+), 51 deletions(-) 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..cf7995a86 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,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef RASTERLITE_INCLUDE_HPP #define RASTERLITE_INCLUDE_HPP @@ -29,4 +28,4 @@ extern "C" { #include } -#endif // RASTERLITE_FEATURESET_HPP +#endif // RASTERLITE_INCLUDE_HPP From c0273234b6cd96ef591af313d808ff238a82dc5e Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 14:50:24 +0200 Subject: [PATCH 06/64] - aligned coding style in sqlite plugin --- plugins/input/sqlite/sqlite_datasource.cpp | 126 ++++++++++----------- plugins/input/sqlite/sqlite_datasource.hpp | 79 +++++++------ plugins/input/sqlite/sqlite_featureset.cpp | 29 ++--- plugins/input/sqlite/sqlite_featureset.hpp | 35 +++--- plugins/input/sqlite/sqlite_types.hpp | 101 ++++++++--------- 5 files changed, 178 insertions(+), 192 deletions(-) diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index c36767cf7..4e6f3b8aa 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,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -// $Id$ #include "sqlite_datasource.hpp" #include "sqlite_featureset.hpp" @@ -27,9 +26,7 @@ // mapnik #include #include - -// to enable extent fallback hack -#include +#include // to enable extent fallback hack // boost #include @@ -39,15 +36,9 @@ #include #include - using boost::lexical_cast; using boost::bad_lexical_cast; -using mapnik::datasource; -using mapnik::parameters; - -DATASOURCE_PLUGIN(sqlite_datasource) - using mapnik::box2d; using mapnik::coord2d; using mapnik::query; @@ -55,31 +46,34 @@ 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" 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()) { @@ -144,27 +138,27 @@ 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_); + dataset_ = new sqlite_connection(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); } @@ -197,10 +191,10 @@ void sqlite_datasource::bind() const 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) + 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); + const int type_oid = rs->column_type(i); + const char* fld_name = rs->column_name(i); switch (type_oid) { case SQLITE_INTEGER: @@ -233,9 +227,9 @@ void sqlite_datasource::bind() const break; default: - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG std::clog << "Sqlite Plugin: unknown type_oid=" << type_oid << std::endl; - #endif +#endif break; } } @@ -252,13 +246,15 @@ void sqlite_datasource::bind() const if (key_field_.empty()) { - use_pragma_table_info = true; + 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)); + // TODO - we can't trust so much the rowid here + if (key_field_ == "rowid") + { + desc_.add_descriptor(attribute_descriptor("rowid", mapnik::Integer)); + } } if (use_pragma_table_info) @@ -325,7 +321,7 @@ void sqlite_datasource::bind() const desc_.add_descriptor(attribute_descriptor(fld_name, mapnik::String)); } } - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG else { // "Column Affinity" says default to "Numeric" but for now we pass.. @@ -338,7 +334,7 @@ void sqlite_datasource::bind() const << "' unhandled due to unknown type: " << fld_type << std::endl; } - #endif +#endif } if (! found_table) @@ -377,12 +373,12 @@ void sqlite_datasource::bind() const { has_spatial_index_ = true; } - #ifdef MAPNIK_DEBUG +#ifdef MAPNIK_DEBUG else { std::clog << "SQLite Plugin: rtree index lookup did not succeed: '" << sqlite3_errmsg(*(*dataset_)) << "'\n"; } - #endif +#endif } if (! metadata_.empty() && ! extent_initialized_) @@ -399,7 +395,7 @@ void sqlite_datasource::bind() const double xmax = rs->column_double (2); double ymax = rs->column_double (3); - extent_.init (xmin,ymin,xmax,ymax); + extent_.init (xmin, ymin, xmax, ymax); extent_initialized_ = true; } } @@ -421,10 +417,10 @@ void sqlite_datasource::bind() const 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_.init(xmin, ymin, xmax, ymax); extent_initialized_ = true; } - catch (bad_lexical_cast &ex) + 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; } @@ -503,7 +499,7 @@ void sqlite_datasource::bind() const while (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) { // create a tmp feature to be able to parse geometry @@ -534,8 +530,8 @@ void sqlite_datasource::bind() const { std::ostringstream type_error; type_error << "Sqlite Plugin: invalid type for key field '" - << key_field_ << "' when creating index '" << index_table_ - << "' type was: " << type_oid << ""; + << key_field_ << "' when creating index '" << index_table_ + << "' type was: " << type_oid << ""; throw datasource_exception(type_error.str()); } @@ -680,24 +676,24 @@ 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; @@ -752,10 +748,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,12 +767,12 @@ 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_; @@ -795,7 +791,7 @@ 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_) { @@ -826,9 +822,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..9d83b2855 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,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef SQLITE_DATASOURCE_HPP #define SQLITE_DATASOURCE_HPP @@ -38,47 +37,45 @@ #include "sqlite_types.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 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; }; - #endif // SQLITE_DATASOURCE_HPP diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 4ca836722..7e7dfd4b3 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 @@ -49,35 +48,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 +96,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..b24274bd9 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,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef SQLITE_FEATURESET_HPP #define SQLITE_FEATURESET_HPP @@ -36,26 +35,24 @@ // sqlite #include "sqlite_types.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 diff --git a/plugins/input/sqlite/sqlite_types.hpp b/plugins/input/sqlite/sqlite_types.hpp index ba06b0c18..3da0e55b3 100644 --- a/plugins/input/sqlite/sqlite_types.hpp +++ b/plugins/input/sqlite/sqlite_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,13 +19,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ #ifndef SQLITE_TYPES_HPP #define SQLITE_TYPES_HPP -// stdc++ -#include +// stl +#include // mapnik #include @@ -40,32 +39,25 @@ extern "C" { } -//============================================================================== - class sqlite_utils { public: - - static void dequote(std::string & z) + static void dequote(std::string& z) { - boost::algorithm::trim_if(z,boost::algorithm::is_any_of("[]'\"`")); + boost::algorithm::trim_if(z, boost::algorithm::is_any_of("[]'\"`")); } - }; -//============================================================================== - class sqlite_resultset { public: - - sqlite_resultset (sqlite3_stmt* stmt) + sqlite_resultset(sqlite3_stmt* stmt) : stmt_(stmt) { } - ~sqlite_resultset () + virtual ~sqlite_resultset() { if (stmt_) { @@ -73,14 +65,14 @@ public: } } - bool is_valid () + bool is_valid() { return stmt_ != 0; } - bool step_next () + bool step_next() { - const int status = sqlite3_step (stmt_); + const int status = sqlite3_step(stmt_); if (status != SQLITE_ROW && status != SQLITE_DONE) { std::ostringstream s; @@ -97,56 +89,56 @@ public: return status == SQLITE_ROW; } - int column_count () + int column_count() { - return sqlite3_column_count (stmt_); + return sqlite3_column_count(stmt_); } - int column_type (int col) + int column_type(int col) { - return sqlite3_column_type (stmt_, col); + return sqlite3_column_type(stmt_, col); } - const char* column_name (int col) + const char* column_name(int col) { - return sqlite3_column_name (stmt_, col); + return sqlite3_column_name(stmt_, col); } - bool column_isnull (int col) + bool column_isnull(int col) { - return sqlite3_column_type (stmt_, col) == SQLITE_NULL; + return sqlite3_column_type(stmt_, col) == SQLITE_NULL; } - int column_integer (int col) + int column_integer(int col) { - return sqlite3_column_int (stmt_, col); + return sqlite3_column_int(stmt_, col); } - int column_integer64 (int col) + int column_integer64(int col) { - return sqlite3_column_int64 (stmt_, col); + return sqlite3_column_int64(stmt_, col); } - double column_double (int col) + double column_double(int col) { - return sqlite3_column_double (stmt_, col); + return sqlite3_column_double(stmt_, col); } - const char* column_text (int col, int& len) + const char* column_text(int col, int& len) { - len = sqlite3_column_bytes (stmt_, col); - return (const char*) sqlite3_column_text (stmt_, col); + len = sqlite3_column_bytes(stmt_, col); + return (const char*) sqlite3_column_text(stmt_, col); } - const char* column_text (int col) + const char* column_text(int col) { - return (const char*) sqlite3_column_text (stmt_, col); + return (const char*) sqlite3_column_text(stmt_, col); } - const void* column_blob (int col, int& bytes) + const void* column_blob(int col, int& bytes) { - bytes = sqlite3_column_bytes (stmt_, col); - return (const char*) sqlite3_column_blob (stmt_, col); + bytes = sqlite3_column_bytes(stmt_, col); + return (const char*) sqlite3_column_blob(stmt_, col); } sqlite3_stmt* get_statement() @@ -160,13 +152,11 @@ private: }; -//============================================================================== - class sqlite_connection { public: - sqlite_connection (const std::string& file) + sqlite_connection(const std::string& file) : db_(0) { // sqlite3_open_v2 is available earlier but @@ -175,28 +165,28 @@ public: const int rc = sqlite3_enable_shared_cache(1); if (rc != SQLITE_OK) { - throw mapnik::datasource_exception (sqlite3_errmsg (db_)); + 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)) + 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_)) + if (sqlite3_open(file.c_str(), &db_)) #endif { std::ostringstream s; - s << "Sqlite Plugin: " << sqlite3_errmsg (db_); + s << "Sqlite Plugin: " << sqlite3_errmsg(db_); - throw mapnik::datasource_exception (s.str()); + throw mapnik::datasource_exception(s.str()); } } - virtual ~sqlite_connection () + virtual ~sqlite_connection() { if (db_) { - sqlite3_close (db_); + sqlite3_close(db_); } } @@ -204,10 +194,16 @@ public: { 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()); @@ -217,7 +213,7 @@ public: { sqlite3_stmt* stmt = 0; - const int rc = sqlite3_prepare_v2 (db_, sql.c_str(), -1, &stmt, 0); + const int rc = sqlite3_prepare_v2(db_, sql.c_str(), -1, &stmt, 0); if (rc != SQLITE_OK) { throw_sqlite_error(sql); @@ -251,5 +247,4 @@ private: sqlite3* db_; }; - -#endif //SQLITE_TYPES_HPP +#endif // SQLITE_TYPES_HPP From 2a4fe24ea9cdd3a4953122e5f61a54d960dc24bc Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 15:27:28 +0200 Subject: [PATCH 07/64] - modified coding style in shape plugin --- plugins/input/shape/shape_featureset.cpp | 180 ++--- .../input/shape/shape_index_featureset.cpp | 140 ++-- .../input/shape/shape_index_featureset.hpp | 62 +- plugins/input/shape/shape_io.cpp | 653 +++++++++--------- plugins/input/shape/shape_io.hpp | 50 +- plugins/input/shape/shapefile.hpp | 106 +-- plugins/input/shape/shp_index.hpp | 60 +- 7 files changed, 656 insertions(+), 595 deletions(-) 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_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 From 05a32a18e5af350b0f8593c712dae23c4b1fe4a1 Mon Sep 17 00:00:00 2001 From: kunitoki Date: Sat, 22 Oct 2011 16:04:05 +0200 Subject: [PATCH 08/64] - aligned coding style in osm plugin --- plugins/input/osm/basiccurl.cpp | 85 +++--- plugins/input/osm/basiccurl.h | 28 +- plugins/input/osm/dataset_deliverer.cpp | 112 +++++--- plugins/input/osm/dataset_deliverer.h | 33 ++- plugins/input/osm/osm.cpp | 333 +++++++++++++----------- plugins/input/osm/osm.h | 96 ++++--- plugins/input/osm/osm_datasource.cpp | 119 ++++----- plugins/input/osm/osm_datasource.hpp | 40 ++- plugins/input/osm/osm_featureset.cpp | 106 ++++---- plugins/input/osm/osm_featureset.hpp | 55 ++-- plugins/input/osm/osmparser.h | 47 +++- plugins/input/osm/osmtagtypes.h | 48 +++- plugins/input/osm/render.cpp | 94 ++++--- 13 files changed, 705 insertions(+), 491 deletions(-) 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..0736720c7 100755 --- a/plugins/input/osm/basiccurl.h +++ b/plugins/input/osm/basiccurl.h @@ -1,3 +1,25 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2011 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + #ifndef BASICCURL_H #define BASICCURL_H @@ -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; } From e45948c2ab8bed230f30c178e59c913fcf697b24 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sat, 22 Oct 2011 17:25:09 -0700 Subject: [PATCH 09/64] formatting --- src/wkb.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wkb.cpp b/src/wkb.cpp index 2e434f990..365853571 100644 --- a/src/wkb.cpp +++ b/src/wkb.cpp @@ -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_) From 2f7d85e6d83e8034b9fc15d8dd446cc07f031ffd Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sat, 22 Oct 2011 17:27:02 -0700 Subject: [PATCH 10/64] touchup feature.to_string() operator to display id differently than attributes --- include/mapnik/feature.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 462733e3d..f36aa7d0e 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -160,8 +160,8 @@ public: 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) { From 60abc741139b5501edaba1f6aea49f4f17dfcb7d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sat, 22 Oct 2011 17:28:30 -0700 Subject: [PATCH 11/64] sqlite plugin now autodetects wkb_format thanks to @kunitoki --- tests/data/good_maps/interior_point.xml | 1 - tests/data/good_maps/line_symbolizer2.xml | 1 - tests/data/good_maps/markers_symbolizer_lines.xml | 1 - tests/data/good_maps/markers_symbolizer_points.xml | 1 - tests/data/good_maps/markers_symbolizer_points_gradient.xml | 2 +- tests/data/good_maps/markers_symbolizer_points_stacked.xml | 1 - tests/data/good_maps/point_symbolizer.xml | 1 - tests/data/good_maps/point_symbolizer_ignore_placements.xml | 1 - tests/data/good_maps/sqlite.xml | 1 - tests/data/good_maps/text_rotation.xml | 1 - 10 files changed, 1 insertion(+), 10 deletions(-) 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