A large set of changes that help allow WKT for int64_t type geometeries, modified some strategies, made it so that the clipper would use mapnik geometries.

This commit is contained in:
Blake Thompson 2015-04-21 09:34:52 -05:00
parent edda6cb13f
commit d7f7bc18c1
17 changed files with 849 additions and 463 deletions

View file

@ -35,6 +35,7 @@
#define clipper_hpp
#include <mapnik/config.hpp>
#include <mapnik/geometry.hpp>
#define CLIPPER_VERSION "6.2.6"
@ -46,7 +47,7 @@
//#define use_xyz
//use_lines: Enables line clipping. Adds a very minor cost to performance.
//#define use_lines
#define use_lines
//use_deprecated: Enables temporary support for the obsolete functions
//#define use_deprecated
@ -76,37 +77,41 @@ enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative };
static cInt const loRange = 0x7FFF;
static cInt const hiRange = 0x7FFF;
#else
typedef signed long long cInt;
typedef std::int64_t cInt;
static cInt const loRange = 0x3FFFFFFF;
static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL;
typedef signed long long long64; //used by Int128 class
typedef unsigned long long ulong64;
typedef std::int64_t long64; //used by Int128 class
typedef std::uint64_t ulong64;
#endif
/*
struct IntPoint {
cInt X;
cInt Y;
cInt x;
cInt y;
#ifdef use_xyz
cInt Z;
cInt z;
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {};
#else
IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {};
IntPoint(cInt x_ = 0, cInt y_ = 0): x(x_), y(y_) {};
#endif
friend inline bool operator== (const IntPoint& a, const IntPoint& b)
{
return a.X == b.X && a.Y == b.Y;
return a.x == b.x && a.y == b.y;
}
friend inline bool operator!= (const IntPoint& a, const IntPoint& b)
{
return a.X != b.X || a.Y != b.Y;
return a.x != b.x || a.y != b.y;
}
};
};*/
typedef mapnik::geometry::point<cInt> IntPoint;
//------------------------------------------------------------------------------
typedef std::vector< IntPoint > Path;
typedef std::vector< Path > Paths;
//typedef std::vector< IntPoint > Path;
typedef mapnik::geometry::line_string<cInt> Path;
typedef mapnik::geometry::multi_line_string<cInt> Paths;
inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;}
inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;}
@ -117,10 +122,10 @@ std::ostream& operator <<(std::ostream &s, const Paths &p);
struct DoublePoint
{
double X;
double Y;
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
double x;
double y;
DoublePoint(double x_ = 0, double y_ = 0) : x(x_), y(y_) {}
DoublePoint(IntPoint ip) : x((double)ip.x), y((double)ip.y) {}
};
//------------------------------------------------------------------------------
@ -189,7 +194,7 @@ void MinkowskiDiff(const Path& poly1, const Path& poly2, Paths& solution);
void PolyTreeToPaths(const PolyTree& polytree, Paths& paths);
void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths);
void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths);
MAPNIK_DECL void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths);
void ReversePath(Path& p);
void ReversePaths(Paths& p);

File diff suppressed because it is too large Load diff

View file

@ -46,6 +46,14 @@ struct point
point(point const& other) = default;
point(point && other) noexcept = default;
point & operator=(point const& other) = default;
friend inline bool operator== (point<T> const& a, point<T> const& b)
{
return a.x == b.x && a.y == b.y;
}
friend inline bool operator!= (point<T> const& a, point <T> const& b)
{
return a.x != b.x || a.y != b.y;
}
value_type x;
value_type y;
};
@ -55,6 +63,8 @@ template <typename T>
struct line_string : std::vector<point<T> >
{
line_string() = default;
line_string (std::size_t size)
: std::vector<point<T> >(size) {}
line_string (line_string && other) = default ;
line_string& operator=(line_string &&) = default;
line_string (line_string const& ) = default;
@ -64,7 +74,21 @@ struct line_string : std::vector<point<T> >
};
template <typename T>
struct linear_ring : line_string<T> {};
struct linear_ring : line_string<T>
{
linear_ring() = default;
linear_ring(std::size_t size)
: line_string<T>(size) {}
linear_ring (linear_ring && other) = default ;
linear_ring& operator=(linear_ring &&) = default;
linear_ring(line_string<T> && other)
: line_string<T>(other) {}
linear_ring (linear_ring const& ) = default;
linear_ring(line_string<T> const& other)
: line_string<T>(other) {}
linear_ring& operator=(linear_ring const&) = default;
};
template <typename T>
struct polygon

