added features(const query&) to postgis datasource
This commit is contained in:
parent
4825baa5b6
commit
fa6d2af40e
3 changed files with 34 additions and 14 deletions
|
@ -130,7 +130,6 @@ FeaturesetPtr PostgisDatasource::featuresAll(const CoordTransform& t) const
|
|||
return FeaturesetPtr(0);
|
||||
}
|
||||
|
||||
|
||||
FeaturesetPtr PostgisDatasource::featuresInBox(const CoordTransform& t,
|
||||
const mapnik::Envelope<double>& box) const
|
||||
{
|
||||
|
@ -150,12 +149,36 @@ FeaturesetPtr PostgisDatasource::featuresInBox(const CoordTransform& t,
|
|||
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,t);
|
||||
fs=new PostgisFeatureset(rs);
|
||||
}
|
||||
}
|
||||
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,
|
||||
const mapnik::coord2d& pt) const
|
||||
|
@ -177,7 +200,7 @@ FeaturesetPtr PostgisDatasource::featuresAtPoint(const CoordTransform& t,
|
|||
s << pt.x << " " << pt.y << ")'::box3d,"<<srid_<<") && "<<geometryColumn_;
|
||||
std::cout << s.str()<<std::endl;
|
||||
ref_ptr<ResultSet> rs=conn->executeQuery(s.str(),1);
|
||||
fs=new PostgisFeatureset(rs,t);
|
||||
fs=new PostgisFeatureset(rs);
|
||||
}
|
||||
}
|
||||
return FeaturesetPtr(fs);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* 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
|
||||
#define POSTGIS_HH
|
||||
|
@ -46,6 +46,8 @@ public:
|
|||
FeaturesetPtr featuresAll(const CoordTransform& t) const;
|
||||
FeaturesetPtr featuresInBox(const CoordTransform& t,const mapnik::Envelope<double>& box) const;
|
||||
FeaturesetPtr featuresAtPoint(const CoordTransform& t,const mapnik::coord2d& pt) const;
|
||||
FeaturesetPtr features(const query& q) const;
|
||||
|
||||
const mapnik::Envelope<double>& envelope() const;
|
||||
PostgisDatasource(const Parameters ¶ms);
|
||||
~PostgisDatasource();
|
||||
|
@ -59,11 +61,10 @@ class PostgisFeatureset : public Featureset
|
|||
{
|
||||
private:
|
||||
ref_ptr<ResultSet> rs_;
|
||||
CoordTransform t_;
|
||||
mutable int totalGeomSize_;
|
||||
mutable int count_;
|
||||
public:
|
||||
PostgisFeatureset(const ref_ptr<ResultSet>& rs,const CoordTransform& t);
|
||||
PostgisFeatureset(const ref_ptr<ResultSet>& rs);
|
||||
void dispose();
|
||||
Feature* next();
|
||||
~PostgisFeatureset();
|
||||
|
|
|
@ -21,18 +21,14 @@
|
|||
|
||||
#include "postgis.hh"
|
||||
|
||||
PostgisFeatureset::PostgisFeatureset(const ref_ptr<ResultSet>& rs,const CoordTransform& t)
|
||||
PostgisFeatureset::PostgisFeatureset(const ref_ptr<ResultSet>& rs)
|
||||
: rs_(rs),
|
||||
t_(t),
|
||||
totalGeomSize_(0),
|
||||
count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
count_(0) {}
|
||||
|
||||
Feature* PostgisFeatureset::next()
|
||||
{
|
||||
VectorFeature *feature=0;
|
||||
Feature *feature=0;
|
||||
if (rs_->next())
|
||||
{
|
||||
// read gid,srid,geometry and create feature
|
||||
|
@ -43,7 +39,7 @@ Feature* PostgisFeatureset::next()
|
|||
|
||||
if (geom)
|
||||
{
|
||||
feature=new VectorFeature(id,geom);
|
||||
feature=new Feature(id,geom);
|
||||
totalGeomSize_+=size;
|
||||
++count_;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue