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:
Artem Pavlenko 2007-06-12 08:59:54 +00:00
parent e8d5172a64
commit 8010d5433f
22 changed files with 502 additions and 499 deletions

View file

@ -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,10 +54,10 @@ 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):
return 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)

View file

@ -43,11 +43,22 @@ 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();
}
}
return mapnik::datasource_cache::create(params);

View file

@ -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",&parameters::get)
.def_pickle(parameters_pickle_suite())
;
}

View file

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

View file

@ -113,7 +113,7 @@ namespace mapnik
projection proj1(lay.srs());
proj_transform prj_trans(proj0,proj1);
double x0 = ext.minx();
double y0 = ext.miny();
double z0 = 0.0;
@ -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
@ -140,8 +142,8 @@ namespace mapnik
bool active_rules=false;
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();

View file

@ -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()
{
@ -90,91 +82,89 @@ namespace mapnik {
virtual ~geometry() {}
};
template <typename T>
class point : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry<T>::value_type value_type;
private:
vertex_type pt_;
public:
point(int srid)
: geometry<T>(srid)
{}
int type() const
{
template <typename T>
class point : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry<T>::value_type value_type;
private:
vertex_type pt_;
public:
point() : geometry<T>() {}
int type() const
{
return Point;
}
void label_position(double *x, double *y) const
{
}
void label_position(double *x, double *y) const
{
*x = pt_.x;
*y = pt_.y;
}
void move_to(value_type x,value_type y)
{
}
void move_to(value_type x,value_type y)
{
pt_.x = x;
pt_.y = y;
}
void line_to(value_type ,value_type ) {}
unsigned num_points() const
{
}
void line_to(value_type ,value_type ) {}
unsigned num_points() const
{
return 1;
}
unsigned vertex(double* x, double* y)
{
}
unsigned vertex(double* x, double* y)
{
*x = pt_.x;
*y = pt_.y;
return SEG_LINETO;
}
void rewind(unsigned ) {}
bool hit_test(value_type x,value_type y, double tol) const
{
}
void rewind(unsigned ) {}
bool hit_test(value_type x,value_type y, double tol) const
{
return point_in_circle(pt_.x,pt_.y, x,y,tol);
}
void set_capacity(size_t) {}
virtual ~point() {}
};
template <typename T, template <typename> class Container=vertex_vector2>
class polygon : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry_base::value_type value_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
polygon(int srid)
: geometry_base(srid),
}
void set_capacity(size_t) {}
virtual ~point() {}
};
template <typename T, template <typename> class Container=vertex_vector2>
class polygon : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry_base::value_type value_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
polygon()
: geometry_base(),
itr_(0)
{}
int type() const
{
{}
int type() const
{
return Polygon;
}
void label_position(double *x, double *y) const
{
}
void label_position(double *x, double *y) const
{
unsigned size = cont_.size();
if (size < 3)
{
cont_.get_vertex(0,x,y);
return;
cont_.get_vertex(0,x,y);
return;
}
double ai;
double atmp = 0;
double xtmp = 0;
@ -187,82 +177,82 @@ namespace mapnik {
unsigned i,j;
for (i = size-1,j = 0; j < size; i = j, ++j)
{
cont_.get_vertex(i,&x0,&y0);
cont_.get_vertex(j,&x1,&y1);
ai = x0 * y1 - x1 * y0;
atmp += ai;
xtmp += (x1 + x0) * ai;
ytmp += (y1 + y0) * ai;
cont_.get_vertex(i,&x0,&y0);
cont_.get_vertex(j,&x1,&y1);
ai = x0 * y1 - x1 * y0;
atmp += ai;
xtmp += (x1 + x0) * ai;
ytmp += (y1 + y0) * ai;
}
if (atmp != 0)
{
*x = xtmp/(3*atmp);
*y = ytmp /(3*atmp);
return;
*x = xtmp/(3*atmp);
*y = ytmp /(3*atmp);
return;
}
*x=x0;
*y=y0;
}
void line_to(value_type x,value_type y)
{
}
void line_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_LINETO);
}
void move_to(value_type x,value_type y)
{
}
void move_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_MOVETO);
}
unsigned num_points() const
{
}
unsigned num_points() const
{
return cont_.size();
}
unsigned vertex(double* x, double* y)
{
}
unsigned vertex(double* x, double* y)
{
return cont_.get_vertex(itr_++,x,y);
}
void rewind(unsigned )
{
}
void rewind(unsigned )
{
itr_=0;
}
bool hit_test(value_type x,value_type y, double) const
{
}
bool hit_test(value_type x,value_type y, double) const
{
return point_inside_path(x,y,cont_.begin(),cont_.end());
}
void set_capacity(size_t size)
{
}
void set_capacity(size_t size)
{
cont_.set_capacity(size);
}
virtual ~polygon() {}
};
template <typename T, template <typename> class Container=vertex_vector2>
class line_string : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry_base::value_type value_type;
typedef typename geometry<T>::vertex_type vertex_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
line_string(int srid)
: geometry_base(srid),
}
virtual ~polygon() {}
};
template <typename T, template <typename> class Container=vertex_vector2>
class line_string : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry_base::value_type value_type;
typedef typename geometry<T>::vertex_type vertex_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
line_string()
: geometry_base(),
itr_(0)
{}
int type() const
{
{}
int type() const
{
return LineString;
}
void label_position(double *x, double *y) const
{
}
void label_position(double *x, double *y) const
{
// calculate mid point on line string
double x0=0;
double y0=0;
@ -272,91 +262,90 @@ namespace mapnik {
unsigned size = cont_.size();
if (size == 1)
{
cont_.get_vertex(0,x,y);
cont_.get_vertex(0,x,y);
}
else if (size == 2)
{
cont_.get_vertex(0,&x0,&y0);
cont_.get_vertex(1,&x1,&y1);
*x = 0.5 * (x1 + x0);
*y = 0.5 * (y1 + y0);
cont_.get_vertex(0,&x0,&y0);
cont_.get_vertex(1,&x1,&y1);
*x = 0.5 * (x1 + x0);
*y = 0.5 * (y1 + y0);
}
else
{
double len=0.0;
for (unsigned pos = 1; pos < size; ++pos)
{
cont_.get_vertex(pos-1,&x0,&y0);
cont_.get_vertex(pos,&x1,&y1);
double dx = x1 - x0;
double dy = y1 - y0;
len += sqrt(dx * dx + dy * dy);
}
double midlen = 0.5 * len;
double dist = 0.0;
for (unsigned pos = 1; pos < size;++pos)
{
cont_.get_vertex(pos-1,&x0,&y0);
cont_.get_vertex(pos,&x1,&y1);
double dx = x1 - x0;
double dy = y1 - y0;
double seg_len = sqrt(dx * dx + dy * dy);
if (( dist + seg_len) >= midlen)
{
double r = (midlen - dist)/seg_len;
*x = x0 + (x1 - x0) * r;
*y = y0 + (y1 - y0) * r;
break;
}
dist += seg_len;
}
}
}
void line_to(value_type x,value_type y)
{
double len=0.0;
for (unsigned pos = 1; pos < size; ++pos)
{
cont_.get_vertex(pos-1,&x0,&y0);
cont_.get_vertex(pos,&x1,&y1);
double dx = x1 - x0;
double dy = y1 - y0;
len += sqrt(dx * dx + dy * dy);
}
double midlen = 0.5 * len;
double dist = 0.0;
for (unsigned pos = 1; pos < size;++pos)
{
cont_.get_vertex(pos-1,&x0,&y0);
cont_.get_vertex(pos,&x1,&y1);
double dx = x1 - x0;
double dy = y1 - y0;
double seg_len = sqrt(dx * dx + dy * dy);
if (( dist + seg_len) >= midlen)
{
double r = (midlen - dist)/seg_len;
*x = x0 + (x1 - x0) * r;
*y = y0 + (y1 - y0) * r;
break;
}
dist += seg_len;
}
}
}
void line_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_LINETO);
}
void move_to(value_type x,value_type y)
{
}
void move_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_MOVETO);
}
unsigned num_points() const
{
}
unsigned num_points() const
{
return cont_.size();
}
unsigned vertex(double* x, double* y)
{
}
unsigned vertex(double* x, double* y)
{
return cont_.get_vertex(itr_++,x,y);
}
void rewind(unsigned )
{
}
void rewind(unsigned )
{
itr_=0;
}
bool hit_test(value_type x,value_type y, double tol) const
{
}
bool hit_test(value_type x,value_type y, double tol) const
{
return point_on_path(x,y,cont_.begin(),cont_.end(),tol);
}
void set_capacity(size_t size)
{
}
void set_capacity(size_t size)
{
cont_.set_capacity(size);
}
virtual ~line_string() {}
};
typedef point<vertex2d> point_impl;
typedef line_string<vertex2d,vertex_vector2> line_string_impl;
typedef polygon<vertex2d,vertex_vector2> polygon_impl;
typedef geometry<vertex2d> geometry_type;
typedef boost::shared_ptr<geometry_type> geometry_ptr;
}
virtual ~line_string() {}
};
typedef point<vertex2d> point_impl;
typedef line_string<vertex2d,vertex_vector2> line_string_impl;
typedef polygon<vertex2d,vertex_vector2> polygon_impl;
typedef geometry<vertex2d> geometry_type;
typedef boost::shared_ptr<geometry_type> geometry_ptr;
}
#endif //GEOMETRY_HPP

