geometry is_empty refactoring

This commit is contained in:
Dane Springmeyer 2015-03-24 14:16:58 -07:00
parent 546e46756c
commit 852776d5e3
7 changed files with 102 additions and 11 deletions

View file

@ -44,6 +44,7 @@
#include <mapnik/geometry_envelope.hpp>
#include <mapnik/geometry_is_valid.hpp>
#include <mapnik/geometry_is_simple.hpp>
#include <mapnik/geometry_is_empty.hpp>
#include <mapnik/geometry_correct.hpp>
#include <mapnik/geometry_centroid.hpp>
@ -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)

View file

@ -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);
}

View file

@ -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 <mapnik/geometry.hpp>
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

View file

@ -34,7 +34,7 @@
#include <mapnik/wkb.hpp>
#include <mapnik/util/trim.hpp>
#include <mapnik/util/fs.hpp>
#include <mapnik/geometry_empty.hpp>
#include <mapnik/geometry_is_empty.hpp>
// boost
#include <boost/algorithm/string.hpp>
@ -449,7 +449,7 @@ boost::optional<mapnik::datasource_geometry_t> 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;
}

View file

@ -30,7 +30,7 @@
#include <mapnik/unicode.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/geometry_empty.hpp>
#include <mapnik/geometry_is_empty.hpp>
#include <mapnik/geometry_envelope.hpp>
// 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;
}

View file

@ -36,7 +36,7 @@
#include <mapnik/params.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/fs.hpp>
#include <mapnik/geometry_empty.hpp>
#include <mapnik/geometry_is_empty.hpp>
#include <mapnik/geometry_envelope.hpp>
// 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<double> 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<double> 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<double> bbox = mapnik::geometry::envelope(geom);
if (bbox.valid())

View file

@ -29,7 +29,7 @@
#include <mapnik/global.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/geometry_empty.hpp>
#include <mapnik/geometry_is_empty.hpp>
#include <mapnik/geometry_envelope.hpp>
#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<double> bbox = mapnik::geometry::envelope(geom);
if (bbox.valid())