From 02dce6a7568495cb7b55e9cef3ce1235a34ea359 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 9 Dec 2011 12:25:13 +0000 Subject: [PATCH] make shape_io work with geometry_container concept --- plugins/input/shape/shape_featureset.cpp | 38 +-- .../input/shape/shape_index_featureset.cpp | 35 +-- plugins/input/shape/shape_io.cpp | 246 +----------------- plugins/input/shape/shape_io.hpp | 16 +- 4 files changed, 24 insertions(+), 311 deletions(-) diff --git a/plugins/input/shape/shape_featureset.cpp b/plugins/input/shape/shape_featureset.cpp index 9a6753b52..779c3869d 100644 --- a/plugins/input/shape/shape_featureset.cpp +++ b/plugins/input/shape/shape_featureset.cpp @@ -248,55 +248,25 @@ feature_ptr shape_featureset::next() } case shape_io::shape_polyline: - { - geometry_type* line = shape_.read_polyline(); - feature->add_geometry(line); - ++count_; - break; - } - case shape_io::shape_polylinem: - { - geometry_type* line = shape_.read_polylinem(); - feature->add_geometry(line); - ++count_; - break; - } - case shape_io::shape_polylinez: { - geometry_type* line = shape_.read_polylinez(); - feature->add_geometry(line); + shape_.read_polyline(feature->paths()); ++count_; break; } - + case shape_io::shape_polygon: - { - geometry_type* poly = shape_.read_polygon(); - feature->add_geometry(poly); - ++count_; - break; - } - case shape_io::shape_polygonm: - { - geometry_type* poly = shape_.read_polygonm(); - feature->add_geometry(poly); - ++count_; - break; - } - case shape_io::shape_polygonz: { - geometry_type* poly = shape_.read_polygonz(); - feature->add_geometry(poly); + shape_.read_polygon(feature->paths()); ++count_; break; } } } - + feature->set_id(shape_.id_); if (attr_ids_.size()) { diff --git a/plugins/input/shape/shape_index_featureset.cpp b/plugins/input/shape/shape_index_featureset.cpp index b25e8c644..0c0fcadc5 100644 --- a/plugins/input/shape/shape_index_featureset.cpp +++ b/plugins/input/shape/shape_index_featureset.cpp @@ -193,49 +193,18 @@ feature_ptr shape_index_featureset::next() } case shape_io::shape_polyline: - { - geometry_type* line = shape_.read_polyline(); - feature->add_geometry(line); - ++count_; - break; - } - case shape_io::shape_polylinem: - { - geometry_type* line = shape_.read_polylinem(); - feature->add_geometry(line); - ++count_; - break; - } - case shape_io::shape_polylinez: { - geometry_type* line = shape_.read_polylinez(); - feature->add_geometry(line); + shape_.read_polyline(feature->paths()); ++count_; break; } - case shape_io::shape_polygon: - { - geometry_type* poly = shape_.read_polygon(); - feature->add_geometry(poly); - ++count_; - break; - } - case shape_io::shape_polygonm: - { - geometry_type* poly = shape_.read_polygonm(); - feature->add_geometry(poly); - ++count_; - break; - } - case shape_io::shape_polygonz: { - geometry_type* poly = shape_.read_polygonz(); - feature->add_geometry(poly); + shape_.read_polygon(feature->paths()); ++count_; break; } diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index 04aa48814..54b7f32fc 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -106,18 +106,16 @@ dbf_file& shape_io::dbf() return dbf_; } -geometry_type* shape_io::read_polyline() +void shape_io::read_polyline(mapnik::geometry_container & geom) { shape_file::record_type record(reclength_ * 2 - 36); shp_.read_record(record); - + int num_parts = record.read_ndr_integer(); int num_points = record.read_ndr_integer(); - geometry_type* line = new geometry_type(mapnik::LineString); - line->set_capacity(num_points + num_parts); if (num_parts == 1) { - line->set_capacity(num_points + 1); + geometry_type* line = new geometry_type(mapnik::LineString); record.skip(4); double x = record.read_double(); double y = record.read_double(); @@ -128,6 +126,7 @@ geometry_type* shape_io::read_polyline() y = record.read_double(); line->line_to(x, y); } + geom.push_back(line); } else { @@ -140,6 +139,7 @@ geometry_type* shape_io::read_polyline() int start, end; for (int k = 0; k < num_parts; ++k) { + geometry_type* line = new geometry_type(mapnik::LineString); start = parts[k]; if (k == num_parts - 1) { @@ -160,135 +160,9 @@ geometry_type* shape_io::read_polyline() y = record.read_double(); line->line_to(x, y); } + geom.push_back(line); } } - return line; -} - -geometry_type* shape_io::read_polylinem() -{ - shape_file::record_type record(reclength_ * 2 - 36); - shp_.read_record(record); - - int num_parts = record.read_ndr_integer(); - int num_points = record.read_ndr_integer(); - geometry_type* line = new geometry_type(mapnik::LineString); - line->set_capacity(num_points + num_parts); - if (num_parts == 1) - { - record.skip(4); - double x = record.read_double(); - double y = record.read_double(); - line->move_to(x, y); - for (int i = 1; i < num_points; ++i) - { - x = record.read_double(); - y = record.read_double(); - line->line_to(x, y); - } - } - else - { - std::vector parts(num_parts); - for (int i = 0; i < num_parts; ++i) - { - parts[i] = record.read_ndr_integer(); - } - - int start, end; - for (int k = 0; k < num_parts; ++k) - { - start = parts[k]; - if (k == num_parts - 1) - { - end = num_points; - } - else - { - end = parts[k + 1]; - } - - double x = record.read_double(); - double y = record.read_double(); - line->move_to(x, y); - - for (int j = start + 1; j < end; ++j) - { - x = record.read_double(); - y = record.read_double(); - line->line_to(x, y); - } - } - } - - // m-range - //double m0=record.read_double(); - //double m1=record.read_double(); - - //for (int i=0;iset_capacity(num_points + num_parts); - if (num_parts == 1) - { - record.skip(4); - double x = record.read_double(); - double y = record.read_double(); - line->move_to(x, y); - for (int i = 1; i < num_points; ++i) - { - x = record.read_double(); - y = record.read_double(); - line->line_to(x, y); - } - } - else - { - std::vector parts(num_parts); - for (int i = 0; i < num_parts; ++i) - { - parts[i] = record.read_ndr_integer(); - } - - int start, end; - for (int k = 0; k < num_parts; ++k) - { - start = parts[k]; - if (k == num_parts - 1) - { - end = num_points; - } - else - { - end = parts[k + 1]; - } - - double x = record.read_double(); - double y = record.read_double(); - line->move_to(x, y); - - for (int j = start + 1; j < end; ++j) - { - x = record.read_double(); - y = record.read_double(); - line->line_to(x, y); - } - } - } - // z-range //double z0=record.read_double(); //double z1=record.read_double(); @@ -306,19 +180,17 @@ geometry_type* shape_io::read_polylinez() // double m=record.read_double(); //} - return line; } -geometry_type* shape_io::read_polygon() +void shape_io::read_polygon(mapnik::geometry_container & geom) { shape_file::record_type record(reclength_ * 2 - 36); shp_.read_record(record); - + int num_parts = record.read_ndr_integer(); int num_points = record.read_ndr_integer(); std::vector parts(num_parts); - geometry_type* poly = new geometry_type(mapnik::Polygon); - poly->set_capacity(num_points + num_parts); + for (int i = 0; i < num_parts; ++i) { parts[i] = record.read_ndr_integer(); @@ -326,6 +198,7 @@ geometry_type* shape_io::read_polygon() for (int k = 0; k < num_parts; k++) { + geometry_type* poly = new geometry_type(mapnik::Polygon); int start = parts[k]; int end; if (k == num_parts - 1) @@ -347,101 +220,8 @@ geometry_type* shape_io::read_polygon() y = record.read_double(); poly->line_to(x, y); } + geom.push_back(poly); } - return poly; -} - -geometry_type* shape_io::read_polygonm() -{ - shape_file::record_type record(reclength_ * 2 - 36); - shp_.read_record(record); - - int num_parts = record.read_ndr_integer(); - int num_points = record.read_ndr_integer(); - std::vector parts(num_parts); - geometry_type* poly = new geometry_type(mapnik::Polygon); - poly->set_capacity(num_points + num_parts); - for (int i = 0; i < num_parts; ++i) - { - parts[i] = record.read_ndr_integer(); - } - - for (int k = 0; k < num_parts; k++) - { - int start = parts[k]; - int end; - if (k == num_parts - 1) - { - end = num_points; - } - else - { - end = parts[k + 1]; - } - - double x = record.read_double(); - double y = record.read_double(); - poly->move_to(x, y); - - for (int j = start + 1; j < end; j++) - { - x = record.read_double(); - y = record.read_double(); - poly->line_to(x, y); - } - } - - // m-range - //double m0=record.read_double(); - //double m1=record.read_double(); - - //for (int i=0;i parts(num_parts); - geometry_type* poly = new geometry_type(mapnik::Polygon); - poly->set_capacity(num_points + num_parts); - for (int i = 0; i < num_parts; ++i) - { - parts[i] = record.read_ndr_integer(); - } - - for (int k = 0; k < num_parts; k++) - { - int start = parts[k]; - int end; - if (k == num_parts - 1) - { - end = num_points; - } - else - { - end = parts[k + 1]; - } - - double x = record.read_double(); - double y = record.read_double(); - poly->move_to(x, y); - - for (int j = start + 1; j < end; j++) - { - x = record.read_double(); - y = record.read_double(); - poly->line_to(x, y); - } - } - // z-range //double z0=record.read_double(); //double z1=record.read_double(); @@ -458,6 +238,6 @@ geometry_type* shape_io::read_polygonz() //{ // double m=record.read_double(); //} - - return poly; } + + diff --git a/plugins/input/shape/shape_io.hpp b/plugins/input/shape/shape_io.hpp index 1623402df..1421ec0ab 100644 --- a/plugins/input/shape/shape_io.hpp +++ b/plugins/input/shape/shape_io.hpp @@ -23,6 +23,8 @@ #ifndef SHAPE_IO_HPP #define SHAPE_IO_HPP +// mapnik +#include // boost #include #include @@ -56,9 +58,8 @@ public: ~shape_io(); shape_file& shp(); - //shape_file& shx(); dbf_file& dbf(); - + inline boost::shared_ptr& index() { return index_; @@ -72,16 +73,10 @@ public: void move_to(int id); int type() const; const box2d& current_extent() const; - mapnik::geometry_type* read_polyline(); - mapnik::geometry_type* read_polylinem(); - mapnik::geometry_type* read_polylinez(); - mapnik::geometry_type* read_polygon(); - mapnik::geometry_type* read_polygonm(); - mapnik::geometry_type* read_polygonz(); - + void read_polyline(mapnik::geometry_container & geom); + void read_polygon(mapnik::geometry_container & geom); unsigned type_; shape_file shp_; - //shape_file shx_; dbf_file dbf_; boost::shared_ptr index_; unsigned reclength_; @@ -89,7 +84,6 @@ public: box2d cur_extent_; static const std::string SHP; - //static const std::string SHX; static const std::string DBF; static const std::string INDEX; };