generic box2d<double> envelope(geometry const& )
This commit is contained in:
parent
ab151a095e
commit
8400be91c7
17 changed files with 197 additions and 91 deletions
|
@ -38,7 +38,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/wkt/wkt_factory.hpp> // from_wkt
|
||||
#include <mapnik/util/geometry_to_wkt.hpp>
|
||||
#include <mapnik/json/geometry_parser.hpp> // from_geojson
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
#include <mapnik/value.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
//#include <mapnik/geometry_container.hpp>
|
||||
#include <mapnik/geometry_envelope.hpp>
|
||||
//
|
||||
#include <mapnik/feature_kv_iterator.hpp>
|
||||
#include <mapnik/util/noncopyable.hpp>
|
||||
|
||||
|
@ -206,9 +207,7 @@ public:
|
|||
|
||||
inline box2d<double> envelope() const
|
||||
{
|
||||
box2d<double> result;
|
||||
std::cerr << "ENVELOPE" << std::endl;
|
||||
return result;
|
||||
return mapnik::new_geometry::envelope(geom_);
|
||||
}
|
||||
|
||||
inline raster_ptr const& get_raster() const
|
||||
|
|
|
@ -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 <boost/ptr_container/ptr_vector.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
using geometry_container = boost::ptr_vector<geometry_type>;
|
||||
|
||||
}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_CONTAINER_HPP
|
111
include/mapnik/geometry_envelope.hpp
Normal file
111
include/mapnik/geometry_envelope.hpp
Normal file
|
@ -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 <mapnik/geometry_impl.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
|
||||
namespace mapnik { namespace new_geometry {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct geometry_envelope
|
||||
{
|
||||
using bbox_type = box2d<double>;
|
||||
|
||||
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<double>(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<mapnik::new_geometry::line_string>(poly.exterior_ring));
|
||||
}
|
||||
|
||||
bbox_type operator() (mapnik::new_geometry::multi_point const& multi_point) const
|
||||
{
|
||||
return (*this) (static_cast<mapnik::new_geometry::line_string>(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<double> envelope(mapnik::new_geometry::geometry const& geom)
|
||||
{
|
||||
return detail::geometry_envelope() (geom);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_ENVELOPE_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<point> {};
|
||||
struct multi_point : line_string {};
|
||||
struct multi_line_string : std::vector<line_string> {};
|
||||
struct multi_polygon : std::vector<polygon3> {};
|
||||
struct geometry_collection;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/json/geometry_generator_grammar.hpp>
|
||||
#include <mapnik/json/properties_generator_grammar.hpp>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/json/geometry_grammar.hpp>
|
||||
|
||||
// boost
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/util/path_iterator.hpp>
|
||||
|
||||
// boost
|
||||
|
@ -43,8 +43,9 @@ template <>
|
|||
struct is_container<mapnik::vertex_adapter const> : mpl::true_ {} ;
|
||||
|
||||
// make gcc and darwin toolsets happy.
|
||||
template <>
|
||||
struct is_container<mapnik::geometry_container const> : mpl::false_ {} ;
|
||||
// FIXME
|
||||
//template <>
|
||||
//struct is_container<mapnik::geometry_container const> : mpl::false_ {} ;
|
||||
|
||||
//
|
||||
template <>
|
||||
|
|
|
@ -25,38 +25,68 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/geometry_impl.hpp>
|
||||
|
||||
//#include <mapnik/datasource.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
static inline void to_ds_type(mapnik::geometry_container const& paths,
|
||||
boost::optional<mapnik::datasource::geometry_t> & 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<mapnik::datasource::geometry_t>(paths.front().type()));
|
||||
}
|
||||
else if (paths.size() > 1)
|
||||
{
|
||||
int multi_type = 0;
|
||||
for (auto const& geom : paths)
|
||||
{
|
||||
int type = static_cast<int>(geom.type());
|
||||
if (multi_type > 0 && multi_type != type)
|
||||
{
|
||||
result.reset(datasource::Collection);
|
||||
}
|
||||
multi_type = type;
|
||||
result.reset(static_cast<mapnik::datasource::geometry_t>(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
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/svg/geometry_svg_generator.hpp>
|
||||
|
||||
// boost
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/make_unique.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/vertex.hpp>
|
||||
|
||||
// stl
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/wkt/wkt_generator_grammar.hpp>
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/wkt/wkt_grammar.hpp>
|
||||
#include <mapnik/wkt/wkt_generator_grammar.hpp>
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/vertex.hpp>
|
||||
|
||||
namespace mapnik { namespace wkt {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*****************************************************************************/
|
||||
#if 0 // FIXME
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
|
||||
#include <mapnik/json/feature_generator_grammar_impl.hpp>
|
||||
#include <mapnik/json/geometry_generator_grammar_impl.hpp>
|
||||
#include <mapnik/json/properties_generator_grammar_impl.hpp>
|
||||
|
|
|
@ -21,14 +21,15 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry_container.hpp>
|
||||
#include <mapnik/wkt/wkt_generator_grammar_impl.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace mapnik { namespace wkt {
|
||||
|
||||
using sink_type = std::back_insert_iterator<std::string>;
|
||||
template struct wkt_generator<sink_type, mapnik::geometry_type>;
|
||||
template struct wkt_multi_generator<sink_type, mapnik::geometry_container>;
|
||||
#if 0
|
||||
//using sink_type = std::back_insert_iterator<std::string>;
|
||||
//template struct wkt_generator<sink_type, mapnik::geometry_type>;
|
||||
//template struct wkt_multi_generator<sink_type, mapnik::geometry_container>;
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#if 0 // FIXME
|
||||
#include <mapnik/wkt/wkt_grammar_impl.hpp>
|
||||
#include <string>
|
||||
|
||||
|
@ -27,3 +28,5 @@ namespace mapnik { namespace wkt {
|
|||
using iterator_type = std::string::const_iterator;
|
||||
template struct wkt_collection_grammar<iterator_type>;
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue