8010d5433f
2. Pass resolution to bbox query 3. Use variant<int,double,string> as parameter value e.g in Python: ds = Raster(file="/path/to/file",lox = 12312.4,.....) Added extractor facility to work with mapnik::parameter (C++): mapnik::parameters params; params["parameter0"] = 123.456; params["parameter1"] = "123.456"; // initialize with string extract double later boost::optional<double> val0 = params.get<double>("parameter0"); if (val0) { std::cout << *val0; } // with default value. NOTE: there is no 'parameter2' in params boost::optional<double> val2 = params.get<double>("parameter2",654.321); std::cout << * val2; // 4. Added Gdal factory method in __init__.py ds = Gdal(file="/tmp/file.tiff")
94 lines
2.7 KiB
C++
94 lines
2.7 KiB
C++
/*****************************************************************************
|
|
*
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
*
|
|
* Copyright (C) 2006 Artem Pavlenko
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
*****************************************************************************/
|
|
|
|
//$Id: connection.hpp 17 2005-03-08 23:58:43Z pavlenko $
|
|
|
|
#ifndef CONNECTION_HPP
|
|
#define CONNECTION_HPP
|
|
|
|
extern "C"
|
|
{
|
|
#include "libpq-fe.h"
|
|
}
|
|
|
|
#include "resultset.hpp"
|
|
|
|
class ResultSet;
|
|
class Connection
|
|
{
|
|
private:
|
|
PGconn *conn_;
|
|
public:
|
|
Connection(std::string const& connection_str)
|
|
{
|
|
conn_=PQconnectdb(connection_str.c_str());
|
|
if (PQstatus(conn_) == CONNECTION_BAD)
|
|
{
|
|
std::clog << "connection ["<< connection_str<< "] failed\n"
|
|
<< PQerrorMessage(conn_)<< std::endl;
|
|
}
|
|
}
|
|
|
|
bool execute(const std::string& sql) const
|
|
{
|
|
PGresult *result=PQexec(conn_,sql.c_str());
|
|
bool ok=(result && PQresultStatus(result)==PGRES_COMMAND_OK);
|
|
PQclear(result);
|
|
return ok;
|
|
}
|
|
boost::shared_ptr<ResultSet> executeQuery(const std::string& sql,int type=0) const
|
|
{
|
|
PGresult *result=0;
|
|
if (type==1)
|
|
{
|
|
result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
|
|
return boost::shared_ptr<ResultSet>(new ResultSet(result));
|
|
}
|
|
result=PQexec(conn_,sql.c_str());
|
|
return boost::shared_ptr<ResultSet>(new ResultSet(result));
|
|
}
|
|
|
|
std::string client_encoding() const
|
|
{
|
|
return PQparameterStatus(conn_,"client_encoding");
|
|
}
|
|
|
|
bool isOK() const
|
|
{
|
|
return (PQstatus(conn_)!=CONNECTION_BAD);
|
|
}
|
|
|
|
void close()
|
|
{
|
|
PQfinish(conn_);
|
|
}
|
|
|
|
~Connection()
|
|
{
|
|
PQfinish(conn_);
|
|
#ifdef MAPNIK_DEBUG
|
|
std::clog << "close connection " << conn_ << "\n";
|
|
#endif
|
|
}
|
|
};
|
|
|
|
#endif //CONNECTION_HPP
|