View file

@ -26,39 +26,84 @@
#include <string>
#include <map>
#include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <boost/none.hpp>
#include <boost/lexical_cast.hpp>
namespace mapnik
{
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
{
param_map::const_iterator itr=find(key);
if (itr != end())
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
{
return itr->second;
var_ = boost::lexical_cast<T>(val);
}
return std::string();
}
param_map::const_iterator iterator(std::string const& key) const
{
catch (boost::bad_lexical_cast & ) {}
}
boost::optional<T> & var_;
};
class parameters : public param_map
{
template <typename T>
struct converter
{
typedef boost::optional<T> return_type;
static return_type extract(parameters const& params,std::string const& name, boost::optional<T> const& default_value)
{
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 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
{
return find(key);
}
}
param_map::iterator iterator(std::string const& key)
{
param_map::iterator iterator(std::string const& key)
{
return find(key);
}
};
}
};
}
#endif //PARAMS_HPP

View file

@ -32,80 +32,56 @@
#include <mapnik/envelope.hpp>
#include <mapnik/feature.hpp>
namespace mapnik
{
class query
{
private:
Envelope<double> bbox_;
filter<Feature>* filter_;
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>)
{}
namespace mapnik {
class query
{
private:
Envelope<double> bbox_;
double resolution_;
std::set<std::string> names_;
public:
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)
query(const query& other)
: bbox_(other.bbox_),
filter_(other.filter_->clone())
{}
query& operator=(const query& other)
{
filter<Feature>* tmp=other.filter_->clone();
delete filter_;
filter_=tmp;
resolution_(other.resolution_),
names_(other.names_)
{}
query& operator=(const query& other)
{
if (this == &other) return *this;
bbox_=other.bbox_;
resolution_=other.resolution_;
names_=other.names_;
return *this;
}
const filter<Feature>* get_filter() const
{
return filter_;
}
const Envelope<double>& get_bbox() const
{
}
double resolution() const
{
return resolution_;
}
const Envelope<double>& get_bbox() const
{
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)
{
}
void add_property_name(const std::string& name)
{
names_.insert(name);
}
const std::set<std::string>& property_names() const
{
}
const std::set<std::string>& property_names() const
{
return names_;
}
~query()
{
delete filter_;
}
};
}
};
}

