Merge branch 'mapnik-geometry-template' into mapnik-geometry

This commit is contained in:
artemp 2015-04-22 12:28:21 +02:00
commit 0f998c28b2
88 changed files with 2933 additions and 1788 deletions

View file

@ -33,11 +33,11 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
void render(mapnik::geometry::multi_polygon const& geom, void render(mapnik::geometry::multi_polygon<double> const& geom,
mapnik::box2d<double> const& extent, mapnik::box2d<double> const& extent,
std::string const& name) std::string const& name)
{ {
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry::polygon_vertex_adapter>; using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry::polygon_vertex_adapter<double>>;
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>; using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
using renderer = agg::renderer_scanline_aa_solid<ren_base>; using renderer = agg::renderer_scanline_aa_solid<ren_base>;
mapnik::image_rgba8 im(256,256); mapnik::image_rgba8 im(256,256);
@ -54,7 +54,7 @@ void render(mapnik::geometry::multi_polygon const& geom,
agg::rasterizer_scanline_aa<> ras; agg::rasterizer_scanline_aa<> ras;
for (auto const& poly : geom) for (auto const& poly : geom)
{ {
mapnik::geometry::polygon_vertex_adapter va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
path_type path(tr,va,prj_trans); path_type path(tr,va,prj_trans);
ras.add_path(path); ras.add_path(path);
} }
@ -69,7 +69,7 @@ class test1 : public benchmark::test_case
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public: public:
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter>; using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
test1(mapnik::parameters const& params, test1(mapnik::parameters const& params,
std::string const& wkt_in, std::string const& wkt_in,
mapnik::box2d<double> const& extent) mapnik::box2d<double> const& extent)
@ -79,7 +79,7 @@ public:
expected_("./benchmark/data/polygon_clipping_agg") {} expected_("./benchmark/data/polygon_clipping_agg") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -89,13 +89,13 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double>>())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon const& poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
@ -107,8 +107,8 @@ public:
clipped.rewind(0); clipped.rewind(0);
mapnik::geometry::polygon poly2; mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
// exterior ring // exterior ring
unsigned cmd; unsigned cmd;
double x, y, x0, y0; double x, y, x0, y0;
@ -147,7 +147,7 @@ public:
std::string expect = expected_+".png"; std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png"; std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon mp; mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(poly2); mp.emplace_back(poly2);
auto env = mapnik::geometry::envelope(mp); auto env = mapnik::geometry::envelope(mp);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
@ -160,7 +160,7 @@ public:
} }
bool operator()() const bool operator()() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -170,7 +170,7 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double>>())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
@ -179,8 +179,8 @@ public:
for (unsigned i=0;i<iterations_;++i) for (unsigned i=0;i<iterations_;++i)
{ {
unsigned count = 0; unsigned count = 0;
mapnik::geometry::polygon const& poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box( clipped.clip_box(
extent_.minx(), extent_.minx(),
@ -212,7 +212,7 @@ class test2 : public benchmark::test_case
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public: public:
using poly_clipper = agg::conv_clipper<mapnik::geometry::polygon_vertex_adapter, agg::path_storage>; using poly_clipper = agg::conv_clipper<mapnik::geometry::polygon_vertex_adapter<double>, agg::path_storage>;
test2(mapnik::parameters const& params, test2(mapnik::parameters const& params,
std::string const& wkt_in, std::string const& wkt_in,
mapnik::box2d<double> const& extent) mapnik::box2d<double> const& extent)
@ -222,7 +222,7 @@ public:
expected_("./benchmark/data/polygon_clipping_clipper") {} expected_("./benchmark/data/polygon_clipping_clipper") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -232,19 +232,19 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double>>())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
agg::path_storage ps; agg::path_storage ps;
ps.move_to(extent_.minx(), extent_.miny()); ps.move_to(extent_.minx(), extent_.miny());
ps.line_to(extent_.minx(), extent_.maxy()); ps.line_to(extent_.minx(), extent_.maxy());
ps.line_to(extent_.maxx(), extent_.maxy()); ps.line_to(extent_.maxx(), extent_.maxy());
ps.line_to(extent_.maxx(), extent_.miny()); ps.line_to(extent_.maxx(), extent_.miny());
ps.close_polygon(); ps.close_polygon();
mapnik::geometry::polygon_vertex_adapter va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
poly_clipper clipped(va,ps, poly_clipper clipped(va,ps,
agg::clipper_and, agg::clipper_and,
agg::clipper_non_zero, agg::clipper_non_zero,
@ -253,8 +253,8 @@ public:
unsigned cmd; unsigned cmd;
double x,y; double x,y;
clipped.rewind(0); clipped.rewind(0);
mapnik::geometry::polygon poly2; mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
// TODO: handle resulting multipolygon // TODO: handle resulting multipolygon
// exterior ring // exterior ring
while (true) while (true)
@ -274,7 +274,7 @@ public:
mapnik::geometry::correct(poly2); mapnik::geometry::correct(poly2);
std::string expect = expected_+".png"; std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png"; std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon mp; mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(poly2); mp.emplace_back(poly2);
auto env = mapnik::geometry::envelope(mp); auto env = mapnik::geometry::envelope(mp);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
@ -287,7 +287,7 @@ public:
} }
bool operator()() const bool operator()() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -297,12 +297,12 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double>>())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon const& poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
agg::path_storage ps; agg::path_storage ps;
ps.move_to(extent_.minx(), extent_.miny()); ps.move_to(extent_.minx(), extent_.miny());
ps.line_to(extent_.minx(), extent_.maxy()); ps.line_to(extent_.minx(), extent_.maxy());
@ -313,7 +313,7 @@ public:
for (unsigned i=0;i<iterations_;++i) for (unsigned i=0;i<iterations_;++i)
{ {
unsigned count = 0; unsigned count = 0;
mapnik::geometry::polygon_vertex_adapter va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
poly_clipper clipped(va,ps, poly_clipper clipped(va,ps,
agg::clipper_and, agg::clipper_and,
agg::clipper_non_zero, agg::clipper_non_zero,
@ -350,7 +350,7 @@ public:
expected_("./benchmark/data/polygon_clipping_boost") {} expected_("./benchmark/data/polygon_clipping_boost") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -360,24 +360,26 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double> >())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
std::deque<mapnik::geometry::polygon> result;
std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(extent_,poly,result); boost::geometry::intersection(extent_,poly,result);
std::string expect = expected_+".png"; std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png"; std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon mp; mapnik::geometry::multi_polygon<double> mp;
for (auto const& geom: result) for (auto const& geom: result)
{ {
//std::clog << boost::geometry::dsv(geom) << "\n"; //std::clog << boost::geometry::dsv(geom) << "\n";
mp.emplace_back(geom); mp.emplace_back(geom);
} }
mapnik::geometry::geometry geom2(mp); mapnik::geometry::geometry<double> geom2(mp);
auto env = mapnik::geometry::envelope(geom2); auto env = mapnik::geometry::envelope(geom2);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{ {
@ -389,7 +391,7 @@ public:
} }
bool operator()() const bool operator()() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -399,22 +401,23 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double> >())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
bool valid = true; bool valid = true;
for (unsigned i=0;i<iterations_;++i) for (unsigned i=0;i<iterations_;++i)
{ {
std::deque<mapnik::geometry::polygon> result; std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(extent_,poly,result); boost::geometry::intersection(extent_,poly,result);
unsigned count = 0; unsigned count = 0;
for (auto const& geom : result) for (auto const& geom : result)
{ {
mapnik::geometry::polygon_vertex_adapter va(geom); mapnik::geometry::polygon_vertex_adapter<double> va(geom);
unsigned cmd; unsigned cmd;
double x,y; double x,y;
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) { while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) {
@ -446,7 +449,7 @@ public:
expected_("./benchmark/data/polygon_clipping_clipper") {} expected_("./benchmark/data/polygon_clipping_clipper") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -456,16 +459,16 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double> >())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
ClipperLib::Clipper clipper; ClipperLib::Clipper clipper;
std::vector<ClipperLib::IntPoint> path; mapnik::geometry::line_string<std::int64_t> path;
for (auto const& pt : poly.exterior_ring) for (auto const& pt : poly.exterior_ring)
{ {
double x = pt.x; double x = pt.x;
@ -491,7 +494,7 @@ public:
} }
} }
std::cerr << "path size=" << path.size() << std::endl; std::cerr << "path size=" << path.size() << std::endl;
std::vector<ClipperLib::IntPoint> clip_box; mapnik::geometry::line_string<std::int64_t> clip_box;
clip_box.emplace_back(static_cast<ClipperLib::cInt>(extent_.minx()),static_cast<ClipperLib::cInt>(extent_.miny())); clip_box.emplace_back(static_cast<ClipperLib::cInt>(extent_.minx()),static_cast<ClipperLib::cInt>(extent_.miny()));
clip_box.emplace_back(static_cast<ClipperLib::cInt>(extent_.maxx()),static_cast<ClipperLib::cInt>(extent_.miny())); clip_box.emplace_back(static_cast<ClipperLib::cInt>(extent_.maxx()),static_cast<ClipperLib::cInt>(extent_.miny()));
clip_box.emplace_back(static_cast<ClipperLib::cInt>(extent_.maxx()),static_cast<ClipperLib::cInt>(extent_.maxy())); clip_box.emplace_back(static_cast<ClipperLib::cInt>(extent_.maxx()),static_cast<ClipperLib::cInt>(extent_.maxy()));
@ -507,7 +510,7 @@ public:
clipper.Execute(ClipperLib::ctIntersection, polygons, ClipperLib::pftNonZero, ClipperLib::pftNonZero); clipper.Execute(ClipperLib::ctIntersection, polygons, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
clipper.Clear(); clipper.Clear();
ClipperLib::PolyNode* polynode = polygons.GetFirst(); ClipperLib::PolyNode* polynode = polygons.GetFirst();
mapnik::geometry::multi_polygon mp; mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(); mp.emplace_back();
bool first = true; bool first = true;
while (polynode) while (polynode)
@ -518,15 +521,15 @@ public:
else mp.emplace_back(); // start new polygon else mp.emplace_back(); // start new polygon
for (auto const& pt : polynode->Contour) for (auto const& pt : polynode->Contour)
{ {
mp.back().exterior_ring.add_coord(pt.X, pt.Y); mp.back().exterior_ring.add_coord(pt.x, pt.y);
} }
// childrens are interior rings // childrens are interior rings
for (auto const* ring : polynode->Childs) for (auto const* ring : polynode->Childs)
{ {
mapnik::geometry::linear_ring hole; mapnik::geometry::linear_ring<double> hole;
for (auto const& pt : ring->Contour) for (auto const& pt : ring->Contour)
{ {
hole.add_coord(pt.X, pt.Y); hole.add_coord(pt.x, pt.y);
} }
mp.back().add_hole(std::move(hole)); mp.back().add_hole(std::move(hole));
} }
@ -535,7 +538,7 @@ public:
} }
std::string expect = expected_+".png"; std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png"; std::string actual = expected_+"_actual.png";
mapnik::geometry::geometry geom2(mp); mapnik::geometry::geometry<double> geom2(mp);
auto env = mapnik::geometry::envelope(geom2); auto env = mapnik::geometry::envelope(geom2);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{ {
@ -547,7 +550,7 @@ public:
} }
bool operator()() const bool operator()() const
{ {
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom)) if (!mapnik::from_wkt(wkt_in_, geom))
{ {
throw std::runtime_error("Failed to parse WKT"); throw std::runtime_error("Failed to parse WKT");
@ -557,22 +560,24 @@ public:
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon>()) if (!geom.is<mapnik::geometry::polygon<double> >())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
bool valid = true; bool valid = true;
for (unsigned i=0;i<iterations_;++i) for (unsigned i=0;i<iterations_;++i)
{ {
std::deque<mapnik::geometry::polygon> result; std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(extent_,poly,result); boost::geometry::intersection(extent_,poly,result);
unsigned count = 0; unsigned count = 0;
for (auto const& geom : result) for (auto const& geom : result)
{ {
mapnik::geometry::polygon_vertex_adapter va(geom); mapnik::geometry::polygon_vertex_adapter<double> va(geom);
unsigned cmd; unsigned cmd;
double x,y; double x,y;
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) { while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) {

View file

@ -62,9 +62,9 @@
namespace { namespace {
std::shared_ptr<mapnik::geometry::geometry> from_wkb_impl(std::string const& wkb) std::shared_ptr<mapnik::geometry::geometry<double> > from_wkb_impl(std::string const& wkb)
{ {
std::shared_ptr<mapnik::geometry::geometry> geom = std::make_shared<mapnik::geometry::geometry>(); std::shared_ptr<mapnik::geometry::geometry<double> > geom = std::make_shared<mapnik::geometry::geometry<double> >();
try try
{ {
*geom = std::move(mapnik::geometry_utils::from_wkb(wkb.c_str(), wkb.size())); *geom = std::move(mapnik::geometry_utils::from_wkb(wkb.c_str(), wkb.size()));
@ -76,17 +76,17 @@ std::shared_ptr<mapnik::geometry::geometry> from_wkb_impl(std::string const& wkb
return geom; return geom;
} }
std::shared_ptr<mapnik::geometry::geometry> from_wkt_impl(std::string const& wkt) std::shared_ptr<mapnik::geometry::geometry<double> > from_wkt_impl(std::string const& wkt)
{ {
std::shared_ptr<mapnik::geometry::geometry> geom = std::make_shared<mapnik::geometry::geometry>(); std::shared_ptr<mapnik::geometry::geometry<double> > geom = std::make_shared<mapnik::geometry::geometry<double> >();
if (!mapnik::from_wkt(wkt, *geom)) if (!mapnik::from_wkt(wkt, *geom))
throw std::runtime_error("Failed to parse WKT geometry"); throw std::runtime_error("Failed to parse WKT geometry");
return geom; return geom;
} }
std::shared_ptr<mapnik::geometry::geometry> from_geojson_impl(std::string const& json) std::shared_ptr<mapnik::geometry::geometry<double> > from_geojson_impl(std::string const& json)
{ {
std::shared_ptr<mapnik::geometry::geometry> geom = std::make_shared<mapnik::geometry::geometry>(); std::shared_ptr<mapnik::geometry::geometry<double> > geom = std::make_shared<mapnik::geometry::geometry<double> >();
if (!mapnik::json::from_geojson(json, *geom)) if (!mapnik::json::from_geojson(json, *geom))
throw std::runtime_error("Failed to parse geojson geometry"); throw std::runtime_error("Failed to parse geojson geometry");
return geom; return geom;
@ -101,7 +101,7 @@ inline std::string boost_version()
return s.str(); return s.str();
} }
PyObject* to_wkb_impl(mapnik::geometry::geometry const& geom, mapnik::wkbByteOrder byte_order) PyObject* to_wkb_impl(mapnik::geometry::geometry<double> const& geom, mapnik::wkbByteOrder byte_order)
{ {
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,byte_order); mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,byte_order);
if (wkb) if (wkb)
@ -120,7 +120,7 @@ PyObject* to_wkb_impl(mapnik::geometry::geometry const& geom, mapnik::wkbByteOrd
} }
} }
std::string to_geojson_impl(mapnik::geometry::geometry const& geom) std::string to_geojson_impl(mapnik::geometry::geometry<double> const& geom)
{ {
std::string wkt; std::string wkt;
if (!mapnik::util::to_geojson(wkt, geom)) if (!mapnik::util::to_geojson(wkt, geom))
@ -130,7 +130,7 @@ std::string to_geojson_impl(mapnik::geometry::geometry const& geom)
return wkt; return wkt;
} }
std::string to_wkt_impl(mapnik::geometry::geometry const& geom) std::string to_wkt_impl(mapnik::geometry::geometry<double> const& geom)
{ {
std::string wkt; std::string wkt;
if (!mapnik::util::to_wkt(wkt,geom)) if (!mapnik::util::to_wkt(wkt,geom))
@ -140,49 +140,49 @@ std::string to_wkt_impl(mapnik::geometry::geometry const& geom)
return wkt; return wkt;
} }
mapnik::geometry::geometry_types geometry_type_impl(mapnik::geometry::geometry const& geom) mapnik::geometry::geometry_types geometry_type_impl(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::geometry::geometry_type(geom); return mapnik::geometry::geometry_type(geom);
} }
mapnik::box2d<double> geometry_envelope_impl(mapnik::geometry::geometry const& geom) mapnik::box2d<double> geometry_envelope_impl(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::geometry::envelope(geom); return mapnik::geometry::envelope(geom);
} }
bool geometry_is_valid_impl(mapnik::geometry::geometry const& geom) bool geometry_is_valid_impl(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::geometry::is_valid(geom); return mapnik::geometry::is_valid(geom);
} }
bool geometry_is_simple_impl(mapnik::geometry::geometry const& geom) bool geometry_is_simple_impl(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::geometry::is_simple(geom); return mapnik::geometry::is_simple(geom);
} }
bool geometry_is_empty_impl(mapnik::geometry::geometry const& geom) bool geometry_is_empty_impl(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::geometry::is_empty(geom); return mapnik::geometry::is_empty(geom);
} }
void geometry_correct_impl(mapnik::geometry::geometry & geom) void geometry_correct_impl(mapnik::geometry::geometry<double> & geom)
{ {
mapnik::geometry::correct(geom); mapnik::geometry::correct(geom);
} }
void polygon_set_exterior_impl(mapnik::geometry::polygon & poly, mapnik::geometry::linear_ring const& ring) void polygon_set_exterior_impl(mapnik::geometry::polygon<double> & poly, mapnik::geometry::linear_ring<double> const& ring)
{ {
poly.exterior_ring = ring; // copy poly.exterior_ring = ring; // copy
} }
void polygon_add_hole_impl(mapnik::geometry::polygon & poly, mapnik::geometry::linear_ring const& ring) void polygon_add_hole_impl(mapnik::geometry::polygon<double> & poly, mapnik::geometry::linear_ring<double> const& ring)
{ {
poly.interior_rings.push_back(ring); // copy poly.interior_rings.push_back(ring); // copy
} }
mapnik::geometry::point geometry_centroid_impl(mapnik::geometry::geometry const& geom) mapnik::geometry::point<double> geometry_centroid_impl(mapnik::geometry::geometry<double> const& geom)
{ {
mapnik::geometry::point pt; mapnik::geometry::point<double> pt;
mapnik::geometry::centroid(geom, pt); mapnik::geometry::centroid(geom, pt);
return pt; return pt;
} }
@ -192,9 +192,9 @@ void export_geometry()
{ {
using namespace boost::python; using namespace boost::python;
implicitly_convertible<mapnik::geometry::point, mapnik::geometry::geometry>(); implicitly_convertible<mapnik::geometry::point<double>, mapnik::geometry::geometry<double> >();
implicitly_convertible<mapnik::geometry::line_string, mapnik::geometry::geometry>(); implicitly_convertible<mapnik::geometry::line_string<double>, mapnik::geometry::geometry<double> >();
implicitly_convertible<mapnik::geometry::polygon, mapnik::geometry::geometry>(); implicitly_convertible<mapnik::geometry::polygon<double>, mapnik::geometry::geometry<double> >();
enum_<mapnik::geometry::geometry_types>("GeometryType") enum_<mapnik::geometry::geometry_types>("GeometryType")
.value("Unknown",mapnik::geometry::geometry_types::Unknown) .value("Unknown",mapnik::geometry::geometry_types::Unknown)
.value("Point",mapnik::geometry::geometry_types::Point) .value("Point",mapnik::geometry::geometry_types::Point)
@ -217,10 +217,10 @@ void export_geometry()
using mapnik::geometry::linear_ring; using mapnik::geometry::linear_ring;
using mapnik::geometry::polygon; using mapnik::geometry::polygon;
class_<point>("Point", init<double, double>((arg("x"), arg("y")), class_<point<double> >("Point", init<double, double>((arg("x"), arg("y")),
"Constructs a new Point object\n")) "Constructs a new Point object\n"))
.add_property("x", &point::x, "X coordinate") .add_property("x", &point<double>::x, "X coordinate")
.add_property("y", &point::y, "Y coordinate") .add_property("y", &point<double>::y, "Y coordinate")
.def("is_valid", &geometry_is_valid_impl) .def("is_valid", &geometry_is_valid_impl)
.def("is_simple", &geometry_is_simple_impl) .def("is_simple", &geometry_is_simple_impl)
.def("to_geojson",&to_geojson_impl) .def("to_geojson",&to_geojson_impl)
@ -228,9 +228,9 @@ void export_geometry()
.def("to_wkt",&to_wkt_impl) .def("to_wkt",&to_wkt_impl)
; ;
class_<line_string>("LineString", init<>( class_<line_string<double> >("LineString", init<>(
"Constructs a new LineString object\n")) "Constructs a new LineString object\n"))
.def("add_coord", &line_string::add_coord, "Adds coord") .def("add_coord", &line_string<double>::add_coord, "Adds coord")
.def("is_valid", &geometry_is_valid_impl) .def("is_valid", &geometry_is_valid_impl)
.def("is_simple", &geometry_is_simple_impl) .def("is_simple", &geometry_is_simple_impl)
.def("to_geojson",&to_geojson_impl) .def("to_geojson",&to_geojson_impl)
@ -238,14 +238,14 @@ void export_geometry()
.def("to_wkt",&to_wkt_impl) .def("to_wkt",&to_wkt_impl)
; ;
class_<linear_ring>("LinearRing", init<>( class_<linear_ring<double> >("LinearRing", init<>(
"Constructs a new LinearRtring object\n")) "Constructs a new LinearRtring object\n"))
.def("add_coord", &linear_ring::add_coord, "Adds coord") .def("add_coord", &linear_ring<double>::add_coord, "Adds coord")
; ;
class_<polygon>("Polygon", init<>( class_<polygon<double> >("Polygon", init<>(
"Constructs a new Polygon object\n")) "Constructs a new Polygon object\n"))
.add_property("exterior_ring", &polygon::exterior_ring , "Exterior ring") .add_property("exterior_ring", &polygon<double>::exterior_ring , "Exterior ring")
.def("add_hole", &polygon_add_hole_impl, "Add interior ring") .def("add_hole", &polygon_add_hole_impl, "Add interior ring")
.def("num_rings", polygon_set_exterior_impl, "Number of rings (at least 1)") .def("num_rings", polygon_set_exterior_impl, "Number of rings (at least 1)")
.def("is_valid", &geometry_is_valid_impl) .def("is_valid", &geometry_is_valid_impl)
@ -255,7 +255,7 @@ void export_geometry()
.def("to_wkt",&to_wkt_impl) .def("to_wkt",&to_wkt_impl)
; ;
class_<geometry, std::shared_ptr<geometry>, boost::noncopyable>("Geometry",no_init) class_<geometry<double>, std::shared_ptr<geometry<double> >, boost::noncopyable>("Geometry",no_init)
.def("envelope",&geometry_envelope_impl) .def("envelope",&geometry_envelope_impl)
.def("from_geojson", from_geojson_impl) .def("from_geojson", from_geojson_impl)
.def("from_wkt", from_wkt_impl) .def("from_wkt", from_wkt_impl)

View file

@ -227,8 +227,8 @@ namespace agg
{ {
ClipperLib::IntPoint v; ClipperLib::IntPoint v;
v.X = Round(x * m_scaling_factor); v.x = Round(x * m_scaling_factor);
v.Y = Round(y * m_scaling_factor); v.y = Round(y * m_scaling_factor);
m_vertex_accumulator.add( v ); m_vertex_accumulator.add( v );
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -248,8 +248,8 @@ namespace agg
{ {
m_vertex++; m_vertex++;
if(m_vertex >= (int)m_result[m_contour].size()) return false; if(m_vertex >= (int)m_result[m_contour].size()) return false;
*x = (double)m_result[ m_contour ][ m_vertex ].X / m_scaling_factor; *x = (double)m_result[ m_contour ][ m_vertex ].x / m_scaling_factor;
*y = (double)m_result[ m_contour ][ m_vertex ].Y / m_scaling_factor; *y = (double)m_result[ m_contour ][ m_vertex ].y / m_scaling_factor;
return true; return true;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View file

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

File diff suppressed because it is too large Load diff

View file

@ -195,17 +195,17 @@ public:
return ctx_; return ctx_;
} }
inline void set_geometry(geometry::geometry && geom) inline void set_geometry(geometry::geometry<double> && geom)
{ {
geom_ = std::move(geom); geom_ = std::move(geom);
} }
inline void set_geometry_copy(geometry::geometry const& geom) inline void set_geometry_copy(geometry::geometry<double> const& geom)
{ {
geom_ = geom; geom_ = geom;
} }
inline geometry::geometry const& get_geometry() const inline geometry::geometry<double> const& get_geometry() const
{ {
return geom_; return geom_;
} }
@ -262,7 +262,7 @@ private:
mapnik::value_integer id_; mapnik::value_integer id_;
context_ptr ctx_; context_ptr ctx_;
cont_type data_; cont_type data_;
geometry::geometry geom_; geometry::geometry<double> geom_;
raster_ptr raster_; raster_ptr raster_;
}; };

View file

@ -31,11 +31,12 @@
namespace mapnik { namespace geometry { namespace mapnik { namespace geometry {
template <typename T>
struct point struct point
{ {
using value_type = double; using value_type = T;
point() {} point() {}
point(double x_, double y_) point(T x_, T y_)
: x(x_), y(y_) : x(x_), y(y_)
{} {}
// temp - remove when geometry is templated on value_type // temp - remove when geometry is templated on value_type
@ -45,35 +46,62 @@ struct point
point(point const& other) = default; point(point const& other) = default;
point(point && other) noexcept = default; point(point && other) noexcept = default;
point & operator=(point const& other) = 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 x;
value_type y; value_type y;
}; };
struct line_string : std::vector<point>
template <typename T>
struct line_string : std::vector<point<T> >
{ {
line_string() = default; line_string() = default;
line_string (std::size_t size)
: std::vector<point<T> >(size) {}
line_string (line_string && other) = default ; line_string (line_string && other) = default ;
line_string& operator=(line_string &&) = default; line_string& operator=(line_string &&) = default;
line_string (line_string const& ) = default; line_string (line_string const& ) = default;
line_string& operator=(line_string const&) = default; line_string& operator=(line_string const&) = default;
inline std::size_t num_points() const { return size(); } inline std::size_t num_points() const { return std::vector<point<T>>::template size(); }
inline void add_coord(double x, double y) { emplace_back(x,y);} inline void add_coord(T x, T y) { std::vector<point<T>>::template emplace_back(x,y);}
}; };
template <typename 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;
struct linear_ring : line_string {}; };
template <typename T>
struct polygon struct polygon
{ {
linear_ring exterior_ring; linear_ring<T> exterior_ring;
std::vector<linear_ring> interior_rings; std::vector<linear_ring<T>> interior_rings;
inline void set_exterior_ring(linear_ring && ring) inline void set_exterior_ring(linear_ring<T> && ring)
{ {
exterior_ring = std::move(ring); exterior_ring = std::move(ring);
} }
inline void add_hole(linear_ring && ring) inline void add_hole(linear_ring<T> && ring)
{ {
interior_rings.emplace_back(std::move(ring)); interior_rings.emplace_back(std::move(ring));
} }
@ -86,21 +114,32 @@ struct polygon
} }
}; };
struct multi_point : line_string {}; template <typename T>
struct multi_line_string : std::vector<line_string> {}; struct multi_point : line_string<T> {};
struct multi_polygon : std::vector<polygon> {};
struct geometry_collection;
struct geometry_empty {};
using geometry = mapnik::util::variant<geometry_empty,
point,
line_string,
polygon,
multi_point,
multi_line_string,
multi_polygon,
mapnik::util::recursive_wrapper<geometry_collection> >;
struct geometry_collection : std::vector<geometry> {}; template <typename T>
struct multi_line_string : std::vector<line_string<T>> {};
template <typename T>
struct multi_polygon : std::vector<polygon<T>> {};
template <typename T>
struct geometry_collection;
struct geometry_empty {};
template <typename T>
using geometry = mapnik::util::variant<geometry_empty,
point<T>,
line_string<T>,
polygon<T>,
multi_point<T>,
multi_line_string<T>,
multi_polygon<T>,
mapnik::util::recursive_wrapper<geometry_collection<T> > >;
template <typename T>
struct geometry_collection : std::vector<geometry<T>> {};
}} }}

View file

@ -35,49 +35,51 @@
#include <boost/geometry/core/tag.hpp> #include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp> #include <boost/geometry/core/tags.hpp>
// //
#include <mapnik/geometry.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
// register point // register point
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point, double, cs::cartesian, x, y) BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<double>, double, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<std::int64_t>, std::int64_t, cs::cartesian, x, y)
// ring // ring
BOOST_GEOMETRY_REGISTER_RING(mapnik::geometry::linear_ring) BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(mapnik::geometry::linear_ring)
// needed by box2d<double> // needed by box2d<double>
BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2d, double, cs::cartesian, x, y) BOOST_GEOMETRY_REGISTER_POINT_2D(mapnik::coord2d, double, cs::cartesian, x, y)
namespace boost { namespace boost {
template <> template <typename CoordinateType>
struct range_iterator<mapnik::geometry::line_string> struct range_iterator<mapnik::geometry::line_string<CoordinateType> >
{ {
using type = mapnik::geometry::line_string::iterator; using type = typename mapnik::geometry::line_string<CoordinateType>::iterator;
}; };
template <> template <typename CoordinateType>
struct range_const_iterator<mapnik::geometry::line_string> struct range_const_iterator<mapnik::geometry::line_string<CoordinateType> >
{ {
using type = mapnik::geometry::line_string::const_iterator; using type = typename mapnik::geometry::line_string<CoordinateType>::const_iterator;
}; };
inline mapnik::geometry::line_string::iterator template <typename CoordinateType>
range_begin(mapnik::geometry::line_string & line) {return line.begin();} inline typename mapnik::geometry::line_string<CoordinateType>::iterator
range_begin(mapnik::geometry::line_string<CoordinateType> & line) {return line.begin();}
inline mapnik::geometry::line_string::iterator template <typename CoordinateType>
range_end(mapnik::geometry::line_string & line) {return line.end();} inline typename mapnik::geometry::line_string<CoordinateType>::iterator
range_end(mapnik::geometry::line_string<CoordinateType> & line) {return line.end();}
inline mapnik::geometry::line_string::const_iterator template <typename CoordinateType>
range_begin(mapnik::geometry::line_string const& line) {return line.begin();} inline typename mapnik::geometry::line_string<CoordinateType>::const_iterator
range_begin(mapnik::geometry::line_string<CoordinateType> const& line) {return line.begin();}
inline mapnik::geometry::line_string::const_iterator
range_end(mapnik::geometry::line_string const& line) {return line.end();}
template <typename CoordinateType>
inline typename mapnik::geometry::line_string<CoordinateType>::const_iterator
range_end(mapnik::geometry::line_string<CoordinateType> const& line) {return line.end();}
namespace geometry { namespace traits { namespace geometry { namespace traits {
// register mapnik::box2d<double> // register mapnik::box2d<double>
template<> struct tag<mapnik::box2d<double> > { using type = box_tag; }; template<> struct tag<mapnik::box2d<double> > { using type = box_tag; };
template<> struct point_type<mapnik::box2d<double> > { using type = mapnik::coord2d; }; template<> struct point_type<mapnik::box2d<double> > { using type = mapnik::coord2d; };
template <> template <>
@ -113,95 +115,99 @@ struct indexed_access<mapnik::box2d<double>, max_corner, 1>
}; };
// mapnik::geometry::line_string // mapnik::geometry::line_string
template<> template<typename CoordinateType>
struct tag<mapnik::geometry::line_string> struct tag<mapnik::geometry::line_string<CoordinateType> >
{ {
using type = linestring_tag; using type = linestring_tag;
}; };
// mapnik::geometry::polygon // mapnik::geometry::polygon
template<> template<typename CoordinateType>
struct tag<mapnik::geometry::polygon> struct tag<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = polygon_tag; using type = polygon_tag;
}; };
template <> template <typename CoordinateType>
struct point_order<mapnik::geometry::linear_ring> struct point_order<mapnik::geometry::linear_ring<CoordinateType> >
{ {
static const order_selector value = counterclockwise; static const order_selector value = counterclockwise;
}; };
template<> template<typename CoordinateType>
struct tag<mapnik::geometry::multi_point> struct tag<mapnik::geometry::multi_point<CoordinateType> >
{ {
using type = multi_point_tag; using type = multi_point_tag;
}; };
template<> template<typename CoordinateType>
struct tag<mapnik::geometry::multi_line_string> struct tag<mapnik::geometry::multi_line_string<CoordinateType> >
{ {
using type = multi_linestring_tag; using type = multi_linestring_tag;
}; };
template<> struct tag<mapnik::geometry::multi_polygon> template<typename CoordinateType>
struct tag<mapnik::geometry::multi_polygon<CoordinateType> >
{ {
using type = multi_polygon_tag; using type = multi_polygon_tag;
}; };
// ring // ring
template<> struct ring_const_type<mapnik::geometry::polygon> template <typename CoordinateType>
struct ring_const_type<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = mapnik::geometry::linear_ring const&; using type = typename mapnik::geometry::linear_ring<CoordinateType> const&;
}; };
template<> struct ring_mutable_type<mapnik::geometry::polygon> template <typename CoordinateType>
struct ring_mutable_type<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = mapnik::geometry::linear_ring&; using type = typename mapnik::geometry::linear_ring<CoordinateType>&;
}; };
// interior // interior
template<> struct interior_const_type<mapnik::geometry::polygon> template <typename CoordinateType>
struct interior_const_type<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = std::vector<mapnik::geometry::linear_ring> const&; using type = typename std::vector<mapnik::geometry::linear_ring<CoordinateType> > const&;
}; };
template<> struct interior_mutable_type<mapnik::geometry::polygon> template <typename CoordinateType>
struct interior_mutable_type<mapnik::geometry::polygon<CoordinateType> >
{ {
using type = std::vector<mapnik::geometry::linear_ring>&; using type = typename std::vector<mapnik::geometry::linear_ring<CoordinateType> >&;
}; };
// exterior // exterior
template<> template <typename CoordinateType>
struct exterior_ring<mapnik::geometry::polygon> struct exterior_ring<mapnik::geometry::polygon<CoordinateType> >
{ {
static mapnik::geometry::linear_ring& get(mapnik::geometry::polygon & p) static mapnik::geometry::linear_ring<CoordinateType> & get(mapnik::geometry::polygon<CoordinateType> & p)
{ {
return p.exterior_ring; return p.exterior_ring;
} }
static mapnik::geometry::linear_ring const& get(mapnik::geometry::polygon const& p) static mapnik::geometry::linear_ring<CoordinateType> const& get(mapnik::geometry::polygon<CoordinateType> const& p)
{ {
return p.exterior_ring; return p.exterior_ring;
} }
}; };
template<> template <typename CoordinateType>
struct interior_rings<mapnik::geometry::polygon> struct interior_rings<mapnik::geometry::polygon<CoordinateType> >
{ {
using holes_type = std::vector<mapnik::geometry::linear_ring>; using holes_type = std::vector<mapnik::geometry::linear_ring<CoordinateType> >;
static holes_type& get(mapnik::geometry::polygon & p) static holes_type& get(mapnik::geometry::polygon<CoordinateType> & p)
{ {
return p.interior_rings; return p.interior_rings;
} }
static holes_type const& get(mapnik::geometry::polygon const& p) static holes_type const& get(mapnik::geometry::polygon<CoordinateType> const& p)
{ {
return p.interior_rings; return p.interior_rings;
} }
}; };
}}} }}}

