From 78c72ee38957a0d16a27ef86c0673178161b9c45 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 24 Feb 2015 15:59:26 +0100 Subject: [PATCH] topojson.input - update to mapnik-geometry --- .../input/topojson/topojson_featureset.cpp | 128 ++++++++---------- src/json/mapnik_topojson_grammar.cpp | 3 +- 2 files changed, 58 insertions(+), 73 deletions(-) diff --git a/plugins/input/topojson/topojson_featureset.cpp b/plugins/input/topojson/topojson_featureset.cpp index 72b6f2cf0..dca3cd138 100644 --- a/plugins/input/topojson/topojson_featureset.cpp +++ b/plugins/input/topojson/topojson_featureset.cpp @@ -95,8 +95,6 @@ struct feature_generator feature_ptr operator() (point const& pt) const { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); - std::unique_ptr point_ptr(new geometry_type(geometry_type::types::Point)); - double x = pt.coord.x; double y = pt.coord.y; if (topo_.tr) @@ -104,9 +102,8 @@ struct feature_generator x = x * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = y * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - - point_ptr->move_to(x,y); - feature->paths().push_back(point_ptr.release()); + mapnik::new_geometry::point point(x, y); + feature->set_geometry(std::move(point)); assign_properties(*feature, pt, tr_); return feature; } @@ -114,11 +111,10 @@ struct feature_generator feature_ptr operator() (multi_point const& multi_pt) const { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); - + mapnik::new_geometry::multi_point multi_point; + multi_point.reserve(multi_pt.points.size()); for (auto const& pt : multi_pt.points) { - std::unique_ptr point_ptr(new geometry_type(geometry_type::types::Point)); - double x = pt.x; double y = pt.y; if (topo_.tr) @@ -126,10 +122,9 @@ struct feature_generator x = x * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = y * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - - point_ptr->move_to(x,y); - feature->paths().push_back(point_ptr.release()); + multi_point.add_coord(x, y); } + feature->set_geometry(std::move(multi_point)); assign_properties(*feature, multi_pt, tr_); return feature; } @@ -137,11 +132,12 @@ struct feature_generator feature_ptr operator() (linestring const& line) const { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); - std::unique_ptr line_ptr(new geometry_type(geometry_type::types::LineString)); - double px = 0, py = 0; index_type arc_index = line.ring; - bool first = true; + + mapnik::new_geometry::line_string line_string; + line_string.reserve( topo_.arcs[arc_index].coordinates.size()); + for (auto pt : topo_.arcs[arc_index].coordinates) { double x = pt.x; @@ -151,18 +147,9 @@ struct feature_generator x = (px += x) * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = (py += y) * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - if (first) - { - first = false; - line_ptr->move_to(x,y); - } - else - { - line_ptr->line_to(x,y); - } + line_string.add_coord(x,y); } - - feature->paths().push_back(line_ptr.release()); + feature->set_geometry(std::move(line_string)); assign_properties(*feature, line, tr_); return feature; } @@ -171,14 +158,15 @@ struct feature_generator { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); + mapnik::new_geometry::multi_line_string multi_line_string; + multi_line_string.reserve(multi_line.rings.size()); for (auto const& index : multi_line.rings) { - std::unique_ptr line_ptr(new geometry_type(geometry_type::types::LineString)); - double px = 0, py = 0; - bool first = true; bool reverse = index < 0; index_type arc_index = reverse ? std::abs(index) - 1 : index; + mapnik::new_geometry::line_string line_string; + line_string.reserve(topo_.arcs[arc_index].coordinates.size()); for (auto pt : topo_.arcs[arc_index].coordinates) { double x = pt.x; @@ -188,18 +176,11 @@ struct feature_generator x = (px += x) * (*topo_.tr).scale_x + (*topo_.tr).translate_x; y = (py += y) * (*topo_.tr).scale_y + (*topo_.tr).translate_y; } - if (first) - { - first = false; - line_ptr->move_to(x,y); - } - else - { - line_ptr->line_to(x,y); - } + line_string.add_coord(x, y); } - feature->paths().push_back(line_ptr.release()); + multi_line_string.push_back(std::move(line_string)); } + feature->set_geometry(std::move(multi_line_string)); assign_properties(*feature, multi_line, tr_); return feature; } @@ -207,12 +188,13 @@ struct feature_generator feature_ptr operator() (polygon const& poly) const { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); - std::unique_ptr poly_ptr(new geometry_type(geometry_type::types::Polygon)); std::vector processed_coords; - + mapnik::new_geometry::polygon polygon; + if (poly.rings.size() > 1) polygon.interior_rings.reserve(poly.rings.size() - 1); + bool first = true; for (auto const& ring : poly.rings) { - bool first = true; + mapnik::new_geometry::linear_ring linear_ring; for (auto const& index : ring) { double px = 0, py = 0; @@ -246,31 +228,29 @@ struct feature_generator { for (auto const& c : simplified | reversed | sliced(0, simplified.size()-1)) { - if (first) - { - first = false; - poly_ptr->move_to(c.x,c.y); - } - else poly_ptr->line_to(c.x,c.y); + linear_ring.emplace_back(c.x, c.y); } } else { for (auto const& c : simplified | sliced(0, simplified.size()-1)) { - if (first) - { - first = false; - poly_ptr->move_to(c.x,c.y); - } - else poly_ptr->line_to(c.x,c.y); + linear_ring.emplace_back(c.x, c.y); } } } - poly_ptr->close_path(); + if (first) + { + first = false; + polygon.set_exterior_ring(std::move(linear_ring)); + } + else + { + polygon.add_hole(std::move(linear_ring)); + } } - feature->paths().push_back(poly_ptr.release()); + feature->set_geometry(std::move(polygon)); assign_properties(*feature, poly, tr_); return feature; } @@ -279,12 +259,19 @@ struct feature_generator { mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_)); std::vector processed_coords; + mapnik::new_geometry::multi_polygon multi_polygon; + multi_polygon.reserve(multi_poly.polygons.size()); + for (auto const& poly : multi_poly.polygons) { - std::unique_ptr poly_ptr(new geometry_type(geometry_type::types::Polygon)); + //std::unique_ptr poly_ptr(new geometry_type(geometry_type::types::Polygon)); + bool first = true; + mapnik::new_geometry::polygon polygon; + if (poly.size() > 1) polygon.interior_rings.reserve(poly.size() - 1); + for (auto const& ring : poly) { - bool first = true; + mapnik::new_geometry::linear_ring linear_ring; for (auto const& index : ring) { double px = 0, py = 0; @@ -312,31 +299,30 @@ struct feature_generator { for (auto const& c : (processed_coords | reversed | sliced(0,processed_coords.size() - 1))) { - if (first) - { - first = false; - poly_ptr->move_to(c.x,c.y); - } - else poly_ptr->line_to(c.x,c.y); + linear_ring.add_coord(c.x, c.y); } } else { for (auto const& c : processed_coords | sliced(0,processed_coords.size() - 1)) { - if (first) - { - first = false; - poly_ptr->move_to(c.x,c.y); - } - else poly_ptr->line_to(c.x,c.y); + linear_ring.add_coord(c.x, c.y); } } } - poly_ptr->close_path(); + if (first) + { + first = false; + polygon.set_exterior_ring(std::move(linear_ring)); + } + else + { + polygon.add_hole(std::move(linear_ring)); + } } - feature->paths().push_back(poly_ptr.release()); + multi_polygon.push_back(std::move(polygon)); } + feature->set_geometry(std::move(multi_polygon)); assign_properties(*feature, multi_poly, tr_); return feature; } diff --git a/src/json/mapnik_topojson_grammar.cpp b/src/json/mapnik_topojson_grammar.cpp index e4cc4be65..81d6552f4 100644 --- a/src/json/mapnik_topojson_grammar.cpp +++ b/src/json/mapnik_topojson_grammar.cpp @@ -19,11 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#if 0 // FIXME + #include #include #include using iterator_type = std::string::const_iterator; template struct mapnik::topojson::topojson_grammar ; -#endif