From 17ace8a3e8cd99ac1b0e0e90cc377dfe64f43620 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 21 Oct 2015 10:55:26 +0100 Subject: [PATCH] shape.input - read shx_file_length in shape_featureset and avoid passing wrong file length by mistake ref #3136 --- plugins/input/shape/shape_datasource.cpp | 11 ----------- plugins/input/shape/shape_datasource.hpp | 1 - plugins/input/shape/shape_featureset.cpp | 12 +++++++++--- plugins/input/shape/shape_featureset.hpp | 1 - 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/plugins/input/shape/shape_datasource.cpp b/plugins/input/shape/shape_datasource.cpp index 47684d309..f2a51601f 100644 --- a/plugins/input/shape/shape_datasource.cpp +++ b/plugins/input/shape/shape_datasource.cpp @@ -64,7 +64,6 @@ shape_datasource::shape_datasource(parameters const& params) : datasource (params), type_(datasource::Vector), file_length_(0), - shx_file_length_(0), indexed_(false), row_limit_(*params.get("row_limit",0)), desc_(shape_datasource::name(), *params.get("encoding","utf-8")) @@ -199,14 +198,6 @@ void shape_datasource::init(shape_io& shape) const double hiy = header.read_double(); extent_.init(lox, loy, hix, hiy); - if (shape.shx().is_open()) - { - shape_file::record_type shx_header(100); - shape.shx().read_record(shx_header); - shx_header.skip(6 * 4); - shx_file_length_ = shx_header.read_xdr_integer(); - } - #ifdef MAPNIK_LOG const double zmin = header.read_double(); const double zmax = header.read_double(); @@ -265,7 +256,6 @@ featureset_ptr shape_datasource::features(query const& q) const shape_name_, q.property_names(), desc_.get_encoding(), - shx_file_length_, row_limit_); } } @@ -303,7 +293,6 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt, double tol shape_name_, names, desc_.get_encoding(), - shx_file_length_, row_limit_); } } diff --git a/plugins/input/shape/shape_datasource.hpp b/plugins/input/shape/shape_datasource.hpp index d20033a61..f702036eb 100644 --- a/plugins/input/shape/shape_datasource.hpp +++ b/plugins/input/shape/shape_datasource.hpp @@ -69,7 +69,6 @@ private: std::string shape_name_; shape_io::shapeType shape_type_; long file_length_; - long shx_file_length_; box2d extent_; bool indexed_; const int row_limit_; diff --git a/plugins/input/shape/shape_featureset.cpp b/plugins/input/shape/shape_featureset.cpp index 44f58ce84..78ebb1da9 100644 --- a/plugins/input/shape/shape_featureset.cpp +++ b/plugins/input/shape/shape_featureset.cpp @@ -41,19 +41,25 @@ shape_featureset::shape_featureset(filterT const& filter, std::string const& shape_name, std::set const& attribute_names, std::string const& encoding, - long shx_file_length, int row_limit) : filter_(filter), shape_(shape_name, false), query_ext_(), feature_bbox_(), tr_(new transcoder(encoding)), - shx_file_length_(shx_file_length), + shx_file_length_(0), row_limit_(row_limit), count_(0), ctx_(std::make_shared()) { - shape_.shx().skip(100); + if (!shape_.shx().is_open()) + { + throw mapnik::datasource_exception("Shape Plugin: can't open '" + shape_name + ".shx' file"); + } + shape_file::record_type shx_header(100); + shape_.shx().read_record(shx_header); + shx_header.skip(6 * 4); + shx_file_length_ = shx_header.read_xdr_integer(); setup_attributes(ctx_, attribute_names, shape_name, shape_, attr_ids_); } diff --git a/plugins/input/shape/shape_featureset.hpp b/plugins/input/shape/shape_featureset.hpp index dd711a054..caa962554 100644 --- a/plugins/input/shape/shape_featureset.hpp +++ b/plugins/input/shape/shape_featureset.hpp @@ -50,7 +50,6 @@ public: std::string const& shape_file, std::set const& attribute_names, std::string const& encoding, - long shx_file_length, int row_limit); virtual ~shape_featureset(); feature_ptr next();