From 18ef4981401b0add2c6311de86de842dd270ad43 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 9 Oct 2006 09:45:45 +0000 Subject: [PATCH] don't rely on feature id column name. --- plugins/input/postgis/postgis.cpp | 4 +- plugins/input/postgis/postgisfs.cpp | 91 ++++++++++++++--------------- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis.cpp index 75a8a232c..41b8896e8 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis.cpp @@ -193,8 +193,8 @@ featureset_ptr postgis_datasource::features(const query& q) const { PoolGuard,shared_ptr > > guard(conn,pool); std::ostringstream s; - // can we rely on 'gid' name??? - s << "select ogc_fid,asbinary("< const& props=q.property_names(); std::set::const_iterator pos=props.begin(); while (pos!=props.end()) diff --git a/plugins/input/postgis/postgisfs.cpp b/plugins/input/postgis/postgisfs.cpp index f2cccfd86..9ef9ed441 100644 --- a/plugins/input/postgis/postgisfs.cpp +++ b/plugins/input/postgis/postgisfs.cpp @@ -32,7 +32,7 @@ using boost::bad_lexical_cast; using std::string; postgis_featureset::postgis_featureset(boost::shared_ptr const& rs, - unsigned num_attrs=0) + unsigned num_attrs=0) : rs_(rs), num_attrs_(num_attrs), totalGeomSize_(0), @@ -42,66 +42,63 @@ feature_ptr postgis_featureset::next() { 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); + 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); - totalGeomSize_+=size; + totalGeomSize_+=size; if (geom) { feature->set_geometry(geom); - unsigned start=2; - for (unsigned pos=0;posgetFieldName(start + pos); - const char* buf=rs_->getValue(start + pos); - //int field_size = rs_->getFieldLength(start + pos); - int oid = rs_->getTypeOID(start + pos); + + for (unsigned pos=1;posgetFieldName(pos); + const char* buf=rs_->getValue(pos); + int oid = rs_->getTypeOID(pos); - if (oid==23) //int4 - { - int val = int4net(buf); - boost::put(*feature,name,val); - } - else if (oid==21) //int2 - { - int val = int2net(buf); - boost::put(*feature,name,val); - } - else if (oid == 700) // float4 - { - float val; - float4net(val,buf); - boost::put(*feature,name,val); - } - else if (oid == 701) // float8 - { - double val; - float8net(val,buf); - boost::put(*feature,name,val); - } - else if (oid==1042 || oid==1043) //bpchar or varchar - { - boost::put(*feature,name,buf); - } - else - { - boost::put(*feature,name,0); - } - } + if (oid==23) //int4 + { + int val = int4net(buf); + boost::put(*feature,name,val); + } + else if (oid==21) //int2 + { + int val = int2net(buf); + boost::put(*feature,name,val); + } + else if (oid == 700) // float4 + { + float val; + float4net(val,buf); + boost::put(*feature,name,val); + } + else if (oid == 701) // float8 + { + double val; + float8net(val,buf); + boost::put(*feature,name,val); + } + else if (oid==1042 || oid==1043) //bpchar or varchar + { + boost::put(*feature,name,buf); + } + else + { + boost::put(*feature,name,0); + } + } ++count_; } - return feature; + return feature; } else { rs_->close(); std::clog << "totalGeomSize="<