View file

@ -31,15 +31,16 @@ namespace mapnik { namespace geometry {
namespace detail { namespace detail {
template <typename T>
struct geometry_centroid struct geometry_centroid
{ {
using result_type = bool; using result_type = bool;
geometry_centroid(point & pt) geometry_centroid(point<T> & pt)
: pt_(pt) {} : pt_(pt) {}
template <typename T> template <typename T1>
result_type operator() (T const& geom) const result_type operator() (T1 const& geom) const
{ {
return util::apply_visitor(*this, geom); return util::apply_visitor(*this, geom);
} }
@ -49,55 +50,55 @@ struct geometry_centroid
return false; return false;
} }
result_type operator() (geometry_collection const& collection) const result_type operator() (geometry_collection<T> const& collection) const
{ {
return false; return false;
} }
result_type operator() (point const& geom) const result_type operator() (point<T> const& geom) const
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} }
result_type operator() (line_string const& geom) const result_type operator() (line_string<T> const& geom) const
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} }
result_type operator() (polygon const& geom) const result_type operator() (polygon<T> const& geom) const
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} }
result_type operator() (multi_point const& geom) const result_type operator() (multi_point<T> const& geom) const
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} }
result_type operator() (multi_line_string const& geom) const result_type operator() (multi_line_string<T> const& geom) const
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} }
result_type operator() (multi_polygon const& geom) const result_type operator() (multi_polygon<T> const& geom) const
{ {
boost::geometry::centroid(geom, pt_); boost::geometry::centroid(geom, pt_);
return true; return true;
} }
point & pt_; point<T> & pt_;
}; };
} }
template <typename T> template <typename T1, typename T2>
inline bool centroid(T const& geom, point & pt) inline bool centroid(T1 const& geom, point<T2> & pt)
{ {
return detail::geometry_centroid(pt)(geom); return detail::geometry_centroid<T2>(pt)(geom);
} }
}} }}

View file

@ -37,12 +37,14 @@ struct geometry_correct
{ {
using result_type = void; using result_type = void;
result_type operator() (geometry & geom) const template <typename T>
result_type operator() (geometry<T> & geom) const
{ {
mapnik::util::apply_visitor(*this, geom); mapnik::util::apply_visitor(*this, geom);
} }
result_type operator() (geometry_collection & collection) const template <typename T>
result_type operator() (geometry_collection<T> & collection) const
{ {
for (auto & geom : collection) for (auto & geom : collection)
{ {
@ -50,12 +52,14 @@ struct geometry_correct
} }
} }
result_type operator() (polygon & poly) const template <typename T>
result_type operator() (polygon<T> & poly) const
{ {
boost::geometry::correct(poly); boost::geometry::correct(poly);
} }
result_type operator() (multi_polygon & multi_poly) const template <typename T>
result_type operator() (multi_polygon<T> & multi_poly) const
{ {
boost::geometry::correct(multi_poly); boost::geometry::correct(multi_poly);
} }

View file

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

View file

@ -29,14 +29,25 @@
#include <vector> #include <vector>
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::point, mapnik::geometry::point<double>,
(double, x) (double, x)
(double, y) (double, y)
) )
BOOST_FUSION_ADAPT_STRUCT( BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::polygon, mapnik::geometry::point<std::int64_t>,
(mapnik::geometry::linear_ring const&, exterior_ring) (std::int64_t, x)
(std::vector<mapnik::geometry::linear_ring> const& , interior_rings)) (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 #endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP

View file

@ -31,42 +31,42 @@ namespace detail {
struct geometry_is_empty struct geometry_is_empty
{ {
bool operator() (mapnik::geometry::geometry const& geom) const bool operator() (mapnik::geometry::geometry<double> const& geom) const
{ {
return mapnik::util::apply_visitor(*this, geom); return mapnik::util::apply_visitor(*this, geom);
} }
bool operator() (mapnik::geometry::point const&) const bool operator() (mapnik::geometry::point<double> const&) const
{ {
return false; return false;
} }
bool operator() (mapnik::geometry::line_string const& geom) const bool operator() (mapnik::geometry::line_string<double> const& geom) const
{ {
return geom.empty(); return geom.empty();
} }
bool operator() (mapnik::geometry::polygon const& geom) const bool operator() (mapnik::geometry::polygon<double> const& geom) const
{ {
return geom.empty(); return geom.empty();
} }
bool operator() (mapnik::geometry::multi_point const& geom) const bool operator() (mapnik::geometry::multi_point<double> const& geom) const
{ {
return geom.empty(); return geom.empty();
} }
bool operator() (mapnik::geometry::multi_line_string const& geom) const bool operator() (mapnik::geometry::multi_line_string<double> const& geom) const
{ {
return geom.empty(); return geom.empty();
} }
bool operator() (mapnik::geometry::multi_polygon const& geom) const bool operator() (mapnik::geometry::multi_polygon<double> const& geom) const
{ {
return geom.empty(); return geom.empty();
} }
bool operator() (mapnik::geometry::geometry_collection const& geom) const bool operator() (mapnik::geometry::geometry_collection<double> const& geom) const
{ {
return geom.empty(); return geom.empty();
} }

View file

@ -35,7 +35,8 @@ struct geometry_is_simple
{ {
using result_type = bool; using result_type = bool;
result_type operator() (geometry const& geom) const template <typename T>
result_type operator() (geometry<T> const& geom) const
{ {
return mapnik::util::apply_visitor(*this, geom); return mapnik::util::apply_visitor(*this, geom);
} }
@ -45,7 +46,8 @@ struct geometry_is_simple
return false; return false;
} }
result_type operator() (geometry_collection const& collection) const template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
@ -54,27 +56,33 @@ struct geometry_is_simple
return true; return true;
} }
result_type operator() (point const& pt) const template <typename T>
result_type operator() (point<T> const& pt) const
{ {
return boost::geometry::is_simple(pt); return boost::geometry::is_simple(pt);
} }
result_type operator() (line_string const& line) const template <typename T>
result_type operator() (line_string<T> const& line) const
{ {
return boost::geometry::is_simple(line); return boost::geometry::is_simple(line);
} }
result_type operator() (polygon const& poly) const template <typename T>
result_type operator() (polygon<T> const& poly) const
{ {
return boost::geometry::is_simple(poly); return boost::geometry::is_simple(poly);
} }
result_type operator() (multi_point const& multi_pt) const template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
{ {
return boost::geometry::is_simple(multi_pt); return boost::geometry::is_simple(multi_pt);
} }
result_type operator() (multi_line_string const& multi_line) const template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
{ {
return boost::geometry::is_simple(multi_line); return boost::geometry::is_simple(multi_line);
} }
result_type operator() (multi_polygon const& multi_poly) const template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
{ {
return boost::geometry::is_simple(multi_poly); return boost::geometry::is_simple(multi_poly);
} }

View file

@ -35,7 +35,8 @@ struct geometry_is_valid
{ {
using result_type = bool; using result_type = bool;
result_type operator() (geometry const& geom) const template <typename T>
result_type operator() (geometry<T> const& geom) const
{ {
return mapnik::util::apply_visitor(*this, geom); return mapnik::util::apply_visitor(*this, geom);
} }
@ -45,7 +46,8 @@ struct geometry_is_valid
return false; return false;
} }
result_type operator() (geometry_collection const& collection) const template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
@ -54,32 +56,38 @@ struct geometry_is_valid
return true; return true;
} }
result_type operator() (point const& pt) const template <typename T>
result_type operator() (point<T> const& pt) const
{ {
return boost::geometry::is_valid(pt); return boost::geometry::is_valid(pt);
} }
result_type operator() (line_string const& line) const template <typename T>
result_type operator() (line_string<T> const& line) const
{ {
return boost::geometry::is_valid(line); return boost::geometry::is_valid(line);
} }
result_type operator() (polygon const& poly) const template <typename T>
result_type operator() (polygon<T> const& poly) const
{ {
return boost::geometry::is_valid(poly); return boost::geometry::is_valid(poly);
} }
result_type operator() (multi_point const& multi_pt) const template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
{ {
return boost::geometry::is_valid(multi_pt); return boost::geometry::is_valid(multi_pt);
} }
result_type operator() (multi_line_string const& multi_line) const template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
{ {
return boost::geometry::is_valid(multi_line); return boost::geometry::is_valid(multi_line);
} }
result_type operator() (multi_polygon const& multi_poly) const template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
{ {
return boost::geometry::is_valid(multi_poly); return boost::geometry::is_valid(multi_poly);
} }

View file

@ -37,7 +37,8 @@ namespace geometry {
// This is done this way so that large geometry collections that only have a few failing points or polygon parts could // This is done this way so that large geometry collections that only have a few failing points or polygon parts could
// still be return with out the few failing projections. // still be return with out the few failing projections.
MAPNIK_DECL geometry reproject_copy(geometry const& geom, proj_transform const& proj_trans, unsigned int & n_err); template <typename T>
MAPNIK_DECL geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template <typename T> template <typename T>
MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err); MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err);

View file

@ -0,0 +1,400 @@
/*****************************************************************************
*
* 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
*
*****************************************************************************/
// mapnik
#include <mapnik/geometry_reprojection.hpp>
#include <mapnik/geometry.hpp>
namespace mapnik {
namespace geometry {
namespace detail {
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int &)
{
return geometry_empty();
}
template <typename T>
point<T> reproject_internal(point<T> const & p, proj_transform const& proj_trans, unsigned int & n_err)
{
point<T> new_p(p);
if (!proj_trans.forward(new_p))
{
++n_err;
}
return new_p;
}
template <typename T>
line_string<T> reproject_internal(line_string<T> const & ls, proj_transform const& proj_trans, unsigned int & n_err)
{
line_string<T> new_ls(ls);
unsigned int err = proj_trans.forward(new_ls);
if (err > 0)
{
n_err += err;
}
return new_ls;
}
template <typename T>
polygon<T> reproject_internal(polygon<T> const & poly, proj_transform const& proj_trans, unsigned int & n_err)
{
polygon<T> new_poly;
linear_ring<T> new_ext(poly.exterior_ring);
unsigned int err = proj_trans.forward(new_ext);
// If the exterior ring doesn't transform don't bother with the holes.
if (err > 0 || new_ext.empty())
{
n_err += err;
}
else
{
new_poly.set_exterior_ring(std::move(new_ext));
new_poly.interior_rings.reserve(poly.interior_rings.size());
for (auto const& lr : poly.interior_rings)
{
linear_ring<T> new_lr(lr);
err = proj_trans.forward(new_lr);
if (err > 0 || new_lr.empty())
{
n_err += err;
// If there is an error in interior ring drop
// it from polygon.
continue;
}
new_poly.add_hole(std::move(new_lr));
}
}
return new_poly;
}
template <typename T>
multi_point<T> reproject_internal(multi_point<T> const & mp, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_point<T> new_mp;
if (proj_trans.is_known())
{
// If the projection is known we do them all at once because it is faster
// since we know that no point will fail reprojection
new_mp.assign(mp.begin(), mp.end());
proj_trans.forward(new_mp);
}
else
{
new_mp.reserve(mp.size());
for (auto const& p : mp)
{
point<T> new_p(p);
if (!proj_trans.forward(new_p))
{
++n_err;
}
else
{
new_mp.emplace_back(std::move(new_p));
}
}
}
return new_mp;
}
template <typename T>
multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_line_string<T> new_mls;
new_mls.reserve(mls.size());
for (auto const& ls : mls)
{
line_string<T> new_ls = reproject_internal(ls, proj_trans, n_err);
if (!new_ls.empty())
{
new_mls.emplace_back(std::move(new_ls));
}
}
return new_mls;
}
template <typename T>
multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_polygon<T> new_mpoly;
new_mpoly.reserve(mpoly.size());
for (auto const& poly : mpoly)
{
polygon<T> new_poly = reproject_internal(poly, proj_trans, n_err);
if (!new_poly.exterior_ring.empty())
{
new_mpoly.emplace_back(std::move(new_poly));
}
}
return new_mpoly;
}
template <typename T>
geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj_transform const& proj_trans, unsigned int & n_err)
{
geometry_collection<T> new_c;
new_c.reserve(c.size());
for (auto const& g : c)
{
geometry<T> new_g(std::move(reproject_copy(g, proj_trans, n_err)));
if (!new_g.template is<geometry_empty>())
{
new_c.emplace_back(std::move(new_g));
}
}
return new_c;
}
template <typename T>
struct geom_reproj_copy_visitor {
geom_reproj_copy_visitor(proj_transform const & proj_trans, unsigned int & n_err)
: proj_trans_(proj_trans),
n_err_(n_err) {}
geometry<T> operator() (geometry_empty const&)
{
return geometry_empty();
}
geometry<T> operator() (point<T> const& p)
{
geometry<T> geom; // default empty
unsigned int intial_err = n_err_;
point<T> new_p = reproject_internal(p, proj_trans_, n_err_);
if (n_err_ > intial_err) return geom;
geom = std::move(new_p);
return geom;
}
geometry<T> operator() (line_string<T> const& ls)
{
geometry<T> geom; // default empty
int intial_err = n_err_;
line_string<T> new_ls = reproject_internal(ls, proj_trans_, n_err_);
if (n_err_ > intial_err || new_ls.empty()) return geom;
geom = std::move(new_ls);
return geom;
}
geometry<T> operator() (polygon<T> const& poly)
{
geometry<T> geom; // default empty
polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_);
if (new_poly.exterior_ring.empty()) return geom;
geom = std::move(new_poly);
return geom;
}
geometry<T> operator() (multi_point<T> const& mp)
{
geometry<T> geom; // default empty
multi_point<T> new_mp = reproject_internal(mp, proj_trans_, n_err_);
if (new_mp.empty()) return geom;
geom = std::move(new_mp);
return geom;
}
geometry<T> operator() (multi_line_string<T> const& mls)
{
geometry<T> geom; // default empty
multi_line_string<T> new_mls = reproject_internal(mls, proj_trans_, n_err_);
if (new_mls.empty()) return geom;
geom = std::move(new_mls);
return geom;
}
geometry<T> operator() (multi_polygon<T> const& mpoly)
{
geometry<T> geom; // default empty
multi_polygon<T> new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
if (new_mpoly.empty()) return geom;
geom = std::move(new_mpoly);
return geom;
}
geometry<T> operator() (geometry_collection<T> const& c)
{
geometry<T> geom; // default empty
geometry_collection<T> new_c = reproject_internal(c, proj_trans_, n_err_);
if (new_c.empty()) return geom;
geom = std::move(new_c);
return geom;
}
private:
proj_transform const& proj_trans_;
unsigned int & n_err_;
};
} // end detail ns
template <typename T>
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err)
{
detail::geom_reproj_copy_visitor<T> visit(proj_trans, n_err);
return mapnik::util::apply_visitor(visit, geom);
}
template <typename T>
T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err)
{
return detail::reproject_internal(geom, proj_trans, n_err);
}
template <typename T>
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int & n_err)
{
proj_transform proj_trans(source, dest);
return reproject_copy(geom, proj_trans, n_err);
}
namespace detail {
struct geom_reproj_visitor {
geom_reproj_visitor(proj_transform const & proj_trans)
: proj_trans_(proj_trans) {}
template <typename T>
bool operator() (geometry<T> & geom)
{
return mapnik::util::apply_visitor((*this), geom);
}
bool operator() (geometry_empty &) { return true; }
template <typename T>
bool operator() (point<T> & p)
{
if (!proj_trans_.forward(p))
{
return false;
}
return true;
}
template <typename T>
bool operator() (line_string<T> & ls)
{
if (proj_trans_.forward(ls) > 0)
{
return false;
}
return true;
}
template <typename T>
bool operator() (polygon<T> & poly)
{
if (proj_trans_.forward(poly.exterior_ring) > 0)
{
return false;
}
for (auto & lr : poly.interior_rings)
{
if (proj_trans_.forward(lr) > 0)
{
return false;
}
}
return true;
}
template <typename T>
bool operator() (multi_point<T> & mp)
{
return (*this) (static_cast<line_string<T> &>(mp));
}
template <typename T>
bool operator() (multi_line_string<T> & mls)
{
for (auto & ls : mls)
{
if (! (*this) (ls))
{
return false;
}
}
return true;
}
template <typename T>
bool operator() (multi_polygon<T> & mpoly)
{
for (auto & poly : mpoly)
{
if(! (*this)(poly))
{
return false;
}
}
return true;
}
template <typename T>
bool operator() (geometry_collection<T> & c)
{
for (auto & g : c)
{
if (! (*this)(g) )
{
return false;
}
}
return true;
}
private:
proj_transform const& proj_trans_;
};
} // end detail ns
template <typename T>
bool reproject(T & geom, proj_transform const& proj_trans)
{
detail::geom_reproj_visitor visit(proj_trans);
return visit(geom);
}
template <typename T>
bool reproject(T & geom, projection const& source, projection const& dest)
{
proj_transform proj_trans(source, dest);
detail::geom_reproj_visitor visit(proj_trans);
return visit(geom);
}
} // end geometry ns
} // end mapnik ns

View file

@ -0,0 +1,198 @@
/*****************************************************************************
*
* 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_STRATEGY_HPP
#define MAPNIK_GEOMETRY_STRATEGY_HPP
#include <mapnik/geometry_adapters.hpp>
namespace mapnik {
namespace geometry {
namespace helper
{
template <std::size_t... Ts>
struct index {};
template <std::size_t N, std::size_t... Ts>
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {};
template <std::size_t... Ts>
struct gen_seq<0, Ts...> : index<Ts...> {};
}
// Groups a set of strategies at runtime, the conversion from P1 to P2 will take place on the LAST strategy.
template <typename... Strategies>
struct strategy_group
{
strategy_group(Strategies const& ... ops)
: ops_(ops ...) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
bool status = true;
p2 = execute_start<P1,P2>(p1, status, ops_);
return status;
}
template <typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{
return execute<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
}
template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
}
template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute(P1 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute<P1,P2>(strat.template execute<P1,P1>(p, status), status, args...);
}
template <typename P1, typename P2, typename T>
inline P2 execute(P1 const& p, bool & status, T const& strat) const
{
return strat.template execute<P1,P2>(p, status);
}
private:
std::tuple<Strategies const& ...> ops_;
};
// The difference between this strategy group and the previous is that the conversion from P1 to P2 happens
// in the first strategy rather then the last strategy.
template <typename... Strategies>
struct strategy_group_first
{
strategy_group_first(Strategies const& ... ops)
: ops_(ops ...) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
bool status = true;
p2 = execute_start<P1,P2>(p1, status, ops_);
return status;
}
template <typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{
return execute_first<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
}
template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
}
template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute_first(P1 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute<P2>(strat.template execute<P1,P2>(p, status), status, args...);
}
template <typename P2, typename T, typename ...Args>
inline P2 execute(P2 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute<P2>(strat.template execute<P2,P2>(p, status), status, args...);
}
template <typename P2, typename T>
inline P2 execute(P2 const& p, bool & status, T const& strat) const
{
return strat.template execute<P2,P2>(p, status);
}
template <typename P2>
inline P2 execute(P2 const& p, bool & status) const
{
return p;
}
private:
std::tuple<Strategies const& ...> ops_;
};
struct scale_strategy
{
scale_strategy(double scale, double offset = 0)
: scale_(scale), offset_(offset) {}
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) * scale_) + offset_;
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
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;
}
private:
double scale_;
double offset_;
};
} // end geometry ns
} // end mapnik ns
#endif //MAPNIK_GEOMETRY_STRATEGY_HPP

View file

@ -34,13 +34,19 @@ struct geometry_to_path
geometry_to_path(path_type & p) geometry_to_path(path_type & p)
: p_(p) {} : p_(p) {}
void operator() (geometry const& geom) const template <typename T>
void operator() (geometry<T> const& geom) const
{ {
return mapnik::util::apply_visitor(*this, geom); mapnik::util::apply_visitor(*this, geom);
} }
void operator() (geometry_empty const&) const
{
// no-op
}
// point // point
void operator() (point const& pt) const template <typename T>
void operator() (point<T> const& pt) const
{ {
//point pt_new; //point pt_new;
//Transformer::apply(pt, pt_new); //Transformer::apply(pt, pt_new);
@ -48,7 +54,8 @@ struct geometry_to_path
} }
// line_string // line_string
void operator() (line_string const& line) const template <typename T>
void operator() (line_string<T> const& line) const
{ {
bool first = true; bool first = true;
for (auto const& pt : line) for (auto const& pt : line)
@ -61,7 +68,8 @@ struct geometry_to_path
} }
// polygon // polygon
void operator() (polygon const& poly) const template <typename T>
void operator() (polygon<T> const& poly) const
{ {
// exterior // exterior
bool first = true; bool first = true;
@ -87,7 +95,8 @@ struct geometry_to_path
} }
// multi point // multi point
void operator() (multi_point const& multi_pt) const template <typename T>
void operator() (multi_point<T> const& multi_pt) const
{ {
for (auto const& pt : multi_pt) for (auto const& pt : multi_pt)
{ {
@ -95,7 +104,8 @@ struct geometry_to_path
} }
} }
// multi_line_string // multi_line_string
void operator() (multi_line_string const& multi_line) const template <typename T>
void operator() (multi_line_string<T> const& multi_line) const
{ {
for (auto const& line : multi_line) for (auto const& line : multi_line)
{ {
@ -104,7 +114,8 @@ struct geometry_to_path
} }
// multi_polygon // multi_polygon
void operator() (multi_polygon const& multi_poly) const template <typename T>
void operator() (multi_polygon<T> const& multi_poly) const
{ {
for (auto const& poly : multi_poly) for (auto const& poly : multi_poly)
{ {
@ -112,7 +123,8 @@ struct geometry_to_path
} }
} }
void operator() (geometry_collection const& collection) const template <typename T>
void operator() (geometry_collection<T> const& collection) const
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
@ -120,7 +132,6 @@ struct geometry_to_path
} }
} }
path_type & p_; path_type & p_;
}; };

View file

@ -29,22 +29,89 @@
namespace mapnik { namespace geometry { namespace detail { namespace mapnik { namespace geometry { namespace detail {
template <typename Transformer> 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 struct geometry_transform
{ {
geometry_transform(Transformer const& transformer) geometry_transform(Transformer const& transformer)
: transformer_(transformer) {} : transformer_(transformer) {}
using result_type = geometry; using result_type = geometry<V>;
geometry operator() (geometry_empty const& empty) const geometry<V> operator() (geometry_empty const& empty) const
{ {
return empty; return empty;
} }
geometry operator() (geometry_collection const& collection) const template <typename T>
geometry<V> operator() (geometry_collection<T> const& collection) const
{ {
geometry_collection collection_out; geometry_collection<V> collection_out;
for (auto const& geom : collection) for (auto const& geom : collection)
{ {
collection_out.push_back(std::move((*this)(geom))); collection_out.push_back(std::move((*this)(geom)));
@ -52,32 +119,102 @@ struct geometry_transform
return collection_out; return collection_out;
} }
geometry operator() (geometry const& geom) const template <typename T>
geometry<V> operator() (geometry<T> const& geom) const
{ {
return mapnik::util::apply_visitor(*this, geom); return mapnik::util::apply_visitor(*this, geom);
} }
template <typename T> template <typename T>
geometry operator() (T const& geom) const geometry<V> operator() (point<T> const& geom) const
{ {
using geometry_type = T; return std::move(transform_geometry<V>(geom, transformer_));
geometry_type geom_transformed; }
if (!boost::geometry::transform(geom, geom_transformed, transformer_))
template <typename T>
geometry<V> operator() (line_string<T> const& geom) const
{ {
throw std::runtime_error("Can't transformm geometry"); return std::move(transform_geometry<V>(geom, transformer_));
} }
return geom_transformed;
template <typename T>
geometry<V> operator() (polygon<T> const& geom) const
{
return std::move(transform_geometry<V>(geom, transformer_));
} }
template <typename T>
geometry<V> operator() (multi_point<T> const& geom) const
{
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (multi_line_string<T> const& geom) const
{
return std::move(transform_geometry<V>(geom, transformer_));
}
template <typename T>
geometry<V> operator() (multi_polygon<T> const& geom) const
{
return std::move(transform_geometry<V>(geom, transformer_));
}
Transformer const& transformer_; Transformer const& transformer_;
}; };
} // ns detail } // ns detail
template <typename T0, typename T1> template <typename T0, typename T1, typename T2>
geometry transform(T0 const& geom, T1 const& transformer) geometry<T0> transform(geometry<T1> const& geom, T2 const& transformer)
{ {
return detail::geometry_transform<T1>(transformer)(geom); 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 #endif // MAPNIK_GEOMETRY_TRANSFORM_HPP

View file

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

View file

@ -54,11 +54,11 @@ struct hit_test_visitor
return false; return false;
} }
bool operator() (geometry::point const& geom) const bool operator() (geometry::point<double> const& geom) const
{ {
return distance(geom.x, geom.y, x_, y_) <= tol_; return distance(geom.x, geom.y, x_, y_) <= tol_;
} }
bool operator() (geometry::multi_point const& geom) const bool operator() (geometry::multi_point<double> const& geom) const
{ {
for (auto const& pt : geom) for (auto const& pt : geom)
{ {
@ -66,7 +66,7 @@ struct hit_test_visitor
} }
return false; return false;
} }
bool operator() (geometry::line_string const& geom) const bool operator() (geometry::line_string<double> const& geom) const
{ {
std::size_t num_points = geom.num_points(); std::size_t num_points = geom.num_points();
if (num_points > 1) if (num_points > 1)
@ -81,7 +81,7 @@ struct hit_test_visitor
} }
return false; return false;
} }
bool operator() (geometry::multi_line_string const& geom) const bool operator() (geometry::multi_line_string<double> const& geom) const
{ {
for (auto const& line: geom) for (auto const& line: geom)
{ {
@ -89,7 +89,7 @@ struct hit_test_visitor
} }
return false; return false;
} }
bool operator() (geometry::polygon const& geom) const bool operator() (geometry::polygon<double> const& geom) const
{ {
auto const& exterior = geom.exterior_ring; auto const& exterior = geom.exterior_ring;
std::size_t num_points = exterior.num_points(); std::size_t num_points = exterior.num_points();
@ -126,7 +126,7 @@ struct hit_test_visitor
} }
return inside; return inside;
} }
bool operator() (geometry::multi_polygon const& geom) const bool operator() (geometry::multi_polygon<double> const& geom) const
{ {
for (auto const& poly: geom) for (auto const& poly: geom)
{ {
@ -134,7 +134,7 @@ struct hit_test_visitor
} }
return false; return false;
} }
bool operator() (geometry::geometry_collection const& collection) const bool operator() (geometry::geometry_collection<double> const& collection) const
{ {
for (auto const& geom: collection) for (auto const& geom: collection)
{ {
@ -150,7 +150,7 @@ struct hit_test_visitor
} }
inline bool hit_test(mapnik::geometry::geometry const& geom, double x, double y, double tol) inline bool hit_test(mapnik::geometry::geometry<double> const& geom, double x, double y, double tol)
{ {
return mapnik::util::apply_visitor(detail::hit_test_visitor(x,y,tol), geom); return mapnik::util::apply_visitor(detail::hit_test_visitor(x,y,tol), geom);
} }

View file

@ -42,7 +42,7 @@
namespace mapnik { namespace json { namespace mapnik { namespace json {
using position = mapnik::geometry::point; using position = mapnik::geometry::point<double>;
using boxes = std::vector<std::pair<box2d<double>, std::pair<std::size_t, std::size_t>>>; using boxes = std::vector<std::pair<box2d<double>, std::pair<std::size_t, std::size_t>>>;
namespace qi = boost::spirit::qi; namespace qi = boost::spirit::qi;

View file

@ -65,9 +65,9 @@ struct end_container<mapnik::feature_impl const>
template <> template <>
struct transform_attribute<const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>, struct transform_attribute<const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>,
mapnik::geometry::geometry const& , karma::domain> mapnik::geometry::geometry<double> const& , karma::domain>
{ {
using type = mapnik::geometry::geometry const&; using type = mapnik::geometry::geometry<double> const&;
static type pre(const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>& f) static type pre(const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>& f)
{ {
return boost::fusion::at<mpl::int_<0> >(f).get_geometry(); return boost::fusion::at<mpl::int_<0> >(f).get_geometry();
@ -98,7 +98,7 @@ struct feature_generator_grammar :
{ {
feature_generator_grammar(); feature_generator_grammar();
karma::rule<OutputIterator, FeatureType const&()> feature; karma::rule<OutputIterator, FeatureType const&()> feature;
geometry_generator_grammar<OutputIterator, mapnik::geometry::geometry> geometry; geometry_generator_grammar<OutputIterator, mapnik::geometry::geometry<double> > geometry;
properties_generator_grammar<OutputIterator, FeatureType> properties; properties_generator_grammar<OutputIterator, FeatureType> properties;
boost::phoenix::function<get_id<FeatureType> > id_; boost::phoenix::function<get_id<FeatureType> > id_;
}; };

View file

@ -94,22 +94,22 @@ struct geometry_generator_grammar :
geometry_generator_grammar(); geometry_generator_grammar();
karma::rule<OutputIterator, Geometry const&()> geometry; karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch; karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry const&()> point; karma::rule<OutputIterator, geometry::geometry<double> const&()> point;
karma::rule<OutputIterator, geometry::point const&()> point_coord; karma::rule<OutputIterator, geometry::point<double> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry const&()> linestring; karma::rule<OutputIterator, geometry::geometry<double> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string const&()> linestring_coord; karma::rule<OutputIterator, geometry::line_string<double> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry const&()> polygon; karma::rule<OutputIterator, geometry::geometry<double> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon const&()> polygon_coord; karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring const&()> exterior_ring_coord; karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring> const&()> interior_ring_coord; karma::rule<OutputIterator, std::vector<geometry::linear_ring<double> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_point; karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point const& ()> multi_point_coord; karma::rule<OutputIterator, geometry::multi_point<double> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_linestring; karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string const& ()> multi_linestring_coord; karma::rule<OutputIterator, geometry::multi_line_string<double> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_polygon; karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon const& ()> multi_polygon_coord; karma::rule<OutputIterator, geometry::multi_polygon<double> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> geometry_collection; karma::rule<OutputIterator, geometry::geometry<double> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection const& ()> geometries; karma::rule<OutputIterator, geometry::geometry_collection<double> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type; boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::real_generator<double, detail::json_coordinate_policy<double> > coordinate; karma::real_generator<double, detail::json_coordinate_policy<double> > coordinate;

View file

@ -40,13 +40,13 @@ namespace qi = boost::spirit::qi;
template <typename Iterator, typename ErrorHandler = error_handler<Iterator> > template <typename Iterator, typename ErrorHandler = error_handler<Iterator> >
struct geometry_grammar : struct geometry_grammar :
qi::grammar<Iterator, mapnik::geometry::geometry() ,space_type> qi::grammar<Iterator, mapnik::geometry::geometry<double>() ,space_type>
{ {
geometry_grammar(); geometry_grammar();
qi::rule<Iterator, mapnik::geometry::geometry(), space_type> start; qi::rule<Iterator, mapnik::geometry::geometry<double>(), space_type> start;
qi::rule<Iterator, qi::locals<int, mapnik::json::coordinates>, mapnik::geometry::geometry(), space_type> geometry; qi::rule<Iterator, qi::locals<int, mapnik::json::coordinates>, mapnik::geometry::geometry<double>(), space_type> geometry;
qi::symbols<char, int> geometry_type_dispatch; qi::symbols<char, int> geometry_type_dispatch;
qi::rule<Iterator, mapnik::geometry::geometry_collection(), space_type> geometry_collection; qi::rule<Iterator, mapnik::geometry::geometry_collection<double>(), space_type> geometry_collection;
positions_grammar<Iterator> coordinates; positions_grammar<Iterator> coordinates;
boost::phoenix::function<create_geometry_impl> create_geometry; boost::phoenix::function<create_geometry_impl> create_geometry;
// error handler // error handler

View file

@ -34,7 +34,7 @@
namespace mapnik { namespace json { namespace mapnik { namespace json {
inline bool from_geojson(std::string const& json, mapnik::geometry::geometry & geom) inline bool from_geojson(std::string const& json, mapnik::geometry::geometry<double> & geom)
{ {
using namespace boost::spirit; using namespace boost::spirit;
static const geometry_grammar<char const*> g; static const geometry_grammar<char const*> g;

View file

@ -39,7 +39,7 @@ struct create_point
void operator() (position const& pos) const void operator() (position const& pos) const
{ {
mapnik::geometry::point point(pos.x, pos.y); mapnik::geometry::point<double> point(pos.x, pos.y);
geom_ = std::move(point); geom_ = std::move(point);
} }
@ -59,7 +59,7 @@ struct create_linestring
std::size_t size = ring.size(); std::size_t size = ring.size();
if (size > 1) if (size > 1)
{ {
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
line.reserve(size); line.reserve(size);
for (auto && pt : ring) for (auto && pt : ring)
{ {
@ -83,7 +83,7 @@ struct create_polygon
void operator() (std::vector<positions> const& rings) const void operator() (std::vector<positions> const& rings) const
{ {
mapnik::geometry::polygon poly; mapnik::geometry::polygon<double> poly;
std::size_t num_rings = rings.size(); std::size_t num_rings = rings.size();
if (num_rings > 1) if (num_rings > 1)
poly.interior_rings.reserve(num_rings - 1); poly.interior_rings.reserve(num_rings - 1);
@ -91,7 +91,7 @@ struct create_polygon
for ( std::size_t i = 0; i < num_rings; ++i) for ( std::size_t i = 0; i < num_rings; ++i)
{ {
std::size_t size = rings[i].size(); std::size_t size = rings[i].size();
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
ring.reserve(size); ring.reserve(size);
for ( auto && pt : rings[i]) for ( auto && pt : rings[i])
{ {
@ -120,7 +120,7 @@ struct create_multipoint
void operator() (positions const& points) const void operator() (positions const& points) const
{ {
mapnik::geometry::multi_point multi_point; mapnik::geometry::multi_point<double> multi_point;
multi_point.reserve(points.size()); multi_point.reserve(points.size());
for (auto && pos : points) for (auto && pos : points)
{ {
@ -143,12 +143,12 @@ struct create_multilinestring
void operator() (std::vector<positions> const& rings) const void operator() (std::vector<positions> const& rings) const
{ {
mapnik::geometry::multi_line_string multi_line; mapnik::geometry::multi_line_string<double> multi_line;
multi_line.reserve(rings.size()); multi_line.reserve(rings.size());
for (auto const& ring : rings) for (auto const& ring : rings)
{ {
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
line.reserve(ring.size()); line.reserve(ring.size());
for (auto && pt : ring) for (auto && pt : ring)
{ {
@ -173,11 +173,11 @@ struct create_multipolygon
void operator()(std::vector<std::vector<positions> > const& rings_array) const void operator()(std::vector<std::vector<positions> > const& rings_array) const
{ {
mapnik::geometry::multi_polygon multi_poly; mapnik::geometry::multi_polygon<double> multi_poly;
multi_poly.reserve(rings_array.size()); multi_poly.reserve(rings_array.size());
for (auto const& rings : rings_array) for (auto const& rings : rings_array)
{ {
mapnik::geometry::polygon poly; mapnik::geometry::polygon<double> poly;
std::size_t num_rings = rings.size(); std::size_t num_rings = rings.size();
if ( num_rings > 1) if ( num_rings > 1)
poly.interior_rings.reserve(num_rings - 1); poly.interior_rings.reserve(num_rings - 1);
@ -185,7 +185,7 @@ struct create_multipolygon
for ( std::size_t i = 0; i < num_rings; ++i) for ( std::size_t i = 0; i < num_rings; ++i)
{ {
std::size_t size = rings[i].size(); std::size_t size = rings[i].size();
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
ring.reserve(size); ring.reserve(size);
for ( auto && pt : rings[i]) for ( auto && pt : rings[i])
{ {

View file

@ -45,7 +45,7 @@ namespace mapnik { namespace json {
struct empty {}; struct empty {};
using position = mapnik::geometry::point; using position = mapnik::geometry::point<double>;
using positions = std::vector<position>; using positions = std::vector<position>;
using coordinates = util::variant<empty, position, positions, std::vector<positions>, std::vector<std::vector<positions> > > ; using coordinates = util::variant<empty, position, positions, std::vector<positions>, std::vector<std::vector<positions> > > ;

View file

@ -219,13 +219,13 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
if (placement == MARKER_POINT_PLACEMENT && if (placement == MARKER_POINT_PLACEMENT &&
multi_policy == MARKER_WHOLE_MULTI) multi_policy == MARKER_WHOLE_MULTI)
{ {
geometry::point pt; geometry::point<double> pt;
// test if centroid is contained by bounding box // test if centroid is contained by bounding box
if (geometry::centroid(geom, pt) && converter.disp_.args_.bbox.contains(pt.x, pt.y)) if (geometry::centroid(geom, pt) && converter.disp_.args_.bbox.contains(pt.x, pt.y))
{ {
// unset any clipping since we're now dealing with a point // unset any clipping since we're now dealing with a point
converter.template unset<clip_poly_tag>(); converter.template unset<clip_poly_tag>();
geometry::point_vertex_adapter va(pt); geometry::point_vertex_adapter<double> va(pt);
converter.apply(va); converter.apply(va);
} }
} }
@ -236,13 +236,13 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
// TODO: consider using true area for polygon types // TODO: consider using true area for polygon types
if (type == geometry::geometry_types::MultiPolygon) if (type == geometry::geometry_types::MultiPolygon)
{ {
geometry::multi_polygon const& multi_poly = mapnik::util::get<geometry::multi_polygon>(geom); geometry::multi_polygon<double> const& multi_poly = mapnik::util::get<geometry::multi_polygon<double> >(geom);
double maxarea = 0; double maxarea = 0;
geometry::polygon const* largest = 0; geometry::polygon<double> const* largest = 0;
for (geometry::polygon const& poly : multi_poly) for (geometry::polygon<double> const& poly : multi_poly)
{ {
box2d<double> bbox = geometry::envelope(poly); box2d<double> bbox = geometry::envelope(poly);
geometry::polygon_vertex_adapter va(poly); geometry::polygon_vertex_adapter<double> va(poly);
double area = bbox.width() * bbox.height(); double area = bbox.width() * bbox.height();
if (area > maxarea) if (area > maxarea)
{ {
@ -252,7 +252,7 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
} }
if (largest) if (largest)
{ {
geometry::polygon_vertex_adapter va(*largest); geometry::polygon_vertex_adapter<double> va(*largest);
converter.apply(va); converter.apply(va);
} }
} }

View file

@ -78,7 +78,7 @@ public:
} }
else else
{ {
geometry::geometry const& geom = (*pos_)->get_geometry(); geometry::geometry<double> const& geom = (*pos_)->get_geometry();
if (bbox_.intersects(geometry::envelope(geom))) if (bbox_.intersects(geometry::envelope(geom)))
{ {
return *pos_++; return *pos_++;

View file

@ -26,12 +26,13 @@
// mapnik // mapnik
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/util/noncopyable.hpp> #include <mapnik/util/noncopyable.hpp>
#include <mapnik/geometry_adapters.hpp>
namespace mapnik { namespace mapnik {
namespace geometry { namespace geometry {
struct point; template <typename T> struct point;
struct line_string; template <typename T> struct line_string;
} }
class projection; class projection;
template <typename T> class box2d; template <typename T> class box2d;
@ -46,12 +47,12 @@ public:
bool is_known() const; bool is_known() const;
bool forward (double& x, double& y , double& z) const; bool forward (double& x, double& y , double& z) const;
bool backward (double& x, double& y , double& z) const; bool backward (double& x, double& y , double& z) const;
bool forward (double *x, double *y , double *z, int point_count) const; bool forward (double *x, double *y , double *z, int point_count, int offset = 1) const;
bool backward (double *x, double *y , double *z, int point_count) const; bool backward (double *x, double *y , double *z, int point_count, int offset = 1) const;
bool forward (geometry::point & p) const; bool forward (geometry::point<double> & p) const;
bool backward (geometry::point & p) const; bool backward (geometry::point<double> & p) const;
unsigned int forward (geometry::line_string & ls) const; unsigned int forward (geometry::line_string<double> & ls) const;
unsigned int backward (geometry::line_string & ls) const; unsigned int backward (geometry::line_string<double> & ls) const;
bool forward (box2d<double> & box) const; bool forward (box2d<double> & box) const;
bool backward (box2d<double> & box) const; bool backward (box2d<double> & box) const;
bool forward (box2d<double> & box, int points) const; bool forward (box2d<double> & box, int points) const;
@ -68,6 +69,105 @@ private:
bool wgs84_to_merc_; bool wgs84_to_merc_;
bool merc_to_wgs84_; bool merc_to_wgs84_;
}; };
struct proj_strategy
{
proj_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_.forward(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_;
};
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 #endif // MAPNIK_PROJ_TRANSFORM_HPP

View file

@ -40,9 +40,9 @@ struct apply_local_alignment
x_(x), x_(x),
y_(y) {} y_(y) {}
void operator() (geometry::polygon_vertex_adapter & va) void operator() (geometry::polygon_vertex_adapter<double> & va)
{ {
using clipped_geometry_type = agg::conv_clip_polygon<geometry::polygon_vertex_adapter>; using clipped_geometry_type = agg::conv_clip_polygon<geometry::polygon_vertex_adapter<double> >;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>; using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
clipped_geometry_type clipped(va); clipped_geometry_type clipped(va);
clipped.clip_box(clip_box_.minx(),clip_box_.miny(),clip_box_.maxx(),clip_box_.maxy()); clipped.clip_box(clip_box_.minx(),clip_box_.miny(),clip_box_.maxx(),clip_box_.maxy());

View file

@ -36,7 +36,7 @@ namespace mapnik {
namespace detail { namespace detail {
template <typename F1, typename F2, typename F3> template <typename F1, typename F2, typename F3>
void make_building(geometry::polygon const& poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func) void make_building(geometry::polygon<double> const& poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func)
{ {
const std::unique_ptr<path_type> frame(new path_type(path_type::types::LineString)); const std::unique_ptr<path_type> frame(new path_type(path_type::types::LineString));
const std::unique_ptr<path_type> roof(new path_type(path_type::types::Polygon)); const std::unique_ptr<path_type> roof(new path_type(path_type::types::Polygon));
@ -44,7 +44,7 @@ void make_building(geometry::polygon const& poly, double height, F1 const& face_
double x0 = 0; double x0 = 0;
double y0 = 0; double y0 = 0;
double x,y; double x,y;
geometry::polygon_vertex_adapter va(poly); geometry::polygon_vertex_adapter<double> va(poly);
va.rewind(0); va.rewind(0);
for (unsigned cm = va.vertex(&x, &y); cm != SEG_END; for (unsigned cm = va.vertex(&x, &y); cm != SEG_END;
cm = va.vertex(&x, &y)) cm = va.vertex(&x, &y))
@ -115,14 +115,14 @@ void render_building_symbolizer(mapnik::feature_impl const& feature,
{ {
auto const& geom = feature.get_geometry(); auto const& geom = feature.get_geometry();
if (geom.is<geometry::polygon>()) if (geom.is<geometry::polygon<double> >())
{ {
auto const& poly = geom.get<geometry::polygon>(); auto const& poly = geom.get<geometry::polygon<double> >();
detail::make_building(poly, height, face_func, frame_func, roof_func); detail::make_building(poly, height, face_func, frame_func, roof_func);
} }
else if (geom.is<geometry::multi_polygon>()) else if (geom.is<geometry::multi_polygon<double> >())
{ {
auto const& multi_poly = geom.get<geometry::multi_polygon>(); auto const& multi_poly = geom.get<geometry::multi_polygon<double> >();
for (auto const& poly : multi_poly) for (auto const& poly : multi_poly)
{ {
detail::make_building(poly, height, face_func, frame_func, roof_func); detail::make_building(poly, height, face_func, frame_func, roof_func);

View file

@ -343,7 +343,7 @@ void render_group_symbolizer(group_symbolizer const& sym,
// try to ensure that we don't get edge artefacts due to any // try to ensure that we don't get edge artefacts due to any
// symbolizers with avoid-edges set: only the avoid-edges of // symbolizers with avoid-edges set: only the avoid-edges of
// the group symbolizer itself should matter. // the group symbolizer itself should matter.
geometry::point origin_pt(x,y); geometry::point<double> origin_pt(x,y);
sub_feature->set_geometry(origin_pt); sub_feature->set_geometry(origin_pt);
// get the layout for this set of properties // get the layout for this set of properties
for (auto const& rule : props->get_rules()) for (auto const& rule : props->get_rules())

View file

@ -63,8 +63,8 @@ void render_point_symbolizer(point_symbolizer const &sym,
agg::trans_affine recenter_tr = recenter * tr; agg::trans_affine recenter_tr = recenter * tr;
box2d<double> label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common.scale_factor_); box2d<double> label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common.scale_factor_);
mapnik::geometry::geometry const& geometry = feature.get_geometry(); mapnik::geometry::geometry<double> const& geometry = feature.get_geometry();
mapnik::geometry::point pt; mapnik::geometry::point<double> pt;
if (placement == CENTROID_POINT_PLACEMENT) if (placement == CENTROID_POINT_PLACEMENT)
{ {
if (!geometry::centroid(geometry, pt)) return; if (!geometry::centroid(geometry, pt)) return;

View file

@ -62,9 +62,9 @@ class base_symbolizer_helper
{ {
public: public:
using point_cref = std::reference_wrapper<geometry::point const>; using point_cref = std::reference_wrapper<geometry::point<double> const>;
using line_string_cref = std::reference_wrapper<geometry::line_string const>; using line_string_cref = std::reference_wrapper<geometry::line_string<double> const>;
using polygon_cref = std::reference_wrapper<geometry::polygon const>; using polygon_cref = std::reference_wrapper<geometry::polygon<double> const>;
using geometry_cref = util::variant<point_cref, line_string_cref, polygon_cref>; using geometry_cref = util::variant<point_cref, line_string_cref, polygon_cref>;
// Using list instead of vector, because we delete random elements and need iterators to stay valid. // Using list instead of vector, because we delete random elements and need iterators to stay valid.
using geometry_container_type = std::list<geometry_cref>; using geometry_container_type = std::list<geometry_cref>;

View file

@ -42,44 +42,44 @@ struct datasource_geometry_type
return mapnik::datasource_geometry_t::Unknown; return mapnik::datasource_geometry_t::Unknown;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::point const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::point<double> const&) const
{ {
return mapnik::datasource_geometry_t::Point; return mapnik::datasource_geometry_t::Point;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::line_string const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::line_string<double> const&) const
{ {
return mapnik::datasource_geometry_t::LineString; return mapnik::datasource_geometry_t::LineString;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::polygon const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::polygon<double> const&) const
{ {
return mapnik::datasource_geometry_t::Polygon; return mapnik::datasource_geometry_t::Polygon;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_point const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_point<double> const&) const
{ {
return mapnik::datasource_geometry_t::Point; return mapnik::datasource_geometry_t::Point;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_line_string const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_line_string<double> const&) const
{ {
return mapnik::datasource_geometry_t::LineString; return mapnik::datasource_geometry_t::LineString;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_polygon const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_polygon<double> const&) const
{ {
return mapnik::datasource_geometry_t::Polygon; return mapnik::datasource_geometry_t::Polygon;
} }
mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_collection const&) const mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_collection<double> const&) const
{ {
return mapnik::datasource_geometry_t::Collection; return mapnik::datasource_geometry_t::Collection;
} }
}; };
} // detail } // detail
static inline mapnik::datasource_geometry_t to_ds_type(mapnik::geometry::geometry const& geom) static inline mapnik::datasource_geometry_t to_ds_type(mapnik::geometry::geometry<double> const& geom)
{ {
return util::apply_visitor(detail::datasource_geometry_type(), geom); return util::apply_visitor(detail::datasource_geometry_type(), geom);
} }

View file

@ -29,10 +29,10 @@
namespace mapnik { namespace util { namespace mapnik { namespace util {
inline bool to_geojson(std::string & json, mapnik::geometry::geometry const& geom) inline bool to_geojson(std::string & json, mapnik::geometry::geometry<double> const& geom)
{ {
using sink_type = std::back_insert_iterator<std::string>; using sink_type = std::back_insert_iterator<std::string>;
static const mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry> grammar; static const mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry<double> > grammar;
sink_type sink(json); sink_type sink(json);
return boost::spirit::karma::generate(sink, grammar, geom); return boost::spirit::karma::generate(sink, grammar, geom);
} }

View file

@ -131,7 +131,7 @@ struct wkb_buffer
using wkb_buffer_ptr = std::unique_ptr<wkb_buffer>; using wkb_buffer_ptr = std::unique_ptr<wkb_buffer>;
wkb_buffer_ptr point_wkb( geometry::point const& pt, wkbByteOrder byte_order) wkb_buffer_ptr point_wkb( geometry::point<double> const& pt, wkbByteOrder byte_order)
{ {
std::size_t size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point std::size_t size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size); wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
@ -144,7 +144,7 @@ wkb_buffer_ptr point_wkb( geometry::point const& pt, wkbByteOrder byte_order)
return std::move(wkb); return std::move(wkb);
} }
wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByteOrder byte_order) wkb_buffer_ptr line_string_wkb(geometry::line_string<double> const& line, wkbByteOrder byte_order)
{ {
unsigned num_points = line.size(); unsigned num_points = line.size();
assert(num_points > 1); assert(num_points > 1);
@ -156,7 +156,7 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByteOrder b
write(ss, num_points, 4, byte_order); write(ss, num_points, 4, byte_order);
for (unsigned i=0; i< num_points; ++i) for (unsigned i=0; i< num_points; ++i)
{ {
geometry::point const& pt = line[i]; geometry::point<double> const& pt = line[i];
write(ss, pt.x, 8, byte_order); write(ss, pt.x, 8, byte_order);
write(ss, pt.y, 8, byte_order); write(ss, pt.y, 8, byte_order);
} }
@ -164,7 +164,7 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByteOrder b
return std::move(wkb); return std::move(wkb);
} }
wkb_buffer_ptr polygon_wkb( geometry::polygon const& poly, wkbByteOrder byte_order) wkb_buffer_ptr polygon_wkb( geometry::polygon<double> const& poly, wkbByteOrder byte_order)
{ {
std::size_t size = 1 + 4 + 4 ; // byteOrder + wkbType + numRings std::size_t size = 1 + 4 + 4 ; // byteOrder + wkbType + numRings
size += 4 + 2 * 8 * poly.exterior_ring.size(); size += 4 + 2 * 8 * poly.exterior_ring.size();
@ -202,7 +202,7 @@ wkb_buffer_ptr polygon_wkb( geometry::polygon const& poly, wkbByteOrder byte_ord
return std::move(wkb); return std::move(wkb);
} }
wkb_buffer_ptr multi_point_wkb( geometry::multi_point const& multi_pt, wkbByteOrder byte_order) wkb_buffer_ptr multi_point_wkb( geometry::multi_point<double> const& multi_pt, wkbByteOrder byte_order)
{ {
std::size_t size = 1 + 4 + 4 + (1 + 4 + 8 * 2) * multi_pt.size() ; // byteOrder + wkbType + num_point + Point.size * num_points std::size_t size = 1 + 4 + 4 + (1 + 4 + 8 * 2) * multi_pt.size() ; // byteOrder + wkbType + num_point + Point.size * num_points
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size); wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
@ -233,7 +233,7 @@ struct geometry_to_wkb
geometry_to_wkb(wkbByteOrder byte_order) geometry_to_wkb(wkbByteOrder byte_order)
: byte_order_(byte_order) {} : byte_order_(byte_order) {}
result_type operator() (geometry::geometry const& geom) const result_type operator() (geometry::geometry<double> const& geom) const
{ {
return util::apply_visitor(*this, geom); return util::apply_visitor(*this, geom);
} }
@ -243,24 +243,24 @@ struct geometry_to_wkb
return result_type(); return result_type();
} }
result_type operator() (geometry::point const& pt) const result_type operator() (geometry::point<double> const& pt) const
{ {
return point_wkb(pt, byte_order_); return point_wkb(pt, byte_order_);
} }
result_type operator() (geometry::line_string const& line) const result_type operator() (geometry::line_string<double> const& line) const
{ {
return line_string_wkb(line, byte_order_); return line_string_wkb(line, byte_order_);
} }
result_type operator() (geometry::polygon const& poly) const result_type operator() (geometry::polygon<double> const& poly) const
{ {
return polygon_wkb(poly, byte_order_); return polygon_wkb(poly, byte_order_);
} }
// multi/collection // multi/collection
result_type operator() (geometry::multi_point const& multi_pt) const result_type operator() (geometry::multi_point<double> const& multi_pt) const
{ {
return multi_point_wkb(multi_pt, byte_order_); return multi_point_wkb(multi_pt, byte_order_);
} }

View file

@ -32,10 +32,18 @@
namespace mapnik { namespace util { namespace mapnik { namespace util {
inline bool to_wkt(std::string & wkt, mapnik::geometry::geometry const& geom) inline bool to_wkt(std::string & wkt, mapnik::geometry::geometry<double> const& geom)
{ {
using sink_type = std::back_insert_iterator<std::string>; using sink_type = std::back_insert_iterator<std::string>;
static const mapnik::wkt::wkt_generator_grammar<sink_type, mapnik::geometry::geometry> 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); sink_type sink(wkt);
return boost::spirit::karma::generate(sink, generator, geom); return boost::spirit::karma::generate(sink, generator, geom);
} }

View file

@ -28,90 +28,178 @@
namespace boost { namespace spirit { namespace traits { namespace boost { namespace spirit { namespace traits {
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::point const&, karma::domain> mapnik::geometry::point<double> const&, karma::domain>
{ {
using type = mapnik::geometry::point const&; using type = mapnik::geometry::point<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::point>(geom); return mapnik::util::get<mapnik::geometry::point<double> >(geom);
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::line_string const&, karma::domain> mapnik::geometry::line_string<double> const&, karma::domain>
{ {
using type = mapnik::geometry::line_string const&; using type = mapnik::geometry::line_string<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::line_string>(geom); return mapnik::util::get<mapnik::geometry::line_string<double> >(geom);
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::polygon const&, karma::domain> mapnik::geometry::polygon<double> const&, karma::domain>
{ {
using type = mapnik::geometry::polygon const&; using type = mapnik::geometry::polygon<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::polygon>(geom); return mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::polygon const, struct transform_attribute<mapnik::geometry::polygon<double> const,
std::vector<mapnik::geometry::linear_ring> const&, karma::domain> std::vector<mapnik::geometry::linear_ring<double> > const&, karma::domain>
{ {
using type = std::vector<mapnik::geometry::linear_ring> const&; using type = std::vector<mapnik::geometry::linear_ring<double> > const&;
static type pre(mapnik::geometry::polygon const& poly) static type pre(mapnik::geometry::polygon<double> const& poly)
{ {
return poly.interior_rings; return poly.interior_rings;
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::multi_point const&, karma::domain> mapnik::geometry::multi_point<double> const&, karma::domain>
{ {
using type = mapnik::geometry::multi_point const&; using type = mapnik::geometry::multi_point<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::multi_point>(geom); return mapnik::util::get<mapnik::geometry::multi_point<double> >(geom);
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::multi_line_string const&, karma::domain> mapnik::geometry::multi_line_string<double> const&, karma::domain>
{ {
using type = mapnik::geometry::multi_line_string const&; using type = mapnik::geometry::multi_line_string<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::multi_line_string>(geom); return mapnik::util::get<mapnik::geometry::multi_line_string<double> >(geom);
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::multi_polygon const&, karma::domain> mapnik::geometry::multi_polygon<double> const&, karma::domain>
{ {
using type = mapnik::geometry::multi_polygon const&; using type = mapnik::geometry::multi_polygon<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::multi_polygon>(geom); return mapnik::util::get<mapnik::geometry::multi_polygon<double> >(geom);
} }
}; };
template <> template <>
struct transform_attribute<mapnik::geometry::geometry const, struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::geometry_collection const&, karma::domain> mapnik::geometry::geometry_collection<double> const&, karma::domain>
{ {
using type = mapnik::geometry::geometry_collection const&; using type = mapnik::geometry::geometry_collection<double> const&;
static type pre(mapnik::geometry::geometry const& geom) static type pre(mapnik::geometry::geometry<double> const& geom)
{ {
return mapnik::util::get<mapnik::geometry::geometry_collection>(geom); return mapnik::util::get<mapnik::geometry::geometry_collection<double> >(geom);
}
};
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);
} }
}; };

View file

@ -29,11 +29,12 @@
namespace mapnik { namespace geometry { namespace mapnik { namespace geometry {
template <typename T>
struct point_vertex_adapter struct point_vertex_adapter
{ {
using value_type = typename point::value_type; using value_type = typename point<T>::value_type;
point_vertex_adapter(point const& pt) point_vertex_adapter(point<T> const& pt)
: pt_(pt), : pt_(pt),
first_(true) {} first_(true) {}
@ -59,14 +60,15 @@ struct point_vertex_adapter
return geometry_types::Point; return geometry_types::Point;
} }
point const& pt_; point<T> const& pt_;
mutable bool first_; mutable bool first_;
}; };
template <typename T>
struct line_string_vertex_adapter struct line_string_vertex_adapter
{ {
using value_type = typename point::value_type; using value_type = typename point<T>::value_type;
line_string_vertex_adapter(line_string const& line) line_string_vertex_adapter(line_string<T> const& line)
: line_(line), : line_(line),
current_index_(0), current_index_(0),
end_index_(line.size()) end_index_(line.size())
@ -76,7 +78,7 @@ struct line_string_vertex_adapter
{ {
if (current_index_ != end_index_) if (current_index_ != end_index_)
{ {
point const& coord = line_[current_index_++]; point<T> const& coord = line_[current_index_++];
*x = coord.x; *x = coord.x;
*y = coord.y; *y = coord.y;
if (current_index_ == 1) if (current_index_ == 1)
@ -101,16 +103,17 @@ struct line_string_vertex_adapter
return geometry_types::LineString; return geometry_types::LineString;
} }
line_string const& line_; line_string<T> const& line_;
mutable std::size_t current_index_; mutable std::size_t current_index_;
const std::size_t end_index_; const std::size_t end_index_;
}; };
template <typename T>
struct polygon_vertex_adapter struct polygon_vertex_adapter
{ {
using value_type = typename point::value_type; using value_type = typename point<T>::value_type;
polygon_vertex_adapter(polygon const& poly) polygon_vertex_adapter(polygon<T> const& poly)
: poly_(poly), : poly_(poly),
rings_itr_(0), rings_itr_(0),
rings_end_(poly_.interior_rings.size() + 1), rings_end_(poly_.interior_rings.size() + 1),
@ -135,7 +138,7 @@ struct polygon_vertex_adapter
} }
if (current_index_ < end_index_) if (current_index_ < end_index_)
{ {
point const& coord = (rings_itr_ == 0) ? point<T> const& coord = (rings_itr_ == 0) ?
poly_.exterior_ring[current_index_++] : poly_.interior_rings[rings_itr_- 1][current_index_++]; poly_.exterior_ring[current_index_++] : poly_.interior_rings[rings_itr_- 1][current_index_++];
*x = coord.x; *x = coord.x;
*y = coord.y; *y = coord.y;
@ -156,7 +159,7 @@ struct polygon_vertex_adapter
{ {
current_index_ = 0; current_index_ = 0;
end_index_ = poly_.interior_rings[rings_itr_ - 1].size(); end_index_ = poly_.interior_rings[rings_itr_ - 1].size();
point const& coord = poly_.interior_rings[rings_itr_ - 1][current_index_++]; point<T> const& coord = poly_.interior_rings[rings_itr_ - 1][current_index_++];
*x = coord.x; *x = coord.x;
*y = coord.y; *y = coord.y;
return mapnik::SEG_MOVETO; return mapnik::SEG_MOVETO;
@ -170,7 +173,7 @@ struct polygon_vertex_adapter
} }
private: private:
polygon const& poly_; polygon<T> const& poly_;
mutable std::size_t rings_itr_; mutable std::size_t rings_itr_;
mutable std::size_t rings_end_; mutable std::size_t rings_end_;
mutable std::size_t current_index_; mutable std::size_t current_index_;
@ -178,10 +181,11 @@ private:
mutable bool start_loop_; mutable bool start_loop_;
}; };
template <typename T>
struct ring_vertex_adapter struct ring_vertex_adapter
{ {
using value_type = typename point::value_type; using value_type = typename point<T>::value_type;
ring_vertex_adapter(linear_ring const& ring) ring_vertex_adapter(linear_ring<T> const& ring)
: ring_(ring), : ring_(ring),
current_index_(0), current_index_(0),
end_index_(ring_.size()), end_index_(ring_.size()),
@ -223,49 +227,49 @@ struct ring_vertex_adapter
} }
private: private:
linear_ring const& ring_; linear_ring<T> const& ring_;
mutable std::size_t current_index_; mutable std::size_t current_index_;
mutable std::size_t end_index_; mutable std::size_t end_index_;
mutable bool start_loop_; mutable bool start_loop_;
}; };
template <typename T> template <typename T>
struct vertex_adapter_traits{}; struct vertex_adapter_traits {};
template <> template <>
struct vertex_adapter_traits<point> struct vertex_adapter_traits<point<double> >
{ {
using type = point_vertex_adapter; using type = point_vertex_adapter<double>;
}; };
template <> template <>
struct vertex_adapter_traits<line_string> struct vertex_adapter_traits<line_string<double> >
{ {
using type = line_string_vertex_adapter; using type = line_string_vertex_adapter<double>;
}; };
template <> template <>
struct vertex_adapter_traits<polygon> struct vertex_adapter_traits<polygon<double> >
{ {
using type = polygon_vertex_adapter; using type = polygon_vertex_adapter<double>;
}; };
template <> template <>
struct vertex_adapter_traits<multi_point> struct vertex_adapter_traits<multi_point<double> >
{ {
using type = point_vertex_adapter; using type = point_vertex_adapter<double>;
}; };
template <> template <>
struct vertex_adapter_traits<multi_line_string> struct vertex_adapter_traits<multi_line_string<double> >
{ {
using type = line_string_vertex_adapter; using type = line_string_vertex_adapter<double>;
}; };
template <> template <>
struct vertex_adapter_traits<multi_polygon> struct vertex_adapter_traits<multi_polygon<double> >
{ {
using type = polygon_vertex_adapter; using type = polygon_vertex_adapter<double>;
}; };
}} }}

View file

@ -43,52 +43,60 @@ struct vertex_processor
{ {
// no-op // no-op
} }
void operator() (point const& pt)
template <typename T1>
void operator() (point<T1> const& pt)
{ {
point_vertex_adapter va(pt); point_vertex_adapter<T1> va(pt);
proc_(va); proc_(va);
} }
void operator() (line_string const& line) template <typename T1>
void operator() (line_string<T1> const& line)
{ {
line_string_vertex_adapter va(line); line_string_vertex_adapter<T1> va(line);
proc_(va); proc_(va);
} }
void operator() (polygon const& poly) template <typename T1>
void operator() (polygon<T1> const& poly)
{ {
polygon_vertex_adapter va(poly); polygon_vertex_adapter<T1> va(poly);
proc_(va); proc_(va);
} }
void operator() (multi_point const& multi_pt) template <typename T1>
void operator() (multi_point<T1> const& multi_pt)
{ {
for (auto const& pt : multi_pt) for (auto const& pt : multi_pt)
{ {
point_vertex_adapter va(pt); point_vertex_adapter<T1> va(pt);
proc_(va); proc_(va);
} }
} }
void operator() (multi_line_string const& multi_line) template <typename T1>
void operator() (multi_line_string<T1> const& multi_line)
{ {
for (auto const& line : multi_line) for (auto const& line : multi_line)
{ {
line_string_vertex_adapter va(line); line_string_vertex_adapter<T1> va(line);
proc_(va); proc_(va);
} }
} }
void operator() (multi_polygon const& multi_poly) template <typename T1>
void operator() (multi_polygon<T1> const& multi_poly)
{ {
for ( auto const& poly : multi_poly) for ( auto const& poly : multi_poly)
{ {
polygon_vertex_adapter va(poly); polygon_vertex_adapter<T1> va(poly);
proc_(va); proc_(va);
} }
} }
void operator() (geometry_collection const& collection) template <typename T1>
void operator() (geometry_collection<T1> const& collection)
{ {
for (auto const& geom : collection) for (auto const& geom : collection)
{ {

View file

@ -178,6 +178,63 @@ public:
return extent_; return extent_;
} }
}; };
struct view_strategy
{
view_strategy(view_transform const& tr)
: tr_(tr) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
using coordinate_type = typename boost::geometry::coordinate_type<P2>::type;
double x = boost::geometry::get<0>(p1);
double y = boost::geometry::get<1>(p1);
tr_.forward(&x,&y);
boost::geometry::set<0>(p2, boost::numeric_cast<coordinate_type>(x));
boost::geometry::set<1>(p2, boost::numeric_cast<coordinate_type>(y));
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
view_transform const& tr_;
};
struct unview_strategy
{
unview_strategy(view_transform const& tr)
: tr_(tr) {}
template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
using coordinate_type = typename boost::geometry::coordinate_type<P2>::type;
double x = boost::geometry::get<0>(p1);
double y = boost::geometry::get<1>(p1);
tr_.backward(&x,&y);
boost::geometry::set<0>(p2, boost::numeric_cast<coordinate_type>(x));
boost::geometry::set<1>(p2, boost::numeric_cast<coordinate_type>(y));
return true;
}
template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}
view_transform const& tr_;
};
} }
#endif // MAPNIK_VIEW_TRANSFORM_HPP #endif // MAPNIK_VIEW_TRANSFORM_HPP

View file

@ -90,7 +90,7 @@ static inline bool merc2lonlat(double * x, double * y , int point_count)
return true; return true;
} }
static inline bool lonlat2merc(geometry::line_string & ls) static inline bool lonlat2merc(geometry::line_string<double> & ls)
{ {
for(auto & p : ls) for(auto & p : ls)
{ {
@ -105,7 +105,7 @@ static inline bool lonlat2merc(geometry::line_string & ls)
return true; return true;
} }
static inline bool merc2lonlat(geometry::line_string & ls) static inline bool merc2lonlat(geometry::line_string<double> & ls)
{ {
for (auto & p : ls) for (auto & p : ls)
{ {

View file

@ -59,7 +59,7 @@ class MAPNIK_DECL geometry_utils : private util::noncopyable
{ {
public: public:
static mapnik::geometry::geometry from_wkb(const char* wkb, static mapnik::geometry::geometry<double> from_wkb(const char* wkb,
unsigned size, unsigned size,
wkbFormat format = wkbGeneric); wkbFormat format = wkbGeneric);
}; };

View file

@ -34,7 +34,7 @@
namespace mapnik { namespace mapnik {
inline bool from_wkt(std::string const& wkt, mapnik::geometry::geometry & geom) inline bool from_wkt(std::string const& wkt, mapnik::geometry::geometry<double> & geom)
{ {
using namespace boost::spirit; using namespace boost::spirit;
static const mapnik::wkt::wkt_grammar<std::string::const_iterator> g; static const mapnik::wkt::wkt_grammar<std::string::const_iterator> g;

View file

@ -85,9 +85,10 @@ struct wkt_coordinate_policy : karma::real_policies<T>
return base_type::fraction_part(sink, n, adjprec, precision); 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 : struct wkt_generator_grammar :
karma::grammar<OutputIterator, Geometry const& ()> karma::grammar<OutputIterator, Geometry const& ()>
{ {
@ -95,26 +96,56 @@ struct wkt_generator_grammar :
// rules // rules
karma::rule<OutputIterator, Geometry const&()> geometry; karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch; karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry const&()> point; karma::rule<OutputIterator, geometry::geometry<T> const&()> point;
karma::rule<OutputIterator, geometry::point const&()> point_coord; karma::rule<OutputIterator, geometry::point<T> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry const&()> linestring; karma::rule<OutputIterator, geometry::geometry<T> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string const&()> linestring_coord; karma::rule<OutputIterator, geometry::line_string<T> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry const&()> polygon; karma::rule<OutputIterator, geometry::geometry<T> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon const&()> polygon_coord; karma::rule<OutputIterator, geometry::polygon<T> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring const&()> exterior_ring_coord; karma::rule<OutputIterator, geometry::linear_ring<T> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring> const&()> interior_ring_coord; karma::rule<OutputIterator, std::vector<geometry::linear_ring<T> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_point; karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point const& ()> multi_point_coord; karma::rule<OutputIterator, geometry::multi_point<T> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_linestring; karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string const& ()> multi_linestring_coord; karma::rule<OutputIterator, geometry::multi_line_string<T> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_polygon; karma::rule<OutputIterator, geometry::geometry<T> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon const& ()> multi_polygon_coord; karma::rule<OutputIterator, geometry::multi_polygon<T> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> geometry_collection; karma::rule<OutputIterator, geometry::geometry<T> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection const& ()> geometries; karma::rule<OutputIterator, geometry::geometry_collection<T> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type; boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::symbols<mapnik::geometry::geometry_types, char const*> empty; 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 { namespace mapnik { namespace wkt {
template <typename OutputIterator, typename Geometry> template <typename OutputIterator, typename Geometry, typename T>
wkt_generator_grammar<OutputIterator, Geometry>::wkt_generator_grammar() wkt_generator_grammar<OutputIterator, Geometry,T>::wkt_generator_grammar()
: wkt_generator_grammar::base_type(geometry) : wkt_generator_grammar::base_type(geometry)
{ {
boost::spirit::karma::_val_type _val; boost::spirit::karma::_val_type _val;
@ -75,7 +75,92 @@ wkt_generator_grammar<OutputIterator, Geometry>::wkt_generator_grammar()
<< (geometry_collection | empty[_1 = _a])) << (geometry_collection | empty[_1 = _a]))
| |
(&uint_(geometry::geometry_types::Unknown)[_1 = _a] (&uint_(geometry::geometry_types::Unknown)[_1 = _a]
<< lit("POINT EMPTY")) // special case for geometry_empty as mapnik::geometry::point can't be empty << 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(',')
;
}
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(")") point = lit("POINT(") << point_coord << lit(")")

View file

@ -85,29 +85,29 @@ struct add_hole
} }
template <typename Iterator> template <typename Iterator>
struct wkt_grammar : qi::grammar<Iterator, void(mapnik::geometry::geometry&) , ascii::space_type> struct wkt_grammar : qi::grammar<Iterator, void(mapnik::geometry::geometry<double> &) , ascii::space_type>
{ {
wkt_grammar(); wkt_grammar();
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> geometry_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> geometry_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> point_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> point_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> linestring_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> linestring_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> polygon_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> polygon_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> multipoint_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> multipoint_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> multilinestring_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> multilinestring_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> multipolygon_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> multipolygon_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> geometrycollection_tagged_text; qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> geometrycollection_tagged_text;
qi::rule<Iterator, mapnik::geometry::point(), ascii::space_type> point_text; qi::rule<Iterator, mapnik::geometry::point<double>(), ascii::space_type> point_text;
qi::rule<Iterator, mapnik::geometry::line_string(), ascii::space_type> linestring_text; qi::rule<Iterator, mapnik::geometry::line_string<double>(), ascii::space_type> linestring_text;
qi::rule<Iterator, mapnik::geometry::linear_ring(), ascii::space_type> linearring_text; qi::rule<Iterator, mapnik::geometry::linear_ring<double>(), ascii::space_type> linearring_text;
qi::rule<Iterator, mapnik::geometry::polygon(), ascii::space_type> polygon_text; qi::rule<Iterator, mapnik::geometry::polygon<double>(), ascii::space_type> polygon_text;
qi::rule<Iterator, mapnik::geometry::multi_point(), ascii::space_type> multipoint_text; qi::rule<Iterator, mapnik::geometry::multi_point<double>(), ascii::space_type> multipoint_text;
qi::rule<Iterator, mapnik::geometry::multi_line_string(), ascii::space_type> multilinestring_text; qi::rule<Iterator, mapnik::geometry::multi_line_string<double>(), ascii::space_type> multilinestring_text;
qi::rule<Iterator, mapnik::geometry::multi_polygon(), ascii::space_type> multipolygon_text; qi::rule<Iterator, mapnik::geometry::multi_polygon<double>(), ascii::space_type> multipolygon_text;
qi::rule<Iterator, qi::locals<mapnik::geometry::geometry>, qi::rule<Iterator, qi::locals<mapnik::geometry::geometry<double> >,
mapnik::geometry::geometry_collection(), ascii::space_type> geometrycollection_text; mapnik::geometry::geometry_collection<double>(), ascii::space_type> geometrycollection_text;
qi::rule<Iterator, mapnik::geometry::point(), ascii::space_type> point; qi::rule<Iterator, mapnik::geometry::point<double>(), ascii::space_type> point;
qi::rule<Iterator, mapnik::geometry::line_string(), ascii::space_type> points; qi::rule<Iterator, mapnik::geometry::line_string<double>(), ascii::space_type> points;
qi::rule<Iterator, mapnik::geometry::linear_ring(), ascii::space_type> ring_points; qi::rule<Iterator, mapnik::geometry::linear_ring<double>(), ascii::space_type> ring_points;
qi::rule<Iterator,ascii::space_type> empty_set; qi::rule<Iterator,ascii::space_type> empty_set;
boost::phoenix::function<detail::assign> assign; boost::phoenix::function<detail::assign> assign;
boost::phoenix::function<detail::move_part> move_part; boost::phoenix::function<detail::move_part> move_part;

View file

@ -63,7 +63,7 @@ wkt_grammar<Iterator>::wkt_grammar()
// <point text> ::= <empty set> | <left paren> <point> <right paren> // <point text> ::= <empty set> | <left paren> <point> <right paren>
point_text = (lit("(") >> point >> lit(')')) point_text = (lit("(") >> point >> lit(')'))
//| empty_set - we're catching 'POINT EMPTY' case in point_tagged_text rule ^^ by creating geometry_empty //| empty_set - we're catching 'POINT EMPTY' case in point_tagged_text rule ^^ by creating geometry_empty
// because our geometry::point can't be empty // because our geometry::point<double> can't be empty
; ;
//<linestring tagged text> ::= linestring <linestring text> //<linestring tagged text> ::= linestring <linestring text>
@ -133,7 +133,7 @@ wkt_grammar<Iterator>::wkt_grammar()
// geometry collection text // geometry collection text
geometrycollection_text = (lit('(') geometrycollection_text = (lit('(')
>> ( eps[_a = construct<geometry::geometry>()] >> ( eps[_a = construct<geometry::geometry<double> >()]
>> geometry_tagged_text(_a)[move_part(_val,_a)] % lit(',')) >> geometry_tagged_text(_a)[move_part(_val,_a)] % lit(','))
>> lit(')')) >> lit(')'))
| |

View file

@ -541,7 +541,7 @@ void csv_datasource::parse_csv(T & stream,
{ {
break; break;
} }
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (mapnik::from_wkt(value, geom)) if (mapnik::from_wkt(value, geom))
{ {
// correct orientations etc // correct orientations etc
@ -581,7 +581,7 @@ void csv_datasource::parse_csv(T & stream,
{ {
break; break;
} }
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
if (mapnik::json::from_geojson(value, geom)) if (mapnik::json::from_geojson(value, geom))
{ {
feature->set_geometry(std::move(geom)); feature->set_geometry(std::move(geom));
@ -816,7 +816,7 @@ void csv_datasource::parse_csv(T & stream,
{ {
if (parsed_x && parsed_y) if (parsed_x && parsed_y)
{ {
mapnik::geometry::point pt(x,y); mapnik::geometry::point<double> pt(x,y);
feature->set_geometry(std::move(pt)); feature->set_geometry(std::move(pt));
features_.push_back(feature); features_.push_back(feature);
null_geom = false; null_geom = false;

View file

@ -613,7 +613,7 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
{ {
// construct feature // construct feature
feature_ptr feature = feature_factory::create(ctx_,1); feature_ptr feature = feature_factory::create(ctx_,1);
feature->set_geometry(mapnik::geometry::point(pt.x,pt.y)); feature->set_geometry(mapnik::geometry::point<double>(pt.x,pt.y));
feature->put_new("value",value); feature->put_new("value",value);
if (raster_has_nodata) if (raster_has_nodata)
{ {

View file

@ -29,7 +29,7 @@
#include <ogr_core.h> #include <ogr_core.h>
#include <ogr_geometry.h> #include <ogr_geometry.h>
mapnik::geometry::geometry ogr_converter::convert_geometry(OGRGeometry* ogr_geom) mapnik::geometry::geometry<double> ogr_converter::convert_geometry(OGRGeometry* ogr_geom)
{ {
// NOTE: wkbFlatten macro in ogr flattens 2.5d types into base 2d type // NOTE: wkbFlatten macro in ogr flattens 2.5d types into base 2d type
switch (wkbFlatten(ogr_geom->getGeometryType())) switch (wkbFlatten(ogr_geom->getGeometryType()))
@ -65,19 +65,19 @@ mapnik::geometry::geometry ogr_converter::convert_geometry(OGRGeometry* ogr_geom
MAPNIK_LOG_WARN(ogr) << "ogr_converter: unknown <ogr> geometry_type=" MAPNIK_LOG_WARN(ogr) << "ogr_converter: unknown <ogr> geometry_type="
<< wkbFlatten(ogr_geom->getGeometryType()); << wkbFlatten(ogr_geom->getGeometryType());
} }
return mapnik::geometry::geometry(); return mapnik::geometry::geometry<double>();
break; break;
} }
} }
mapnik::geometry::point ogr_converter::convert_point(OGRPoint* ogr_geom) mapnik::geometry::point<double> ogr_converter::convert_point(OGRPoint* ogr_geom)
{ {
return mapnik::geometry::point(ogr_geom->getX(), ogr_geom->getY()); return mapnik::geometry::point<double>(ogr_geom->getX(), ogr_geom->getY());
} }
mapnik::geometry::multi_point ogr_converter::convert_multipoint(OGRMultiPoint* ogr_geom) mapnik::geometry::multi_point<double> ogr_converter::convert_multipoint(OGRMultiPoint* ogr_geom)
{ {
mapnik::geometry::multi_point geom; mapnik::geometry::multi_point<double> geom;
int num_geometries = ogr_geom->getNumGeometries(); int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries); geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i) for (int i = 0; i < num_geometries; ++i)
@ -88,9 +88,9 @@ mapnik::geometry::multi_point ogr_converter::convert_multipoint(OGRMultiPoint* o
return geom; return geom;
} }
mapnik::geometry::line_string ogr_converter::convert_linestring(OGRLineString* ogr_geom) mapnik::geometry::line_string<double> ogr_converter::convert_linestring(OGRLineString* ogr_geom)
{ {
mapnik::geometry::line_string geom; mapnik::geometry::line_string<double> geom;
int num_points = ogr_geom->getNumPoints(); int num_points = ogr_geom->getNumPoints();
geom.reserve(num_points); geom.reserve(num_points);
for (int i = 0; i < num_points; ++i) for (int i = 0; i < num_points; ++i)
@ -100,9 +100,9 @@ mapnik::geometry::line_string ogr_converter::convert_linestring(OGRLineString* o
return geom; return geom;
} }
mapnik::geometry::multi_line_string ogr_converter::convert_multilinestring(OGRMultiLineString* ogr_geom) mapnik::geometry::multi_line_string<double> ogr_converter::convert_multilinestring(OGRMultiLineString* ogr_geom)
{ {
mapnik::geometry::multi_line_string geom; mapnik::geometry::multi_line_string<double> geom;
int num_geometries = ogr_geom->getNumGeometries(); int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries); geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i) for (int i = 0; i < num_geometries; ++i)
@ -114,10 +114,10 @@ mapnik::geometry::multi_line_string ogr_converter::convert_multilinestring(OGRMu
} }
mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr_geom) mapnik::geometry::polygon<double> ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
{ {
mapnik::geometry::polygon geom; mapnik::geometry::polygon<double> geom;
mapnik::geometry::linear_ring exterior; mapnik::geometry::linear_ring<double> exterior;
OGRLinearRing* ogr_exterior = ogr_geom->getExteriorRing(); OGRLinearRing* ogr_exterior = ogr_geom->getExteriorRing();
int num_points = ogr_exterior->getNumPoints(); int num_points = ogr_exterior->getNumPoints();
exterior.reserve(num_points); exterior.reserve(num_points);
@ -131,7 +131,7 @@ mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
for (int r = 0; r < num_interior; ++r) for (int r = 0; r < num_interior; ++r)
{ {
OGRLinearRing* ogr_interior = ogr_geom->getInteriorRing(r); OGRLinearRing* ogr_interior = ogr_geom->getInteriorRing(r);
mapnik::geometry::linear_ring interior; mapnik::geometry::linear_ring<double> interior;
int num_interior_points = ogr_interior->getNumPoints(); int num_interior_points = ogr_interior->getNumPoints();
interior.reserve(num_interior_points); interior.reserve(num_interior_points);
for (int i = 0; i < num_interior_points; ++i) for (int i = 0; i < num_interior_points; ++i)
@ -143,9 +143,9 @@ mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
return geom; return geom;
} }
mapnik::geometry::multi_polygon ogr_converter::convert_multipolygon(OGRMultiPolygon* ogr_geom) mapnik::geometry::multi_polygon<double> ogr_converter::convert_multipolygon(OGRMultiPolygon* ogr_geom)
{ {
mapnik::geometry::multi_polygon geom; mapnik::geometry::multi_polygon<double> geom;
int num_geometries = ogr_geom->getNumGeometries(); int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries); geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i) for (int i = 0; i < num_geometries; ++i)
@ -156,9 +156,9 @@ mapnik::geometry::multi_polygon ogr_converter::convert_multipolygon(OGRMultiPoly
return geom; return geom;
} }
mapnik::geometry::geometry_collection ogr_converter::convert_collection(OGRGeometryCollection* ogr_geom) mapnik::geometry::geometry_collection<double> ogr_converter::convert_collection(OGRGeometryCollection* ogr_geom)
{ {
mapnik::geometry::geometry_collection geom; mapnik::geometry::geometry_collection<double> geom;
int num_geometries = ogr_geom->getNumGeometries(); int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries); geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i) for (int i = 0; i < num_geometries; ++i)

View file

@ -39,14 +39,14 @@ class ogr_converter
{ {
public: public:
static mapnik::geometry::geometry convert_geometry (OGRGeometry* ogr_geom); static mapnik::geometry::geometry<double> convert_geometry (OGRGeometry* ogr_geom);
static mapnik::geometry::point convert_point (OGRPoint* ogr_geom); static mapnik::geometry::point<double> convert_point (OGRPoint* ogr_geom);
static mapnik::geometry::multi_point convert_multipoint (OGRMultiPoint* ogr_geom); static mapnik::geometry::multi_point<double> convert_multipoint (OGRMultiPoint* ogr_geom);
static mapnik::geometry::line_string convert_linestring (OGRLineString* ogr_geom); static mapnik::geometry::line_string<double> convert_linestring (OGRLineString* ogr_geom);
static mapnik::geometry::multi_line_string convert_multilinestring (OGRMultiLineString* ogr_geom); static mapnik::geometry::multi_line_string<double> convert_multilinestring (OGRMultiLineString* ogr_geom);
static mapnik::geometry::polygon convert_polygon (OGRPolygon* ogr_geom); static mapnik::geometry::polygon<double> convert_polygon (OGRPolygon* ogr_geom);
static mapnik::geometry::multi_polygon convert_multipolygon (OGRMultiPolygon* ogr_geom); static mapnik::geometry::multi_polygon<double> convert_multipolygon (OGRMultiPolygon* ogr_geom);
static mapnik::geometry::geometry_collection convert_collection (OGRGeometryCollection* ogr_geom); static mapnik::geometry::geometry_collection<double> convert_collection (OGRGeometryCollection* ogr_geom);
}; };
#endif // OGR_CONVERTER_HPP #endif // OGR_CONVERTER_HPP

View file

@ -63,7 +63,7 @@ feature_ptr osm_featureset<filterT>::next()
feature = feature_factory::create(ctx_, cur_item->id); feature = feature_factory::create(ctx_, cur_item->id);
double lat = static_cast<osm_node*>(cur_item)->lat; double lat = static_cast<osm_node*>(cur_item)->lat;
double lon = static_cast<osm_node*>(cur_item)->lon; double lon = static_cast<osm_node*>(cur_item)->lon;
feature->set_geometry(mapnik::geometry::point(lon,lat)); feature->set_geometry(mapnik::geometry::point<double>(lon,lat));
} }
else if (dataset_->current_item_is_way()) else if (dataset_->current_item_is_way())
{ {
@ -81,7 +81,7 @@ feature_ptr osm_featureset<filterT>::next()
feature = feature_factory::create(ctx_, cur_item->id); feature = feature_factory::create(ctx_, cur_item->id);
if (static_cast<osm_way*>(cur_item)->is_polygon()) if (static_cast<osm_way*>(cur_item)->is_polygon())
{ {
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
for (unsigned int count = 0; for (unsigned int count = 0;
count < static_cast<osm_way*>(cur_item)->nodes.size(); count < static_cast<osm_way*>(cur_item)->nodes.size();
count++) count++)
@ -89,13 +89,13 @@ feature_ptr osm_featureset<filterT>::next()
ring.add_coord(static_cast<osm_way*>(cur_item)->nodes[count]->lon, ring.add_coord(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
static_cast<osm_way*>(cur_item)->nodes[count]->lat); static_cast<osm_way*>(cur_item)->nodes[count]->lat);
} }
mapnik::geometry::polygon geom; mapnik::geometry::polygon<double> geom;
geom.set_exterior_ring(std::move(ring)); geom.set_exterior_ring(std::move(ring));
feature->set_geometry(std::move(geom)); feature->set_geometry(std::move(geom));
} }
else else
{ {
mapnik::geometry::line_string geom; mapnik::geometry::line_string<double> geom;
for (unsigned int count = 0; for (unsigned int count = 0;
count < static_cast<osm_way*>(cur_item)->nodes.size(); count < static_cast<osm_way*>(cur_item)->nodes.size();
count++) count++)

View file

@ -122,7 +122,7 @@ feature_ptr postgis_featureset::next()
int size = rs_->getFieldLength(0); int size = rs_->getFieldLength(0);
const char *data = rs_->getValue(0); const char *data = rs_->getValue(0);
mapnik::geometry::geometry geometry = geometry_utils::from_wkb(data, size); mapnik::geometry::geometry<double> geometry = geometry_utils::from_wkb(data, size);
feature->set_geometry(std::move(geometry)); feature->set_geometry(std::move(geometry));
totalGeomSize_ += size; totalGeomSize_ += size;

View file

@ -87,7 +87,7 @@ feature_ptr shape_featureset<filterT>::next()
double y = record.read_double(); double y = record.read_double();
if (!filter_.pass(mapnik::box2d<double>(x,y,x,y))) if (!filter_.pass(mapnik::box2d<double>(x,y,x,y)))
continue; continue;
feature->set_geometry(mapnik::geometry::point(x,y)); feature->set_geometry(mapnik::geometry::point<double>(x,y));
break; break;
} }
case shape_io::shape_multipoint: case shape_io::shape_multipoint:
@ -97,12 +97,12 @@ feature_ptr shape_featureset<filterT>::next()
shape_io::read_bbox(record, feature_bbox_); shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue; if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer(); int num_points = record.read_ndr_integer();
mapnik::geometry::multi_point multi_point; mapnik::geometry::multi_point<double> multi_point;
for (int i = 0; i < num_points; ++i) for (int i = 0; i < num_points; ++i)
{ {
double x = record.read_double(); double x = record.read_double();
double y = record.read_double(); double y = record.read_double();
multi_point.emplace_back(mapnik::geometry::point(x, y)); multi_point.emplace_back(mapnik::geometry::point<double>(x, y));
} }
feature->set_geometry(std::move(multi_point)); feature->set_geometry(std::move(multi_point));
break; break;

View file

@ -103,7 +103,7 @@ feature_ptr shape_index_featureset<filterT>::next()
{ {
double x = record.read_double(); double x = record.read_double();
double y = record.read_double(); double y = record.read_double();
feature->set_geometry(mapnik::geometry::point(x,y)); feature->set_geometry(mapnik::geometry::point<double>(x,y));
break; break;
} }
case shape_io::shape_multipoint: case shape_io::shape_multipoint:
@ -113,12 +113,12 @@ feature_ptr shape_index_featureset<filterT>::next()
shape_io::read_bbox(record, feature_bbox_); shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue; if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer(); int num_points = record.read_ndr_integer();
mapnik::geometry::multi_point multi_point; mapnik::geometry::multi_point<double> multi_point;
for (int i = 0; i < num_points; ++i) for (int i = 0; i < num_points; ++i)
{ {
double x = record.read_double(); double x = record.read_double();
double y = record.read_double(); double y = record.read_double();
multi_point.emplace_back(mapnik::geometry::point(x, y)); multi_point.emplace_back(mapnik::geometry::point<double>(x, y));
} }
feature->set_geometry(std::move(multi_point)); feature->set_geometry(std::move(multi_point));
break; break;

View file

@ -88,15 +88,15 @@ void shape_io::read_bbox(shape_file::record_type & record, mapnik::box2d<double>
bbox.init(lox, loy, hix, hiy); bbox.init(lox, loy, hix, hiy);
} }
mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & record) mapnik::geometry::geometry<double> shape_io::read_polyline(shape_file::record_type & record)
{ {
mapnik::geometry::geometry geom; // default empty mapnik::geometry::geometry<double> geom; // default empty
int num_parts = record.read_ndr_integer(); int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer(); int num_points = record.read_ndr_integer();
if (num_parts == 1) if (num_parts == 1)
{ {
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
line.reserve(num_points); line.reserve(num_points);
record.skip(4); record.skip(4);
for (int i = 0; i < num_points; ++i) for (int i = 0; i < num_points; ++i)
@ -116,7 +116,7 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & rec
} }
int start, end; int start, end;
mapnik::geometry::multi_line_string multi_line; mapnik::geometry::multi_line_string<double> multi_line;
for (int k = 0; k < num_parts; ++k) for (int k = 0; k < num_parts; ++k)
{ {
start = parts[k]; start = parts[k];
@ -129,7 +129,7 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & rec
end = parts[k + 1]; end = parts[k + 1];
} }
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
line.reserve(end - start); line.reserve(end - start);
for (int j = start; j < end; ++j) for (int j = start; j < end; ++j)
{ {
@ -145,9 +145,9 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & rec
} }
mapnik::geometry::geometry shape_io::read_polygon(shape_file::record_type & record) mapnik::geometry::geometry<double> shape_io::read_polygon(shape_file::record_type & record)
{ {
mapnik::geometry::geometry geom; // default empty mapnik::geometry::geometry<double> geom; // default empty
int num_parts = record.read_ndr_integer(); int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer(); int num_points = record.read_ndr_integer();
@ -158,15 +158,15 @@ mapnik::geometry::geometry shape_io::read_polygon(shape_file::record_type & reco
parts[i] = record.read_ndr_integer(); parts[i] = record.read_ndr_integer();
} }
mapnik::geometry::multi_polygon multi_poly; mapnik::geometry::multi_polygon<double> multi_poly;
mapnik::geometry::polygon poly; mapnik::geometry::polygon<double> poly;
for (int k = 0; k < num_parts; ++k) for (int k = 0; k < num_parts; ++k)
{ {
int start = parts[k]; int start = parts[k];
int end; int end;
if (k == num_parts - 1) end = num_points; if (k == num_parts - 1) end = num_points;
else end = parts[k + 1]; else end = parts[k + 1];
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
ring.reserve(end - start); ring.reserve(end - start);
for (int j = start; j < end; ++j) for (int j = start; j < end; ++j)
{ {

View file

@ -76,8 +76,8 @@ public:
void move_to(std::streampos pos); void move_to(std::streampos pos);
static void read_bbox(shape_file::record_type & record, mapnik::box2d<double> & bbox); static void read_bbox(shape_file::record_type & record, mapnik::box2d<double> & bbox);
static mapnik::geometry::geometry read_polyline(shape_file::record_type & record); static mapnik::geometry::geometry<double> read_polyline(shape_file::record_type & record);
static mapnik::geometry::geometry read_polygon(shape_file::record_type & record); static mapnik::geometry::geometry<double> read_polygon(shape_file::record_type & record);
shapeType type_; shapeType type_;
shape_file shp_; shape_file shp_;

View file

@ -448,7 +448,7 @@ boost::optional<mapnik::datasource_geometry_t> sqlite_datasource::get_geometry_t
if (data) if (data)
{ {
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, format_); mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, format_);
if (mapnik::geometry::is_empty(geom)) if (mapnik::geometry::is_empty(geom))
{ {
continue; continue;

View file

@ -81,7 +81,7 @@ feature_ptr sqlite_featureset::next()
} }
feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1)); feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1));
mapnik::geometry::geometry geom = geometry_utils::from_wkb(data, size, format_); mapnik::geometry::geometry<double> geom = geometry_utils::from_wkb(data, size, format_);
if (mapnik::geometry::is_empty(geom)) if (mapnik::geometry::is_empty(geom))
{ {
continue; continue;

View file

@ -196,7 +196,7 @@ public:
const char* data = static_cast<const char*>(rs->column_blob(0, size)); const char* data = static_cast<const char*>(rs->column_blob(0, size));
if (data) if (data)
{ {
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto); mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
if (!mapnik::geometry::is_empty(geom)) if (!mapnik::geometry::is_empty(geom))
{ {
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
@ -280,7 +280,7 @@ public:
const char* data = (const char*) rs->column_blob(0, size); const char* data = (const char*) rs->column_blob(0, size);
if (data) if (data)
{ {
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto); mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
if (!mapnik::geometry::is_empty(geom)) if (!mapnik::geometry::is_empty(geom))
{ {
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
@ -356,7 +356,7 @@ public:
const char* data = static_cast<const char*>(rs->column_blob(0, size)); const char* data = static_cast<const char*>(rs->column_blob(0, size));
if (data) if (data)
{ {
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto); mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
if (!mapnik::geometry::is_empty(geom)) if (!mapnik::geometry::is_empty(geom))
{ {
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);

View file

@ -10,7 +10,8 @@ hello_featureset::hello_featureset(mapnik::box2d<double> const& box, std::string
: box_(box), : box_(box),
feature_id_(1), feature_id_(1),
tr_(new mapnik::transcoder(encoding)), tr_(new mapnik::transcoder(encoding)),
ctx_(std::make_shared<mapnik::context_type>()) { ctx_(std::make_shared<mapnik::context_type>())
{
// add known field names to attributes schema // add known field names to attributes schema
ctx_->push("key"); ctx_->push("key");
} }
@ -35,7 +36,7 @@ mapnik::feature_ptr hello_featureset::next()
mapnik::coord2d center = box_.center(); mapnik::coord2d center = box_.center();
// create a new point geometry // create a new point geometry
feature->set_geometry(mapnik::geometry::point(center.x,center.y)); feature->set_geometry(mapnik::geometry::point<double>(center.x,center.y));
// return the feature! // return the feature!
return feature; return feature;
@ -53,7 +54,7 @@ mapnik::feature_ptr hello_featureset::next()
// take the outer ring of the bbox that was used to query // take the outer ring of the bbox that was used to query
// to dynamically generate a fake line // to dynamically generate a fake line
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
line.reserve(4); line.reserve(4);
line.add_coord(box_.minx(),box_.maxy()); line.add_coord(box_.minx(),box_.maxy());
line.add_coord(box_.maxx(),box_.maxy()); line.add_coord(box_.maxx(),box_.maxy());

View file

@ -96,7 +96,7 @@ struct feature_generator
x = x * (*topo_.tr).scale_x + (*topo_.tr).translate_x; x = x * (*topo_.tr).scale_x + (*topo_.tr).translate_x;
y = y * (*topo_.tr).scale_y + (*topo_.tr).translate_y; y = y * (*topo_.tr).scale_y + (*topo_.tr).translate_y;
} }
mapnik::geometry::point point(x, y); mapnik::geometry::point<double> point(x, y);
feature->set_geometry(std::move(point)); feature->set_geometry(std::move(point));
assign_properties(*feature, pt, tr_); assign_properties(*feature, pt, tr_);
return feature; return feature;
@ -105,7 +105,7 @@ struct feature_generator
feature_ptr operator() (multi_point const& multi_pt) const feature_ptr operator() (multi_point const& multi_pt) const
{ {
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
mapnik::geometry::multi_point multi_point; mapnik::geometry::multi_point<double> multi_point;
multi_point.reserve(multi_pt.points.size()); multi_point.reserve(multi_pt.points.size());
for (auto const& pt : multi_pt.points) for (auto const& pt : multi_pt.points)
{ {
@ -129,7 +129,7 @@ struct feature_generator
double px = 0, py = 0; double px = 0, py = 0;
index_type arc_index = line.ring; index_type arc_index = line.ring;
mapnik::geometry::line_string line_string; mapnik::geometry::line_string<double> line_string;
line_string.reserve( topo_.arcs[arc_index].coordinates.size()); line_string.reserve( topo_.arcs[arc_index].coordinates.size());
for (auto pt : topo_.arcs[arc_index].coordinates) for (auto pt : topo_.arcs[arc_index].coordinates)
@ -152,14 +152,14 @@ struct feature_generator
{ {
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
mapnik::geometry::multi_line_string multi_line_string; mapnik::geometry::multi_line_string<double> multi_line_string;
multi_line_string.reserve(multi_line.rings.size()); multi_line_string.reserve(multi_line.rings.size());
for (auto const& index : multi_line.rings) for (auto const& index : multi_line.rings)
{ {
double px = 0, py = 0; double px = 0, py = 0;
bool reverse = index < 0; bool reverse = index < 0;
index_type arc_index = reverse ? std::abs(index) - 1 : index; index_type arc_index = reverse ? std::abs(index) - 1 : index;
mapnik::geometry::line_string line_string; mapnik::geometry::line_string<double> line_string;
line_string.reserve(topo_.arcs[arc_index].coordinates.size()); line_string.reserve(topo_.arcs[arc_index].coordinates.size());
for (auto pt : topo_.arcs[arc_index].coordinates) for (auto pt : topo_.arcs[arc_index].coordinates)
{ {
@ -183,12 +183,12 @@ struct feature_generator
{ {
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
std::vector<mapnik::topojson::coordinate> processed_coords; std::vector<mapnik::topojson::coordinate> processed_coords;
mapnik::geometry::polygon polygon; mapnik::geometry::polygon<double> polygon;
if (poly.rings.size() > 1) polygon.interior_rings.reserve(poly.rings.size() - 1); if (poly.rings.size() > 1) polygon.interior_rings.reserve(poly.rings.size() - 1);
bool first = true; bool first = true;
for (auto const& ring : poly.rings) for (auto const& ring : poly.rings)
{ {
mapnik::geometry::linear_ring linear_ring; mapnik::geometry::linear_ring<double> linear_ring;
for (auto const& index : ring) for (auto const& index : ring)
{ {
double px = 0, py = 0; double px = 0, py = 0;
@ -248,18 +248,18 @@ struct feature_generator
{ {
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
std::vector<mapnik::topojson::coordinate> processed_coords; std::vector<mapnik::topojson::coordinate> processed_coords;
mapnik::geometry::multi_polygon multi_polygon; mapnik::geometry::multi_polygon<double> multi_polygon;
multi_polygon.reserve(multi_poly.polygons.size()); multi_polygon.reserve(multi_poly.polygons.size());
for (auto const& poly : multi_poly.polygons) for (auto const& poly : multi_poly.polygons)
{ {
bool first = true; bool first = true;
mapnik::geometry::polygon polygon; mapnik::geometry::polygon<double> polygon;
if (poly.size() > 1) polygon.interior_rings.reserve(poly.size() - 1); if (poly.size() > 1) polygon.interior_rings.reserve(poly.size() - 1);
for (auto const& ring : poly) for (auto const& ring : poly)
{ {
mapnik::geometry::linear_ring linear_ring; mapnik::geometry::linear_ring<double> linear_ring;
for (auto const& index : ring) for (auto const& index : ring)
{ {
double px = 0, py = 0; double px = 0, py = 0;

View file

@ -110,7 +110,7 @@ struct RingRenderer {
using renderer_base = agg::renderer_base<pixfmt_comp_type>; using renderer_base = agg::renderer_base<pixfmt_comp_type>;
using renderer_type = agg::renderer_scanline_aa_solid<renderer_base>; using renderer_type = agg::renderer_scanline_aa_solid<renderer_base>;
using path_type = transform_path_adapter<view_transform, geometry::ring_vertex_adapter>; using path_type = transform_path_adapter<view_transform, geometry::ring_vertex_adapter<double> >;
RingRenderer(rasterizer & ras_ptr, RingRenderer(rasterizer & ras_ptr,
BufferType & im, BufferType & im,
@ -122,7 +122,7 @@ struct RingRenderer {
prj_trans_(prj_trans), prj_trans_(prj_trans),
sl_() {} sl_() {}
void draw_ring(geometry::linear_ring const& ring, void draw_ring(geometry::linear_ring<double> const& ring,
agg::rgba8 const& color) agg::rgba8 const& color)
{ {
ras_ptr_.reset(); ras_ptr_.reset();
@ -130,7 +130,7 @@ struct RingRenderer {
pixfmt_comp_type pixf(buf); pixfmt_comp_type pixf(buf);
renderer_base renb(pixf); renderer_base renb(pixf);
renderer_type ren(renb); renderer_type ren(renb);
geometry::ring_vertex_adapter va(ring); geometry::ring_vertex_adapter<double> va(ring);
path_type path(tr_,va,prj_trans_); path_type path(tr_,va,prj_trans_);
ras_ptr_.add_path(path); ras_ptr_.add_path(path);
ras_ptr_.filling_rule(agg::fill_non_zero); ras_ptr_.filling_rule(agg::fill_non_zero);
@ -138,7 +138,7 @@ struct RingRenderer {
agg::render_scanlines(ras_ptr_, sl_, ren); agg::render_scanlines(ras_ptr_, sl_, ren);
} }
void draw_outline(geometry::linear_ring const& ring, void draw_outline(geometry::linear_ring<double> const& ring,
agg::rgba8 const& color, agg::rgba8 const& color,
double stroke_width=3) double stroke_width=3)
{ {
@ -147,7 +147,7 @@ struct RingRenderer {
pixfmt_comp_type pixf(buf); pixfmt_comp_type pixf(buf);
renderer_base renb(pixf); renderer_base renb(pixf);
renderer_type ren(renb); renderer_type ren(renb);
geometry::ring_vertex_adapter va(ring); geometry::ring_vertex_adapter<double> va(ring);
path_type path(tr_,va,prj_trans_); path_type path(tr_,va,prj_trans_);
agg::conv_stroke<path_type> stroke(path); agg::conv_stroke<path_type> stroke(path);
stroke.width(stroke_width); stroke.width(stroke_width);
@ -170,7 +170,7 @@ struct render_ring_visitor {
render_ring_visitor(RingRenderer<BufferType> & renderer) render_ring_visitor(RingRenderer<BufferType> & renderer)
: renderer_(renderer) {} : renderer_(renderer) {}
void operator()(mapnik::geometry::multi_polygon const& geom) void operator()(mapnik::geometry::multi_polygon<double> const& geom)
{ {
for (auto const& poly : geom) for (auto const& poly : geom)
{ {
@ -178,7 +178,7 @@ struct render_ring_visitor {
} }
} }
void operator()(mapnik::geometry::polygon const& geom) void operator()(mapnik::geometry::polygon<double> const& geom)
{ {
agg::rgba8 red(255,0,0,255); agg::rgba8 red(255,0,0,255);
agg::rgba8 green(0,255,255,255); agg::rgba8 green(0,255,255,255);

View file

@ -26,16 +26,25 @@
namespace mapnik { namespace mapnik {
namespace geometry { namespace geometry {
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(geometry<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(mapnik::base_symbolizer_helper::geometry_cref const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(mapnik::base_symbolizer_helper::geometry_cref const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_empty const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_empty const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(point const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(point<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(line_string const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(line_string<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(polygon const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(polygon<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_point const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(multi_point<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_line_string const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(multi_line_string<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_polygon const& geom); template MAPNIK_DECL mapnik::box2d<double> envelope(multi_polygon<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_collection 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 geometry
} // end ns mapnik } // end ns mapnik

View file

@ -22,399 +22,51 @@
// mapnik // mapnik
#include <mapnik/geometry_reprojection.hpp> #include <mapnik/geometry_reprojection.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry_reprojection_impl.hpp>
namespace mapnik { namespace mapnik {
namespace geometry { namespace geometry {
namespace detail { template MAPNIK_DECL geometry<double> reproject_copy(geometry<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
geometry_empty reproject_internal(geometry_empty const&, proj_transform const&, unsigned int &)
{
return geometry_empty();
}
point reproject_internal(point const & p, proj_transform const& proj_trans, unsigned int & n_err)
{
point new_p(p);
if (!proj_trans.forward(new_p))
{
++n_err;
}
return new_p;
}
line_string reproject_internal(line_string const & ls, proj_transform const& proj_trans, unsigned int & n_err)
{
line_string new_ls(ls);
unsigned int err = proj_trans.forward(new_ls);
if (err > 0)
{
n_err += err;
}
return new_ls;
}
polygon reproject_internal(polygon const & poly, proj_transform const& proj_trans, unsigned int & n_err)
{
polygon new_poly;
linear_ring new_ext(poly.exterior_ring);
unsigned int err = proj_trans.forward(new_ext);
// If the exterior ring doesn't transform don't bother with the holes.
if (err > 0 || new_ext.empty())
{
n_err += err;
}
else
{
new_poly.set_exterior_ring(std::move(new_ext));
new_poly.interior_rings.reserve(poly.interior_rings.size());
for (auto const& lr : poly.interior_rings)
{
linear_ring new_lr(lr);
err = proj_trans.forward(new_lr);
if (err > 0 || new_lr.empty())
{
n_err += err;
// If there is an error in interior ring drop
// it from polygon.
continue;
}
new_poly.add_hole(std::move(new_lr));
}
}
return new_poly;
}
multi_point reproject_internal(multi_point const & mp, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_point new_mp;
if (proj_trans.is_known())
{
// If the projection is known we do them all at once because it is faster
// since we know that no point will fail reprojection
new_mp.assign(mp.begin(), mp.end());
proj_trans.forward(new_mp);
}
else
{
new_mp.reserve(mp.size());
for (auto const& p : mp)
{
point new_p(p);
if (!proj_trans.forward(new_p))
{
++n_err;
}
else
{
new_mp.emplace_back(std::move(new_p));
}
}
}
return new_mp;
}
multi_line_string reproject_internal(multi_line_string const & mls, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_line_string new_mls;
new_mls.reserve(mls.size());
for (auto const& ls : mls)
{
line_string new_ls = reproject_internal(ls, proj_trans, n_err);
if (!new_ls.empty())
{
new_mls.emplace_back(std::move(new_ls));
}
}
return new_mls;
}
multi_polygon reproject_internal(multi_polygon const & mpoly, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_polygon new_mpoly;
new_mpoly.reserve(mpoly.size());
for (auto const& poly : mpoly)
{
polygon new_poly = reproject_internal(poly, proj_trans, n_err);
if (!new_poly.exterior_ring.empty())
{
new_mpoly.emplace_back(std::move(new_poly));
}
}
return new_mpoly;
}
geometry_collection reproject_internal(geometry_collection const & c, proj_transform const& proj_trans, unsigned int & n_err)
{
geometry_collection new_c;
new_c.reserve(c.size());
for (auto const& g : c)
{
geometry new_g(std::move(reproject_copy(g, proj_trans, n_err)));
if (!new_g.is<geometry_empty>())
{
new_c.emplace_back(std::move(new_g));
}
}
return new_c;
}
struct geom_reproj_copy_visitor {
geom_reproj_copy_visitor(proj_transform const & proj_trans, unsigned int & n_err)
: proj_trans_(proj_trans),
n_err_(n_err) {}
geometry operator() (geometry_empty const&)
{
return geometry_empty();
}
geometry operator() (point const& p)
{
geometry geom; // default empty
unsigned int intial_err = n_err_;
point new_p = reproject_internal(p, proj_trans_, n_err_);
if (n_err_ > intial_err) return geom;
geom = std::move(new_p);
return geom;
}
geometry operator() (line_string const& ls)
{
geometry geom; // default empty
int intial_err = n_err_;
line_string new_ls = reproject_internal(ls, proj_trans_, n_err_);
if (n_err_ > intial_err || new_ls.empty()) return geom;
geom = std::move(new_ls);
return geom;
}
geometry operator() (polygon const& poly)
{
geometry geom; // default empty
polygon new_poly = reproject_internal(poly, proj_trans_, n_err_);
if (new_poly.exterior_ring.empty()) return geom;
geom = std::move(new_poly);
return geom;
}
geometry operator() (multi_point const& mp)
{
geometry geom; // default empty
multi_point new_mp = reproject_internal(mp, proj_trans_, n_err_);
if (new_mp.empty()) return geom;
geom = std::move(new_mp);
return geom;
}
geometry operator() (multi_line_string const& mls)
{
geometry geom; // default empty
multi_line_string new_mls = reproject_internal(mls, proj_trans_, n_err_);
if (new_mls.empty()) return geom;
geom = std::move(new_mls);
return geom;
}
geometry operator() (multi_polygon const& mpoly)
{
geometry geom; // default empty
multi_polygon new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
if (new_mpoly.empty()) return geom;
geom = std::move(new_mpoly);
return geom;
}
geometry operator() (geometry_collection const& c)
{
geometry geom; // default empty
geometry_collection new_c = reproject_internal(c, proj_trans_, n_err_);
if (new_c.empty()) return geom;
geom = std::move(new_c);
return geom;
}
private:
proj_transform const& proj_trans_;
unsigned int & n_err_;
};
} // end detail ns
geometry reproject_copy(geometry const& geom, proj_transform const& proj_trans, unsigned int & n_err)
{
detail::geom_reproj_copy_visitor visit(proj_trans, n_err);
return mapnik::util::apply_visitor(visit, geom);
}
template <typename T>
T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err)
{
return detail::reproject_internal(geom, proj_trans, n_err);
}
template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL point reproject_copy(point const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL point<double> reproject_copy(point<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL line_string reproject_copy(line_string const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL line_string<double> reproject_copy(line_string<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL polygon reproject_copy(polygon const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL polygon<double> reproject_copy(polygon<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_point reproject_copy(multi_point const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL multi_point<double> reproject_copy(multi_point<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_line_string reproject_copy(multi_line_string const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL multi_line_string<double> reproject_copy(multi_line_string<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_polygon reproject_copy(multi_polygon const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL multi_polygon<double> reproject_copy(multi_polygon<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL geometry_collection reproject_copy(geometry_collection const& geom, proj_transform const& proj_trans, unsigned int & n_err); template MAPNIK_DECL geometry_collection<double> reproject_copy(geometry_collection<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template <typename T> template MAPNIK_DECL geometry<double> reproject_copy(geometry<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int & n_err)
{
proj_transform proj_trans(source, dest);
return reproject_copy(geom, proj_trans, n_err);
}
template MAPNIK_DECL geometry reproject_copy(geometry const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL point reproject_copy(point const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL point<double> reproject_copy(point<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL line_string reproject_copy(line_string const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL line_string<double> reproject_copy(line_string<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL polygon reproject_copy(polygon const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL polygon<double> reproject_copy(polygon<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_point reproject_copy(multi_point const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL multi_point<double> reproject_copy(multi_point<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_line_string reproject_copy(multi_line_string const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL multi_line_string<double> reproject_copy(multi_line_string<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_polygon reproject_copy(multi_polygon const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL multi_polygon<double> reproject_copy(multi_polygon<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL geometry_collection reproject_copy(geometry_collection const& geom, projection const& source, projection const& dest, unsigned int & n_err); template MAPNIK_DECL geometry_collection<double> reproject_copy(geometry_collection<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
namespace detail { template MAPNIK_DECL bool reproject(geometry<double> & geom, proj_transform const& proj_trans);
struct geom_reproj_visitor {
geom_reproj_visitor(proj_transform const & proj_trans)
: proj_trans_(proj_trans) {}
bool operator() (geometry & geom)
{
return mapnik::util::apply_visitor((*this), geom);
}
bool operator() (geometry_empty &) { return true; }
bool operator() (point & p)
{
if (!proj_trans_.forward(p))
{
return false;
}
return true;
}
bool operator() (line_string & ls)
{
if (proj_trans_.forward(ls) > 0)
{
return false;
}
return true;
}
bool operator() (polygon & poly)
{
if (proj_trans_.forward(poly.exterior_ring) > 0)
{
return false;
}
for (auto & lr : poly.interior_rings)
{
if (proj_trans_.forward(lr) > 0)
{
return false;
}
}
return true;
}
bool operator() (multi_point & mp)
{
return (*this) (static_cast<line_string &>(mp));
}
bool operator() (multi_line_string & mls)
{
for (auto & ls : mls)
{
if (! (*this) (ls))
{
return false;
}
}
return true;
}
bool operator() (multi_polygon & mpoly)
{
for (auto & poly : mpoly)
{
if(! (*this)(poly))
{
return false;
}
}
return true;
}
bool operator() (geometry_collection & c)
{
for (auto & g : c)
{
if (! (*this)(g) )
{
return false;
}
}
return true;
}
private:
proj_transform const& proj_trans_;
};
} // end detail ns
template <typename T>
bool reproject(T & geom, proj_transform const& proj_trans)
{
detail::geom_reproj_visitor visit(proj_trans);
return visit(geom);
}
template MAPNIK_DECL bool reproject(geometry & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(geometry_empty & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(geometry_empty & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(point & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(point<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(line_string & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(line_string<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(polygon & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(polygon<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_point & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(multi_point<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_line_string & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(multi_line_string<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_polygon & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(multi_polygon<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(geometry_collection & geom, proj_transform const& proj_trans); template MAPNIK_DECL bool reproject(geometry_collection<double> & geom, proj_transform const& proj_trans);
template <typename T> template MAPNIK_DECL bool reproject(geometry<double> & geom, projection const& source, projection const& dest);
bool reproject(T & geom, projection const& source, projection const& dest)
{
proj_transform proj_trans(source, dest);
detail::geom_reproj_visitor visit(proj_trans);
return visit(geom);
}
template MAPNIK_DECL bool reproject(geometry & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(geometry_empty & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(geometry_empty & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(point & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(point<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(line_string & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(line_string<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(polygon & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(polygon<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_point & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(multi_point<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_line_string & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(multi_line_string<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_polygon & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(multi_polygon<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(geometry_collection & geom, projection const& source, projection const& dest); template MAPNIK_DECL bool reproject(geometry_collection<double> & geom, projection const& source, projection const& dest);
} // end geometry ns } // end geometry ns

View file

@ -32,4 +32,4 @@ using sink_type = std::back_insert_iterator<std::string>;
template struct mapnik::json::properties_generator_grammar<sink_type, mapnik::feature_impl>; template struct mapnik::json::properties_generator_grammar<sink_type, mapnik::feature_impl>;
template struct mapnik::json::feature_generator_grammar<sink_type, mapnik::feature_impl>; template struct mapnik::json::feature_generator_grammar<sink_type, mapnik::feature_impl>;
template struct mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry>; template struct mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry<double> >;

View file

@ -97,14 +97,17 @@ bool proj_transform::forward (double & x, double & y , double & z) const
return forward(&x, &y, &z, 1); return forward(&x, &y, &z, 1);
} }
bool proj_transform::forward (geometry::point & p) const bool proj_transform::forward (geometry::point<double> & p) const
{ {
double z = 0; double z = 0;
return forward(&(p.x), &(p.y), &z, 1); return forward(&(p.x), &(p.y), &z, 1);
} }
unsigned int proj_transform::forward (geometry::line_string & ls) const unsigned int proj_transform::forward (geometry::line_string<double> & ls) const
{ {
std::size_t size = ls.size();
if (size == 0) return 0;
if (is_source_equal_dest_) if (is_source_equal_dest_)
return 0; return 0;
@ -119,18 +122,18 @@ unsigned int proj_transform::forward (geometry::line_string & ls) const
return 0; return 0;
} }
unsigned int err_n = 0; geometry::point<double> * ptr = ls.data();
for (auto & p : ls) double * x = reinterpret_cast<double*>(ptr);
double * y = x + 1;
double * z = NULL;
if(!forward(x, y, z, size, 2))
{ {
if (!forward(p)) return size;
{
err_n++;
} }
} return 0;
return err_n;
} }
bool proj_transform::forward (double * x, double * y , double * z, int point_count) const bool proj_transform::forward (double * x, double * y , double * z, int point_count, int offset) const
{ {
if (is_source_equal_dest_) if (is_source_equal_dest_)
@ -150,13 +153,13 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
{ {
int i; int i;
for(i=0; i<point_count; i++) { for(i=0; i<point_count; i++) {
x[i] *= DEG_TO_RAD; x[i*offset] *= DEG_TO_RAD;
y[i] *= DEG_TO_RAD; y[i*offset] *= DEG_TO_RAD;
} }
} }
if (pj_transform( source_.proj_, dest_.proj_, point_count, if (pj_transform( source_.proj_, dest_.proj_, point_count,
0, x,y,z) != 0) offset, x,y,z) != 0)
{ {
return false; return false;
} }
@ -165,15 +168,15 @@ bool proj_transform::forward (double * x, double * y , double * z, int point_cou
{ {
int i; int i;
for(i=0; i<point_count; i++) { for(i=0; i<point_count; i++) {
x[i] *= RAD_TO_DEG; x[i*offset] *= RAD_TO_DEG;
y[i] *= RAD_TO_DEG; y[i*offset] *= RAD_TO_DEG;
} }
} }
#endif #endif
return true; return true;
} }
bool proj_transform::backward (double * x, double * y , double * z, int point_count) const bool proj_transform::backward (double * x, double * y , double * z, int point_count, int offset) const
{ {
if (is_source_equal_dest_) if (is_source_equal_dest_)
return true; return true;
@ -192,13 +195,13 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
{ {
int i; int i;
for(i=0; i<point_count; i++) { for(i=0; i<point_count; i++) {
x[i] *= DEG_TO_RAD; x[i*offset] *= DEG_TO_RAD;
y[i] *= DEG_TO_RAD; y[i*offset] *= DEG_TO_RAD;
} }
} }
if (pj_transform( dest_.proj_, source_.proj_, point_count, if (pj_transform( dest_.proj_, source_.proj_, point_count,
0, x,y,z) != 0) offset, x,y,z) != 0)
{ {
return false; return false;
} }
@ -207,8 +210,8 @@ bool proj_transform::backward (double * x, double * y , double * z, int point_co
{ {
int i; int i;
for(i=0; i<point_count; i++) { for(i=0; i<point_count; i++) {
x[i] *= RAD_TO_DEG; x[i*offset] *= RAD_TO_DEG;
y[i] *= RAD_TO_DEG; y[i*offset] *= RAD_TO_DEG;
} }
} }
#endif #endif
@ -220,14 +223,17 @@ bool proj_transform::backward (double & x, double & y , double & z) const
return backward(&x, &y, &z, 1); return backward(&x, &y, &z, 1);
} }
bool proj_transform::backward (geometry::point & p) const bool proj_transform::backward (geometry::point<double> & p) const
{ {
double z = 0; double z = 0;
return backward(&(p.x), &(p.y), &z, 1); return backward(&(p.x), &(p.y), &z, 1);
} }
unsigned int proj_transform::backward (geometry::line_string & ls) const unsigned int proj_transform::backward (geometry::line_string<double> & ls) const
{ {
std::size_t size = ls.size();
if (size == 0) return 0;
if (is_source_equal_dest_) if (is_source_equal_dest_)
return 0; return 0;
@ -242,15 +248,15 @@ unsigned int proj_transform::backward (geometry::line_string & ls) const
return 0; return 0;
} }
unsigned int err_n = 0; geometry::point<double> * ptr = ls.data();
for (auto & p : ls) double * x = reinterpret_cast<double*>(ptr);
double * y = x + 1;
double * z = NULL;
if(!backward(x, y, z, size, 2))
{ {
if (!backward(p)) return size;
{
err_n++;
} }
} return 0;
return err_n;
} }
bool proj_transform::forward (box2d<double> & box) const bool proj_transform::forward (box2d<double> & box) const

View file

@ -86,14 +86,14 @@ struct split_multi_geometries
minimum_path_length_(minimum_path_length) {} minimum_path_length_(minimum_path_length) {}
void operator() (geometry::geometry_empty const&) const {} void operator() (geometry::geometry_empty const&) const {}
void operator() (geometry::multi_point const& multi_pt) const void operator() (geometry::multi_point<double> const& multi_pt) const
{ {
for ( auto const& pt : multi_pt ) for ( auto const& pt : multi_pt )
{ {
cont_.push_back(std::move(base_symbolizer_helper::geometry_cref(std::cref(pt)))); cont_.push_back(std::move(base_symbolizer_helper::geometry_cref(std::cref(pt))));
} }
} }
void operator() (geometry::multi_line_string const& multi_line) const void operator() (geometry::multi_line_string<double> const& multi_line) const
{ {
for ( auto const& line : multi_line ) for ( auto const& line : multi_line )
{ {
@ -101,7 +101,7 @@ struct split_multi_geometries
} }
} }
void operator() (geometry::polygon const& poly) const void operator() (geometry::polygon<double> const& poly) const
{ {
if (minimum_path_length_ > 0) if (minimum_path_length_ > 0)
{ {
@ -117,7 +117,7 @@ struct split_multi_geometries
} }
} }
void operator() (geometry::multi_polygon const& multi_poly) const void operator() (geometry::multi_polygon<double> const& multi_poly) const
{ {
for ( auto const& poly : multi_poly ) for ( auto const& poly : multi_poly )
{ {
@ -125,7 +125,7 @@ struct split_multi_geometries
} }
} }
void operator() (geometry::geometry_collection const& collection) const void operator() (geometry::geometry_collection<double> const& collection) const
{ {
for ( auto const& geom : collection) for ( auto const& geom : collection)
{ {
@ -173,7 +173,7 @@ base_symbolizer_helper::base_symbolizer_helper(
struct largest_bbox_first struct largest_bbox_first
{ {
bool operator() (geometry::geometry const* g0, geometry::geometry const* g1) const bool operator() (geometry::geometry<double> const* g0, geometry::geometry<double> const* g1) const
{ {
box2d<double> b0 = geometry::envelope(*g0); box2d<double> b0 = geometry::envelope(*g0);
box2d<double> b1 = geometry::envelope(*g1); box2d<double> b1 = geometry::envelope(*g1);
@ -239,13 +239,13 @@ void base_symbolizer_helper::initialize_points() const
// FIXME: how to handle MultiLineString? // FIXME: how to handle MultiLineString?
if (type == geometry::geometry_types::LineString) if (type == geometry::geometry_types::LineString)
{ {
auto const& line = mapnik::util::get<geometry::line_string>(geom); auto const& line = mapnik::util::get<geometry::line_string<double> >(geom);
geometry::line_string_vertex_adapter va(line); geometry::line_string_vertex_adapter<double> va(line);
success = label::middle_point(va, label_x,label_y); success = label::middle_point(va, label_x,label_y);
} }
else if (how_placed == POINT_PLACEMENT) else if (how_placed == POINT_PLACEMENT)
{ {
geometry::point pt; geometry::point<double> pt;
geometry::centroid(geom, pt); geometry::centroid(geom, pt);
label_x = pt.x; label_x = pt.x;
label_y = pt.y; label_y = pt.y;
@ -255,8 +255,8 @@ void base_symbolizer_helper::initialize_points() const
{ {
if (type == geometry::geometry_types::Polygon) if (type == geometry::geometry_types::Polygon)
{ {
auto const& poly = mapnik::util::get<geometry::polygon>(geom); auto const& poly = mapnik::util::get<geometry::polygon<double> >(geom);
geometry::polygon_vertex_adapter va(poly); geometry::polygon_vertex_adapter<double> va(poly);
success = label::interior_position(va, label_x, label_y); success = label::interior_position(va, label_x, label_y);
} }
} }
@ -333,8 +333,8 @@ bool text_symbolizer_helper::next_line_placement() const
if (geo_itr_->is<base_symbolizer_helper::line_string_cref>()) // line_string if (geo_itr_->is<base_symbolizer_helper::line_string_cref>()) // line_string
{ {
auto const& line = util::get<geometry::line_string const>(*geo_itr_); auto const& line = util::get<geometry::line_string<double> const>(*geo_itr_);
geometry::line_string_vertex_adapter va(line); geometry::line_string_vertex_adapter<double> va(line);
converter_.apply(va); converter_.apply(va);
if (adapter_.status()) if (adapter_.status())
{ {

View file

@ -118,9 +118,9 @@ public:
needSwap_ = byteOrder_ ? wkbXDR : wkbNDR; needSwap_ = byteOrder_ ? wkbXDR : wkbNDR;
} }
mapnik::geometry::geometry read() mapnik::geometry::geometry<double> read()
{ {
mapnik::geometry::geometry geom = mapnik::geometry::geometry_empty(); mapnik::geometry::geometry<double> geom = mapnik::geometry::geometry_empty();
int type = read_integer(); int type = read_integer();
switch (type) switch (type)
{ {
@ -263,19 +263,19 @@ private:
} }
template <bool Z = false, bool M = false> template <bool Z = false, bool M = false>
mapnik::geometry::point read_point() mapnik::geometry::point<double> read_point()
{ {
double x = read_double(); double x = read_double();
double y = read_double(); double y = read_double();
if (Z) pos_ += 8; if (Z) pos_ += 8;
if (M) pos_ += 8; if (M) pos_ += 8;
return mapnik::geometry::point(x, y); return mapnik::geometry::point<double>(x, y);
} }
template <bool Z = false, bool M = false> template <bool Z = false, bool M = false>
mapnik::geometry::multi_point read_multipoint() mapnik::geometry::multi_point<double> read_multipoint()
{ {
mapnik::geometry::multi_point multi_point; mapnik::geometry::multi_point<double> multi_point;
int num_points = read_integer(); int num_points = read_integer();
multi_point.reserve(num_points); multi_point.reserve(num_points);
for (int i = 0; i < num_points; ++i) for (int i = 0; i < num_points; ++i)
@ -287,23 +287,23 @@ private:
} }
template <bool M = false, bool Z = false> template <bool M = false, bool Z = false>
mapnik::geometry::line_string read_linestring() mapnik::geometry::line_string<double> read_linestring()
{ {
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
int num_points = read_integer(); int num_points = read_integer();
if (num_points > 0) if (num_points > 0)
{ {
line.reserve(num_points); line.reserve(num_points);
read_coords<mapnik::geometry::line_string, M, Z>(line, num_points); read_coords<mapnik::geometry::line_string<double>, M, Z>(line, num_points);
} }
return line; return line;
} }
template <bool M = false, bool Z = false> template <bool M = false, bool Z = false>
mapnik::geometry::multi_line_string read_multilinestring() mapnik::geometry::multi_line_string<double> read_multilinestring()
{ {
int num_lines = read_integer(); int num_lines = read_integer();
mapnik::geometry::multi_line_string multi_line; mapnik::geometry::multi_line_string<double> multi_line;
multi_line.reserve(num_lines); multi_line.reserve(num_lines);
for (int i = 0; i < num_lines; ++i) for (int i = 0; i < num_lines; ++i)
{ {
@ -314,10 +314,10 @@ private:
} }
template <bool M = false, bool Z = false> template <bool M = false, bool Z = false>
mapnik::geometry::polygon read_polygon() mapnik::geometry::polygon<double> read_polygon()
{ {
int num_rings = read_integer(); int num_rings = read_integer();
mapnik::geometry::polygon poly; mapnik::geometry::polygon<double> poly;
if (num_rings > 1) if (num_rings > 1)
{ {
poly.interior_rings.reserve(num_rings - 1); poly.interior_rings.reserve(num_rings - 1);
@ -325,12 +325,12 @@ private:
for (int i = 0; i < num_rings; ++i) for (int i = 0; i < num_rings; ++i)
{ {
mapnik::geometry::linear_ring ring; mapnik::geometry::linear_ring<double> ring;
int num_points = read_integer(); int num_points = read_integer();
if (num_points > 0) if (num_points > 0)
{ {
ring.reserve(num_points); ring.reserve(num_points);
read_coords<mapnik::geometry::linear_ring, M, Z>(ring, num_points); read_coords<mapnik::geometry::linear_ring<double>, M, Z>(ring, num_points);
} }
if ( i == 0) poly.set_exterior_ring(std::move(ring)); if ( i == 0) poly.set_exterior_ring(std::move(ring));
else poly.add_hole(std::move(ring)); else poly.add_hole(std::move(ring));
@ -339,10 +339,10 @@ private:
} }
template <bool M = false, bool Z = false> template <bool M = false, bool Z = false>
mapnik::geometry::multi_polygon read_multipolygon() mapnik::geometry::multi_polygon<double> read_multipolygon()
{ {
int num_polys = read_integer(); int num_polys = read_integer();
mapnik::geometry::multi_polygon multi_poly; mapnik::geometry::multi_polygon<double> multi_poly;
for (int i = 0; i < num_polys; ++i) for (int i = 0; i < num_polys; ++i)
{ {
pos_ += 5; pos_ += 5;
@ -351,10 +351,10 @@ private:
return multi_poly; return multi_poly;
} }
mapnik::geometry::geometry_collection read_collection() mapnik::geometry::geometry_collection<double> read_collection()
{ {
int num_geometries = read_integer(); int num_geometries = read_integer();
mapnik::geometry::geometry_collection collection; mapnik::geometry::geometry_collection<double> collection;
for (int i = 0; i < num_geometries; ++i) for (int i = 0; i < num_geometries; ++i)
{ {
pos_ += 1; // skip byte order pos_ += 1; // skip byte order
@ -405,12 +405,12 @@ private:
}; };
mapnik::geometry::geometry geometry_utils::from_wkb(const char* wkb, mapnik::geometry::geometry<double> geometry_utils::from_wkb(const char* wkb,
unsigned size, unsigned size,
wkbFormat format) wkbFormat format)
{ {
wkb_reader reader(wkb, size, format); wkb_reader reader(wkb, size, format);
mapnik::geometry::geometry geom(reader.read()); mapnik::geometry::geometry<double> geom(reader.read());
mapnik::geometry::correct(geom); mapnik::geometry::correct(geom);
return geom; return geom;
} }

View file

@ -27,6 +27,7 @@
namespace mapnik { namespace wkt { namespace mapnik { namespace wkt {
using sink_type = std::back_insert_iterator<std::string>; using sink_type = std::back_insert_iterator<std::string>;
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry>; 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

@ -50,7 +50,7 @@ int main(int argc, char** argv)
feature->put("name",ustr); feature->put("name",ustr);
//auto pt = std::make_unique<mapnik::geometry_type>(mapnik::geometry::geometry_types::Point); //auto pt = std::make_unique<mapnik::geometry_type>(mapnik::geometry::geometry_types::Point);
//pt->move_to(128,128); //pt->move_to(128,128);
mapnik::geometry::point pt(128,128); mapnik::geometry::point<double> pt(128,128);
feature->set_geometry(std::move(pt)); feature->set_geometry(std::move(pt));
mapnik::parameters params; mapnik::parameters params;

View file

@ -18,10 +18,10 @@ int main(int argc, char** argv)
try try
{ {
// reused these for simplicity // reused these for simplicity
mapnik::geometry::point centroid; mapnik::geometry::point<double> centroid;
{ {
// single point // single point
mapnik::geometry::point pt(10,10); mapnik::geometry::point<double> pt(10,10);
BOOST_TEST( mapnik::geometry::centroid(pt, centroid)); BOOST_TEST( mapnik::geometry::centroid(pt, centroid));
BOOST_TEST( pt.x == centroid.x); BOOST_TEST( pt.x == centroid.x);
BOOST_TEST( pt.y == centroid.y); BOOST_TEST( pt.y == centroid.y);
@ -29,7 +29,7 @@ int main(int argc, char** argv)
// linestring with three consecutive verticies // linestring with three consecutive verticies
{ {
mapnik::geometry::line_string line; mapnik::geometry::line_string<double> line;
line.add_coord(0, 0); line.add_coord(0, 0);
line.add_coord(25, 25); line.add_coord(25, 25);
line.add_coord(50, 50); line.add_coord(50, 50);

View file

@ -68,7 +68,7 @@ int main(int argc, char** argv)
try { try {
// spatialite blob // spatialite blob
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob, mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob,
sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]), sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]),
mapnik::wkbSpatiaLite); mapnik::wkbSpatiaLite);
BOOST_TEST(mapnik::geometry::is_valid(geom) && mapnik::geometry::is_simple(geom)); BOOST_TEST(mapnik::geometry::is_valid(geom) && mapnik::geometry::is_simple(geom));

View file

@ -29,13 +29,13 @@ SECTION("hello world") {
REQUIRE( feat1->id() == static_cast<mapnik::value_integer>(1) ); REQUIRE( feat1->id() == static_cast<mapnik::value_integer>(1) );
REQUIRE( feat2->id() == static_cast<mapnik::value_integer>(2) ); REQUIRE( feat2->id() == static_cast<mapnik::value_integer>(2) );
auto const& geom1 = feat1->get_geometry(); auto const& geom1 = feat1->get_geometry();
REQUIRE( geom1.is<mapnik::geometry::point>() ); REQUIRE( geom1.is<mapnik::geometry::point<double> >() );
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom1); auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom1);
REQUIRE( point.x == bbox.center().x ); REQUIRE( point.x == bbox.center().x );
REQUIRE( point.y == bbox.center().y ); REQUIRE( point.y == bbox.center().y );
auto const& geom2 = feat2->get_geometry(); auto const& geom2 = feat2->get_geometry();
REQUIRE( geom2.is<mapnik::geometry::line_string>() ); REQUIRE( geom2.is<mapnik::geometry::line_string<double> >() );
auto const& line = mapnik::util::get<mapnik::geometry::line_string>(geom2); auto const& line = mapnik::util::get<mapnik::geometry::line_string<double> >(geom2);
REQUIRE( line.size() == 4 ); REQUIRE( line.size() == 4 );
REQUIRE( line[0].x == bbox.minx() ); REQUIRE( line[0].x == bbox.minx() );
REQUIRE( line[0].y == bbox.maxy() ); REQUIRE( line[0].y == bbox.maxy() );

View file

@ -11,11 +11,11 @@ TEST_CASE("geometry") {
SECTION("json point") { SECTION("json point") {
mapnik::util::file input("./tests/data/json/fixtures/point1.json"); mapnik::util::file input("./tests/data/json/fixtures/point1.json");
auto json = input.data(); auto json = input.data();
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
std::string json_string(json.get()); std::string json_string(json.get());
REQUIRE( mapnik::json::from_geojson(json_string, geom) ); REQUIRE( mapnik::json::from_geojson(json_string, geom) );
REQUIRE( geom.is<mapnik::geometry::point>() ); REQUIRE( geom.is<mapnik::geometry::point<double> >() );
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom); auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom);
REQUIRE( point.x == 30 ); REQUIRE( point.x == 30 );
REQUIRE( point.y == 10 ); REQUIRE( point.y == 10 );
std::string new_json; std::string new_json;
@ -25,11 +25,11 @@ SECTION("json point") {
SECTION("json point reversed") { SECTION("json point reversed") {
mapnik::util::file input("./tests/data/json/fixtures/point2.json"); mapnik::util::file input("./tests/data/json/fixtures/point2.json");
auto json = input.data(); auto json = input.data();
mapnik::geometry::geometry geom; mapnik::geometry::geometry<double> geom;
std::string json_string(json.get()); std::string json_string(json.get());
REQUIRE( mapnik::json::from_geojson(json_string,geom) ); REQUIRE( mapnik::json::from_geojson(json_string,geom) );
REQUIRE( geom.is<mapnik::geometry::point>() ); REQUIRE( geom.is<mapnik::geometry::point<double> >() );
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom); auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom);
REQUIRE( point.x == 30 ); REQUIRE( point.x == 30 );
REQUIRE( point.y == 10 ); REQUIRE( point.y == 10 );
} }

View file

@ -6,10 +6,10 @@
TEST_CASE("geometry ops - envelope") { TEST_CASE("geometry ops - envelope") {
SECTION("envelope_test") { SECTION("envelope_test - double") {
using namespace mapnik::geometry; using namespace mapnik::geometry;
{ {
geometry geom(point(1,2)); geometry<double> geom(point<double>(1,2));
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == 1 ); REQUIRE( bbox.minx() == 1 );
REQUIRE( bbox.miny() == 2 ); REQUIRE( bbox.miny() == 2 );
@ -18,16 +18,16 @@ SECTION("envelope_test") {
} }
{ {
// Test empty geom // Test empty geom
geometry geom(std::move(mapnik::geometry::geometry_empty())); geometry<double> geom(std::move(mapnik::geometry::geometry_empty()));
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE_FALSE( bbox.valid() ); REQUIRE_FALSE( bbox.valid() );
} }
{ {
line_string line; line_string<double> line;
line.add_coord(0,0); line.add_coord(0,0);
line.add_coord(1,1); line.add_coord(1,1);
line.add_coord(2,2); line.add_coord(2,2);
geometry geom(line); geometry<double> geom(line);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == 0 ); REQUIRE( bbox.minx() == 0 );
REQUIRE( bbox.miny() == 0 ); REQUIRE( bbox.miny() == 0 );
@ -35,18 +35,18 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxy() == 2 ); REQUIRE( bbox.maxy() == 2 );
} }
{ {
line_string line; line_string<double> line;
line.add_coord(0,0); line.add_coord(0,0);
line.add_coord(1,1); line.add_coord(1,1);
line.add_coord(2,2); line.add_coord(2,2);
line_string line2; line_string<double> line2;
line2.add_coord(0,0); line2.add_coord(0,0);
line2.add_coord(-1,-1); line2.add_coord(-1,-1);
line2.add_coord(-2,-2); line2.add_coord(-2,-2);
multi_line_string multi_line; multi_line_string<double> multi_line;
multi_line.emplace_back(std::move(line)); multi_line.emplace_back(std::move(line));
multi_line.emplace_back(std::move(line2)); multi_line.emplace_back(std::move(line2));
geometry geom(multi_line); geometry<double> geom(multi_line);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == -2 ); REQUIRE( bbox.minx() == -2 );
REQUIRE( bbox.miny() == -2 ); REQUIRE( bbox.miny() == -2 );
@ -54,24 +54,24 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxy() == 2 ); REQUIRE( bbox.maxy() == 2 );
} }
{ {
polygon poly; polygon<double> poly;
linear_ring ring; linear_ring<double> ring;
ring.add_coord(0,0); ring.add_coord(0,0);
ring.add_coord(-10,0); ring.add_coord(-10,0);
ring.add_coord(-10,10); ring.add_coord(-10,10);
ring.add_coord(0,10); ring.add_coord(0,10);
ring.add_coord(0,0); ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring)); poly.set_exterior_ring(std::move(ring));
geometry geom(poly); geometry<double> geom(poly);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom); mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == -10 ); REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 ); REQUIRE( bbox.miny() == 0 );
REQUIRE( bbox.maxx() == 0 ); REQUIRE( bbox.maxx() == 0 );
REQUIRE( bbox.maxy() == 10 ); REQUIRE( bbox.maxy() == 10 );
multi_polygon mp; multi_polygon<double> mp;
mp.push_back(poly); mp.push_back(poly);
geometry geom_mp(mp); geometry<double> geom_mp(mp);
bbox = mapnik::geometry::envelope(geom_mp); bbox = mapnik::geometry::envelope(geom_mp);
REQUIRE( bbox.minx() == -10 ); REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 ); REQUIRE( bbox.miny() == 0 );
@ -91,7 +91,7 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxx() == 0 ); REQUIRE( bbox.maxx() == 0 );
REQUIRE( bbox.maxy() == 10 ); REQUIRE( bbox.maxy() == 10 );
geometry_collection gc; geometry_collection<double> gc;
bbox = mapnik::geometry::envelope(gc); bbox = mapnik::geometry::envelope(gc);
REQUIRE_FALSE( bbox.valid() ); REQUIRE_FALSE( bbox.valid() );
gc.push_back(geom_mp); gc.push_back(geom_mp);
@ -100,7 +100,7 @@ SECTION("envelope_test") {
REQUIRE( bbox.miny() == 0 ); REQUIRE( bbox.miny() == 0 );
REQUIRE( bbox.maxx() == 0 ); REQUIRE( bbox.maxx() == 0 );
REQUIRE( bbox.maxy() == 10 ); REQUIRE( bbox.maxy() == 10 );
gc.emplace_back(point(-50,-50)); gc.emplace_back(point<double>(-50,-50));
bbox = mapnik::geometry::envelope(gc); bbox = mapnik::geometry::envelope(gc);
REQUIRE( bbox.minx() == -50 ); REQUIRE( bbox.minx() == -50 );
REQUIRE( bbox.miny() == -50 ); REQUIRE( bbox.miny() == -50 );
@ -110,22 +110,22 @@ SECTION("envelope_test") {
{ {
// polygon with hole // polygon with hole
polygon poly; polygon<double> poly;
linear_ring ring; linear_ring<double> ring;
ring.add_coord(0,0); ring.add_coord(0,0);
ring.add_coord(-10,0); ring.add_coord(-10,0);
ring.add_coord(-10,10); ring.add_coord(-10,10);
ring.add_coord(0,10); ring.add_coord(0,10);
ring.add_coord(0,0); ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring)); poly.set_exterior_ring(std::move(ring));
linear_ring hole; linear_ring<double> hole;
hole.add_coord(-7,7); hole.add_coord(-7,7);
hole.add_coord(-7,3); hole.add_coord(-7,3);
hole.add_coord(-3,3); hole.add_coord(-3,3);
hole.add_coord(-3,7); hole.add_coord(-3,7);
hole.add_coord(-7,7); hole.add_coord(-7,7);
poly.add_hole(std::move(hole)); poly.add_hole(std::move(hole));
geometry geom(poly); geometry<double> geom(poly);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(poly); mapnik::box2d<double> bbox = mapnik::geometry::envelope(poly);
REQUIRE( bbox.minx() == -10 ); REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 ); REQUIRE( bbox.miny() == 0 );
@ -133,7 +133,7 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxy() == 10 ); REQUIRE( bbox.maxy() == 10 );
// add another hole inside the first hole // add another hole inside the first hole
// which should be considered a hit // which should be considered a hit
linear_ring fill; linear_ring<double> fill;
fill.add_coord(-6,4); fill.add_coord(-6,4);
fill.add_coord(-6,6); fill.add_coord(-6,6);
fill.add_coord(-4,6); fill.add_coord(-4,6);

View file

@ -79,7 +79,8 @@ auto zip_crange(Conts&... conts)
using namespace mapnik::geometry; using namespace mapnik::geometry;
void assert_g_equal(geometry const& g1, geometry const& g2); template <typename T>
void assert_g_equal(geometry<T> const& g1, geometry<T> const& g2);
struct geometry_equal_visitor struct geometry_equal_visitor
{ {
@ -95,13 +96,15 @@ struct geometry_equal_visitor
REQUIRE(true); REQUIRE(true);
} }
void operator() (point const& p1, point const& p2) template <typename T>
void operator() (point<T> const& p1, point<T> const& p2)
{ {
REQUIRE(p1.x == Approx(p2.x)); REQUIRE(p1.x == Approx(p2.x));
REQUIRE(p1.y == Approx(p2.y)); REQUIRE(p1.y == Approx(p2.y));
} }
void operator() (line_string const& ls1, line_string const& ls2) template <typename T>
void operator() (line_string<T> const& ls1, line_string<T> const& ls2)
{ {
if (ls1.size() != ls2.size()) if (ls1.size() != ls2.size())
{ {
@ -110,14 +113,15 @@ struct geometry_equal_visitor
for(auto const& p : zip_crange(ls1, ls2)) for(auto const& p : zip_crange(ls1, ls2))
{ {
REQUIRE(p.get<0>().x == Approx(p.get<1>().x)); REQUIRE(p.template get<0>().x == Approx(p.template get<1>().x));
REQUIRE(p.get<0>().y == Approx(p.get<1>().y)); REQUIRE(p.template get<0>().y == Approx(p.template get<1>().y));
} }
} }
void operator() (polygon const& p1, polygon const& p2) template <typename T>
void operator() (polygon<T> const& p1, polygon<T> const& p2)
{ {
(*this)(static_cast<line_string const&>(p1.exterior_ring), static_cast<line_string const&>(p2.exterior_ring)); (*this)(static_cast<line_string<T> const&>(p1.exterior_ring), static_cast<line_string<T> const&>(p2.exterior_ring));
if (p1.interior_rings.size() != p2.interior_rings.size()) if (p1.interior_rings.size() != p2.interior_rings.size())
{ {
@ -126,16 +130,18 @@ struct geometry_equal_visitor
for (auto const& p : zip_crange(p1.interior_rings, p2.interior_rings)) for (auto const& p : zip_crange(p1.interior_rings, p2.interior_rings))
{ {
(*this)(static_cast<line_string const&>(p.get<0>()),static_cast<line_string const&>(p.get<1>())); (*this)(static_cast<line_string<T> const&>(p.template get<0>()),static_cast<line_string<T> const&>(p.template get<1>()));
} }
} }
void operator() (multi_point const& mp1, multi_point const& mp2) template <typename T>
void operator() (multi_point<T> const& mp1, multi_point<T> const& mp2)
{ {
(*this)(static_cast<line_string const&>(mp1), static_cast<line_string const&>(mp2)); (*this)(static_cast<line_string<T> const&>(mp1), static_cast<line_string<T> const&>(mp2));
} }
void operator() (multi_line_string const& mls1, multi_line_string const& mls2) template <typename T>
void operator() (multi_line_string<T> const& mls1, multi_line_string<T> const& mls2)
{ {
if (mls1.size() != mls2.size()) if (mls1.size() != mls2.size())
{ {
@ -144,11 +150,12 @@ struct geometry_equal_visitor
for (auto const& ls : zip_crange(mls1, mls2)) for (auto const& ls : zip_crange(mls1, mls2))
{ {
(*this)(ls.get<0>(),ls.get<1>()); (*this)(ls.template get<0>(),ls.template get<1>());
} }
} }
void operator() (multi_polygon const& mpoly1, multi_polygon const& mpoly2) template <typename T>
void operator() (multi_polygon<T> const& mpoly1, multi_polygon<T> const& mpoly2)
{ {
if (mpoly1.size() != mpoly2.size()) if (mpoly1.size() != mpoly2.size())
{ {
@ -157,14 +164,15 @@ struct geometry_equal_visitor
for (auto const& poly : zip_crange(mpoly1, mpoly2)) for (auto const& poly : zip_crange(mpoly1, mpoly2))
{ {
(*this)(poly.get<0>(),poly.get<1>()); (*this)(poly.template get<0>(),poly.template get<1>());
} }
} }
void operator() (mapnik::util::recursive_wrapper<geometry_collection> const& c1_, mapnik::util::recursive_wrapper<geometry_collection> const& c2_) template <typename T>
void operator() (mapnik::util::recursive_wrapper<geometry_collection<T> > const& c1_, mapnik::util::recursive_wrapper<geometry_collection<T> > const& c2_)
{ {
geometry_collection const& c1 = static_cast<geometry_collection const&>(c1_); geometry_collection<T> const& c1 = static_cast<geometry_collection<T> const&>(c1_);
geometry_collection const& c2 = static_cast<geometry_collection const&>(c2_); geometry_collection<T> const& c2 = static_cast<geometry_collection<T> const&>(c2_);
if (c1.size() != c2.size()) if (c1.size() != c2.size())
{ {
REQUIRE(false); REQUIRE(false);
@ -172,11 +180,12 @@ struct geometry_equal_visitor
for (auto const& g : zip_crange(c1, c2)) for (auto const& g : zip_crange(c1, c2))
{ {
assert_g_equal(g.get<0>(),g.get<1>()); assert_g_equal(g.template get<0>(),g.template get<1>());
} }
} }
void operator() (geometry_collection const& c1, geometry_collection const& c2) template <typename T>
void operator() (geometry_collection<T> const& c1, geometry_collection<T> const& c2)
{ {
if (c1.size() != c2.size()) if (c1.size() != c2.size())
{ {
@ -185,12 +194,13 @@ struct geometry_equal_visitor
for (auto const& g : zip_crange(c1, c2)) for (auto const& g : zip_crange(c1, c2))
{ {
assert_g_equal(g.get<0>(),g.get<1>()); assert_g_equal(g.template get<0>(),g.template get<1>());
} }
} }
}; };
void assert_g_equal(geometry const& g1, geometry const& g2) template <typename T>
void assert_g_equal(geometry<T> const& g1, geometry<T> const& g2)
{ {
return mapnik::util::apply_visitor(geometry_equal_visitor(), g1, g2); return mapnik::util::apply_visitor(geometry_equal_visitor(), g1, g2);
} }

View file

@ -6,57 +6,57 @@
TEST_CASE("geometry ops") { TEST_CASE("geometry ops") {
SECTION("hit_test_filter") { SECTION("hit_test_filter - double") {
using namespace mapnik::geometry; using namespace mapnik::geometry;
{ {
geometry geom(point(0,0)); geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,0,0,0) ); REQUIRE( mapnik::hit_test(geom,0,0,0) );
} }
{ {
geometry geom(point(0,0)); geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,1,0,1) ); REQUIRE( mapnik::hit_test(geom,1,0,1) );
} }
{ {
geometry geom(point(0,0)); geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,0,1,1) ); REQUIRE( mapnik::hit_test(geom,0,1,1) );
} }
{ {
geometry geom(point(0,0)); geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,1,1,1.5) ); REQUIRE( mapnik::hit_test(geom,1,1,1.5) );
} }
{ {
line_string line; line_string<double> line;
line.add_coord(0,0); line.add_coord(0,0);
line.add_coord(1,1); line.add_coord(1,1);
line.add_coord(2,2); line.add_coord(2,2);
geometry geom(line); geometry<double> geom(line);
REQUIRE( mapnik::hit_test(geom,0,0,1.5) ); REQUIRE( mapnik::hit_test(geom,0,0,1.5) );
} }
{ {
line_string line; line_string<double> line;
line.add_coord(0,0); line.add_coord(0,0);
line.add_coord(1,1); line.add_coord(1,1);
line.add_coord(2,2); line.add_coord(2,2);
multi_line_string multi_line; multi_line_string<double> multi_line;
multi_line.emplace_back(std::move(line)); multi_line.emplace_back(std::move(line));
geometry geom(multi_line); geometry<double> geom(multi_line);
REQUIRE( mapnik::hit_test(geom,0,0,1.5) ); REQUIRE( mapnik::hit_test(geom,0,0,1.5) );
} }
{ {
polygon poly; polygon<double> poly;
linear_ring ring; linear_ring<double> ring;
ring.add_coord(0,0); ring.add_coord(0,0);
ring.add_coord(-10,0); ring.add_coord(-10,0);
ring.add_coord(-10,10); ring.add_coord(-10,10);
ring.add_coord(0,10); ring.add_coord(0,10);
ring.add_coord(0,0); ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring)); poly.set_exterior_ring(std::move(ring));
geometry geom(poly); geometry<double> geom(poly);
REQUIRE( mapnik::hit_test(geom,-5,5,0) ); REQUIRE( mapnik::hit_test(geom,-5,5,0) );
multi_polygon mp; multi_polygon<double> mp;
mp.push_back(poly); mp.push_back(poly);
geometry geom_mp(mp); geometry<double> geom_mp(mp);
REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) ); REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) );
correct(geom); correct(geom);
@ -64,44 +64,44 @@ SECTION("hit_test_filter") {
correct(geom_mp); correct(geom_mp);
REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) ); REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) );
geometry_collection gc; geometry_collection<double> gc;
REQUIRE( !mapnik::hit_test(geometry(gc),-5,5,0) ); REQUIRE( !mapnik::hit_test(geometry<double>(gc),-5,5,0) );
gc.push_back(geom_mp); gc.push_back(geom_mp);
REQUIRE( mapnik::hit_test(geometry(gc),-5,5,0) ); REQUIRE( mapnik::hit_test(geometry<double>(gc),-5,5,0) );
REQUIRE( !mapnik::hit_test(geometry(gc),-50,-50,0) ); REQUIRE( !mapnik::hit_test(geometry<double>(gc),-50,-50,0) );
gc.emplace_back(point(-50,-50)); gc.emplace_back(point<double>(-50,-50));
REQUIRE( mapnik::hit_test(geometry(gc),-50,-50,0) ); REQUIRE( mapnik::hit_test(geometry<double>(gc),-50,-50,0) );
} }
{ {
// polygon with hole // polygon with hole
polygon poly; polygon<double> poly;
linear_ring ring; linear_ring<double> ring;
ring.add_coord(0,0); ring.add_coord(0,0);
ring.add_coord(-10,0); ring.add_coord(-10,0);
ring.add_coord(-10,10); ring.add_coord(-10,10);
ring.add_coord(0,10); ring.add_coord(0,10);
ring.add_coord(0,0); ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring)); poly.set_exterior_ring(std::move(ring));
linear_ring hole; linear_ring<double> hole;
hole.add_coord(-7,7); hole.add_coord(-7,7);
hole.add_coord(-7,3); hole.add_coord(-7,3);
hole.add_coord(-3,3); hole.add_coord(-3,3);
hole.add_coord(-3,7); hole.add_coord(-3,7);
hole.add_coord(-7,7); hole.add_coord(-7,7);
poly.add_hole(std::move(hole)); poly.add_hole(std::move(hole));
geometry geom(poly); geometry<double> geom(poly);
REQUIRE( !mapnik::hit_test(geom,-5,5,0) ); REQUIRE( !mapnik::hit_test(geom,-5,5,0) );
// add another hole inside the first hole // add another hole inside the first hole
// which should be considered a hit // which should be considered a hit
linear_ring fill; linear_ring<double> fill;
fill.add_coord(-6,4); fill.add_coord(-6,4);
fill.add_coord(-6,6); fill.add_coord(-6,6);
fill.add_coord(-4,6); fill.add_coord(-4,6);
fill.add_coord(-4,4); fill.add_coord(-4,4);
fill.add_coord(-6,4); fill.add_coord(-6,4);
poly.add_hole(std::move(fill)); poly.add_hole(std::move(fill));
REQUIRE( mapnik::hit_test(geometry(poly),-5,5,0) ); REQUIRE( mapnik::hit_test(geometry<double>(poly),-5,5,0) );
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,118 @@
#include "catch.hpp"
#include "geometry_equal.hpp"
#include <mapnik/geometry.hpp>
#include <mapnik/projection.hpp>
#include <mapnik/proj_transform.hpp>
#include <mapnik/view_transform.hpp>
#include <mapnik/geometry_transform.hpp>
#include <mapnik/geometry_strategy.hpp>
TEST_CASE("geometry strategy tests") {
SECTION("proj and view strategy") {
using namespace mapnik::geometry;
mapnik::box2d<double> e(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
mapnik::view_transform vt(256, 256, e);
mapnik::view_strategy vs(vt);
mapnik::unview_strategy uvs(vt);
mapnik::projection source("+init=epsg:4326");
mapnik::projection dest("+init=epsg:3857");
mapnik::proj_transform proj_trans(source, dest);
mapnik::proj_transform proj_trans_rev(dest, source);
mapnik::proj_strategy ps(proj_trans);
mapnik::proj_strategy ps_rev(proj_trans_rev);
{
// Test first that proj strategy works properly
point<double> p1(-97.553098,35.523105);
point<double> r1(-1.08596e+07, 4.2352e+06);
point<double> p3 = transform<double>(p1, ps);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
{
// Test next that view_strategy works
point<double> p1(-1.08596e+07, 4.2352e+06);
point<double> r1(58.6287 , 100.945);
point<double> p3 = transform<double>(p1, vs);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
{
// Test next that view_strategy works as single process in strategy group
point<double> p1(-1.08596e+07, 4.2352e+06);
point<double> r1(58.6287 , 100.945);
using sg_type = strategy_group<mapnik::view_strategy>;
sg_type sg(vs);
point<double> p3 = transform<double>(p1, sg);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
{
// Test that both work grouped together in strategy group
using sg_type = strategy_group<mapnik::proj_strategy, mapnik::view_strategy >;
sg_type sg(ps, vs);
point<double> p1(-97.553098,35.523105);
point<double> r1(58.6287 , 100.945);
point<double> p3 = transform<double>(p1, sg);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
{
// Test that both work grouped together passing in geometry
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<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);
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}
{
// Test that it works pulling back int
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<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);
}
{
// Test with scaling as well. This would be like projection from 4326 to a vector tile.
mapnik::geometry::scale_strategy ss(16, 0.5);
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<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);
}
{
// Test the entire process in reverse! This would be like converting a vector tile coordinate to 4326.
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<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;
assert_g_equal(r1, p3);
}
}
}

View file

@ -6,13 +6,13 @@
TEST_CASE("vertex_adapters") { TEST_CASE("vertex_adapters") {
SECTION("polygon") { SECTION("polygon") {
mapnik::geometry::polygon g; mapnik::geometry::polygon<double> g;
g.exterior_ring.add_coord(1,1); g.exterior_ring.add_coord(1,1);
g.exterior_ring.add_coord(2,2); g.exterior_ring.add_coord(2,2);
g.exterior_ring.add_coord(100,100); g.exterior_ring.add_coord(100,100);
g.exterior_ring.add_coord(1,1); g.exterior_ring.add_coord(1,1);
mapnik::geometry::polygon_vertex_adapter va(g); mapnik::geometry::polygon_vertex_adapter<double> va(g);
double x,y; double x,y;
unsigned cmd; unsigned cmd;
@ -45,14 +45,14 @@ SECTION("polygon") {
} }
SECTION("polygon with hole") { SECTION("polygon with hole") {
mapnik::geometry::polygon g; mapnik::geometry::polygon<double> g;
g.exterior_ring.add_coord(0,0); g.exterior_ring.add_coord(0,0);
g.exterior_ring.add_coord(-10,0); g.exterior_ring.add_coord(-10,0);
g.exterior_ring.add_coord(-10,10); g.exterior_ring.add_coord(-10,10);
g.exterior_ring.add_coord(0,10); g.exterior_ring.add_coord(0,10);
g.exterior_ring.add_coord(0,0); g.exterior_ring.add_coord(0,0);
std::vector<mapnik::geometry::linear_ring> interior_rings; std::vector<mapnik::geometry::linear_ring<double> > interior_rings;
mapnik::geometry::linear_ring hole; mapnik::geometry::linear_ring<double> hole;
hole.add_coord(-7,7); hole.add_coord(-7,7);
hole.add_coord(-7,3); hole.add_coord(-7,3);
hole.add_coord(-3,3); hole.add_coord(-3,3);
@ -60,7 +60,7 @@ SECTION("polygon with hole") {
hole.add_coord(-7,7); hole.add_coord(-7,7);
g.add_hole(std::move(hole)); g.add_hole(std::move(hole));
mapnik::geometry::linear_ring hole_in_hole; mapnik::geometry::linear_ring<double> hole_in_hole;
hole_in_hole.add_coord(-6,4); hole_in_hole.add_coord(-6,4);
hole_in_hole.add_coord(-6,6); hole_in_hole.add_coord(-6,6);
hole_in_hole.add_coord(-4,6); hole_in_hole.add_coord(-4,6);
@ -68,7 +68,7 @@ SECTION("polygon with hole") {
hole_in_hole.add_coord(-6,4); hole_in_hole.add_coord(-6,4);
g.add_hole(std::move(hole_in_hole)); g.add_hole(std::move(hole_in_hole));
mapnik::geometry::polygon_vertex_adapter va(g); mapnik::geometry::polygon_vertex_adapter<double> va(g);
double x,y; double x,y;
unsigned cmd; unsigned cmd;
@ -99,7 +99,7 @@ SECTION("polygon with hole") {
REQUIRE( y == 0 ); REQUIRE( y == 0 );
// exterior ring via ring_vertex_adapter // exterior ring via ring_vertex_adapter
mapnik::geometry::ring_vertex_adapter va2(g.exterior_ring); mapnik::geometry::ring_vertex_adapter<double> va2(g.exterior_ring);
cmd = va2.vertex(&x,&y); cmd = va2.vertex(&x,&y);
REQUIRE( cmd == mapnik::SEG_MOVETO ); REQUIRE( cmd == mapnik::SEG_MOVETO );
REQUIRE( x == 0 ); REQUIRE( x == 0 );

View file

@ -81,7 +81,7 @@ int main (int argc, char ** argv )
while(f) while(f)
{ {
std::cerr << *f << std::endl; std::cerr << *f << std::endl;
mapnik::geometry::geometry const& geom = f->get_geometry(); mapnik::geometry::geometry<double> const& geom = f->get_geometry();
// NDR // NDR
{ {
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,mapnik::wkbNDR); mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,mapnik::wkbNDR);

View file

@ -389,7 +389,7 @@ void pgsql2sqlite(Connection conn,
if (oid == geometry_oid) if (oid == geometry_oid)
{ {
mapnik::Feature feat(ctx,pkid); mapnik::Feature feat(ctx,pkid);
mapnik::geometry::geometry geom = geometry_utils::from_wkb(buf, size, wkbGeneric); mapnik::geometry::geometry<double> geom = geometry_utils::from_wkb(buf, size, wkbGeneric);
if (!mapnik::geometry::is_empty(geom)) if (!mapnik::geometry::is_empty(geom))
{ {
box2d<double> bbox = mapnik::geometry::envelope(geom); box2d<double> bbox = mapnik::geometry::envelope(geom);