geometry - add generic is_valid(), is_simple() and correct()
This commit is contained in:
parent
d25ef607a2
commit
38dc240d6d
5 changed files with 231 additions and 1 deletions
|
@ -42,6 +42,10 @@
|
|||
#include <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/geometry_type.hpp>
|
||||
#include <mapnik/geometry_envelope.hpp>
|
||||
#include <mapnik/geometry_is_valid.hpp>
|
||||
#include <mapnik/geometry_is_simple.hpp>
|
||||
#include <mapnik/geometry_correct.hpp>
|
||||
|
||||
//#include <mapnik/wkt/wkt_factory.hpp> // from_wkt
|
||||
//#include <mapnik/util/geometry_to_wkt.hpp>
|
||||
#include <mapnik/json/geometry_parser.hpp> // from_geojson
|
||||
|
@ -232,6 +236,21 @@ mapnik::box2d<double> geometry_envelope_impl(mapnik::new_geometry::geometry cons
|
|||
return mapnik::new_geometry::envelope(geom);
|
||||
}
|
||||
|
||||
bool geometry_is_valid_impl(mapnik::new_geometry::geometry const& geom)
|
||||
{
|
||||
return mapnik::new_geometry::is_valid(geom);
|
||||
}
|
||||
|
||||
bool geometry_is_simple_impl(mapnik::new_geometry::geometry const& geom)
|
||||
{
|
||||
return mapnik::new_geometry::is_simple(geom);
|
||||
}
|
||||
|
||||
void geometry_correct_impl(mapnik::new_geometry::geometry & geom)
|
||||
{
|
||||
mapnik::new_geometry::correct(geom);
|
||||
}
|
||||
|
||||
/*
|
||||
// https://github.com/mapnik/mapnik/issues/1437
|
||||
std::string to_svg2( mapnik::geometry_container const& geom)
|
||||
|
@ -273,6 +292,9 @@ void export_geometry()
|
|||
.staticmethod("from_geojson")
|
||||
// .def("__str__",&mapnik::geometry_type::to_string)
|
||||
.def("type",&geometry_type_impl)
|
||||
.def("is_valid", &geometry_is_valid_impl)
|
||||
.def("is_simple", &geometry_is_simple_impl)
|
||||
.def("correct", &geometry_correct_impl)
|
||||
//.def("to_wkb",&to_wkb)
|
||||
//.def("to_wkt",&to_wkt)
|
||||
.def("to_geojson",&to_geojson_impl)
|
||||
|
|
72
include/mapnik/geometry_correct.hpp
Normal file
72
include/mapnik/geometry_correct.hpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* 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_CORRECT_HPP
|
||||
#define MAPNIK_GEOMETRY_CORRECT_HPP
|
||||
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/correct.hpp>
|
||||
|
||||
namespace mapnik { namespace new_geometry {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct geometry_correct
|
||||
{
|
||||
using result_type = void;
|
||||
|
||||
result_type operator() (geometry_collection & collection) const
|
||||
{
|
||||
for (auto & geom : collection)
|
||||
{
|
||||
(*this)(geom);
|
||||
}
|
||||
}
|
||||
|
||||
result_type operator() (polygon & poly) const
|
||||
{
|
||||
return boost::geometry::correct(poly);
|
||||
}
|
||||
|
||||
result_type operator() (multi_polygon & multi_poly) const
|
||||
{
|
||||
return boost::geometry::correct(multi_poly);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
result_type operator() (T & geom) const
|
||||
{
|
||||
//no-op
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
inline void correct(mapnik::new_geometry::geometry & geom)
|
||||
{
|
||||
return mapnik::util::apply_visitor(detail::geometry_correct(), geom);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_CORRECT_HPP
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
* 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
|
||||
|
|
68
include/mapnik/geometry_is_simple.hpp
Normal file
68
include/mapnik/geometry_is_simple.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* 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_IS_SIMPLE_HPP
|
||||
#define MAPNIK_GEOMETRY_IS_SIMPLE_HPP
|
||||
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/is_simple.hpp>
|
||||
|
||||
namespace mapnik { namespace new_geometry {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct geometry_is_simple
|
||||
{
|
||||
using result_type = bool;
|
||||
|
||||
result_type operator() (geometry const& geom) const
|
||||
{
|
||||
return mapnik::util::apply_visitor(*this, geom);
|
||||
}
|
||||
|
||||
result_type operator() (geometry_collection const& collection) const
|
||||
{
|
||||
for (auto const& geom : collection)
|
||||
{
|
||||
if ( !(*this)(geom)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
result_type operator() (T const& geom) const
|
||||
{
|
||||
return boost::geometry::is_simple(geom);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
inline bool is_simple(mapnik::new_geometry::geometry const& geom)
|
||||
{
|
||||
return detail::geometry_is_simple() (geom);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_IS_SIMPLE_HPP
|
68
include/mapnik/geometry_is_valid.hpp
Normal file
68
include/mapnik/geometry_is_valid.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* 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_IS_VALID_HPP
|
||||
#define MAPNIK_GEOMETRY_IS_VALID_HPP
|
||||
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/is_valid.hpp>
|
||||
|
||||
namespace mapnik { namespace new_geometry {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct geometry_is_valid
|
||||
{
|
||||
using result_type = bool;
|
||||
|
||||
result_type operator() (geometry const& geom) const
|
||||
{
|
||||
return mapnik::util::apply_visitor(*this, geom);
|
||||
}
|
||||
|
||||
result_type operator() (geometry_collection const& collection) const
|
||||
{
|
||||
for (auto const& geom : collection)
|
||||
{
|
||||
if ( !(*this)(geom)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
result_type operator() (T const& geom) const
|
||||
{
|
||||
return boost::geometry::is_valid(geom);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
inline bool is_valid(mapnik::new_geometry::geometry const& geom)
|
||||
{
|
||||
return detail::geometry_is_valid() (geom);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_IS_VALID_HPP
|
Loading…
Add table
Reference in a new issue