upgrade shape.input to new feature impl

This commit is contained in:
Artem Pavlenko 2012-01-12 10:04:08 +00:00
parent 62fcb51e2f
commit 0dc71c9eda
6 changed files with 24 additions and 17 deletions

View file

@ -121,7 +121,7 @@ const field_descriptor& dbf_file::descriptor(int col) const
}
void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature const& f) const throw()
void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f) const throw()
{
using namespace boost::spirit;
@ -139,7 +139,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
// FIXME - avoid constructing std::string on stack
std::string str(record_+fields_[col].offset_,fields_[col].length_);
boost::trim(str);
f[name] = tr.transcode(str.c_str());
f.put(name,tr.transcode(str.c_str()));
break;
}
case 'N':
@ -148,7 +148,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
if (record_[fields_[col].offset_] == '*')
{
boost::put(f,name,0);
f.put(name,0);
break;
}
if ( fields_[col].dec_>0 )
@ -157,7 +157,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
const char *itr = record_+fields_[col].offset_;
const char *end = itr + fields_[col].length_;
qi::phrase_parse(itr,end,double_,ascii::space,val);
boost::put(f,name,val);
f.put(name,val);
}
else
{
@ -165,7 +165,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
const char *itr = record_+fields_[col].offset_;
const char *end = itr + fields_[col].length_;
qi::phrase_parse(itr,end,int_,ascii::space,val);
boost::put(f,name,val);
f.put(name,val);
}
break;
}

View file

@ -71,7 +71,7 @@ public:
field_descriptor const& descriptor(int col) const;
void move_to(int index);
std::string string_value(int col) const;
void add_attribute(int col, transcoder const& tr, Feature const& f) const throw();
void add_attribute(int col, transcoder const& tr, Feature & f) const throw();
private:
void read_header();
int read_short();

View file

@ -34,6 +34,7 @@
using mapnik::geometry_type;
using mapnik::feature_factory;
using mapnik::context_ptr;
template <typename filterT>
shape_featureset<filterT>::shape_featureset(const filterT& filter,
@ -43,7 +44,6 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
long file_length,
int row_limit)
: filter_(filter),
//shape_type_(shape_io::shape_null),
shape_(shape_name, false),
query_ext_(),
tr_(new transcoder(encoding)),
@ -51,23 +51,26 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
count_(0),
row_limit_(row_limit)
{
ctx_ = boost::make_shared<mapnik::context>();
shape_.shp().skip(100);
//attributes
typename std::set<std::string>::const_iterator pos = attribute_names.begin();
while (pos != attribute_names.end())
{
bool found_name = false;
for (int i = 0; i < shape_.dbf().num_fields(); ++i)
{
if (shape_.dbf().descriptor(i).name_ == *pos)
{
{
ctx_->push(*pos);
attr_ids_.push_back(i);
found_name = true;
break;
}
}
if (! found_name)
{
std::ostringstream s;
@ -115,7 +118,7 @@ feature_ptr shape_featureset<filterT>::next()
if (pos < std::streampos(file_length_ * 2))
{
int type = shape_.type();
feature_ptr feature(feature_factory::create(shape_.id_));
feature_ptr feature(feature_factory::create(ctx_, shape_.id_));
if (type == shape_io::shape_point)
{
@ -266,7 +269,7 @@ feature_ptr shape_featureset<filterT>::next()
}
}
}
// FIXME
feature->set_id(shape_.id_);
if (attr_ids_.size())
{

View file

@ -36,12 +36,13 @@ using mapnik::Featureset;
using mapnik::box2d;
using mapnik::feature_ptr;
using mapnik::transcoder;
using mapnik::context_ptr;
template <typename filterT>
class shape_featureset : public Featureset
{
filterT filter_;
//int shape_type_;
context_ptr ctx_;
shape_io shape_;
box2d<double> query_ext_;
boost::scoped_ptr<transcoder> tr_;

View file

@ -49,6 +49,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
count_(0),
row_limit_(row_limit)
{
ctx_ = boost::make_shared<mapnik::context>();
shape_.shp().skip(100);
boost::shared_ptr<shape_file> index = shape_.index();
@ -69,7 +70,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
#endif
itr_ = ids_.begin();
// deal with attributes
std::set<std::string>::const_iterator pos = attribute_names.begin();
while (pos != attribute_names.end())
@ -79,6 +80,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
{
if (shape_.dbf().descriptor(i).name_ == *pos)
{
ctx_->push(*pos);
attr_ids_.insert(i);
found_name = true;
break;
@ -119,7 +121,7 @@ feature_ptr shape_index_featureset<filterT>::next()
shape_.move_to(pos);
int type = shape_.type();
feature_ptr feature(feature_factory::create(shape_.id_));
feature_ptr feature(feature_factory::create(ctx_,shape_.id_));
if (type == shape_io::shape_point)
{
double x = shape_.shp().read_double();
@ -210,7 +212,7 @@ feature_ptr shape_index_featureset<filterT>::next()
}
}
}
// FIXME
feature->set_id(shape_.id_);
if (attr_ids_.size())
{

View file

@ -39,6 +39,7 @@
using mapnik::Featureset;
using mapnik::box2d;
using mapnik::feature_ptr;
using mapnik::context_ptr;
template <typename filterT>
class shape_index_featureset : public Featureset
@ -55,7 +56,7 @@ public:
private:
filterT filter_;
//int shape_type_;
context_ptr ctx_;
shape_io & shape_;
boost::scoped_ptr<transcoder> tr_;
std::vector<int> ids_;