diff --git a/plugins/input/postgis/postgis.cpp b/plugins/input/postgis/postgis.cpp index b7823feca..75a8a232c 100644 --- a/plugins/input/postgis/postgis.cpp +++ b/plugins/input/postgis/postgis.cpp @@ -31,7 +31,7 @@ DATASOURCE_PLUGIN(postgis_datasource) -const std::string postgis_datasource::GEOMETRY_COLUMNS="geometry_columns"; + const std::string postgis_datasource::GEOMETRY_COLUMNS="geometry_columns"; const std::string postgis_datasource::SPATIAL_REF_SYS="spatial_ref_system"; using std::clog; @@ -48,9 +48,9 @@ postgis_datasource::postgis_datasource(const parameters& params) type_(datasource::Vector), desc_(params.get("name")), creator_(params.get("host"), - params.get("dbname"), - params.get("user"), - params.get("password")) + params.get("dbname"), + params.get("user"), + params.get("password")) { ConnectionManager *mgr=ConnectionManager::instance(); @@ -59,92 +59,92 @@ postgis_datasource::postgis_datasource(const parameters& params) shared_ptr > pool=mgr->getPool(creator_.id()); if (pool) { - const shared_ptr& conn = pool->borrowObject(); - if (conn && conn->isOK()) - { - PoolGuard,shared_ptr > > guard(conn,pool); + const shared_ptr& conn = pool->borrowObject(); + if (conn && conn->isOK()) + { + PoolGuard,shared_ptr > > guard(conn,pool); - std::string table_name=table_from_sql(table_); + std::string table_name=table_from_sql(table_); - std::ostringstream s; - s << "select f_geometry_column,srid,type from "; - s << GEOMETRY_COLUMNS <<" where f_table_name='"< rs=conn->executeQuery(s.str()); + shared_ptr rs=conn->executeQuery(s.str()); - if (rs->next()) - { - try - { - srid_ = lexical_cast(rs->getValue("srid")); - desc_.set_srid(srid_); - } - catch (bad_lexical_cast &ex) - { - clog << ex.what() << endl; - } - geometryColumn_=rs->getValue("f_geometry_column"); - std::string postgisType=rs->getValue("type"); - } - rs->close(); - s.str(""); - s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)"; - s << " from (select estimated_extent('"<next()) + { + try + { + srid_ = lexical_cast(rs->getValue("srid")); + desc_.set_srid(srid_); + } + catch (bad_lexical_cast &ex) + { + clog << ex.what() << endl; + } + geometryColumn_=rs->getValue("f_geometry_column"); + std::string postgisType=rs->getValue("type"); + } + rs->close(); + s.str(""); + s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)"; + s << " from (select estimated_extent('"<executeQuery(s.str()); - if (rs->next()) - { - try - { - double lox=lexical_cast(rs->getValue(0)); - double loy=lexical_cast(rs->getValue(1)); - double hix=lexical_cast(rs->getValue(2)); - double hiy=lexical_cast(rs->getValue(3)); - extent_.init(lox,loy,hix,hiy); - } - catch (bad_lexical_cast &ex) - { - clog << ex.what() << endl; - } - } - rs->close(); + rs=conn->executeQuery(s.str()); + if (rs->next()) + { + try + { + double lox=lexical_cast(rs->getValue(0)); + double loy=lexical_cast(rs->getValue(1)); + double hix=lexical_cast(rs->getValue(2)); + double hiy=lexical_cast(rs->getValue(3)); + extent_.init(lox,loy,hix,hiy); + } + catch (bad_lexical_cast &ex) + { + clog << ex.what() << endl; + } + } + rs->close(); - // collect attribute desc - s.str(""); - s << "select * from "<executeQuery(s.str()); - if (rs->next()) - { - int count = rs->getNumFields(); - for (int i=0;igetFieldName(i); - int length = rs->getFieldLength(i); + // collect attribute desc + s.str(""); + s << "select * from "<executeQuery(s.str()); + if (rs->next()) + { + int count = rs->getNumFields(); + for (int i=0;igetFieldName(i); + int length = rs->getFieldLength(i); - int type_oid = rs->getTypeOID(i); - switch (type_oid) - { - case 17285: // geometry - desc_.add_descriptor(attribute_descriptor(fld_name,Geometry)); - break; - case 21: // int2 - case 23: // int4 - desc_.add_descriptor(attribute_descriptor(fld_name,Integer,false,length)); - break; + int type_oid = rs->getTypeOID(i); + switch (type_oid) + { + case 17285: // geometry + desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Geometry)); + break; + case 21: // int2 + case 23: // int4 + desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer,false,length)); + break; case 701: // float8 - desc_.add_descriptor(attribute_descriptor(fld_name,Double,false,length)); - case 1042: // bpchar - case 1043: // varchar - desc_.add_descriptor(attribute_descriptor(fld_name,String)); - break; - default: // shouldn't get here - clog << "unknown type_oid="< const& props=q.property_names(); - std::set::const_iterator pos=props.begin(); - while (pos!=props.end()) - { - s <<",\""<<*pos<<"\""; - ++pos; - } + const shared_ptr& conn = pool->borrowObject(); + if (conn && conn->isOK()) + { + 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()) + { + s <<",\""<<*pos<<"\""; + ++pos; + } - s << " from " << table_<<" where "< rs=conn->executeQuery(s.str(),1); - fs=new postgis_featureset(rs,props.size()); - } + s << " from " << table_<<" where "< rs=conn->executeQuery(s.str(),1); + fs=new postgis_featureset(rs,props.size()); + } } return featureset_ptr(fs); } diff --git a/plugins/input/shape/shape.cpp b/plugins/input/shape/shape.cpp index e7d9d4d9a..99454efdd 100644 --- a/plugins/input/shape/shape.cpp +++ b/plugins/input/shape/shape.cpp @@ -52,18 +52,18 @@ shape_datasource::shape_datasource(const parameters ¶ms) case 'D': case 'M': case 'L': - desc_.add_descriptor(attribute_descriptor(fld_name,String)); + desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String)); break; case 'N': case 'F': { if (fd.dec_>0) { - desc_.add_descriptor(attribute_descriptor(fld_name,Double,false,8)); + desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double,false,8)); } else { - desc_.add_descriptor(attribute_descriptor(fld_name,Integer,false,4)); + desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer,false,4)); } break; }