From 820b6bb23a618b47e80efc5cb0d1ec68d21c7080 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Thu, 8 Sep 2005 13:09:04 +0000 Subject: [PATCH] return ref_ptr from datasource next() method should play better with python --- datasources/postgis/postgis.cpp | 26 ++++++------ datasources/postgis/postgis.hpp | 22 +++++----- datasources/postgis/postgisfs.cpp | 14 +++---- datasources/shape/shape_featureset.cpp | 38 +++++++++-------- datasources/shape/shape_featureset.hpp | 2 +- datasources/shape/shape_index_featureset.cpp | 38 +++++++++-------- datasources/shape/shape_index_featureset.hpp | 2 +- include/datasource.hpp | 2 +- src/render.cpp | 43 ++++++++++---------- 9 files changed, 98 insertions(+), 89 deletions(-) diff --git a/datasources/postgis/postgis.cpp b/datasources/postgis/postgis.cpp index 2aab6a6e0..1f6848439 100644 --- a/datasources/postgis/postgis.cpp +++ b/datasources/postgis/postgis.cpp @@ -25,10 +25,10 @@ #include #include "connection_manager.hpp" -DATASOURCE_PLUGIN(PostgisDatasource); +DATASOURCE_PLUGIN(postgis_datasource); -const std::string PostgisDatasource::GEOMETRY_COLUMNS="geometry_columns"; -const std::string PostgisDatasource::SPATIAL_REF_SYS="spatial_ref_system"; +const std::string postgis_datasource::GEOMETRY_COLUMNS="geometry_columns"; +const std::string postgis_datasource::SPATIAL_REF_SYS="spatial_ref_system"; using std::cerr; using std::cout; @@ -37,7 +37,7 @@ using std::endl; using boost::lexical_cast; using boost::bad_lexical_cast; -PostgisDatasource::PostgisDatasource(const Parameters& params) +postgis_datasource::postgis_datasource(const Parameters& params) : table_(params.get("table")), type_(datasource::Vector), desc_(params.get("name")), @@ -142,24 +142,24 @@ PostgisDatasource::PostgisDatasource(const Parameters& params) } } -std::string PostgisDatasource::name_="postgis"; +std::string postgis_datasource::name_="postgis"; -std::string PostgisDatasource::name() +std::string postgis_datasource::name() { return name_; } -int PostgisDatasource::type() const +int postgis_datasource::type() const { return type_; } -layer_descriptor const& PostgisDatasource::get_descriptor() const +layer_descriptor const& postgis_datasource::get_descriptor() const { return desc_; } -std::string PostgisDatasource::table_from_sql(const std::string& sql) +std::string postgis_datasource::table_from_sql(const std::string& sql) { std::string table_name(sql); transform(table_name.begin(),table_name.end(),table_name.begin(),tolower); @@ -174,7 +174,7 @@ std::string PostgisDatasource::table_from_sql(const std::string& sql) return table_name; } -featureset_ptr PostgisDatasource::features(const query& q) const +featureset_ptr postgis_datasource::features(const query& q) const { Featureset *fs=0; Envelope const& box=q.get_bbox(); @@ -202,15 +202,15 @@ featureset_ptr PostgisDatasource::features(const query& q) const s << box.maxx() << " " << box.maxy() << ")'::box3d,"< rs=conn->executeQuery(s.str(),1); - fs=new PostgisFeatureset(rs,props.size()); + fs=new postgis_featureset(rs,props.size()); } } return featureset_ptr(fs); } -const Envelope& PostgisDatasource::envelope() const +const Envelope& postgis_datasource::envelope() const { return extent_; } -PostgisDatasource::~PostgisDatasource() {} +postgis_datasource::~postgis_datasource() {} diff --git a/datasources/postgis/postgis.hpp b/datasources/postgis/postgis.hpp index 23c82a6e0..d067bdbd8 100644 --- a/datasources/postgis/postgis.hpp +++ b/datasources/postgis/postgis.hpp @@ -33,7 +33,7 @@ using namespace mapnik; -class PostgisDatasource : public datasource +class postgis_datasource : public datasource { static const std::string GEOMETRY_COLUMNS; static const std::string SPATIAL_REF_SYS; @@ -54,15 +54,15 @@ public: featureset_ptr features(const query& q) const; mapnik::Envelope const& envelope() const; layer_descriptor const& get_descriptor() const; - PostgisDatasource(const Parameters ¶ms); - ~PostgisDatasource(); + postgis_datasource(const Parameters ¶ms); + ~postgis_datasource(); private: static std::string table_from_sql(const std::string& sql); - PostgisDatasource(const PostgisDatasource&); - PostgisDatasource& operator=(const PostgisDatasource&); + postgis_datasource(const postgis_datasource&); + postgis_datasource& operator=(const postgis_datasource&); }; -class PostgisFeatureset : public Featureset +class postgis_featureset : public Featureset { private: ref_ptr rs_; @@ -70,13 +70,13 @@ private: mutable int totalGeomSize_; mutable int count_; public: - PostgisFeatureset(const ref_ptr& rs,unsigned num_attrs); + postgis_featureset(const ref_ptr& rs,unsigned num_attrs); void dispose(); - Feature* next(); - ~PostgisFeatureset(); + feature_ptr next(); + ~postgis_featureset(); private: - PostgisFeatureset(const PostgisFeatureset&); - const PostgisFeatureset& operator=(const PostgisFeatureset&); + postgis_featureset(const postgis_featureset&); + const postgis_featureset& operator=(const postgis_featureset&); }; #endif //POSTGIS_HPP diff --git a/datasources/postgis/postgisfs.cpp b/datasources/postgis/postgisfs.cpp index 788e7d157..6e1e18a62 100644 --- a/datasources/postgis/postgisfs.cpp +++ b/datasources/postgis/postgisfs.cpp @@ -27,21 +27,20 @@ using boost::lexical_cast; using boost::bad_lexical_cast; using std::string; -PostgisFeatureset::PostgisFeatureset(const ref_ptr& rs, +postgis_featureset::postgis_featureset(const ref_ptr& rs, unsigned num_attrs=0) : rs_(rs), num_attrs_(num_attrs), totalGeomSize_(0), count_(0) {} -Feature* PostgisFeatureset::next() +feature_ptr postgis_featureset::next() { - Feature *feature=0; if (rs_->next()) { const char* buf = rs_->getValue(0); int id = int4net(buf); - + feature_ptr feature(new Feature(id)); int size=rs_->getFieldLength(1); const char *data=rs_->getValue(1); geometry_ptr geom=geometry_utils::from_wkb(data,size,-1); @@ -49,7 +48,7 @@ Feature* PostgisFeatureset::next() if (geom) { - feature=new Feature(id,geom); + feature->set_geometry(geom); feature->reserve_props(num_attrs_); unsigned start=2; for (unsigned pos=0;posclose(); std::cout << "totalGeomSize="<& attribute_names,long file_length); virtual ~shape_featureset(); - Feature* next(); + feature_ptr next(); private: shape_featureset(const shape_featureset&); const shape_featureset& operator=(const shape_featureset&); diff --git a/datasources/shape/shape_index_featureset.cpp b/datasources/shape/shape_index_featureset.cpp index 767634558..dfaabedec 100644 --- a/datasources/shape/shape_index_featureset.cpp +++ b/datasources/shape/shape_index_featureset.cpp @@ -58,21 +58,23 @@ shape_index_featureset::shape_index_featureset(const filterT& filter, } template -Feature* shape_index_featureset::next() -{ - Feature *f=0; +feature_ptr shape_index_featureset::next() +{ + if (itr_!=ids_.end()) { int pos=*itr_++; shape_.move_to(pos); int type=shape_.type(); + feature_ptr feature(new Feature(shape_.id_)); + if (type==shape_io::shape_point) { double x=shape_.shp().read_double(); double y=shape_.shp().read_double(); geometry_ptr point(new point_impl(-1)); point->move_to(x,y); - f=new Feature(shape_.id_,point); + feature->set_geometry(point); ++count_; } else if (type == shape_io::shape_pointm) @@ -82,7 +84,7 @@ Feature* shape_index_featureset::next() shape_.shp().read_double();// m geometry_ptr point(new point_impl(-1)); point->move_to(x,y); - f=new Feature(shape_.id_,point); + feature->set_geometry(point); ++count_; } else if (type == shape_io::shape_pointz) @@ -93,7 +95,7 @@ Feature* shape_index_featureset::next() shape_.shp().read_double();// m geometry_ptr point(new point_impl(-1)); point->move_to(x,y); - f=new Feature(shape_.id_,point); + feature->set_geometry(point); ++count_; } else @@ -110,21 +112,21 @@ Feature* shape_index_featureset::next() case shape_io::shape_polyline: { geometry_ptr line = shape_.read_polyline(); - f=new Feature(shape_.id_,line); + feature->set_geometry(line); ++count_; break; } case shape_io::shape_polylinem: { geometry_ptr line = shape_.read_polylinem(); - f=new Feature(shape_.id_,line); + feature->set_geometry(line); ++count_; break; } case shape_io::shape_polylinez: { geometry_ptr line = shape_.read_polylinez(); - f=new Feature(shape_.id_,line); + feature->set_geometry(line); ++count_; break; } @@ -132,35 +134,35 @@ Feature* shape_index_featureset::next() { geometry_ptr poly = shape_.read_polygon(); - f=new Feature(shape_.id_,poly); + feature->set_geometry(poly); ++count_; break; } case shape_io::shape_polygonm: { geometry_ptr poly = shape_.read_polygonm(); - f=new Feature(shape_.id_,poly); + feature->set_geometry(poly); ++count_; break; } case shape_io::shape_polygonz: { geometry_ptr poly = shape_.read_polygonz(); - f=new Feature(shape_.id_,poly); + feature->set_geometry(poly); ++count_; break; } } if (attr_ids_.size()) { - f->reserve_props(attr_ids_.size()); + feature->reserve_props(attr_ids_.size()); shape_.dbf().move_to(shape_.id_); std::vector::const_iterator pos=attr_ids_.begin(); while (pos!=attr_ids_.end()) { try { - shape_.dbf().add_attribute(*pos,f); + shape_.dbf().add_attribute(*pos,feature.get()); } catch (...) { @@ -170,9 +172,13 @@ Feature* shape_index_featureset::next() } } } + return feature; + } + else + { + std::cout<& attribute_names); virtual ~shape_index_featureset(); - Feature* next(); + feature_ptr next(); private: //no copying shape_index_featureset(const shape_index_featureset&); diff --git a/include/datasource.hpp b/include/datasource.hpp index 2f868bae9..d93ec8ad7 100644 --- a/include/datasource.hpp +++ b/include/datasource.hpp @@ -35,7 +35,7 @@ namespace mapnik typedef ref_ptr feature_ptr; struct Featureset { - virtual Feature* next()=0; + virtual feature_ptr next()=0; virtual ~Featureset() {}; }; diff --git a/src/render.cpp b/src/render.cpp index b326fc65e..099140dbf 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -68,7 +68,7 @@ namespace mapnik std::vector else_rules; bool active_rules=false; - const std::vector& rules=style.rules(); + const std::vector& rules=style.get_rules(); std::vector::const_iterator ruleIter=rules.begin(); while (ruleIter!=rules.end()) @@ -104,7 +104,7 @@ namespace mapnik featureset_ptr fs=ds->features(q); if (fs) { - Feature* feature=0; + feature_ptr feature; while ((feature = fs->next())) { bool do_else=true; @@ -148,30 +148,31 @@ namespace mapnik } } } - delete feature; + //delete feature; } } - if (l.isSelectable() && l.selection().size()) //TODO !!! - { + + //if (l.isSelectable() && l.selection().size()) //TODO !!! + //{ //volatile style_cache* styles=style_cache::instance(); - const Style& style=style_cache::instance()->find(l.selection_style()); + // const Style& style=style_cache::instance()->find(l.selection_style()); - std::vector >& selection=l.selection(); + // std::vector >& selection=l.selection(); - Style::Iterator pos = style.begin(); - if (pos!=style.end()) { - std::vector >::iterator itr=selection.begin(); - - while (itr!=selection.end()) - { - geometry_ptr& geom=(*itr)->get_geometry(); - geom->transform(t); - (*pos)->render(*geom,image); - ++itr; - } - } - l.clear_selection(); - } + // Style::Iterator pos = style.begin(); + // if (pos!=style.end()) { + // std::vector >::iterator itr=selection.begin(); + // + // while (itr!=selection.end()) + // { + // geometry_ptr& geom=(*itr)->get_geometry(); + // geom->transform(t); + // (*pos)->render(*geom,image); + // ++itr; + // } + // } + // l.clear_selection(); + //} } } }