fixed missing 'encoding' parameter:

>>> from mapnik import *
>>> ds = Shapefile(file='./demo/data/boundaries',encoding='latin1')
>>> pt = ds.envelope().center()
>>> print ds.describe()
>>> for f in ds.features_at_point(pt):
>>>     print f.properties['NOM_FR'].unicode()
>>>     print f.properties['NOM_FR'].__str__()
This commit is contained in:
Artem Pavlenko 2007-02-14 21:55:04 +00:00
parent eda5386b3f
commit 73bd1ab83e
5 changed files with 36 additions and 16 deletions

View file

@ -23,10 +23,7 @@
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <mapnik/geom_util.hpp>
#include "shape_featureset.hpp"
#include "shape_index_featureset.hpp"
@ -40,10 +37,12 @@ shape_datasource::shape_datasource(const parameters &params)
type_(datasource::Vector),
file_length_(0),
indexed_(false),
desc_(params.get("name"),"latin1")
desc_(params.get("name"),"utf-8")
{
try
{
std::string encoding = params.get("encoding");
if (encoding.length() > 0) desc_.set_encoding(encoding);
shape_io shape(shape_name_);
init(shape);
for (int i=0;i<shape.dbf().num_fields();++i)
@ -152,12 +151,19 @@ featureset_ptr shape_datasource::features(const query& q) const
if (indexed_)
{
return featureset_ptr
(new shape_index_featureset<filter_in_box>(filter,shape_name_,q.property_names()));
(new shape_index_featureset<filter_in_box>(filter,
shape_name_,
q.property_names(),
desc_.get_encoding()));
}
else
{
return featureset_ptr
(new shape_featureset<filter_in_box>(filter,shape_name_,q.property_names(),file_length_));
(new shape_featureset<filter_in_box>(filter,
shape_name_,
q.property_names(),
desc_.get_encoding(),
file_length_));
}
}
@ -179,12 +185,19 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
if (indexed_)
{
return featureset_ptr
(new shape_index_featureset<filter_at_point>(filter,shape_name_,names));
(new shape_index_featureset<filter_at_point>(filter,
shape_name_,
names,
desc_.get_encoding()));
}
else
{
return featureset_ptr
(new shape_featureset<filter_at_point>(filter,shape_name_,names,file_length_));
(new shape_featureset<filter_at_point>(filter,
shape_name_,
names,
desc_.get_encoding(),
file_length_));
}
}

View file

@ -27,12 +27,13 @@ template <typename filterT>
shape_featureset<filterT>::shape_featureset(const filterT& filter,
const std::string& shape_file,
const std::set<std::string>& attribute_names,
std::string const& encoding,
long file_length )
: filter_(filter),
shape_type_(shape_io::shape_null),
shape_(shape_file),
query_ext_(),
tr_(new transcoder("latin1")),
tr_(new transcoder(encoding)),
file_length_(file_length),
count_(0)
{

View file

@ -43,8 +43,11 @@ class shape_featureset : public Featureset
mutable int total_geom_size;
mutable int count_;
public:
shape_featureset(const filterT& filter, const std::string& shape_file,
const std::set<std::string>& attribute_names,long file_length);
shape_featureset(const filterT& filter,
const std::string& shape_file,
const std::set<std::string>& attribute_names,
std::string const& encoding,
long file_length);
virtual ~shape_featureset();
feature_ptr next();
private:

View file

@ -28,11 +28,12 @@
template <typename filterT>
shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
const std::string& shape_file,
const std::set<std::string>& attribute_names)
const std::set<std::string>& attribute_names,
std::string const& encoding)
: filter_(filter),
shape_type_(0),
shape_(shape_file),
tr_(new transcoder("latin1")),
tr_(new transcoder(encoding)),
count_(0)
{

View file

@ -43,8 +43,10 @@ class shape_index_featureset : public Featureset
mutable int count_;
public:
shape_index_featureset(const filterT& filter,const std::string& shape_file,
const std::set<std::string>& attribute_names);
shape_index_featureset(const filterT& filter,
const std::string& shape_file,
const std::set<std::string>& attribute_names,
std::string const& encoding);
virtual ~shape_index_featureset();
feature_ptr next();
private: