shape.input - pass shx_file_length to shape_featureset
This commit is contained in:
parent
a73e8537d8
commit
b798503623
5 changed files with 39 additions and 23 deletions
|
@ -64,6 +64,7 @@ shape_datasource::shape_datasource(parameters const& params)
|
||||||
: datasource (params),
|
: datasource (params),
|
||||||
type_(datasource::Vector),
|
type_(datasource::Vector),
|
||||||
file_length_(0),
|
file_length_(0),
|
||||||
|
shx_file_length_(0),
|
||||||
indexed_(false),
|
indexed_(false),
|
||||||
row_limit_(*params.get<mapnik::value_integer>("row_limit",0)),
|
row_limit_(*params.get<mapnik::value_integer>("row_limit",0)),
|
||||||
desc_(shape_datasource::name(), *params.get<std::string>("encoding","utf-8"))
|
desc_(shape_datasource::name(), *params.get<std::string>("encoding","utf-8"))
|
||||||
|
@ -104,7 +105,7 @@ shape_datasource::shape_datasource(parameters const& params)
|
||||||
init(*shape_ref);
|
init(*shape_ref);
|
||||||
for (int i=0;i<shape_ref->dbf().num_fields();++i)
|
for (int i=0;i<shape_ref->dbf().num_fields();++i)
|
||||||
{
|
{
|
||||||
field_descriptor const& fd=shape_ref->dbf().descriptor(i);
|
field_descriptor const& fd = shape_ref->dbf().descriptor(i);
|
||||||
std::string fld_name=fd.name_;
|
std::string fld_name=fd.name_;
|
||||||
switch (fd.type_)
|
switch (fd.type_)
|
||||||
{
|
{
|
||||||
|
@ -167,36 +168,50 @@ void shape_datasource::init(shape_io& shape)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//first read header from *.shp
|
//first read header from *.shp
|
||||||
int file_code=shape.shp().read_xdr_integer();
|
shape_file::record_type header(100);
|
||||||
if (file_code!=9994)
|
shape.shp().read_record(header);
|
||||||
|
|
||||||
|
int file_code = header.read_xdr_integer();
|
||||||
|
if (file_code != 9994)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << "Shape Plugin: wrong file code " << file_code;
|
s << "Shape Plugin: wrong file code " << file_code;
|
||||||
throw datasource_exception(s.str());
|
throw datasource_exception(s.str());
|
||||||
}
|
}
|
||||||
|
header.skip(5 * 4);
|
||||||
|
file_length_ = header.read_xdr_integer();
|
||||||
|
int version = header.read_ndr_integer();
|
||||||
|
|
||||||
shape.shp().skip(5*4);
|
if (version != 1000)
|
||||||
file_length_=shape.shp().read_xdr_integer();
|
|
||||||
int version=shape.shp().read_ndr_integer();
|
|
||||||
|
|
||||||
if (version!=1000)
|
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << "Shape Plugin: nvalid version number " << version;
|
s << "Shape Plugin: nvalid version number " << version;
|
||||||
throw datasource_exception(s.str());
|
throw datasource_exception(s.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
shape_type_ = static_cast<shape_io::shapeType>(shape.shp().read_ndr_integer());
|
shape_type_ = static_cast<shape_io::shapeType>(header.read_ndr_integer());
|
||||||
if (shape_type_ == shape_io::shape_multipatch)
|
if (shape_type_ == shape_io::shape_multipatch)
|
||||||
throw datasource_exception("Shape Plugin: shapefile multipatch type is not supported");
|
throw datasource_exception("Shape Plugin: shapefile multipatch type is not supported");
|
||||||
|
|
||||||
shape.shp().read_envelope(extent_);
|
const double lox = header.read_double();
|
||||||
|
const double loy = header.read_double();
|
||||||
|
const double hix = header.read_double();
|
||||||
|
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
|
#ifdef MAPNIK_LOG
|
||||||
const double zmin = shape.shp().read_double();
|
const double zmin = header.read_double();
|
||||||
const double zmax = shape.shp().read_double();
|
const double zmax = header.read_double();
|
||||||
const double mmin = shape.shp().read_double();
|
const double mmin = header.read_double();
|
||||||
const double mmax = shape.shp().read_double();
|
const double mmax = header.read_double();
|
||||||
|
|
||||||
MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Z min/max=" << zmin << "," << zmax;
|
MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Z min/max=" << zmin << "," << zmax;
|
||||||
MAPNIK_LOG_DEBUG(shape) << "shape_datasource: M min/max=" << mmin << "," << mmax;
|
MAPNIK_LOG_DEBUG(shape) << "shape_datasource: M min/max=" << mmin << "," << mmax;
|
||||||
|
@ -250,7 +265,7 @@ featureset_ptr shape_datasource::features(query const& q) const
|
||||||
shape_name_,
|
shape_name_,
|
||||||
q.property_names(),
|
q.property_names(),
|
||||||
desc_.get_encoding(),
|
desc_.get_encoding(),
|
||||||
file_length_,
|
shx_file_length_,
|
||||||
row_limit_);
|
row_limit_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ private:
|
||||||
std::string shape_name_;
|
std::string shape_name_;
|
||||||
shape_io::shapeType shape_type_;
|
shape_io::shapeType shape_type_;
|
||||||
long file_length_;
|
long file_length_;
|
||||||
|
long shx_file_length_;
|
||||||
box2d<double> extent_;
|
box2d<double> extent_;
|
||||||
bool indexed_;
|
bool indexed_;
|
||||||
const int row_limit_;
|
const int row_limit_;
|
||||||
|
|
|
@ -41,19 +41,18 @@ shape_featureset<filterT>::shape_featureset(filterT const& filter,
|
||||||
std::string const& shape_name,
|
std::string const& shape_name,
|
||||||
std::set<std::string> const& attribute_names,
|
std::set<std::string> const& attribute_names,
|
||||||
std::string const& encoding,
|
std::string const& encoding,
|
||||||
long file_length,
|
long shx_file_length,
|
||||||
int row_limit)
|
int row_limit)
|
||||||
: filter_(filter),
|
: filter_(filter),
|
||||||
shape_(shape_name, false),
|
shape_(shape_name, false),
|
||||||
query_ext_(),
|
query_ext_(),
|
||||||
feature_bbox_(),
|
feature_bbox_(),
|
||||||
tr_(new transcoder(encoding)),
|
tr_(new transcoder(encoding)),
|
||||||
file_length_(file_length),
|
shx_file_length_(shx_file_length),
|
||||||
row_limit_(row_limit),
|
row_limit_(row_limit),
|
||||||
count_(0),
|
count_(0),
|
||||||
ctx_(std::make_shared<mapnik::context_type>())
|
ctx_(std::make_shared<mapnik::context_type>())
|
||||||
{
|
{
|
||||||
shape_.shp().skip(100);
|
|
||||||
shape_.shx().skip(100);
|
shape_.shx().skip(100);
|
||||||
setup_attributes(ctx_, attribute_names, shape_name, shape_, attr_ids_);
|
setup_attributes(ctx_, attribute_names, shape_name, shape_, attr_ids_);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +64,8 @@ feature_ptr shape_featureset<filterT>::next()
|
||||||
{
|
{
|
||||||
return feature_ptr();
|
return feature_ptr();
|
||||||
}
|
}
|
||||||
while (!shape_.shx().is_eof())
|
|
||||||
|
while (shape_.shx().pos() < 2 * shx_file_length_)
|
||||||
{
|
{
|
||||||
int offset = shape_.shx().read_xdr_integer();
|
int offset = shape_.shx().read_xdr_integer();
|
||||||
int record_length = shape_.shx().read_xdr_integer();
|
int record_length = shape_.shx().read_xdr_integer();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
std::string const& shape_file,
|
std::string const& shape_file,
|
||||||
std::set<std::string> const& attribute_names,
|
std::set<std::string> const& attribute_names,
|
||||||
std::string const& encoding,
|
std::string const& encoding,
|
||||||
long file_length,
|
long shx_file_length,
|
||||||
int row_limit);
|
int row_limit);
|
||||||
virtual ~shape_featureset();
|
virtual ~shape_featureset();
|
||||||
feature_ptr next();
|
feature_ptr next();
|
||||||
|
@ -61,7 +61,7 @@ private:
|
||||||
box2d<double> query_ext_;
|
box2d<double> query_ext_;
|
||||||
mutable box2d<double> feature_bbox_;
|
mutable box2d<double> feature_bbox_;
|
||||||
const std::unique_ptr<transcoder> tr_;
|
const std::unique_ptr<transcoder> tr_;
|
||||||
long file_length_;
|
long shx_file_length_;
|
||||||
std::vector<int> attr_ids_;
|
std::vector<int> attr_ids_;
|
||||||
mapnik::value_integer row_limit_;
|
mapnik::value_integer row_limit_;
|
||||||
mutable int count_;
|
mutable int count_;
|
||||||
|
|
|
@ -85,8 +85,8 @@ public:
|
||||||
shape_file shx_;
|
shape_file shx_;
|
||||||
dbf_file dbf_;
|
dbf_file dbf_;
|
||||||
std::unique_ptr<shape_file> index_;
|
std::unique_ptr<shape_file> index_;
|
||||||
unsigned reclength_;
|
int reclength_;
|
||||||
unsigned id_;
|
int id_;
|
||||||
box2d<double> cur_extent_;
|
box2d<double> cur_extent_;
|
||||||
|
|
||||||
static const std::string SHP;
|
static const std::string SHP;
|
||||||
|
|
Loading…
Add table
Reference in a new issue