View file

@ -33,11 +33,11 @@ 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&);
};
}
#endif //WKB_HPP
#endif //WKB_HPP

View file

@ -34,24 +34,26 @@ 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_)
{
double tr[6];
dataset_->GetGeoTransform(tr);
double x0 = tr[0];
double y0 = tr[3];
double x1 = tr[0] + dataset_->GetRasterXSize()*tr[1] + dataset_->GetRasterYSize()*tr[2];
double y1 = tr[3] + dataset_->GetRasterXSize()*tr[4] + dataset_->GetRasterYSize()*tr[5];
extent_.init(x0,y0,x1,y1);
}
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];
double y0 = tr[3];
double x1 = tr[0] + dataset_->GetRasterXSize()*tr[1] + dataset_->GetRasterYSize()*tr[2];
double y1 = tr[3] + dataset_->GetRasterXSize()*tr[4] + dataset_->GetRasterYSize()*tr[5];
extent_.init(x0,y0,x1,y1);
}
gdal_datasource::~gdal_datasource() {}

View file

@ -38,29 +38,16 @@ 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;
}
}
bool execute(const std::string& sql) const
{
PGresult *result=PQexec(conn_,sql.c_str());

View file

@ -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,35 +44,45 @@ class ConnectionCreator
{
public:
ConnectionCreator(string const& host,
string const& port,
string const& dbname,
string const& user,
string const& pass)
: host_(host),
port_(port),
dbname_(dbname),
user_(user),
pass_(pass) {}
T* operator()() const
{
return new T(host_,port_,dbname_,user_,pass_);
}
std::string id() const
{
return host_ + ":"
+ dbname_ + ":"
+ port_ +":"
+ user_ ;
}
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),
user_(user),
pass_(pass) {}
T* operator()() const
{
return new T(connection_string());
}
inline std::string id() const
{
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_;
};

View file

@ -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('"

View file

@ -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)

View file

@ -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
{
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;
}
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)
{
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
{

View file

@ -39,17 +39,15 @@ using mapnik::filter_at_point;
using mapnik::attribute_descriptor;
shape_datasource::shape_datasource(const parameters &params)
: datasource (params) ,
shape_name_(params.get("file")),
: datasource (params),
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)
@ -85,17 +83,19 @@ shape_datasource::shape_datasource(const parameters &params)
}
}
}
catch (datasource_exception& ex)
catch (datasource_exception& ex)
{
std::clog<<ex.what()<<std::endl;
throw;
}
catch (...)
{
std::clog << " got exception ... \n";
throw;
}
}
shape_datasource::~shape_datasource()
{
}
shape_datasource::~shape_datasource() {}
const std::string shape_datasource::name_="shape";

