/usr/include/mapnik/geometry_centroid.hpp is in libmapnik-dev 3.0.12+ds-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | /*****************************************************************************
*
* 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_CENTROID_HPP
#define MAPNIK_GEOMETRY_CENTROID_HPP
#include <mapnik/geometry.hpp>
#include <mapnik/geometry_adapters.hpp>
#include <boost/geometry/algorithms/centroid.hpp>
#include <mapnik/geometry_is_empty.hpp>
#include <mapnik/geometry_remove_empty.hpp>
namespace mapnik { namespace geometry {
namespace detail {
template <typename T>
struct geometry_centroid
{
using result_type = bool;
geometry_centroid(point<T> & pt)
: pt_(pt) {}
template <typename T1>
result_type operator() (T1 const& geom) const
{
return util::apply_visitor(*this, geom);
}
result_type operator() (geometry_empty const&) const
{
return false;
}
result_type operator() (geometry_collection<T> const&) const
{
return false;
}
result_type operator() (point<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator() (line_string<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator() (polygon<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator() (multi_point<T> const& geom) const
{
return centroid_simple(geom);
}
result_type operator() (multi_line_string<T> const& geom) const
{
return centroid_multi(geom);
}
result_type operator() (multi_polygon<T> const& geom) const
{
return centroid_multi(geom);
}
point<T> & pt_;
private:
template <typename Geom>
result_type centroid_simple(Geom const & geom) const
{
try
{
boost::geometry::centroid(geom, pt_);
return true;
}
catch (boost::geometry::centroid_exception const & e)
{
return false;
}
}
template <typename Geom>
result_type centroid_multi(Geom const & geom) const
{
// https://github.com/mapnik/mapnik/issues/3169
#if BOOST_VERSION <= 105900
if (mapnik::geometry::has_empty(geom))
{
Geom stripped = mapnik::geometry::remove_empty(geom);
return centroid_simple(stripped);
}
#endif
return centroid_simple(geom);
}
};
}
template <typename T1, typename T2>
inline bool centroid(T1 const& geom, point<T2> & pt)
{
return detail::geometry_centroid<T2>(pt)(geom);
}
}}
#endif // MAPNIK_GEOMETRY_CENTROID_HPP
|