From 8400be91c72efa86bc0f1816fcb6de0a788be038 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 24 Feb 2015 10:41:12 +0100 Subject: [PATCH] generic `box2d envelope(geometry const& )` --- bindings/python/mapnik_geometry.cpp | 2 +- include/mapnik/feature.hpp | 7 +- include/mapnik/geometry_container.hpp | 39 ------ include/mapnik/geometry_envelope.hpp | 111 ++++++++++++++++++ include/mapnik/geometry_impl.hpp | 18 +-- .../mapnik/json/feature_generator_grammar.hpp | 2 +- include/mapnik/json/geometry_parser.hpp | 2 +- include/mapnik/util/container_adapter.hpp | 7 +- include/mapnik/util/geometry_to_ds_type.hpp | 76 ++++++++---- include/mapnik/util/geometry_to_svg.hpp | 2 +- include/mapnik/util/geometry_to_wkb.hpp | 2 +- include/mapnik/util/geometry_to_wkt.hpp | 2 +- include/mapnik/wkt/wkt_factory.hpp | 2 +- include/mapnik/wkt/wkt_grammar.hpp | 2 +- src/json/mapnik_json_generator_grammar.cpp | 2 +- src/wkt/mapnik_wkt_generator_grammar.cpp | 9 +- src/wkt/mapnik_wkt_grammar.cpp | 3 + 17 files changed, 197 insertions(+), 91 deletions(-) delete mode 100644 include/mapnik/geometry_container.hpp create mode 100644 include/mapnik/geometry_envelope.hpp diff --git a/bindings/python/mapnik_geometry.cpp b/bindings/python/mapnik_geometry.cpp index a64fcc486..c6c20e9e0 100644 --- a/bindings/python/mapnik_geometry.cpp +++ b/bindings/python/mapnik_geometry.cpp @@ -38,7 +38,7 @@ // mapnik #include -#include + #include // from_wkt #include #include // from_geojson diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 26d85fead..8db78ad90 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -29,7 +29,8 @@ #include #include #include -//#include +#include +// #include #include @@ -206,9 +207,7 @@ public: inline box2d envelope() const { - box2d result; - std::cerr << "ENVELOPE" << std::endl; - return result; + return mapnik::new_geometry::envelope(geom_); } inline raster_ptr const& get_raster() const diff --git a/include/mapnik/geometry_container.hpp b/include/mapnik/geometry_container.hpp deleted file mode 100644 index 2c5507db2..000000000 --- a/include/mapnik/geometry_container.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2014 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_CONTAINER_HPP -#define MAPNIK_GEOMETRY_CONTAINER_HPP - -// boost -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wunused-local-typedef" -#include -#pragma GCC diagnostic pop - -namespace mapnik { - -using geometry_container = boost::ptr_vector; - -} - -#endif // MAPNIK_GEOMETRY_CONTAINER_HPP diff --git a/include/mapnik/geometry_envelope.hpp b/include/mapnik/geometry_envelope.hpp new file mode 100644 index 000000000..e09c08ef7 --- /dev/null +++ b/include/mapnik/geometry_envelope.hpp @@ -0,0 +1,111 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2014 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_ENVELOPE_HPP +#define MAPNIK_GEOMETRY_ENVELOPE_HPP + +#include +#include + +namespace mapnik { namespace new_geometry { + +namespace detail { + +struct geometry_envelope +{ + using bbox_type = box2d; + + bbox_type operator() (mapnik::new_geometry::geometry const& geom) const + { + return mapnik::util::apply_visitor(*this, geom); + } + + bbox_type operator() (mapnik::new_geometry::point const& pt) const + { + return mapnik::box2d(pt.x, pt.y, pt.x, pt.y); + } + + bbox_type operator() (mapnik::new_geometry::line_string const& line) const + { + bbox_type bbox; + for (auto const& pt : line) + { + if (!bbox.valid()) bbox.init(pt.x, pt.y, pt.x, pt.y); + else bbox.expand_to_include(pt.x, pt.y); + } + return bbox; + } + + bbox_type operator() (mapnik::new_geometry::polygon3 const& poly) const + { + return (*this) (static_cast(poly.exterior_ring)); + } + + bbox_type operator() (mapnik::new_geometry::multi_point const& multi_point) const + { + return (*this) (static_cast(multi_point)); + } + + bbox_type operator() (mapnik::new_geometry::multi_line_string const& multi_line) const + { + bbox_type bbox; + for (auto const& line : multi_line) + { + if (!bbox.valid()) bbox = (*this)(line); + else bbox.expand_to_include((*this)(line)); + } + return bbox; + } + + bbox_type operator() (mapnik::new_geometry::multi_polygon const& multi_poly) const + { + bbox_type bbox; + for (auto const& poly : multi_poly) + { + if (!bbox.valid()) bbox = (*this)(poly); + else bbox.expand_to_include((*this)(poly)); + } + return bbox; + } + + bbox_type operator() (mapnik::new_geometry::geometry_collection const& collection) const + { + bbox_type bbox; + for (auto const& geom : collection) + { + if (!bbox.valid()) bbox = (*this)(geom); + else bbox.expand_to_include((*this)(geom)); + } + return bbox; + } +}; + +} + +inline mapnik::box2d envelope(mapnik::new_geometry::geometry const& geom) +{ + return detail::geometry_envelope() (geom); +} + +}} + +#endif // MAPNIK_GEOMETRY_ENVELOPE_HPP diff --git a/include/mapnik/geometry_impl.hpp b/include/mapnik/geometry_impl.hpp index 0daeee034..2bfbd87a8 100644 --- a/include/mapnik/geometry_impl.hpp +++ b/include/mapnik/geometry_impl.hpp @@ -37,16 +37,16 @@ namespace mapnik { namespace new_geometry { -static const std::uint8_t geometry_bits = 7; - enum geometry_types : std::uint8_t { - Unknown = 0x00, - Point = 0x01, - LineString = 0x02, - Polygon = 0x03, - PolygonExterior = Polygon, - PolygonInterior = Polygon | ( 1 << geometry_bits) + Unknown = 0, + Point = 1, + LineString = 2, + Polygon = 3, + MultiPoint = 4, + MultiLineString = 5, + MultiPolygon = 6, + GeometryCollection = 7, }; struct point @@ -118,7 +118,7 @@ struct polygon3 } }; -struct multi_point : std::vector {}; +struct multi_point : line_string {}; struct multi_line_string : std::vector {}; struct multi_polygon : std::vector {}; struct geometry_collection; diff --git a/include/mapnik/json/feature_generator_grammar.hpp b/include/mapnik/json/feature_generator_grammar.hpp index 84a30022e..1365fd39a 100644 --- a/include/mapnik/json/feature_generator_grammar.hpp +++ b/include/mapnik/json/feature_generator_grammar.hpp @@ -25,7 +25,7 @@ // mapnik #include -#include + #include #include diff --git a/include/mapnik/json/geometry_parser.hpp b/include/mapnik/json/geometry_parser.hpp index 080b78bc7..3be4bc34a 100644 --- a/include/mapnik/json/geometry_parser.hpp +++ b/include/mapnik/json/geometry_parser.hpp @@ -25,7 +25,7 @@ // mapnik #include -#include + #include // boost diff --git a/include/mapnik/util/container_adapter.hpp b/include/mapnik/util/container_adapter.hpp index 17832dafb..6500e92d2 100644 --- a/include/mapnik/util/container_adapter.hpp +++ b/include/mapnik/util/container_adapter.hpp @@ -25,7 +25,7 @@ // mapnik #include -#include + #include // boost @@ -43,8 +43,9 @@ template <> struct is_container : mpl::true_ {} ; // make gcc and darwin toolsets happy. -template <> -struct is_container : mpl::false_ {} ; +// FIXME +//template <> +//struct is_container : mpl::false_ {} ; // template <> diff --git a/include/mapnik/util/geometry_to_ds_type.hpp b/include/mapnik/util/geometry_to_ds_type.hpp index d1b09d009..598d332e4 100644 --- a/include/mapnik/util/geometry_to_ds_type.hpp +++ b/include/mapnik/util/geometry_to_ds_type.hpp @@ -25,38 +25,68 @@ // mapnik #include -#include -#include +#include + +//#include // boost #include namespace mapnik { namespace util { - static inline void to_ds_type(mapnik::geometry_container const& paths, - boost::optional & result) +namespace detail { + +struct geometry_type +{ + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::geometry const& geom) const { - if (paths.size() == 1) - { - result.reset(static_cast(paths.front().type())); - } - else if (paths.size() > 1) - { - int multi_type = 0; - for (auto const& geom : paths) - { - int type = static_cast(geom.type()); - if (multi_type > 0 && multi_type != type) - { - result.reset(datasource::Collection); - } - multi_type = type; - result.reset(static_cast(type)); - } - } + return mapnik::util::apply_visitor(*this, geom); } - }} + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::point const&) const + { + return mapnik::new_geometry::geometry_types::Point; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::line_string const&) const + { + return mapnik::new_geometry::geometry_types::LineString; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::polygon3 const&) const + { + return mapnik::new_geometry::geometry_types::Polygon; + } + + // multi + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::multi_point const&) const + { + return mapnik::new_geometry::geometry_types::MultiPoint; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::multi_line_string const&) const + { + return mapnik::new_geometry::geometry_types::MultiLineString; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::multi_polygon const&) const + { + return mapnik::new_geometry::geometry_types::MultiPolygon; + } + + mapnik::new_geometry::geometry_types operator () (mapnik::new_geometry::geometry_collection const&) const + { + return mapnik::new_geometry::geometry_types::GeometryCollection; + } +}; +} // detail + +static mapnik::new_geometry::geometry_type(mapnik::new_geometry::geometry const& geom) +{ + return detail::geometry_type()(geom); +} + +}} #endif // MAPNIK_GEOMETRY_TO_DS_TYPE diff --git a/include/mapnik/util/geometry_to_svg.hpp b/include/mapnik/util/geometry_to_svg.hpp index eb9a71278..f93c8cdba 100644 --- a/include/mapnik/util/geometry_to_svg.hpp +++ b/include/mapnik/util/geometry_to_svg.hpp @@ -26,7 +26,7 @@ // mapnik #include #include -#include + #include // boost diff --git a/include/mapnik/util/geometry_to_wkb.hpp b/include/mapnik/util/geometry_to_wkb.hpp index 9835de4e9..5c7caed65 100644 --- a/include/mapnik/util/geometry_to_wkb.hpp +++ b/include/mapnik/util/geometry_to_wkb.hpp @@ -27,7 +27,7 @@ #include #include #include -#include + #include // stl diff --git a/include/mapnik/util/geometry_to_wkt.hpp b/include/mapnik/util/geometry_to_wkt.hpp index aef1226b3..96decfba0 100644 --- a/include/mapnik/util/geometry_to_wkt.hpp +++ b/include/mapnik/util/geometry_to_wkt.hpp @@ -25,7 +25,7 @@ // mapnik #include -#include + #include namespace mapnik { namespace util { diff --git a/include/mapnik/wkt/wkt_factory.hpp b/include/mapnik/wkt/wkt_factory.hpp index 01949eb0f..a818ddf7a 100644 --- a/include/mapnik/wkt/wkt_factory.hpp +++ b/include/mapnik/wkt/wkt_factory.hpp @@ -25,7 +25,7 @@ // mapnik #include -#include + #include #include #include diff --git a/include/mapnik/wkt/wkt_grammar.hpp b/include/mapnik/wkt/wkt_grammar.hpp index 072d4a986..5eb5ae1dc 100644 --- a/include/mapnik/wkt/wkt_grammar.hpp +++ b/include/mapnik/wkt/wkt_grammar.hpp @@ -33,7 +33,7 @@ // mapnik #include -#include + #include namespace mapnik { namespace wkt { diff --git a/src/json/mapnik_json_generator_grammar.cpp b/src/json/mapnik_json_generator_grammar.cpp index f102a03ad..63b04d728 100644 --- a/src/json/mapnik_json_generator_grammar.cpp +++ b/src/json/mapnik_json_generator_grammar.cpp @@ -21,7 +21,7 @@ *****************************************************************************/ #if 0 // FIXME #include -#include + #include #include #include diff --git a/src/wkt/mapnik_wkt_generator_grammar.cpp b/src/wkt/mapnik_wkt_generator_grammar.cpp index 2bea8c85d..aa3ab1cfc 100644 --- a/src/wkt/mapnik_wkt_generator_grammar.cpp +++ b/src/wkt/mapnik_wkt_generator_grammar.cpp @@ -21,14 +21,15 @@ *****************************************************************************/ #include -#include #include #include namespace mapnik { namespace wkt { -using sink_type = std::back_insert_iterator; -template struct wkt_generator; -template struct wkt_multi_generator; +#if 0 +//using sink_type = std::back_insert_iterator; +//template struct wkt_generator; +//template struct wkt_multi_generator; +#endif }} diff --git a/src/wkt/mapnik_wkt_grammar.cpp b/src/wkt/mapnik_wkt_grammar.cpp index 41196c9d8..61df62ce9 100644 --- a/src/wkt/mapnik_wkt_grammar.cpp +++ b/src/wkt/mapnik_wkt_grammar.cpp @@ -20,6 +20,7 @@ * *****************************************************************************/ +#if 0 // FIXME #include #include @@ -27,3 +28,5 @@ namespace mapnik { namespace wkt { using iterator_type = std::string::const_iterator; template struct wkt_collection_grammar; }} + +#endif