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:
parent
eda5386b3f
commit
73bd1ab83e
5 changed files with 36 additions and 16 deletions
|
@ -23,10 +23,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <mapnik/geom_util.hpp>
|
#include <mapnik/geom_util.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include "shape_featureset.hpp"
|
#include "shape_featureset.hpp"
|
||||||
#include "shape_index_featureset.hpp"
|
#include "shape_index_featureset.hpp"
|
||||||
|
|
||||||
|
@ -40,10 +37,12 @@ shape_datasource::shape_datasource(const parameters ¶ms)
|
||||||
type_(datasource::Vector),
|
type_(datasource::Vector),
|
||||||
file_length_(0),
|
file_length_(0),
|
||||||
indexed_(false),
|
indexed_(false),
|
||||||
desc_(params.get("name"),"latin1")
|
desc_(params.get("name"),"utf-8")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
std::string encoding = params.get("encoding");
|
||||||
|
if (encoding.length() > 0) desc_.set_encoding(encoding);
|
||||||
shape_io shape(shape_name_);
|
shape_io shape(shape_name_);
|
||||||
init(shape);
|
init(shape);
|
||||||
for (int i=0;i<shape.dbf().num_fields();++i)
|
for (int i=0;i<shape.dbf().num_fields();++i)
|
||||||
|
@ -110,7 +109,7 @@ void shape_datasource::init(shape_io& shape)
|
||||||
//invalid version number
|
//invalid version number
|
||||||
throw datasource_exception("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().read_envelope(extent_);
|
||||||
shape.shp().skip(4*8);
|
shape.shp().skip(4*8);
|
||||||
|
|
||||||
|
@ -152,12 +151,19 @@ featureset_ptr shape_datasource::features(const query& q) const
|
||||||
if (indexed_)
|
if (indexed_)
|
||||||
{
|
{
|
||||||
return featureset_ptr
|
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
|
else
|
||||||
{
|
{
|
||||||
return featureset_ptr
|
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_)
|
if (indexed_)
|
||||||
{
|
{
|
||||||
return featureset_ptr
|
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
|
else
|
||||||
{
|
{
|
||||||
return featureset_ptr
|
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_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,13 @@ template <typename filterT>
|
||||||
shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
||||||
const std::string& shape_file,
|
const std::string& shape_file,
|
||||||
const std::set<std::string>& attribute_names,
|
const std::set<std::string>& attribute_names,
|
||||||
|
std::string const& encoding,
|
||||||
long file_length )
|
long file_length )
|
||||||
: filter_(filter),
|
: filter_(filter),
|
||||||
shape_type_(shape_io::shape_null),
|
shape_type_(shape_io::shape_null),
|
||||||
shape_(shape_file),
|
shape_(shape_file),
|
||||||
query_ext_(),
|
query_ext_(),
|
||||||
tr_(new transcoder("latin1")),
|
tr_(new transcoder(encoding)),
|
||||||
file_length_(file_length),
|
file_length_(file_length),
|
||||||
count_(0)
|
count_(0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,8 +43,11 @@ class shape_featureset : public Featureset
|
||||||
mutable int total_geom_size;
|
mutable int total_geom_size;
|
||||||
mutable int count_;
|
mutable int count_;
|
||||||
public:
|
public:
|
||||||
shape_featureset(const filterT& filter, const std::string& shape_file,
|
shape_featureset(const filterT& filter,
|
||||||
const std::set<std::string>& attribute_names,long file_length);
|
const std::string& shape_file,
|
||||||
|
const std::set<std::string>& attribute_names,
|
||||||
|
std::string const& encoding,
|
||||||
|
long file_length);
|
||||||
virtual ~shape_featureset();
|
virtual ~shape_featureset();
|
||||||
feature_ptr next();
|
feature_ptr next();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,11 +28,12 @@
|
||||||
template <typename filterT>
|
template <typename filterT>
|
||||||
shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
||||||
const std::string& shape_file,
|
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),
|
: filter_(filter),
|
||||||
shape_type_(0),
|
shape_type_(0),
|
||||||
shape_(shape_file),
|
shape_(shape_file),
|
||||||
tr_(new transcoder("latin1")),
|
tr_(new transcoder(encoding)),
|
||||||
count_(0)
|
count_(0)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,8 +43,10 @@ class shape_index_featureset : public Featureset
|
||||||
mutable int count_;
|
mutable int count_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shape_index_featureset(const filterT& filter,const std::string& shape_file,
|
shape_index_featureset(const filterT& filter,
|
||||||
const std::set<std::string>& attribute_names);
|
const std::string& shape_file,
|
||||||
|
const std::set<std::string>& attribute_names,
|
||||||
|
std::string const& encoding);
|
||||||
virtual ~shape_index_featureset();
|
virtual ~shape_index_featureset();
|
||||||
feature_ptr next();
|
feature_ptr next();
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue