From 852776d5e386ac4d54aba7513c37408abbc59409 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 24 Mar 2015 14:16:58 -0700 Subject: [PATCH] geometry is_empty refactoring --- bindings/python/mapnik_geometry.cpp | 7 ++ include/mapnik/geometry_empty.hpp | 2 +- include/mapnik/geometry_is_empty.hpp | 84 ++++++++++++++++++++++ plugins/input/sqlite/sqlite_datasource.cpp | 4 +- plugins/input/sqlite/sqlite_featureset.cpp | 4 +- plugins/input/sqlite/sqlite_utils.hpp | 8 +-- utils/pgsql2sqlite/pgsql2sqlite.hpp | 4 +- 7 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 include/mapnik/geometry_is_empty.hpp diff --git a/bindings/python/mapnik_geometry.cpp b/bindings/python/mapnik_geometry.cpp index 7193bcb1a..e1bf4af00 100644 --- a/bindings/python/mapnik_geometry.cpp +++ b/bindings/python/mapnik_geometry.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,11 @@ bool geometry_is_simple_impl(mapnik::geometry::geometry const& geom) return mapnik::geometry::is_simple(geom); } +bool geometry_is_empty_impl(mapnik::geometry::geometry const& geom) +{ + return mapnik::geometry::is_empty(geom); +} + void geometry_correct_impl(mapnik::geometry::geometry & geom) { mapnik::geometry::correct(geom); @@ -260,6 +266,7 @@ void export_geometry() .def("type",&geometry_type_impl) .def("is_valid", &geometry_is_valid_impl) .def("is_simple", &geometry_is_simple_impl) + .def("is_empty", &geometry_is_empty_impl) .def("correct", &geometry_correct_impl) .def("centroid",&geometry_centroid_impl) .def("to_wkb",&to_wkb_impl) diff --git a/include/mapnik/geometry_empty.hpp b/include/mapnik/geometry_empty.hpp index c9c9ca584..9b96ef10e 100644 --- a/include/mapnik/geometry_empty.hpp +++ b/include/mapnik/geometry_empty.hpp @@ -74,7 +74,7 @@ struct geometry_empty } -inline bool empty(mapnik::geometry::geometry const& geom) +inline bool is_empty(mapnik::geometry::geometry const& geom) { return detail::geometry_empty()(geom); } diff --git a/include/mapnik/geometry_is_empty.hpp b/include/mapnik/geometry_is_empty.hpp new file mode 100644 index 000000000..10b63c6d4 --- /dev/null +++ b/include/mapnik/geometry_is_empty.hpp @@ -0,0 +1,84 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#ifndef MAPNIK_GEOMETRY_EMPTY_HPP +#define MAPNIK_GEOMETRY_EMPTY_HPP + +#include + +namespace mapnik { namespace geometry { + +namespace detail { + +struct geometry_is_empty +{ + bool operator() (mapnik::geometry::geometry const& geom) const + { + return mapnik::util::apply_visitor(*this, geom); + } + + bool operator() (mapnik::geometry::point const&) const + { + return false; + } + + bool operator() (mapnik::geometry::line_string const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::geometry::polygon const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::geometry::multi_point const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::geometry::multi_line_string const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::geometry::multi_polygon const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::geometry::geometry_collection const& geom) const + { + return geom.empty(); + } +}; + +} + +inline bool is_empty(mapnik::geometry::geometry const& geom) +{ + return detail::geometry_is_empty()(geom); +} + +}} + +#endif // MAPNIK_GEOMETRY_EMPTY_HPP diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index d66d3753b..bba4789aa 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include // boost #include @@ -449,7 +449,7 @@ boost::optional sqlite_datasource::get_geometry_t { mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, format_); - if (mapnik::geometry::empty(geom)) + if (mapnik::geometry::is_empty(geom)) { continue; } diff --git a/plugins/input/sqlite/sqlite_featureset.cpp b/plugins/input/sqlite/sqlite_featureset.cpp index 57d38c914..61701d14f 100644 --- a/plugins/input/sqlite/sqlite_featureset.cpp +++ b/plugins/input/sqlite/sqlite_featureset.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include // ogr @@ -82,7 +82,7 @@ feature_ptr sqlite_featureset::next() feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1)); mapnik::geometry::geometry geom = geometry_utils::from_wkb(data, size, format_); - if (mapnik::geometry::empty(geom)) + if (mapnik::geometry::is_empty(geom)) { continue; } diff --git a/plugins/input/sqlite/sqlite_utils.hpp b/plugins/input/sqlite/sqlite_utils.hpp index 5f9dbef29..194c283fe 100644 --- a/plugins/input/sqlite/sqlite_utils.hpp +++ b/plugins/input/sqlite/sqlite_utils.hpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include // boost @@ -197,7 +197,7 @@ public: if (data) { mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto); - if (!mapnik::geometry::empty(geom)) + if (!mapnik::geometry::is_empty(geom)) { mapnik::box2d bbox = mapnik::geometry::envelope(geom); if (bbox.valid()) @@ -281,7 +281,7 @@ public: if (data) { mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto); - if (!mapnik::geometry::empty(geom)) + if (!mapnik::geometry::is_empty(geom)) { mapnik::box2d bbox = mapnik::geometry::envelope(geom); if (bbox.valid()) @@ -357,7 +357,7 @@ public: if (data) { mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto); - if (!mapnik::geometry::empty(geom)) + if (!mapnik::geometry::is_empty(geom)) { mapnik::box2d bbox = mapnik::geometry::envelope(geom); if (bbox.valid()) diff --git a/utils/pgsql2sqlite/pgsql2sqlite.hpp b/utils/pgsql2sqlite/pgsql2sqlite.hpp index 81e8cbb30..dab2c4b95 100644 --- a/utils/pgsql2sqlite/pgsql2sqlite.hpp +++ b/utils/pgsql2sqlite/pgsql2sqlite.hpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include "connection_manager.hpp" @@ -390,7 +390,7 @@ void pgsql2sqlite(Connection conn, { mapnik::Feature feat(ctx,pkid); mapnik::geometry::geometry geom = geometry_utils::from_wkb(buf, size, wkbGeneric); - if (!mapnik::geometry::empty(geom)) + if (!mapnik::geometry::is_empty(geom)) { box2d bbox = mapnik::geometry::envelope(geom); if (bbox.valid())