Skip to content

Commit

Permalink
fixed missing 'encoding' parameter:
Browse files Browse the repository at this point in the history
>>> 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__()
  • Loading branch information
artemp committed Feb 14, 2007
1 parent eda5386 commit 73bd1ab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
31 changes: 22 additions & 9 deletions plugins/input/shape/shape.cpp
Expand Up @@ -23,10 +23,7 @@
#include <iostream>
#include <fstream>
#include <stdexcept>

#include <mapnik/geom_util.hpp>


#include "shape_featureset.hpp"
#include "shape_index_featureset.hpp"

Expand All @@ -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)
Expand Down Expand Up @@ -110,7 +109,7 @@ void shape_datasource::init(shape_io& shape)
//invalid version number
throw datasource_exception("invalid version number");
}
int shape_type=shape.shp().read_ndr_integer();
int shape_type = shape.shp().read_ndr_integer();
shape.shp().read_envelope(extent_);
shape.shp().skip(4*8);

Expand Down Expand Up @@ -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_));
}
}

Expand All @@ -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_));
}
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/input/shape/shape_featureset.cpp
Expand Up @@ -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)
{
Expand Down
7 changes: 5 additions & 2 deletions plugins/input/shape/shape_featureset.hpp
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions plugins/input/shape/shape_index_featureset.cpp
Expand Up @@ -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)

{
Expand Down
6 changes: 4 additions & 2 deletions plugins/input/shape/shape_index_featureset.hpp
Expand Up @@ -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:
Expand Down

0 comments on commit 73bd1ab

Please sign in to comment.