View file

@ -39,28 +39,28 @@ using mapnik::coord2d;
class shape_datasource : public datasource
{
public:
shape_datasource(const parameters &params);
virtual ~shape_datasource();
public:
shape_datasource(const parameters &params);
virtual ~shape_datasource();
int type() const;
static std::string name();
featureset_ptr features(const query& q) const;
featureset_ptr features_at_point(coord2d const& pt) const;
Envelope<double> envelope() const;
layer_descriptor get_descriptor() const;
private:
shape_datasource(const shape_datasource&);
shape_datasource& operator=(const shape_datasource&);
void init(shape_io& shape);
private:
std::string shape_name_;
int type_;
long file_length_;
Envelope<double> extent_;
bool indexed_;
layer_descriptor desc_;
static const std::string name_;
int type() const;
static std::string name();
featureset_ptr features(const query& q) const;
featureset_ptr features_at_point(coord2d const& pt) const;
Envelope<double> envelope() const;
layer_descriptor get_descriptor() const;
private:
shape_datasource(const shape_datasource&);
shape_datasource& operator=(const shape_datasource&);
void init(shape_io& shape);
private:
int type_;
std::string shape_name_;
long file_length_;
Envelope<double> extent_;
bool indexed_;
layer_descriptor desc_;
static const std::string name_;
};
#endif //SHAPE_HPP

View file

@ -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_;

View file

@ -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_;

View file

@ -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)
{

View file

@ -55,28 +55,31 @@ namespace mapnik
datasource_ptr ds;
try
{
const std::string type=params.get("type");
map<string,boost::shared_ptr<PluginInfo> >::iterator itr=plugins_.find(type);
if (itr!=plugins_.end())
{
if (itr->second->handle())
{
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())
{
create_ds* create_datasource =
(create_ds*) lt_dlsym(itr->second->handle(), "create");
(create_ds*) lt_dlsym(itr->second->handle(), "create");
if (!create_datasource)
{
std::clog << "Cannot load symbols: " << lt_dlerror() << std::endl;
std::clog << "Cannot load symbols: " << lt_dlerror() << std::endl;
}
else
{
ds=datasource_ptr(create_datasource(params),datasource_deleter());
ds=datasource_ptr(create_datasource(params), datasource_deleter());
}
}
else
{
std::clog << "Cannot load library: " << " "<< lt_dlerror() << std::endl;
std::clog << "Cannot load library: " << lt_dlerror() << std::endl;
}
}
}
}
#ifdef MAPNIK_DEBUG
std::clog<<"datasource="<<ds<<" type="<<type<<std::endl;
#endif

View file

@ -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();
}
}