From 60f38780b3348b87c38d5cc29943e120e511b39f Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 20 Feb 2015 17:43:07 +0100 Subject: [PATCH] boost.geometry <-- mapnik-geometry adapters --- include/mapnik/geometry_adapters.hpp | 254 +++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 include/mapnik/geometry_adapters.hpp diff --git a/include/mapnik/geometry_adapters.hpp b/include/mapnik/geometry_adapters.hpp new file mode 100644 index 000000000..959d991e1 --- /dev/null +++ b/include/mapnik/geometry_adapters.hpp @@ -0,0 +1,254 @@ +/***************************************************************************** + * + * 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_ADAPTERS_HPP +#define MAPNIK_GEOMETRY_ADAPTERS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// register point +BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::new_geometry::point, double, cs::cartesian, x, y) +// ring +BOOST_GEOMETRY_REGISTER_RING(mapnik::new_geometry::linear_ring) + +namespace boost { + +template <> +struct range_iterator +{ + using type = mapnik::new_geometry::line_string::iterator_type; +}; + +template <> +struct range_const_iterator +{ + using type = mapnik::new_geometry::line_string::const_iterator_type; +}; + +inline mapnik::new_geometry::line_string::iterator_type +range_begin(mapnik::new_geometry::line_string & line) {return line.begin();} + +inline mapnik::new_geometry::line_string::iterator_type +range_end(mapnik::new_geometry::line_string & line) {return line.end();} + +inline mapnik::new_geometry::line_string::const_iterator_type +range_begin(mapnik::new_geometry::line_string const& line) {return line.begin();} + +inline mapnik::new_geometry::line_string::const_iterator_type +range_end(mapnik::new_geometry::line_string const& line) {return line.end();} + + +// register polygon +namespace geometry { namespace traits { + +template<> struct tag { using type = box_tag; }; + +template<> struct point_type { using type = mapnik::new_geometry::point; }; + + +template <> +struct indexed_access +{ + static inline double get(mapnik::new_geometry::bounding_box const& b) { return b.p0.x;} + static inline void set(mapnik::new_geometry::bounding_box& b, double value) { b.p0.x = value; } +}; + +template <> +struct indexed_access +{ + static inline double get(mapnik::new_geometry::bounding_box const& b) { return b.p0.y;} + static inline void set(mapnik::new_geometry::bounding_box& b, double value) { b.p0.y = value; } +}; + +template <> +struct indexed_access +{ + static inline double get(mapnik::new_geometry::bounding_box const& b) { return b.p1.x;} + static inline void set(mapnik::new_geometry::bounding_box& b, double value) { b.p1.x = value; } +}; + +template <> +struct indexed_access +{ + static inline double get(mapnik::new_geometry::bounding_box const& b) { return b.p1.y;} + static inline void set(mapnik::new_geometry::bounding_box& b, double value) { b.p1.y = value; } +}; + +template<> +struct tag +{ + using type = ring_tag; +}; + +// polygon 2 +template<> struct tag +{ + using type = polygon_tag; +}; + +// ring +template<> struct ring_const_type +{ + using type = mapnik::new_geometry::line_string::cont_type const&; +}; + +template<> struct ring_mutable_type +{ + using type = mapnik::new_geometry::line_string::cont_type&; +}; + +// interior +template<> struct interior_const_type +{ + using rings_type = std::vector; + using type = boost::iterator_range const; +}; + +template<> struct interior_mutable_type +{ + using rings_type = std::vector; + using type = boost::iterator_range; +}; + +// exterior +template<> +struct exterior_ring +{ + static mapnik::new_geometry::line_string::cont_type& get(mapnik::new_geometry::polygon2 & p) + { + return p.rings.front(); + } + + static mapnik::new_geometry::line_string::cont_type const& get(mapnik::new_geometry::polygon2 const& p) + { + return p.rings.front(); + } +}; + +template<> +struct interior_rings +{ + using ring_iterator = std::vector::iterator; + using const_ring_iterator = std::vector::const_iterator; + using holes_type = boost::iterator_range; + using const_holes_type = boost::iterator_range; + static holes_type get(mapnik::new_geometry::polygon2 & p) + { + return boost::make_iterator_range(p.rings.begin() + 1, p.rings.end()); + } + + static const_holes_type get(mapnik::new_geometry::polygon2 const& p) + { + return boost::make_iterator_range(p.rings.begin() + 1, p.rings.end()); + } +}; + + +// mapnik::new_geometry::polygon3 + +template<> struct tag +{ + using type = polygon_tag; +}; + + +template<> struct tag +{ + using type = multi_point_tag; +}; + +template<> struct tag +{ + using type = multi_linestring_tag; +}; + + +template<> struct tag +{ + using type = multi_polygon_tag; +}; + +// ring +template<> struct ring_const_type +{ + using type = mapnik::new_geometry::linear_ring const&; +}; + +template<> struct ring_mutable_type +{ + using type = mapnik::new_geometry::linear_ring&; +}; + +// interior +template<> struct interior_const_type +{ + using type = std::vector const&; +}; + +template<> struct interior_mutable_type +{ + using type = std::vector&; +}; + +// exterior +template<> +struct exterior_ring +{ + static mapnik::new_geometry::linear_ring& get(mapnik::new_geometry::polygon3 & p) + { + return p.exterior_ring; + } + + static mapnik::new_geometry::linear_ring const& get(mapnik::new_geometry::polygon3 const& p) + { + return p.exterior_ring; + } +}; + +template<> +struct interior_rings +{ + using holes_type = std::vector; + static holes_type& get(mapnik::new_geometry::polygon3 & p) + { + return p.interior_rings; + } + + static holes_type const& get(mapnik::new_geometry::polygon3 const& p) + { + return p.interior_rings; + } +}; + + +}}} + + +#endif //MAPNIK_GEOMETRY_ADAPTERS_HPP