use fully qualified names

This commit is contained in:
Artem Pavlenko 2006-07-24 20:06:09 +00:00
parent 6f7d9eab8a
commit d11153ccf8
2 changed files with 106 additions and 106 deletions

View file

@ -31,7 +31,7 @@
DATASOURCE_PLUGIN(postgis_datasource) 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"; const std::string postgis_datasource::SPATIAL_REF_SYS="spatial_ref_system";
using std::clog; using std::clog;
@ -48,9 +48,9 @@ postgis_datasource::postgis_datasource(const parameters& params)
type_(datasource::Vector), type_(datasource::Vector),
desc_(params.get("name")), desc_(params.get("name")),
creator_(params.get("host"), creator_(params.get("host"),
params.get("dbname"), params.get("dbname"),
params.get("user"), params.get("user"),
params.get("password")) params.get("password"))
{ {
ConnectionManager *mgr=ConnectionManager::instance(); ConnectionManager *mgr=ConnectionManager::instance();
@ -59,92 +59,92 @@ postgis_datasource::postgis_datasource(const parameters& params)
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id()); shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
if (pool) if (pool)
{ {
const shared_ptr<Connection>& conn = pool->borrowObject(); const shared_ptr<Connection>& conn = pool->borrowObject();
if (conn && conn->isOK()) if (conn && conn->isOK())
{ {
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool); PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
std::string table_name=table_from_sql(table_); std::string table_name=table_from_sql(table_);
std::ostringstream s; std::ostringstream s;
s << "select f_geometry_column,srid,type from "; s << "select f_geometry_column,srid,type from ";
s << GEOMETRY_COLUMNS <<" where f_table_name='"<<table_name<<"'"; s << GEOMETRY_COLUMNS <<" where f_table_name='"<<table_name<<"'";
shared_ptr<ResultSet> rs=conn->executeQuery(s.str()); shared_ptr<ResultSet> rs=conn->executeQuery(s.str());
if (rs->next()) if (rs->next())
{ {
try try
{ {
srid_ = lexical_cast<int>(rs->getValue("srid")); srid_ = lexical_cast<int>(rs->getValue("srid"));
desc_.set_srid(srid_); desc_.set_srid(srid_);
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast &ex)
{ {
clog << ex.what() << endl; clog << ex.what() << endl;
} }
geometryColumn_=rs->getValue("f_geometry_column"); geometryColumn_=rs->getValue("f_geometry_column");
std::string postgisType=rs->getValue("type"); std::string postgisType=rs->getValue("type");
} }
rs->close(); rs->close();
s.str(""); s.str("");
s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)"; s << "select xmin(ext),ymin(ext),xmax(ext),ymax(ext)";
s << " from (select estimated_extent('"<<table_name<<"','"<<geometryColumn_<<"') as ext) as tmp"; s << " from (select estimated_extent('"<<table_name<<"','"<<geometryColumn_<<"') as ext) as tmp";
rs=conn->executeQuery(s.str()); rs=conn->executeQuery(s.str());
if (rs->next()) if (rs->next())
{ {
try try
{ {
double lox=lexical_cast<double>(rs->getValue(0)); double lox=lexical_cast<double>(rs->getValue(0));
double loy=lexical_cast<double>(rs->getValue(1)); double loy=lexical_cast<double>(rs->getValue(1));
double hix=lexical_cast<double>(rs->getValue(2)); double hix=lexical_cast<double>(rs->getValue(2));
double hiy=lexical_cast<double>(rs->getValue(3)); double hiy=lexical_cast<double>(rs->getValue(3));
extent_.init(lox,loy,hix,hiy); extent_.init(lox,loy,hix,hiy);
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast &ex)
{ {
clog << ex.what() << endl; clog << ex.what() << endl;
} }
} }
rs->close(); rs->close();
// collect attribute desc // collect attribute desc
s.str(""); s.str("");
s << "select * from "<<table_<<" limit 1"; s << "select * from "<<table_<<" limit 1";
rs=conn->executeQuery(s.str()); rs=conn->executeQuery(s.str());
if (rs->next()) if (rs->next())
{ {
int count = rs->getNumFields(); int count = rs->getNumFields();
for (int i=0;i<count;++i) for (int i=0;i<count;++i)
{ {
std::string fld_name=rs->getFieldName(i); std::string fld_name=rs->getFieldName(i);
int length = rs->getFieldLength(i); int length = rs->getFieldLength(i);
int type_oid = rs->getTypeOID(i); int type_oid = rs->getTypeOID(i);
switch (type_oid) switch (type_oid)
{ {
case 17285: // geometry case 17285: // geometry
desc_.add_descriptor(attribute_descriptor(fld_name,Geometry)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Geometry));
break; break;
case 21: // int2 case 21: // int2
case 23: // int4 case 23: // int4
desc_.add_descriptor(attribute_descriptor(fld_name,Integer,false,length)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer,false,length));
break; break;
case 701: // float8 case 701: // float8
desc_.add_descriptor(attribute_descriptor(fld_name,Double,false,length)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double,false,length));
case 1042: // bpchar case 1042: // bpchar
case 1043: // varchar case 1043: // varchar
desc_.add_descriptor(attribute_descriptor(fld_name,String)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
break; break;
default: // shouldn't get here default: // shouldn't get here
clog << "unknown type_oid="<<type_oid<<endl; clog << "unknown type_oid="<<type_oid<<endl;
desc_.add_descriptor(attribute_descriptor(fld_name,String)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
break; break;
} }
} }
} }
} }
} }
} }
@ -188,28 +188,28 @@ featureset_ptr postgis_datasource::features(const query& q) const
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id()); shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
if (pool) if (pool)
{ {
const shared_ptr<Connection>& conn = pool->borrowObject(); const shared_ptr<Connection>& conn = pool->borrowObject();
if (conn && conn->isOK()) if (conn && conn->isOK())
{ {
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool); PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
std::ostringstream s; std::ostringstream s;
// can we rely on 'gid' name??? // can we rely on 'gid' name???
s << "select ogc_fid,asbinary("<<geometryColumn_<<") as geom"; s << "select ogc_fid,asbinary("<<geometryColumn_<<") as geom";
std::set<std::string> const& props=q.property_names(); std::set<std::string> const& props=q.property_names();
std::set<std::string>::const_iterator pos=props.begin(); std::set<std::string>::const_iterator pos=props.begin();
while (pos!=props.end()) while (pos!=props.end())
{ {
s <<",\""<<*pos<<"\""; s <<",\""<<*pos<<"\"";
++pos; ++pos;
} }
s << " from " << table_<<" where "<<geometryColumn_<<" && setSRID('BOX3D("; s << " from " << table_<<" where "<<geometryColumn_<<" && setSRID('BOX3D(";
s << box.minx() << " " << box.miny() << ","; s << box.minx() << " " << box.miny() << ",";
s << box.maxx() << " " << box.maxy() << ")'::box3d,"<<srid_<<")"; s << box.maxx() << " " << box.maxy() << ")'::box3d,"<<srid_<<")";
clog << s.str() << endl; clog << s.str() << endl;
shared_ptr<ResultSet> rs=conn->executeQuery(s.str(),1); shared_ptr<ResultSet> rs=conn->executeQuery(s.str(),1);
fs=new postgis_featureset(rs,props.size()); fs=new postgis_featureset(rs,props.size());
} }
} }
return featureset_ptr(fs); return featureset_ptr(fs);
} }

View file

@ -52,18 +52,18 @@ shape_datasource::shape_datasource(const parameters &params)
case 'D': case 'D':
case 'M': case 'M':
case 'L': case 'L':
desc_.add_descriptor(attribute_descriptor(fld_name,String)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
break; break;
case 'N': case 'N':
case 'F': case 'F':
{ {
if (fd.dec_>0) 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 else
{ {
desc_.add_descriptor(attribute_descriptor(fld_name,Integer,false,4)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer,false,4));
} }
break; break;
} }