1. Removed srid from geometry class
2. Pass resolution to bbox query 3. Use variant<int,double,string> as parameter value e.g in Python: ds = Raster(file="/path/to/file",lox = 12312.4,.....) Added extractor facility to work with mapnik::parameter (C++): mapnik::parameters params; params["parameter0"] = 123.456; params["parameter1"] = "123.456"; // initialize with string extract double later boost::optional<double> val0 = params.get<double>("parameter0"); if (val0) { std::cout << *val0; } // with default value. NOTE: there is no 'parameter2' in params boost::optional<double> val2 = params.get<double>("parameter2",654.321); std::cout << * val2; // 4. Added Gdal factory method in __init__.py ds = Gdal(file="/tmp/file.tiff")
This commit is contained in:
parent
e8d5172a64
commit
8010d5433f
22 changed files with 502 additions and 499 deletions
|
@ -16,9 +16,7 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
from sys import getdlopenflags,setdlopenflags
|
||||
try:
|
||||
|
@ -56,9 +54,9 @@ class _Envelope(Envelope,_injector):
|
|||
|
||||
class _Projection(Projection,_injector):
|
||||
def forward(self,pt):
|
||||
return forward(pt,self)
|
||||
return forward_(pt,self)
|
||||
def inverse(self,pt):
|
||||
return inverse(pt,self)
|
||||
return inverse_(pt,self)
|
||||
|
||||
class _Datasource(Datasource,_injector):
|
||||
def describe(self):
|
||||
|
@ -81,6 +79,10 @@ def Raster(**keywords):
|
|||
keywords['type'] = 'raster'
|
||||
return CreateDatasource(keywords)
|
||||
|
||||
def Gdal (**keywords):
|
||||
keywords['type'] = 'gdal'
|
||||
return CreateDatasource(keywords)
|
||||
|
||||
#register datasources
|
||||
from mapnik import DatasourceCache
|
||||
DatasourceCache.instance().register_datasources('%s' % inputpluginspath)
|
||||
|
|
|
@ -43,10 +43,21 @@ namespace
|
|||
{
|
||||
std::string key = extract<std::string>(keys[i]);
|
||||
object obj = d[key];
|
||||
extract<std::string> ex(obj);
|
||||
if (ex.check())
|
||||
extract<std::string> ex0(obj);
|
||||
extract<int> ex1(obj);
|
||||
extract<double> ex2(obj);
|
||||
|
||||
if (ex0.check())
|
||||
{
|
||||
params[key] = ex();
|
||||
params[key] = ex0();
|
||||
}
|
||||
else if (ex1.check())
|
||||
{
|
||||
params[key] = ex1();
|
||||
}
|
||||
else if (ex2.check())
|
||||
{
|
||||
params[key] = ex2();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
|
|||
for (int i=0;i<len(keys);++i)
|
||||
{
|
||||
std::string key=extract<std::string>(keys[i]);
|
||||
std::string value=extract<std::string>(d[key]);
|
||||
std::string value=extract<std::string>(d[key]); // FIXME: use boost::variant as a value object. Add Py_Int/Py_Float/Py_String extractors.
|
||||
p[key] = value;
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +85,6 @@ void export_parameters()
|
|||
;
|
||||
|
||||
class_<parameters>("Parameters",init<>())
|
||||
//.def("add",add1)
|
||||
//.def("add",add2)
|
||||
.def("get",¶meters::get)
|
||||
.def_pickle(parameters_pickle_suite())
|
||||
;
|
||||
}
|
||||
|
|
|
@ -52,14 +52,12 @@ void export_projection ()
|
|||
using mapnik::projection;
|
||||
|
||||
class_<projection>("Projection", init<optional<std::string const&> >())
|
||||
.def ("forward",&projection::forward)
|
||||
.def ("inverse",&projection::inverse)
|
||||
.def ("params", make_function(&projection::params,
|
||||
return_value_policy<copy_const_reference>()))
|
||||
.add_property ("geographic",&projection::is_geographic)
|
||||
;
|
||||
|
||||
def("forward",&forward);
|
||||
def("inverse",&inverse);
|
||||
def("forward_",&forward);
|
||||
def("inverse_",&inverse);
|
||||
|
||||
}
|
||||
|
|
|
@ -123,6 +123,8 @@ namespace mapnik
|
|||
prj_trans.forward(x0,y0,z0);
|
||||
prj_trans.forward(x1,y1,z1);
|
||||
Envelope<double> bbox(x0,y0,x1,y1);
|
||||
|
||||
double resolution = m_.getWidth()/bbox.width();
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << bbox << "\n";
|
||||
#endif
|
||||
|
@ -141,7 +143,7 @@ namespace mapnik
|
|||
|
||||
feature_type_style const& style=m_.find_style(*stylesIter++);
|
||||
|
||||
query q(bbox); //BBOX query
|
||||
query q(bbox,resolution); //BBOX query
|
||||
|
||||
const std::vector<rule_type>& rules=style.get_rules();
|
||||
std::vector<rule_type>::const_iterator ruleIter=rules.begin();
|
||||
|
|
|
@ -47,16 +47,8 @@ namespace mapnik {
|
|||
public:
|
||||
typedef T vertex_type;
|
||||
typedef typename vertex_type::type value_type;
|
||||
private:
|
||||
int srid_;
|
||||
public:
|
||||
geometry (int srid=-1)
|
||||
: srid_(srid) {}
|
||||
|
||||
int srid() const
|
||||
{
|
||||
return srid_;
|
||||
}
|
||||
geometry () {}
|
||||
|
||||
Envelope<double> envelope()
|
||||
{
|
||||
|
@ -99,14 +91,13 @@ namespace mapnik {
|
|||
private:
|
||||
vertex_type pt_;
|
||||
public:
|
||||
point(int srid)
|
||||
: geometry<T>(srid)
|
||||
{}
|
||||
point() : geometry<T>() {}
|
||||
|
||||
int type() const
|
||||
{
|
||||
return Point;
|
||||
}
|
||||
|
||||
void label_position(double *x, double *y) const
|
||||
{
|
||||
*x = pt_.x;
|
||||
|
@ -155,8 +146,8 @@ namespace mapnik {
|
|||
container_type cont_;
|
||||
mutable unsigned itr_;
|
||||
public:
|
||||
polygon(int srid)
|
||||
: geometry_base(srid),
|
||||
polygon()
|
||||
: geometry_base(),
|
||||
itr_(0)
|
||||
{}
|
||||
|
||||
|
@ -167,7 +158,6 @@ namespace mapnik {
|
|||
|
||||
void label_position(double *x, double *y) const
|
||||
{
|
||||
|
||||
unsigned size = cont_.size();
|
||||
if (size < 3)
|
||||
{
|
||||
|
@ -252,8 +242,8 @@ namespace mapnik {
|
|||
container_type cont_;
|
||||
mutable unsigned itr_;
|
||||
public:
|
||||
line_string(int srid)
|
||||
: geometry_base(srid),
|
||||
line_string()
|
||||
: geometry_base(),
|
||||
itr_(0)
|
||||
{}
|
||||
|
||||
|
@ -312,7 +302,6 @@ namespace mapnik {
|
|||
dist += seg_len;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void line_to(value_type x,value_type y)
|
||||
{
|
||||
|
|
|
@ -26,26 +26,72 @@
|
|||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
typedef boost::variant<int,double,std::string> value_holder;
|
||||
typedef std::pair<const std::string, value_holder> parameter;
|
||||
typedef std::map<const std::string, value_holder> param_map;
|
||||
|
||||
template <typename T>
|
||||
struct value_extractor_visitor : public boost::static_visitor<>
|
||||
{
|
||||
value_extractor_visitor(boost::optional<T> & var)
|
||||
:var_(var) {}
|
||||
|
||||
void operator () (T val) const
|
||||
{
|
||||
var_ = val;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
void operator () (T1 val) const
|
||||
{
|
||||
try
|
||||
{
|
||||
var_ = boost::lexical_cast<T>(val);
|
||||
}
|
||||
catch (boost::bad_lexical_cast & ) {}
|
||||
}
|
||||
|
||||
boost::optional<T> & var_;
|
||||
};
|
||||
|
||||
typedef std::pair<const std::string,std::string> parameter;
|
||||
typedef std::map<const std::string,std::string> param_map;
|
||||
|
||||
class parameters : public param_map
|
||||
{
|
||||
public:
|
||||
|
||||
parameters() {}
|
||||
const std::string get(std::string const& key) const
|
||||
template <typename T>
|
||||
struct converter
|
||||
{
|
||||
param_map::const_iterator itr=find(key);
|
||||
if (itr != end())
|
||||
typedef boost::optional<T> return_type;
|
||||
static return_type extract(parameters const& params,std::string const& name, boost::optional<T> const& default_value)
|
||||
{
|
||||
return itr->second;
|
||||
boost::optional<T> result(default_value);
|
||||
parameters::const_iterator itr = params.find(name);
|
||||
if (itr != params.end())
|
||||
{
|
||||
boost::apply_visitor(value_extractor_visitor<T>(result),itr->second);
|
||||
}
|
||||
return std::string();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
public:
|
||||
parameters() {}
|
||||
|
||||
template <typename T>
|
||||
boost::optional<T> get(std::string const& key) const
|
||||
{
|
||||
return converter<T>::extract(*this,key, boost::none);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
boost::optional<T> get(std::string const& key, T const& default_value) const
|
||||
{
|
||||
return converter<T>::extract(*this,key,boost::optional<T>(default_value));
|
||||
}
|
||||
|
||||
param_map::const_iterator iterator(std::string const& key) const
|
||||
|
@ -57,7 +103,6 @@ namespace mapnik
|
|||
{
|
||||
return find(key);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -32,51 +32,39 @@
|
|||
#include <mapnik/envelope.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
namespace mapnik {
|
||||
class query
|
||||
{
|
||||
private:
|
||||
Envelope<double> bbox_;
|
||||
filter<Feature>* filter_;
|
||||
double resolution_;
|
||||
std::set<std::string> names_;
|
||||
public:
|
||||
query()
|
||||
: bbox_(std::numeric_limits<double>::min(),
|
||||
std::numeric_limits<double>::min(),
|
||||
std::numeric_limits<double>::max(),
|
||||
std::numeric_limits<double>::max()),
|
||||
filter_(new all_filter<Feature>)
|
||||
|
||||
explicit query(const Envelope<double>& bbox, double resolution)
|
||||
: bbox_(bbox),
|
||||
resolution_(resolution)
|
||||
{}
|
||||
|
||||
query(const Envelope<double>& bbox)
|
||||
: bbox_(bbox),
|
||||
filter_(new all_filter<Feature>)
|
||||
{}
|
||||
|
||||
query(const Envelope<double>& bbox, const filter<Feature>& f)
|
||||
: bbox_(bbox),
|
||||
filter_(f.clone())
|
||||
{}
|
||||
|
||||
query(const query& other)
|
||||
: bbox_(other.bbox_),
|
||||
filter_(other.filter_->clone())
|
||||
resolution_(other.resolution_),
|
||||
names_(other.names_)
|
||||
{}
|
||||
|
||||
query& operator=(const query& other)
|
||||
{
|
||||
filter<Feature>* tmp=other.filter_->clone();
|
||||
delete filter_;
|
||||
filter_=tmp;
|
||||
if (this == &other) return *this;
|
||||
bbox_=other.bbox_;
|
||||
resolution_=other.resolution_;
|
||||
names_=other.names_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const filter<Feature>* get_filter() const
|
||||
double resolution() const
|
||||
{
|
||||
return filter_;
|
||||
return resolution_;
|
||||
}
|
||||
|
||||
const Envelope<double>& get_bbox() const
|
||||
|
@ -84,13 +72,6 @@ namespace mapnik
|
|||
return bbox_;
|
||||
}
|
||||
|
||||
void set_filter(const filter<Feature>& f)
|
||||
{
|
||||
filter<Feature>* tmp=f.clone();
|
||||
delete filter_;
|
||||
filter_=tmp;
|
||||
}
|
||||
|
||||
void add_property_name(const std::string& name)
|
||||
{
|
||||
names_.insert(name);
|
||||
|
@ -100,11 +81,6 @@ namespace mapnik
|
|||
{
|
||||
return names_;
|
||||
}
|
||||
|
||||
~query()
|
||||
{
|
||||
delete filter_;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ namespace mapnik
|
|||
class MAPNIK_DECL geometry_utils
|
||||
{
|
||||
public:
|
||||
static geometry_ptr from_wkb(const char* wkb, unsigned size,int srid);
|
||||
static geometry_ptr from_wkb(const char* wkb, unsigned size);
|
||||
private:
|
||||
geometry_utils();
|
||||
geometry_utils(const geometry_utils&);
|
||||
geometry_utils(geometry_utils const&);
|
||||
geometry_utils& operator=(const geometry_utils&);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -34,16 +34,19 @@ using mapnik::coord2d;
|
|||
using mapnik::query;
|
||||
using mapnik::featureset_ptr;
|
||||
using mapnik::layer_descriptor;
|
||||
using mapnik::datasource_exception;
|
||||
|
||||
gdal_datasource::gdal_datasource( parameters const& params)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
desc_(params.get("name"),"utf-8")
|
||||
desc_(*params.get<std::string>("type"),"utf-8")
|
||||
{
|
||||
GDALAllRegister();
|
||||
dataset_ = boost::shared_ptr<GDALDataset>(reinterpret_cast<GDALDataset*>(GDALOpen(params.get("file").c_str(),GA_ReadOnly)));
|
||||
if (dataset_)
|
||||
{
|
||||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
if (!file) throw datasource_exception("missing <file> paramater");
|
||||
|
||||
dataset_ = boost::shared_ptr<GDALDataset>(reinterpret_cast<GDALDataset*>(GDALOpen((*file).c_str(),GA_ReadOnly)));
|
||||
if (!dataset_) throw datasource_exception("failed to create GDALDataset");
|
||||
double tr[6];
|
||||
dataset_->GetGeoTransform(tr);
|
||||
double x0 = tr[0];
|
||||
|
@ -52,7 +55,6 @@ gdal_datasource::gdal_datasource( parameters const& params)
|
|||
double y1 = tr[3] + dataset_->GetRasterXSize()*tr[4] + dataset_->GetRasterYSize()*tr[5];
|
||||
extent_.init(x0,y0,x1,y1);
|
||||
}
|
||||
}
|
||||
|
||||
gdal_datasource::~gdal_datasource() {}
|
||||
|
||||
|
|
|
@ -38,25 +38,12 @@ class Connection
|
|||
private:
|
||||
PGconn *conn_;
|
||||
public:
|
||||
Connection(std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& dbname,
|
||||
std::string const& username,
|
||||
std::string const& password)
|
||||
Connection(std::string const& connection_str)
|
||||
{
|
||||
|
||||
std::string connStr;
|
||||
if (host.length()) connStr += "host="+host;
|
||||
if (port.length()) connStr += " port="+port;
|
||||
if (dbname.length()) connStr+=" dbname="+dbname;
|
||||
if (username.length()) connStr+=" user="+username;
|
||||
if (password.length()) connStr+=" password="+password;
|
||||
connStr+=" connect_timeout=4"; // todo: set by client (param)
|
||||
|
||||
conn_=PQconnectdb(connStr.c_str());
|
||||
conn_=PQconnectdb(connection_str.c_str());
|
||||
if (PQstatus(conn_) == CONNECTION_BAD)
|
||||
{
|
||||
std::clog << "connection to "<< connStr << " failed\n"
|
||||
std::clog << "connection ["<< connection_str<< "] failed\n"
|
||||
<< PQerrorMessage(conn_)<< std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "connection.hpp"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
using mapnik::Pool;
|
||||
using mapnik::singleton;
|
||||
|
@ -43,11 +44,11 @@ class ConnectionCreator
|
|||
{
|
||||
|
||||
public:
|
||||
ConnectionCreator(string const& host,
|
||||
string const& port,
|
||||
string const& dbname,
|
||||
string const& user,
|
||||
string const& pass)
|
||||
ConnectionCreator(boost::optional<string> const& host,
|
||||
boost::optional<string> const& port,
|
||||
boost::optional<string> const& dbname,
|
||||
boost::optional<string> const& user,
|
||||
boost::optional<string> const& pass)
|
||||
: host_(host),
|
||||
port_(port),
|
||||
dbname_(dbname),
|
||||
|
@ -56,22 +57,32 @@ public:
|
|||
|
||||
T* operator()() const
|
||||
{
|
||||
return new T(host_,port_,dbname_,user_,pass_);
|
||||
return new T(connection_string());
|
||||
}
|
||||
|
||||
std::string id() const
|
||||
inline std::string id() const
|
||||
{
|
||||
return host_ + ":"
|
||||
+ dbname_ + ":"
|
||||
+ port_ +":"
|
||||
+ user_ ;
|
||||
return connection_string();
|
||||
}
|
||||
|
||||
inline std::string connection_string() const
|
||||
{
|
||||
std::string connect_str;
|
||||
if (host_) connect_str += "host=" + *host_;
|
||||
if (port_) connect_str += " port=" + *port_;
|
||||
if (dbname_) connect_str += " dbname=" + *dbname_;
|
||||
if (user_) connect_str += " user=" + *user_;
|
||||
if (pass_) connect_str += " password=" + *pass_;
|
||||
connect_str += " connect_timeout=4"; // todo: set by client (param)
|
||||
return connect_str;
|
||||
}
|
||||
|
||||
private:
|
||||
string host_;
|
||||
string port_;
|
||||
string dbname_;
|
||||
string user_;
|
||||
string pass_;
|
||||
boost::optional<string> host_;
|
||||
boost::optional<string> port_;
|
||||
boost::optional<string> dbname_;
|
||||
boost::optional<string> user_;
|
||||
boost::optional<string> pass_;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -48,40 +48,22 @@ using mapnik::attribute_descriptor;
|
|||
|
||||
postgis_datasource::postgis_datasource(parameters const& params)
|
||||
: datasource (params),
|
||||
table_(params.get("table")),
|
||||
table_(*params.get<std::string>("table","")),
|
||||
type_(datasource::Vector),
|
||||
extent_initialized_(false),
|
||||
desc_(params.get("type"),"utf-8"),
|
||||
creator_(params.get("host"),
|
||||
params.get("port"),
|
||||
params.get("dbname"),
|
||||
params.get("user"),
|
||||
params.get("password"))
|
||||
desc_(*params.get<std::string>("type"),"utf-8"),
|
||||
creator_(params.get<std::string>("host"),
|
||||
params.get<std::string>("port"),
|
||||
params.get<std::string>("dbname"),
|
||||
params.get<std::string>("user"),
|
||||
params.get<std::string>("password"))
|
||||
{
|
||||
|
||||
unsigned initial_size;
|
||||
unsigned max_size;
|
||||
|
||||
try
|
||||
{
|
||||
initial_size = boost::lexical_cast<unsigned>(params_.get("initial_size"));
|
||||
}
|
||||
catch (bad_lexical_cast& )
|
||||
{
|
||||
initial_size = 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
max_size = boost::lexical_cast<unsigned>(params_.get("max_size"));
|
||||
}
|
||||
catch (bad_lexical_cast&)
|
||||
{
|
||||
max_size = 10;
|
||||
}
|
||||
boost::optional<int> initial_size = params_.get<int>("inital_size",1);
|
||||
boost::optional<int> max_size = params_.get<int>("max_size",10);
|
||||
|
||||
ConnectionManager *mgr=ConnectionManager::instance();
|
||||
mgr->registerPool(creator_, initial_size, max_size);
|
||||
mgr->registerPool(creator_, *initial_size, *max_size);
|
||||
|
||||
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
|
||||
if (pool)
|
||||
|
@ -275,7 +257,9 @@ Envelope<double> postgis_datasource::envelope() const
|
|||
{
|
||||
std::ostringstream s;
|
||||
std::string table_name = table_from_sql(table_);
|
||||
if (params_.get("estimate_extent") == "true")
|
||||
boost::optional<std::string> estimate_extent = params_.get<std::string>("estimate_extent");
|
||||
|
||||
if (estimate_extent && *estimate_extent == "true")
|
||||
{
|
||||
s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)"
|
||||
<< " from (select estimated_extent('"
|
||||
|
|
|
@ -53,7 +53,7 @@ feature_ptr postgis_featureset::next()
|
|||
feature_ptr feature(new Feature(count_));
|
||||
int size=rs_->getFieldLength(0);
|
||||
const char *data = rs_->getValue(0);
|
||||
geometry_ptr geom = geometry_utils::from_wkb(data,size,-1);
|
||||
geometry_ptr geom = geometry_utils::from_wkb(data,size);
|
||||
totalGeomSize_+=size;
|
||||
|
||||
if (geom)
|
||||
|
|
|
@ -43,32 +43,30 @@ using mapnik::layer_descriptor;
|
|||
using mapnik::featureset_ptr;
|
||||
using mapnik::query;
|
||||
using mapnik::coord2d;
|
||||
using mapnik::datasource_exception;
|
||||
|
||||
raster_datasource::raster_datasource(const parameters& params)
|
||||
: datasource (params),
|
||||
desc_(params.get("name"),"utf-8")
|
||||
desc_(*params.get<std::string>("type"),"utf-8")
|
||||
{
|
||||
filename_=params.get("file");
|
||||
format_=params.get("format");
|
||||
|
||||
try
|
||||
boost::optional<std::string> file=params.get<std::string>("file");
|
||||
if (!file) throw datasource_exception("missing <file> parameter ");
|
||||
filename_ = *file;
|
||||
format_=*params.get<std::string>("format","tiff");
|
||||
boost::optional<double> lox = params.get<double>("lox");
|
||||
boost::optional<double> loy = params.get<double>("loy");
|
||||
boost::optional<double> hix = params.get<double>("hix");
|
||||
boost::optional<double> hiy = params.get<double>("hiy");
|
||||
|
||||
if (lox && loy && hix && hiy)
|
||||
{
|
||||
double lox=lexical_cast<double>(params.get("lox"));
|
||||
double loy=lexical_cast<double>(params.get("loy"));
|
||||
double hix=lexical_cast<double>(params.get("hix"));
|
||||
double hiy=lexical_cast<double>(params.get("hiy"));
|
||||
extent_.init(lox,loy,hix,hiy);
|
||||
}
|
||||
catch (bad_lexical_cast& ex)
|
||||
{
|
||||
clog << ex.what() << endl;
|
||||
extent_.init(*lox,*loy,*hix,*hiy);
|
||||
}
|
||||
else throw datasource_exception("<lox> <loy> <hix> <hiy> are required");
|
||||
}
|
||||
|
||||
|
||||
raster_datasource::~raster_datasource()
|
||||
{
|
||||
}
|
||||
raster_datasource::~raster_datasource() {}
|
||||
|
||||
int raster_datasource::type() const
|
||||
{
|
||||
|
|
|
@ -40,16 +40,14 @@ using mapnik::attribute_descriptor;
|
|||
|
||||
shape_datasource::shape_datasource(const parameters ¶ms)
|
||||
: datasource (params),
|
||||
shape_name_(params.get("file")),
|
||||
shape_name_(*params_.get<std::string>("file","")),
|
||||
type_(datasource::Vector),
|
||||
file_length_(0),
|
||||
indexed_(false),
|
||||
desc_(params.get("name"),"utf-8")
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","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)
|
||||
|
@ -90,12 +88,14 @@ shape_datasource::shape_datasource(const parameters ¶ms)
|
|||
std::clog<<ex.what()<<std::endl;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
shape_datasource::~shape_datasource()
|
||||
catch (...)
|
||||
{
|
||||
std::clog << " got exception ... \n";
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
shape_datasource::~shape_datasource() {}
|
||||
|
||||
const std::string shape_datasource::name_="shape";
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@ private:
|
|||
shape_datasource& operator=(const shape_datasource&);
|
||||
void init(shape_io& shape);
|
||||
private:
|
||||
std::string shape_name_;
|
||||
int type_;
|
||||
std::string shape_name_;
|
||||
long file_length_;
|
||||
Envelope<double> extent_;
|
||||
bool indexed_;
|
||||
|
|
|
@ -71,7 +71,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
{
|
||||
double x=shape_.shp().read_double();
|
||||
double y=shape_.shp().read_double();
|
||||
geometry_ptr point(new point_impl(-1));
|
||||
geometry_ptr point(new point_impl);
|
||||
point->move_to(x,y);
|
||||
feature->set_geometry(point);
|
||||
++count_;
|
||||
|
@ -81,7 +81,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
double x=shape_.shp().read_double();
|
||||
double y=shape_.shp().read_double();
|
||||
shape_.shp().read_double();//m
|
||||
geometry_ptr point(new point_impl(-1));
|
||||
geometry_ptr point(new point_impl);
|
||||
point->move_to(x,y);
|
||||
feature->set_geometry(point);
|
||||
++count_;
|
||||
|
@ -92,7 +92,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
double y=shape_.shp().read_double();
|
||||
shape_.shp().read_double();//z
|
||||
shape_.shp().read_double();//m
|
||||
geometry_ptr point(new point_impl(-1));
|
||||
geometry_ptr point(new point_impl);
|
||||
point->move_to(x,y);
|
||||
feature->set_geometry(point);
|
||||
++count_;
|
||||
|
|
|
@ -85,7 +85,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
{
|
||||
double x=shape_.shp().read_double();
|
||||
double y=shape_.shp().read_double();
|
||||
geometry_ptr point(new point_impl(-1));
|
||||
geometry_ptr point(new point_impl);
|
||||
point->move_to(x,y);
|
||||
feature->set_geometry(point);
|
||||
++count_;
|
||||
|
@ -95,7 +95,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
double x=shape_.shp().read_double();
|
||||
double y=shape_.shp().read_double();
|
||||
shape_.shp().read_double();// m
|
||||
geometry_ptr point(new point_impl(-1));
|
||||
geometry_ptr point(new point_impl);
|
||||
point->move_to(x,y);
|
||||
feature->set_geometry(point);
|
||||
++count_;
|
||||
|
@ -106,7 +106,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
double y=shape_.shp().read_double();
|
||||
shape_.shp().read_double();// z
|
||||
shape_.shp().read_double();// m
|
||||
geometry_ptr point(new point_impl(-1));
|
||||
geometry_ptr point(new point_impl);
|
||||
point->move_to(x,y);
|
||||
feature->set_geometry(point);
|
||||
++count_;
|
||||
|
|
|
@ -96,7 +96,7 @@ geometry_ptr shape_io::read_polyline()
|
|||
shp_.read_record(record);
|
||||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
geometry_ptr line(new line_string_impl(-1));
|
||||
geometry_ptr line(new line_string_impl);
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ geometry_ptr shape_io::read_polylinem()
|
|||
shp_.read_record(record);
|
||||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
geometry_ptr line(new line_string_impl(-1));
|
||||
geometry_ptr line(new line_string_impl);
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
|
@ -214,7 +214,7 @@ geometry_ptr shape_io::read_polylinez()
|
|||
shp_.read_record(record);
|
||||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
geometry_ptr line(new line_string_impl(-1));
|
||||
geometry_ptr line(new line_string_impl);
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
|
@ -285,7 +285,7 @@ geometry_ptr shape_io::read_polygon()
|
|||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
geometry_ptr poly(new polygon_impl(-1));
|
||||
geometry_ptr poly(new polygon_impl);
|
||||
poly->set_capacity(num_points + num_parts);
|
||||
for (int i=0;i<num_parts;++i)
|
||||
{
|
||||
|
@ -326,7 +326,7 @@ geometry_ptr shape_io::read_polygonm()
|
|||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
geometry_ptr poly(new polygon_impl(-1));
|
||||
geometry_ptr poly(new polygon_impl);
|
||||
poly->set_capacity(num_points + num_parts);
|
||||
for (int i=0;i<num_parts;++i)
|
||||
{
|
||||
|
@ -375,7 +375,7 @@ geometry_ptr shape_io::read_polygonz()
|
|||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
geometry_ptr poly(new polygon_impl(-1));
|
||||
geometry_ptr poly(new polygon_impl);
|
||||
poly->set_capacity(num_points + num_parts);
|
||||
for (int i=0;i<num_parts;++i)
|
||||
{
|
||||
|
|
|
@ -55,8 +55,10 @@ namespace mapnik
|
|||
datasource_ptr ds;
|
||||
try
|
||||
{
|
||||
const std::string type=params.get("type");
|
||||
map<string,boost::shared_ptr<PluginInfo> >::iterator itr=plugins_.find(type);
|
||||
boost::optional<std::string> type = params.get<std::string>("type");
|
||||
if (type)
|
||||
{
|
||||
map<string,boost::shared_ptr<PluginInfo> >::iterator itr=plugins_.find(*type);
|
||||
if (itr!=plugins_.end())
|
||||
{
|
||||
if (itr->second->handle())
|
||||
|
@ -74,7 +76,8 @@ namespace mapnik
|
|||
}
|
||||
else
|
||||
{
|
||||
std::clog << "Cannot load library: " << " "<< lt_dlerror() << std::endl;
|
||||
std::clog << "Cannot load library: " << lt_dlerror() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
|
20
src/wkb.cpp
20
src/wkb.cpp
|
@ -36,7 +36,6 @@ namespace mapnik
|
|||
};
|
||||
const char* wkb_;
|
||||
unsigned size_;
|
||||
int srid_;
|
||||
unsigned pos_;
|
||||
wkbByteOrder byteOrder_;
|
||||
bool needSwap_;
|
||||
|
@ -52,10 +51,9 @@ namespace mapnik
|
|||
wkbGeometryCollection=7
|
||||
};
|
||||
|
||||
wkb_reader(const char* wkb,unsigned size,int srid)
|
||||
wkb_reader(const char* wkb,unsigned size)
|
||||
: wkb_(wkb),
|
||||
size_(size),
|
||||
srid_(srid),
|
||||
pos_(0),
|
||||
byteOrder_((wkbByteOrder)wkb_[0])
|
||||
{
|
||||
|
@ -174,7 +172,7 @@ namespace mapnik
|
|||
|
||||
geometry_ptr read_point()
|
||||
{
|
||||
geometry_ptr pt(new point<vertex2d>(srid_));
|
||||
geometry_ptr pt(new point<vertex2d>);
|
||||
double x = read_double();
|
||||
double y = read_double();
|
||||
pt->move_to(x,y);
|
||||
|
@ -183,7 +181,7 @@ namespace mapnik
|
|||
|
||||
geometry_ptr read_multipoint()
|
||||
{
|
||||
geometry_ptr pt(new point<vertex2d>(srid_));
|
||||
geometry_ptr pt(new point<vertex2d>);
|
||||
int num_points = read_integer();
|
||||
for (int i=0;i<num_points;++i)
|
||||
{
|
||||
|
@ -197,7 +195,7 @@ namespace mapnik
|
|||
|
||||
geometry_ptr read_linestring()
|
||||
{
|
||||
geometry_ptr line(new line_string<vertex2d>(srid_));
|
||||
geometry_ptr line(new line_string<vertex2d>);
|
||||
int num_points=read_integer();
|
||||
CoordinateArray ar(num_points);
|
||||
read_coords(ar);
|
||||
|
@ -212,7 +210,7 @@ namespace mapnik
|
|||
|
||||
geometry_ptr read_multilinestring()
|
||||
{
|
||||
geometry_ptr line(new line_string<vertex2d>(srid_));
|
||||
geometry_ptr line(new line_string<vertex2d>);
|
||||
int num_lines=read_integer();
|
||||
|
||||
for (int i=0;i<num_lines;++i)
|
||||
|
@ -234,7 +232,7 @@ namespace mapnik
|
|||
|
||||
geometry_ptr read_polygon()
|
||||
{
|
||||
geometry_ptr poly(new polygon<vertex2d>(srid_));
|
||||
geometry_ptr poly(new polygon<vertex2d>);
|
||||
|
||||
int num_rings=read_integer();
|
||||
|
||||
|
@ -257,7 +255,7 @@ namespace mapnik
|
|||
|
||||
geometry_ptr read_multipolygon()
|
||||
{
|
||||
geometry_ptr poly(new polygon<vertex2d>(srid_));
|
||||
geometry_ptr poly(new polygon<vertex2d>);
|
||||
|
||||
int num_polys=read_integer();
|
||||
for (int i=0;i<num_polys;++i)
|
||||
|
@ -281,9 +279,9 @@ namespace mapnik
|
|||
}
|
||||
};
|
||||
|
||||
geometry_ptr geometry_utils::from_wkb(const char* wkb, unsigned size,int srid)
|
||||
geometry_ptr geometry_utils::from_wkb(const char* wkb, unsigned size)
|
||||
{
|
||||
wkb_reader reader(wkb,size,srid);
|
||||
wkb_reader reader(wkb,size);
|
||||
return reader.read();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue