diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 9594a7da2..458c57a6b 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -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) diff --git a/bindings/python/mapnik_datasource.cpp b/bindings/python/mapnik_datasource.cpp index 44f3ca17c..4755238af 100644 --- a/bindings/python/mapnik_datasource.cpp +++ b/bindings/python/mapnik_datasource.cpp @@ -43,11 +43,22 @@ namespace { std::string key = extract(keys[i]); object obj = d[key]; - extract ex(obj); - if (ex.check()) + extract ex0(obj); + extract ex1(obj); + extract 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); diff --git a/bindings/python/mapnik_parameters.cpp b/bindings/python/mapnik_parameters.cpp index c437f5189..da5534290 100644 --- a/bindings/python/mapnik_parameters.cpp +++ b/bindings/python/mapnik_parameters.cpp @@ -70,7 +70,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite for (int i=0;i(keys[i]); - std::string value=extract(d[key]); + std::string value=extract(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",init<>()) - //.def("add",add1) - //.def("add",add2) - .def("get",¶meters::get) .def_pickle(parameters_pickle_suite()) ; } diff --git a/bindings/python/mapnik_projection.cpp b/bindings/python/mapnik_projection.cpp index 5e88bfef6..768c5879d 100644 --- a/bindings/python/mapnik_projection.cpp +++ b/bindings/python/mapnik_projection.cpp @@ -52,14 +52,12 @@ void export_projection () using mapnik::projection; class_("Projection", init >()) - .def ("forward",&projection::forward) - .def ("inverse",&projection::inverse) .def ("params", make_function(&projection::params, return_value_policy())) .add_property ("geographic",&projection::is_geographic) ; - def("forward",&forward); - def("inverse",&inverse); + def("forward_",&forward); + def("inverse_",&inverse); } diff --git a/include/mapnik/feature_style_processor.hpp b/include/mapnik/feature_style_processor.hpp index d5c42011b..173c4c526 100644 --- a/include/mapnik/feature_style_processor.hpp +++ b/include/mapnik/feature_style_processor.hpp @@ -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 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& rules=style.get_rules(); std::vector::const_iterator ruleIter=rules.begin(); diff --git a/include/mapnik/geometry.hpp b/include/mapnik/geometry.hpp index 047437525..047b0e4c6 100644 --- a/include/mapnik/geometry.hpp +++ b/include/mapnik/geometry.hpp @@ -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 envelope() { @@ -90,91 +82,89 @@ namespace mapnik { virtual ~geometry() {} }; - template - class point : public geometry - { - typedef geometry geometry_base; - typedef typename geometry::vertex_type vertex_type; - typedef typename geometry::value_type value_type; - private: - vertex_type pt_; - public: - point(int srid) - : geometry(srid) - {} - - int type() const - { + template + class point : public geometry + { + typedef geometry geometry_base; + typedef typename geometry::vertex_type vertex_type; + typedef typename geometry::value_type value_type; + private: + vertex_type pt_; + public: + point() : geometry() {} + + 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 class Container=vertex_vector2> - class polygon : public geometry - { - typedef geometry geometry_base; - typedef typename geometry::vertex_type vertex_type; - typedef typename geometry_base::value_type value_type; - typedef Container container_type; - private: - container_type cont_; - mutable unsigned itr_; - public: - polygon(int srid) - : geometry_base(srid), + } + + void set_capacity(size_t) {} + virtual ~point() {} + }; + + template class Container=vertex_vector2> + class polygon : public geometry + { + typedef geometry geometry_base; + typedef typename geometry::vertex_type vertex_type; + typedef typename geometry_base::value_type value_type; + typedef Container 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 class Container=vertex_vector2> - class line_string : public geometry - { - typedef geometry geometry_base; - typedef typename geometry_base::value_type value_type; - typedef typename geometry::vertex_type vertex_type; - typedef Container container_type; - private: - container_type cont_; - mutable unsigned itr_; - public: - line_string(int srid) - : geometry_base(srid), + } + virtual ~polygon() {} + }; + + template class Container=vertex_vector2> + class line_string : public geometry + { + typedef geometry geometry_base; + typedef typename geometry_base::value_type value_type; + typedef typename geometry::vertex_type vertex_type; + typedef Container 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 point_impl; - typedef line_string line_string_impl; - typedef polygon polygon_impl; - - typedef geometry geometry_type; - typedef boost::shared_ptr geometry_ptr; + } + virtual ~line_string() {} + }; + + typedef point point_impl; + typedef line_string line_string_impl; + typedef polygon polygon_impl; + + typedef geometry geometry_type; + typedef boost::shared_ptr geometry_ptr; } #endif //GEOMETRY_HPP diff --git a/include/mapnik/params.hpp b/include/mapnik/params.hpp index 7f85ee79d..6ca7fefed 100644 --- a/include/mapnik/params.hpp +++ b/include/mapnik/params.hpp @@ -26,39 +26,84 @@ #include #include +#include +#include +#include +#include namespace mapnik { - - typedef std::pair parameter; - typedef std::map 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 value_holder; + typedef std::pair parameter; + typedef std::map param_map; + + template + struct value_extractor_visitor : public boost::static_visitor<> + { + value_extractor_visitor(boost::optional & var) + :var_(var) {} + + void operator () (T val) const + { + var_ = val; + } + + template + void operator () (T1 val) const + { + try { - return itr->second; + var_ = boost::lexical_cast(val); } - return std::string(); - } - - param_map::const_iterator iterator(std::string const& key) const - { + catch (boost::bad_lexical_cast & ) {} + } + + boost::optional & var_; + }; + + + class parameters : public param_map + { + template + struct converter + { + typedef boost::optional return_type; + static return_type extract(parameters const& params,std::string const& name, boost::optional const& default_value) + { + boost::optional result(default_value); + parameters::const_iterator itr = params.find(name); + if (itr != params.end()) + { + boost::apply_visitor(value_extractor_visitor(result),itr->second); + } + return result; + } + }; + public: + parameters() {} + + template + boost::optional get(std::string const& key) const + { + return converter::extract(*this,key, boost::none); + } + + template + boost::optional get(std::string const& key, T const& default_value) const + { + return converter::extract(*this,key,boost::optional(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 diff --git a/include/mapnik/query.hpp b/include/mapnik/query.hpp index 586ab45b8..3f089a08d 100644 --- a/include/mapnik/query.hpp +++ b/include/mapnik/query.hpp @@ -32,80 +32,56 @@ #include #include -namespace mapnik -{ - class query - { - private: - Envelope bbox_; - filter* filter_; - std::set names_; - public: - query() - : bbox_(std::numeric_limits::min(), - std::numeric_limits::min(), - std::numeric_limits::max(), - std::numeric_limits::max()), - filter_(new all_filter) - {} +namespace mapnik { + class query + { + private: + Envelope bbox_; + double resolution_; + std::set names_; + public: + + explicit query(const Envelope& bbox, double resolution) + : bbox_(bbox), + resolution_(resolution) + {} + - query(const Envelope& bbox) - : bbox_(bbox), - filter_(new all_filter) - {} - - query(const Envelope& bbox, const filter& 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* 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* get_filter() const - { - return filter_; - } - - const Envelope& get_bbox() const - { + } + + double resolution() const + { + return resolution_; + } + + const Envelope& get_bbox() const + { return bbox_; - } - - void set_filter(const filter& f) - { - filter* 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& property_names() const - { + } + + const std::set& property_names() const + { return names_; - } - - ~query() - { - delete filter_; - } - }; + } + }; } diff --git a/include/mapnik/wkb.hpp b/include/mapnik/wkb.hpp index 884ce486d..5fb1f545a 100644 --- a/include/mapnik/wkb.hpp +++ b/include/mapnik/wkb.hpp @@ -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 diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp index c8c588c6d..19b427c2e 100644 --- a/plugins/input/gdal/gdal_datasource.cpp +++ b/plugins/input/gdal/gdal_datasource.cpp @@ -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("type"),"utf-8") { GDALAllRegister(); - dataset_ = boost::shared_ptr(reinterpret_cast(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 file = params.get("file"); + if (!file) throw datasource_exception("missing paramater"); + + dataset_ = boost::shared_ptr(reinterpret_cast(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() {} diff --git a/plugins/input/postgis/connection.hpp b/plugins/input/postgis/connection.hpp index 561e609ca..12e111d57 100644 --- a/plugins/input/postgis/connection.hpp +++ b/plugins/input/postgis/connection.hpp @@ -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()); diff --git a/plugins/input/postgis/connection_manager.hpp b/plugins/input/postgis/connection_manager.hpp index cd256f4aa..ee3e7ad31 100644 --- a/plugins/input/postgis/connection_manager.hpp +++ b/plugins/input/postgis/connection_manager.hpp @@ -31,6 +31,7 @@ #include "connection.hpp" #include #include +#include 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 const& host, + boost::optional const& port, + boost::optional const& dbname, + boost::optional const& user, + boost::optional 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 host_; + boost::optional port_; + boost::optional dbname_; + boost::optional user_; + boost::optional pass_; }; diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis.cpp index f6ca56245..4ad7cc73a 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis.cpp @@ -48,40 +48,22 @@ using mapnik::attribute_descriptor; postgis_datasource::postgis_datasource(parameters const& params) : datasource (params), - table_(params.get("table")), + table_(*params.get("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("type"),"utf-8"), + creator_(params.get("host"), + params.get("port"), + params.get("dbname"), + params.get("user"), + params.get("password")) { - unsigned initial_size; - unsigned max_size; - - try - { - initial_size = boost::lexical_cast(params_.get("initial_size")); - } - catch (bad_lexical_cast& ) - { - initial_size = 1; - } - - try - { - max_size = boost::lexical_cast(params_.get("max_size")); - } - catch (bad_lexical_cast&) - { - max_size = 10; - } - + boost::optional initial_size = params_.get("inital_size",1); + boost::optional max_size = params_.get("max_size",10); + ConnectionManager *mgr=ConnectionManager::instance(); - mgr->registerPool(creator_, initial_size, max_size); + mgr->registerPool(creator_, *initial_size, *max_size); shared_ptr > pool=mgr->getPool(creator_.id()); if (pool) @@ -275,7 +257,9 @@ Envelope postgis_datasource::envelope() const { std::ostringstream s; std::string table_name = table_from_sql(table_); - if (params_.get("estimate_extent") == "true") + boost::optional estimate_extent = params_.get("estimate_extent"); + + if (estimate_extent && *estimate_extent == "true") { s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)" << " from (select estimated_extent('" diff --git a/plugins/input/postgis/postgisfs.cpp b/plugins/input/postgis/postgisfs.cpp index e40ce3265..075a1b465 100644 --- a/plugins/input/postgis/postgisfs.cpp +++ b/plugins/input/postgis/postgisfs.cpp @@ -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) diff --git a/plugins/input/raster/raster_datasource.cpp b/plugins/input/raster/raster_datasource.cpp index 883c27034..a5fb079e5 100644 --- a/plugins/input/raster/raster_datasource.cpp +++ b/plugins/input/raster/raster_datasource.cpp @@ -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("type"),"utf-8") { - filename_=params.get("file"); - format_=params.get("format"); - - try - { - double lox=lexical_cast(params.get("lox")); - double loy=lexical_cast(params.get("loy")); - double hix=lexical_cast(params.get("hix")); - double hiy=lexical_cast(params.get("hiy")); - extent_.init(lox,loy,hix,hiy); - } - catch (bad_lexical_cast& ex) - { - clog << ex.what() << endl; - } + + boost::optional file=params.get("file"); + if (!file) throw datasource_exception("missing parameter "); + filename_ = *file; + format_=*params.get("format","tiff"); + boost::optional lox = params.get("lox"); + boost::optional loy = params.get("loy"); + boost::optional hix = params.get("hix"); + boost::optional hiy = params.get("hiy"); + + if (lox && loy && hix && hiy) + { + extent_.init(*lox,*loy,*hix,*hiy); + } + else throw datasource_exception(" are required"); } - -raster_datasource::~raster_datasource() -{ -} +raster_datasource::~raster_datasource() {} int raster_datasource::type() const { diff --git a/plugins/input/shape/shape.cpp b/plugins/input/shape/shape.cpp index 6dc1c9870..9085bd416 100644 --- a/plugins/input/shape/shape.cpp +++ b/plugins/input/shape/shape.cpp @@ -39,17 +39,15 @@ using mapnik::filter_at_point; using mapnik::attribute_descriptor; shape_datasource::shape_datasource(const parameters ¶ms) - : datasource (params) , - shape_name_(params.get("file")), + : datasource (params), + shape_name_(*params_.get("file","")), type_(datasource::Vector), file_length_(0), indexed_(false), - desc_(params.get("name"),"utf-8") + desc_(*params.get("type"), *params.get("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 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 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 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 extent_; + bool indexed_; + layer_descriptor desc_; + static const std::string name_; }; #endif //SHAPE_HPP diff --git a/plugins/input/shape/shape_featureset.cpp b/plugins/input/shape/shape_featureset.cpp index 9f78bc30e..05c5907bc 100644 --- a/plugins/input/shape/shape_featureset.cpp +++ b/plugins/input/shape/shape_featureset.cpp @@ -71,7 +71,7 @@ feature_ptr shape_featureset::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::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::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_; diff --git a/plugins/input/shape/shape_index_featureset.cpp b/plugins/input/shape/shape_index_featureset.cpp index fd9f66b53..6a8746c6b 100644 --- a/plugins/input/shape/shape_index_featureset.cpp +++ b/plugins/input/shape/shape_index_featureset.cpp @@ -85,7 +85,7 @@ feature_ptr shape_index_featureset::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::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::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_; diff --git a/plugins/input/shape/shape_io.cpp b/plugins/input/shape/shape_io.cpp index f76f92258..7c527bb17 100644 --- a/plugins/input/shape/shape_io.cpp +++ b/plugins/input/shape/shape_io.cpp @@ -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 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 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 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 >::iterator itr=plugins_.find(type); - if (itr!=plugins_.end()) - { - if (itr->second->handle()) - { + boost::optional type = params.get("type"); + if (type) + { + map >::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="<