added features(const query&) to postgis datasource

This commit is contained in:
Artem Pavlenko 2005-04-04 13:27:23 +00:00
parent 4825baa5b6
commit fa6d2af40e
3 changed files with 34 additions and 14 deletions

View file

@ -130,7 +130,6 @@ FeaturesetPtr PostgisDatasource::featuresAll(const CoordTransform& t) const
return FeaturesetPtr(0); return FeaturesetPtr(0);
} }
FeaturesetPtr PostgisDatasource::featuresInBox(const CoordTransform& t, FeaturesetPtr PostgisDatasource::featuresInBox(const CoordTransform& t,
const mapnik::Envelope<double>& box) const const mapnik::Envelope<double>& box) const
{ {
@ -150,12 +149,36 @@ FeaturesetPtr PostgisDatasource::featuresInBox(const CoordTransform& t,
s << box.maxx() << " " << box.maxy() << ")'::box3d,"<<srid_<<")"; s << box.maxx() << " " << box.maxy() << ")'::box3d,"<<srid_<<")";
std::cout << s.str()<<std::endl; std::cout << s.str()<<std::endl;
ref_ptr<ResultSet> rs=conn->executeQuery(s.str(),1); ref_ptr<ResultSet> rs=conn->executeQuery(s.str(),1);
fs=new PostgisFeatureset(rs,t); fs=new PostgisFeatureset(rs);
} }
} }
return FeaturesetPtr(fs); return FeaturesetPtr(fs);
} }
FeaturesetPtr PostgisDatasource::features(const query& q) const
{
Featureset *fs=0;
const Envelope<double>& box=q.get_bbox();
ConnectionManager *mgr=ConnectionManager::instance();
ref_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
if (pool)
{
const ref_ptr<Connection>& conn = pool->borrowObject();
if (conn && conn->isOK())
{
PoolGuard<ref_ptr<Connection>,ref_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
std::ostringstream s;
s << "select gid,asbinary("<<geometryColumn_<<") as geom from ";
s << table_<<" where "<<geometryColumn_<<" && setSRID('BOX3D(";
s << box.minx() << " " << box.miny() << ",";
s << box.maxx() << " " << box.maxy() << ")'::box3d,"<<srid_<<")";
std::cout << s.str()<<std::endl;
ref_ptr<ResultSet> rs=conn->executeQuery(s.str(),1);
fs=new PostgisFeatureset(rs);
}
}
return FeaturesetPtr(fs);
}
FeaturesetPtr PostgisDatasource::featuresAtPoint(const CoordTransform& t, FeaturesetPtr PostgisDatasource::featuresAtPoint(const CoordTransform& t,
const mapnik::coord2d& pt) const const mapnik::coord2d& pt) const
@ -177,7 +200,7 @@ FeaturesetPtr PostgisDatasource::featuresAtPoint(const CoordTransform& t,
s << pt.x << " " << pt.y << ")'::box3d,"<<srid_<<") && "<<geometryColumn_; s << pt.x << " " << pt.y << ")'::box3d,"<<srid_<<") && "<<geometryColumn_;
std::cout << s.str()<<std::endl; std::cout << s.str()<<std::endl;
ref_ptr<ResultSet> rs=conn->executeQuery(s.str(),1); ref_ptr<ResultSet> rs=conn->executeQuery(s.str(),1);
fs=new PostgisFeatureset(rs,t); fs=new PostgisFeatureset(rs);
} }
} }
return FeaturesetPtr(fs); return FeaturesetPtr(fs);

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
//$Id: postgis.hh 68 2004-11-23 22:39:58Z artem $ //$Id$
#ifndef POSTGIS_HH #ifndef POSTGIS_HH
#define POSTGIS_HH #define POSTGIS_HH
@ -46,6 +46,8 @@ public:
FeaturesetPtr featuresAll(const CoordTransform& t) const; FeaturesetPtr featuresAll(const CoordTransform& t) const;
FeaturesetPtr featuresInBox(const CoordTransform& t,const mapnik::Envelope<double>& box) const; FeaturesetPtr featuresInBox(const CoordTransform& t,const mapnik::Envelope<double>& box) const;
FeaturesetPtr featuresAtPoint(const CoordTransform& t,const mapnik::coord2d& pt) const; FeaturesetPtr featuresAtPoint(const CoordTransform& t,const mapnik::coord2d& pt) const;
FeaturesetPtr features(const query& q) const;
const mapnik::Envelope<double>& envelope() const; const mapnik::Envelope<double>& envelope() const;
PostgisDatasource(const Parameters &params); PostgisDatasource(const Parameters &params);
~PostgisDatasource(); ~PostgisDatasource();
@ -59,11 +61,10 @@ class PostgisFeatureset : public Featureset
{ {
private: private:
ref_ptr<ResultSet> rs_; ref_ptr<ResultSet> rs_;
CoordTransform t_;
mutable int totalGeomSize_; mutable int totalGeomSize_;
mutable int count_; mutable int count_;
public: public:
PostgisFeatureset(const ref_ptr<ResultSet>& rs,const CoordTransform& t); PostgisFeatureset(const ref_ptr<ResultSet>& rs);
void dispose(); void dispose();
Feature* next(); Feature* next();
~PostgisFeatureset(); ~PostgisFeatureset();

View file

@ -21,18 +21,14 @@
#include "postgis.hh" #include "postgis.hh"
PostgisFeatureset::PostgisFeatureset(const ref_ptr<ResultSet>& rs,const CoordTransform& t) PostgisFeatureset::PostgisFeatureset(const ref_ptr<ResultSet>& rs)
: rs_(rs), : rs_(rs),
t_(t),
totalGeomSize_(0), totalGeomSize_(0),
count_(0) count_(0) {}
{
}
Feature* PostgisFeatureset::next() Feature* PostgisFeatureset::next()
{ {
VectorFeature *feature=0; Feature *feature=0;
if (rs_->next()) if (rs_->next())
{ {
// read gid,srid,geometry and create feature // read gid,srid,geometry and create feature
@ -43,7 +39,7 @@ Feature* PostgisFeatureset::next()
if (geom) if (geom)
{ {
feature=new VectorFeature(id,geom); feature=new Feature(id,geom);
totalGeomSize_+=size; totalGeomSize_+=size;
++count_; ++count_;
} }