View file

@ -35,14 +35,15 @@
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
//
#include <mapnik/geometry.hpp>
#include <mapnik/box2d.hpp>
// register point
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<double>, double, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<int>, int, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<std::int64_t>, std::int64_t, cs::cartesian, x, y)
// ring
BOOST_GEOMETRY_REGISTER_RING(mapnik::geometry::linear_ring<double>)
BOOST_GEOMETRY_REGISTER_RING(mapnik::geometry::linear_ring<int>)
BOOST_GEOMETRY_REGISTER_RING(mapnik::geometry::linear_ring<std::int64_t>)
// needed by box2d<double>
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2d, double, cs::cartesian, x, y)
@ -56,9 +57,9 @@ struct range_iterator<mapnik::geometry::line_string<double> >
};
template <>
struct range_iterator<mapnik::geometry::line_string<int> >
struct range_iterator<mapnik::geometry::line_string<std::int64_t> >
{
using type = mapnik::geometry::line_string<int>::iterator;
using type = mapnik::geometry::line_string<std::int64_t>::iterator;
};
template <>
@ -68,9 +69,9 @@ struct range_const_iterator<mapnik::geometry::line_string<double> >
};
template <>
struct range_const_iterator<mapnik::geometry::line_string<int> >
struct range_const_iterator<mapnik::geometry::line_string<std::int64_t> >
{
using type = mapnik::geometry::line_string<int>::const_iterator;
using type = mapnik::geometry::line_string<std::int64_t>::const_iterator;
};
inline mapnik::geometry::line_string<double>::iterator
@ -85,17 +86,17 @@ range_begin(mapnik::geometry::line_string<double> const& line) {return line.begi
inline mapnik::geometry::line_string<double>::const_iterator
range_end(mapnik::geometry::line_string<double> const& line) {return line.end();}
inline mapnik::geometry::line_string<int>::iterator
range_begin(mapnik::geometry::line_string<int> & line) {return line.begin();}
inline mapnik::geometry::line_string<std::int64_t>::iterator
range_begin(mapnik::geometry::line_string<std::int64_t> & line) {return line.begin();}
inline mapnik::geometry::line_string<int>::iterator
range_end(mapnik::geometry::line_string<int> & line) {return line.end();}
inline mapnik::geometry::line_string<std::int64_t>::iterator
range_end(mapnik::geometry::line_string<std::int64_t> & line) {return line.end();}
inline mapnik::geometry::line_string<int>::const_iterator
range_begin(mapnik::geometry::line_string<int> const& line) {return line.begin();}
inline mapnik::geometry::line_string<std::int64_t>::const_iterator
range_begin(mapnik::geometry::line_string<std::int64_t> const& line) {return line.begin();}
inline mapnik::geometry::line_string<int>::const_iterator
range_end(mapnik::geometry::line_string<int> const& line) {return line.end();}
inline mapnik::geometry::line_string<std::int64_t>::const_iterator
range_end(mapnik::geometry::line_string<std::int64_t> const& line) {return line.end();}
namespace geometry { namespace traits {
@ -145,7 +146,7 @@ struct tag<mapnik::geometry::line_string<double> >
};
template<>
struct tag<mapnik::geometry::line_string<int> >
struct tag<mapnik::geometry::line_string<std::int64_t> >
{
using type = linestring_tag;
};
@ -158,7 +159,7 @@ struct tag<mapnik::geometry::polygon<double> >
};
template<>
struct tag<mapnik::geometry::polygon<int> >
struct tag<mapnik::geometry::polygon<std::int64_t> >
{
using type = polygon_tag;
};
@ -170,7 +171,7 @@ struct point_order<mapnik::geometry::linear_ring<double> >
};
template <>
struct point_order<mapnik::geometry::linear_ring<int> >
struct point_order<mapnik::geometry::linear_ring<std::int64_t> >
{
static const order_selector value = counterclockwise;
};
@ -182,7 +183,7 @@ struct tag<mapnik::geometry::multi_point<double> >
};
template<>
struct tag<mapnik::geometry::multi_point<int> >
struct tag<mapnik::geometry::multi_point<std::int64_t> >
{
using type = multi_point_tag;
};
@ -194,7 +195,7 @@ struct tag<mapnik::geometry::multi_line_string<double> >
};
template<>
struct tag<mapnik::geometry::multi_line_string<int> >
struct tag<mapnik::geometry::multi_line_string<std::int64_t> >
{
using type = multi_linestring_tag;
};
@ -204,7 +205,7 @@ template<> struct tag<mapnik::geometry::multi_polygon<double> >
using type = multi_polygon_tag;
};
template<> struct tag<mapnik::geometry::multi_polygon<int> >
template<> struct tag<mapnik::geometry::multi_polygon<std::int64_t> >
{
using type = multi_polygon_tag;
};
@ -215,9 +216,9 @@ template<> struct ring_const_type<mapnik::geometry::polygon<double> >
using type = mapnik::geometry::linear_ring<double> const&;
};
template<> struct ring_const_type<mapnik::geometry::polygon<int> >
template<> struct ring_const_type<mapnik::geometry::polygon<std::int64_t> >
{
using type = mapnik::geometry::linear_ring<int> const&;
using type = mapnik::geometry::linear_ring<std::int64_t> const&;
};
template<> struct ring_mutable_type<mapnik::geometry::polygon<double> >
@ -225,9 +226,9 @@ template<> struct ring_mutable_type<mapnik::geometry::polygon<double> >
using type = mapnik::geometry::linear_ring<double>&;
};
template<> struct ring_mutable_type<mapnik::geometry::polygon<int> >
template<> struct ring_mutable_type<mapnik::geometry::polygon<std::int64_t> >
{
using type = mapnik::geometry::linear_ring<int>&;
using type = mapnik::geometry::linear_ring<std::int64_t>&;
};
// interior
@ -241,14 +242,14 @@ template<> struct interior_mutable_type<mapnik::geometry::polygon<double> >
using type = std::vector<mapnik::geometry::linear_ring<double> >&;
};
template<> struct interior_const_type<mapnik::geometry::polygon<int> >
template<> struct interior_const_type<mapnik::geometry::polygon<std::int64_t> >
{
using type = std::vector<mapnik::geometry::linear_ring<int> > const&;
using type = std::vector<mapnik::geometry::linear_ring<std::int64_t> > const&;
};
template<> struct interior_mutable_type<mapnik::geometry::polygon<int> >
template<> struct interior_mutable_type<mapnik::geometry::polygon<std::int64_t> >
{
using type = std::vector<mapnik::geometry::linear_ring<int> >&;
using type = std::vector<mapnik::geometry::linear_ring<std::int64_t> >&;
};
// exterior
@ -282,29 +283,29 @@ struct interior_rings<mapnik::geometry::polygon<double> >
};
template<>
struct exterior_ring<mapnik::geometry::polygon<int> >
struct exterior_ring<mapnik::geometry::polygon<std::int64_t> >
{
static mapnik::geometry::linear_ring<int> & get(mapnik::geometry::polygon<int> & p)
static mapnik::geometry::linear_ring<std::int64_t> & get(mapnik::geometry::polygon<std::int64_t> & p)
{
return p.exterior_ring;
}
static mapnik::geometry::linear_ring<int> const& get(mapnik::geometry::polygon<int> const& p)
static mapnik::geometry::linear_ring<std::int64_t> const& get(mapnik::geometry::polygon<std::int64_t> const& p)
{
return p.exterior_ring;
}
};
template<>
struct interior_rings<mapnik::geometry::polygon<int> >
struct interior_rings<mapnik::geometry::polygon<std::int64_t> >
{
using holes_type = std::vector<mapnik::geometry::linear_ring<int> >;
static holes_type& get(mapnik::geometry::polygon<int> & p)
using holes_type = std::vector<mapnik::geometry::linear_ring<std::int64_t> >;
static holes_type& get(mapnik::geometry::polygon<std::int64_t> & p)
{
return p.interior_rings;
}
static holes_type const& get(mapnik::geometry::polygon<int> const& p)
static holes_type const& get(mapnik::geometry::polygon<std::int64_t> const& p)
{
return p.interior_rings;
}

View file

@ -44,7 +44,8 @@ struct geometry_envelope
void operator() (mapnik::geometry::geometry_empty const&) const {}
void operator() (mapnik::geometry::point<double> const& pt) const
template <typename T>
void operator() (mapnik::geometry::point<T> const& pt) const
{
if (!bbox.valid())
{
@ -53,7 +54,8 @@ struct geometry_envelope
bbox.expand_to_include(pt.x, pt.y);
}
void operator() (mapnik::geometry::line_string<double> const& line) const
template <typename T>
void operator() (mapnik::geometry::line_string<T> const& line) const
{
bool first = true;
for (auto const& pt : line)
@ -70,7 +72,8 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::polygon<double> const& poly) const
template <typename T>
void operator() (mapnik::geometry::polygon<T> const& poly) const
{
bool first = true;
for (auto const& pt : poly.exterior_ring)
@ -87,7 +90,8 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_point<double> const& multi_point) const
template <typename T>
void operator() (mapnik::geometry::multi_point<T> const& multi_point) const
{
bool first = true;
for (auto const& pt : multi_point)
@ -104,7 +108,8 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_line_string<double> const& multi_line) const
template <typename T>
void operator() (mapnik::geometry::multi_line_string<T> const& multi_line) const
{
for (auto const& line : multi_line)
{
@ -112,7 +117,8 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_polygon<double> const& multi_poly) const
template <typename T>
void operator() (mapnik::geometry::multi_polygon<T> const& multi_poly) const
{
for (auto const& poly : multi_poly)
{
@ -120,7 +126,8 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::geometry_collection<double> const& collection) const
template <typename T>
void operator() (mapnik::geometry::geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{

View file

@ -34,9 +34,20 @@ BOOST_FUSION_ADAPT_STRUCT(
(double, y)
)
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::point<std::int64_t>,
(std::int64_t, x)
(std::int64_t, y)
)
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::polygon<double>,
(mapnik::geometry::linear_ring<double> const&, exterior_ring)
(std::vector<mapnik::geometry::linear_ring<double> > const& , interior_rings))
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::polygon<std::int64_t>,
(mapnik::geometry::linear_ring<std::int64_t> const&, exterior_ring)
(std::vector<mapnik::geometry::linear_ring<std::int64_t> > const& , interior_rings))
#endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP

View file

@ -23,6 +23,8 @@
#ifndef MAPNIK_GEOMETRY_STRATEGY_HPP
#define MAPNIK_GEOMETRY_STRATEGY_HPP
#include <mapnik/geometry_adapters.hpp>
namespace mapnik {
namespace geometry {

View file

@ -29,6 +29,72 @@
namespace mapnik { namespace geometry { namespace detail {
template <typename V, typename T, typename Transformer>
inline point<V> transform_geometry(point<T> const& geom, Transformer const& transformer)
{
point<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
inline multi_point<V> transform_geometry(multi_point<T> const& geom, Transformer const& transformer)
{
multi_point<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
inline line_string<V> transform_geometry(line_string<T> const& geom, Transformer const& transformer)
{
line_string<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
inline multi_line_string<V> transform_geometry(multi_line_string<T> const& geom, Transformer const& transformer)
{
multi_line_string<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
inline polygon<V> transform_geometry(polygon<T> const& geom, Transformer const& transformer)
{
polygon<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}
template <typename V, typename T, typename Transformer>
inline multi_polygon<V> transform_geometry(multi_polygon<T> const& geom, Transformer const& transformer)
{
multi_polygon<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}
template <typename Transformer, typename V>
struct geometry_transform
{
@ -62,91 +128,93 @@ struct geometry_transform
template <typename T>
geometry<V> operator() (point<T> const& geom) const
{
point<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (line_string<T> const& geom) const
{
line_string<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (polygon<T> const& geom) const
{
polygon<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (multi_point<T> const& geom) const
{
multi_point<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (multi_line_string<T> const& geom) const
{
multi_line_string<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (multi_polygon<T> const& geom) const
{
multi_polygon<V> geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
return std::move(transform_geometry<V>(geom, transformer_));
}
/*template <typename T>
geometry<V> operator() (T const& geom) const
{
using geometry_type = T;
geometry_type geom_transformed;
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
{
throw std::runtime_error("Can't transformm geometry");
}
return geom_transformed;
}*/
Transformer const& transformer_;
};
} // ns detail
template <typename T0, typename T1, typename T2>
geometry<T0> transform(T1 const& geom, T2 const& transformer)
geometry<T0> transform(geometry<T1> const& geom, T2 const& transformer)
{
return detail::geometry_transform<T2, T0>(transformer)(geom);
}
template <typename T0, typename T1, typename T2>
geometry<T0> transform(geometry_collection<T1> const& geom, T2 const& transformer)
{
return detail::geometry_transform<T2, T0>(transformer)(geom);
}
template <typename T0, typename T1, typename T2>
point<T0> transform(point<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
multi_point<T0> transform(multi_point<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
line_string<T0> transform(line_string<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
multi_line_string<T0> transform(multi_line_string<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
polygon<T0> transform(polygon<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
template <typename T0, typename T1, typename T2>
multi_polygon<T0> transform(multi_polygon<T1> const& geom, T2 const& transformer)
{
return detail::transform_geometry<T0>(geom, transformer);
}
}}
#endif // MAPNIK_GEOMETRY_TRANSFORM_HPP

View file

@ -42,37 +42,44 @@ struct geometry_type
return mapnik::geometry::geometry_types::Unknown;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::point<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::point<T> const&) const
{
return mapnik::geometry::geometry_types::Point;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::line_string<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::line_string<T> const&) const
{
return mapnik::geometry::geometry_types::LineString;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::polygon<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::polygon<T> const&) const
{
return mapnik::geometry::geometry_types::Polygon;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_point<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_point<T> const&) const
{
return mapnik::geometry::geometry_types::MultiPoint;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_line_string<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_line_string<T> const&) const
{
return mapnik::geometry::geometry_types::MultiLineString;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_polygon<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_polygon<T> const&) const
{
return mapnik::geometry::geometry_types::MultiPolygon;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry_collection<double> const&) const
template <typename T>
mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry_collection<T> const&) const
{
return mapnik::geometry::geometry_types::GeometryCollection;
}

View file

@ -26,9 +26,7 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/util/noncopyable.hpp>
// boost
#include <boost/geometry.hpp>
#include <mapnik/geometry_adapters.hpp>
namespace mapnik {
@ -121,6 +119,55 @@ struct proj_strategy
proj_transform const& prj_trans_;
};
struct proj_backward_strategy
{
proj_backward_strategy(proj_transform const& prj_trans)
: prj_trans_(prj_trans) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = boost::geometry::get<0>(p1);
double y = boost::geometry::get<1>(p1);
double z = 0.0;
if (!prj_trans_.backward(x, y, z)) return false;
try {
boost::geometry::set<0>(p2, boost::numeric_cast<p2_type>(x));
}
catch(boost::numeric::negative_overflow&)
{
boost::geometry::set<0>(p2, std::numeric_limits<p2_type>::min());
}
catch(boost::numeric::positive_overflow&)
{
boost::geometry::set<0>(p2, std::numeric_limits<p2_type>::max());
}
try {
boost::geometry::set<1>(p2, boost::numeric_cast<p2_type>(y));
}
catch(boost::numeric::negative_overflow&)
{
boost::geometry::set<1>(p2, std::numeric_limits<p2_type>::min());
}
catch(boost::numeric::positive_overflow&)
{
boost::geometry::set<1>(p2, std::numeric_limits<p2_type>::max());
}
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
proj_transform const& prj_trans_;
};
}
#endif // MAPNIK_PROJ_TRANSFORM_HPP

View file

@ -35,7 +35,15 @@ namespace mapnik { namespace util {
inline bool to_wkt(std::string & wkt, mapnik::geometry::geometry<double> const& geom)
{
using sink_type = std::back_insert_iterator<std::string>;
static const mapnik::wkt::wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double> > generator;
static const mapnik::wkt::wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double>, double > generator;
sink_type sink(wkt);
return boost::spirit::karma::generate(sink, generator, geom);
}
inline bool to_wkt(std::string & wkt, mapnik::geometry::geometry<std::int64_t> const& geom)
{
using sink_type = std::back_insert_iterator<std::string>;
static const mapnik::wkt::wkt_generator_grammar_int<sink_type, mapnik::geometry::geometry<std::int64_t>, std::int64_t > generator;
sink_type sink(wkt);
return boost::spirit::karma::generate(sink, generator, geom);
}

View file

@ -115,6 +115,94 @@ namespace boost { namespace spirit { namespace traits {
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::point<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::point<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::point<std::int64_t> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::line_string<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::line_string<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::line_string<std::int64_t> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::polygon<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::polygon<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::polygon<std::int64_t> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::polygon<std::int64_t> const,
std::vector<mapnik::geometry::linear_ring<std::int64_t> > const&, karma::domain>
{
using type = std::vector<mapnik::geometry::linear_ring<std::int64_t> > const&;
static type pre(mapnik::geometry::polygon<std::int64_t> const& poly)
{
return poly.interior_rings;
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::multi_point<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::multi_point<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::multi_point<std::int64_t> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::multi_line_string<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::multi_line_string<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::multi_line_string<std::int64_t> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::multi_polygon<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::multi_polygon<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::multi_polygon<std::int64_t> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry<std::int64_t> const,
mapnik::geometry::geometry_collection<std::int64_t> const&, karma::domain>
{
using type = mapnik::geometry::geometry_collection<std::int64_t> const&;
static type pre(mapnik::geometry::geometry<std::int64_t> const& geom)
{
return mapnik::util::get<mapnik::geometry::geometry_collection<std::int64_t> >(geom);
}
};
}}}
#endif // MAPNIK_UTIL_SPIRIT_TRANSFORM_ATTRIBUTE_HPP

View file

@ -85,9 +85,10 @@ struct wkt_coordinate_policy : karma::real_policies<T>
return base_type::fraction_part(sink, n, adjprec, precision);
}
};
}
template <typename OutputIterator, typename Geometry>
template <typename OutputIterator, typename Geometry, typename T>
struct wkt_generator_grammar :
karma::grammar<OutputIterator, Geometry const& ()>
{
@ -95,26 +96,56 @@ struct wkt_generator_grammar :
// rules
karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry<double> const&()> point;
karma::rule<OutputIterator, geometry::point<double> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<double> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<double> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<double> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<double> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<double> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<double> const& ()> geometries;
karma::rule<OutputIterator, geometry::geometry<T> const&()> point;
karma::rule<OutputIterator, geometry::point<T> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<T> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<T> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<T> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<T> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<T> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<T> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<T> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<T> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<T> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<T> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::symbols<mapnik::geometry::geometry_types, char const*> empty;
//
karma::real_generator<double, detail::wkt_coordinate_policy<double> > coordinate;
karma::real_generator<T, detail::wkt_coordinate_policy<T> > coordinate;
};
template <typename OutputIterator, typename Geometry, typename T>
struct wkt_generator_grammar_int :
karma::grammar<OutputIterator, Geometry const& ()>
{
wkt_generator_grammar_int();
// rules
karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry<T> const&()> point;
karma::rule<OutputIterator, geometry::point<T> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<T> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<T> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<T> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<T> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<T> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<T> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<T> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<T> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<T> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<T> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<T> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::symbols<mapnik::geometry::geometry_types, char const*> empty;
//
karma::int_generator<T> coordinate;
};
}}

View file

@ -28,8 +28,8 @@
namespace mapnik { namespace wkt {
template <typename OutputIterator, typename Geometry>
wkt_generator_grammar<OutputIterator, Geometry>::wkt_generator_grammar()
template <typename OutputIterator, typename Geometry, typename T>
wkt_generator_grammar<OutputIterator, Geometry,T>::wkt_generator_grammar()
: wkt_generator_grammar::base_type(geometry)
{
boost::spirit::karma::_val_type _val;
@ -113,4 +113,89 @@ wkt_generator_grammar<OutputIterator, Geometry>::wkt_generator_grammar()
}
template <typename OutputIterator, typename Geometry, typename T>
wkt_generator_grammar_int<OutputIterator, Geometry,T>::wkt_generator_grammar_int()
: wkt_generator_grammar_int::base_type(geometry)
{
boost::spirit::karma::_val_type _val;
boost::spirit::karma::_1_type _1;
boost::spirit::karma::_a_type _a;
boost::spirit::karma::lit_type lit;
boost::spirit::karma::uint_type uint_;
boost::spirit::karma::eps_type eps;
empty.add
(geometry::geometry_types::Point, "POINT EMPTY")
(geometry::geometry_types::LineString, "LINESTRING EMPTY")
(geometry::geometry_types::Polygon, "POLYGON EMPTY")
(geometry::geometry_types::MultiPoint, "MULTIPOINT EMPTY")
(geometry::geometry_types::MultiLineString, "MULTILINESTRING EMPTY")
(geometry::geometry_types::MultiPolygon, "MULTIPOLYGON EMPTY")
(geometry::geometry_types::GeometryCollection, "GEOMETRYCOLLECTION EMPTY")
;
geometry = geometry_dispatch.alias()
;
geometry_dispatch = eps[_a = geometry_type(_val)] <<
(&uint_(geometry::geometry_types::Point)[_1 = _a]
<< point)
|
(&uint_(geometry::geometry_types::LineString)[_1 = _a]
<< (linestring | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::Polygon)[_1 = _a]
<< (polygon | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::MultiPoint)[_1 = _a]
<< ( multi_point | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::MultiLineString)[_1 = _a]
<< (multi_linestring | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::MultiPolygon)[_1 = _a]
<< (multi_polygon | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::GeometryCollection)[_1 = _a]
<< (geometry_collection | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::Unknown)[_1 = _a]
<< lit("POINT EMPTY")) // special case for geometry_empty as mapnik::geometry::point<double> can't be empty
;
point = lit("POINT(") << point_coord << lit(")")
;
linestring = lit("LINESTRING(") << linestring_coord << lit(")")
;
polygon = lit("POLYGON(") << polygon_coord << lit(")")
;
multi_point = lit("MULTIPOINT(") << multi_point_coord << lit(")")
;
multi_linestring = lit("MULTILINESTRING(") << multi_linestring_coord << lit(")")
;
multi_polygon = lit("MULTIPOLYGON(") << multi_polygon_coord << lit(")")
;
geometry_collection = lit("GEOMETRYCOLLECTION(") << geometries << lit(")")
;
point_coord = coordinate << lit(' ') << coordinate
;
linestring_coord = point_coord % lit(',')
;
polygon_coord = lit('(') << exterior_ring_coord << lit(')') << interior_ring_coord
;
exterior_ring_coord = linestring_coord.alias()
;
interior_ring_coord = *(lit(",(") << exterior_ring_coord << lit(')'))
;
multi_point_coord = linestring_coord.alias()
;
multi_linestring_coord = (lit('(') << linestring_coord << lit(')')) % lit(',')
;
multi_polygon_coord = (lit('(') << polygon_coord << lit(')')) % lit(',')
;
geometries = geometry % lit(',')
;
}
}}

View file

@ -37,5 +37,14 @@ template MAPNIK_DECL mapnik::box2d<double> envelope(multi_line_string<double> co
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_polygon<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_collection<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(point<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(line_string<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(polygon<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_point<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_line_string<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_polygon<std::int64_t> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_collection<std::int64_t> const& geom);
} // end ns geometry
} // end ns mapnik

View file

@ -27,6 +27,7 @@
namespace mapnik { namespace wkt {
using sink_type = std::back_insert_iterator<std::string>;
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double> >;
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double>, double >;
template struct wkt_generator_grammar_int<sink_type, mapnik::geometry::geometry<std::int64_t>, std::int64_t >;
}}

View file

@ -26,9 +26,7 @@ SECTION("proj and view strategy") {
// Test first that proj strategy works properly
point<double> p1(-97.553098,35.523105);
point<double> r1(-1.08596e+07, 4.2352e+06);
geometry<double> p2 = transform<double>(p1, ps);
REQUIRE(p2.is<point<double> >());
point<double> p3 = mapnik::util::get<point<double> >(p2);
point<double> p3 = transform<double>(p1, ps);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
@ -36,9 +34,7 @@ SECTION("proj and view strategy") {
// Test next that view_strategy works
point<double> p1(-1.08596e+07, 4.2352e+06);
point<double> r1(58.6287 , 100.945);
geometry<double> p2 = transform<double>(p1, vs);
REQUIRE(p2.is<point<double> >());
point<double> p3 = mapnik::util::get<point<double> >(p2);
point<double> p3 = transform<double>(p1, vs);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
@ -49,9 +45,7 @@ SECTION("proj and view strategy") {
point<double> r1(58.6287 , 100.945);
using sg_type = strategy_group<mapnik::view_strategy>;
sg_type sg(vs);
geometry<double> p2 = transform<double>(p1, sg);
REQUIRE(p2.is<point<double> >());
point<double> p3 = mapnik::util::get<point<double> >(p2);
point<double> p3 = transform<double>(p1, sg);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
@ -62,9 +56,7 @@ SECTION("proj and view strategy") {
sg_type sg(ps, vs);
point<double> p1(-97.553098,35.523105);
point<double> r1(58.6287 , 100.945);
geometry<double> p2 = transform<double>(p1, sg);
REQUIRE(p2.is<point<double> >());
point<double> p3 = mapnik::util::get<point<double> >(p2);
point<double> p3 = transform<double>(p1, sg);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
@ -85,10 +77,10 @@ SECTION("proj and view strategy") {
using sg_type = strategy_group<mapnik::proj_strategy, mapnik::view_strategy >;
sg_type sg(ps, vs);
geometry<double> p1(std::move(point<double>(-97.553098,35.523105)));
point<int> r1(58 , 100);
geometry<int> p2 = transform<int>(p1, sg);
REQUIRE(p2.is<point<int> >());
point<int> p3 = mapnik::util::get<point<int> >(p2);
point<std::int64_t> r1(58 , 100);
geometry<std::int64_t> p2 = transform<std::int64_t>(p1, sg);
REQUIRE(p2.is<point<std::int64_t> >());
point<std::int64_t> p3 = mapnik::util::get<point<std::int64_t> >(p2);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
@ -98,10 +90,10 @@ SECTION("proj and view strategy") {
using sg_type = strategy_group<mapnik::proj_strategy, mapnik::view_strategy, mapnik::geometry::scale_strategy >;
sg_type sg(ps, vs, ss);
geometry<double> p1(std::move(point<double>(-97.553098,35.523105)));
point<int> r1(938 , 1615);
geometry<int> p2 = transform<int>(p1, sg);
REQUIRE(p2.is<point<int> >());
point<int> p3 = mapnik::util::get<point<int> >(p2);
point<std::int64_t> r1(938 , 1615);
geometry<std::int64_t> p2 = transform<std::int64_t>(p1, sg);
REQUIRE(p2.is<point<std::int64_t> >());
point<std::int64_t> p3 = mapnik::util::get<point<std::int64_t> >(p2);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
@ -110,12 +102,12 @@ SECTION("proj and view strategy") {
mapnik::geometry::scale_strategy ss(1.0/16.0);
using sg_type = strategy_group_first<mapnik::geometry::scale_strategy, mapnik::unview_strategy, mapnik::proj_strategy >;
sg_type sg(ss, uvs, ps_rev);
geometry<int> p1(std::move(point<int>(938 , 1615)));
geometry<std::int64_t> p1(std::move(point<std::int64_t>(938 , 1615)));
point<double> r1(-97.5586 , 35.5322);
geometry<double> p2 = transform<double>(p1, sg);
REQUIRE(p2.is<point<double> >());
point<double> p3 = mapnik::util::get<point<double> >(p2);
std::cout << p3.x << " , " << p3.y << std::endl;
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}