Skip to content
Snippets Groups Projects
Commit b4efcdce authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

CLEAN: remove dependency to pqxx and remove all related classes

OTB does not support anymore classes which use pqxx in version 4.0:

Classes removed in OTBv4 are:
        - PostGISConnectionImplementation
        - PostGISTable
        - GISTableFunction
        - PostGISCreateTableTransactor
        - PostGISFromStringTransactor
        - PostGISQueryTransactor
        - TransactorGISTableFunction

You can still access to these classes, related tests and examples in OTB 3.20.
parent 7f6ca50a
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1316 deletions
# - Find PQXX
# Find the native PQXX includes and library
#
# PQXX_FOUND - True if PQXX found.
# PQXX_INCLUDE_DIRS - where to find tinyxml.h, etc.
# PQXX_LIBRARIES - List of libraries when using PQXX.
#
if( PQXX_INCLUDE_DIR )
# Already in cache, be silent
set( PQXX_FIND_QUIETLY TRUE )
endif()
find_path( PQXX_INCLUDE_DIR pqxx/pqxx )
find_library( PQXX_LIBRARY
NAMES pqxx
PATH_SUFFIXES pqxx )
# handle the QUIETLY and REQUIRED arguments and set PQXX_FOUND to TRUE if
# all listed variables are TRUE
include( FindPackageHandleStandardArgs )
FIND_PACKAGE_HANDLE_STANDARD_ARGS( PQXX DEFAULT_MSG PQXX_LIBRARY PQXX_INCLUDE_DIR )
mark_as_advanced( PQXX_INCLUDE_DIR PQXX_LIBRARY )
if(PQXX_FOUND)
set(PQXX_INCLUDE_DIRS ${PQXX_INCLUDE_DIR})
set(PQXX_LIBRARIES ${PQXX_LIBRARY})
else()
set(PQXX_INCLUDE_DIRS)
set(PQXX_LIBRARIES)
endif()
message(STATUS "Importing Pqxx...")
option(OTB_USE_PQXX "Use pqxx library (EXPERIMENTAL)." OFF)
mark_as_advanced(OTB_USE_PQXX)
if(OTB_USE_PQXX)
find_package(Pqxx)
if(PQXX_FOUND)
message(STATUS "Activating Pqxx support")
else()
# Generate an error if no external Pqxx is available
message(FATAL_ERROR "Pqxx required but not found. "
"Turn OTB_USE_PQXX to OFF")
endif()
else()
message(STATUS "Disabling Pqxx support")
endif()
......@@ -78,7 +78,6 @@ set(GETTEXT_MSGMERGE_EXECUTABLE "@GETTEXT_MSGMERGE_EXECUTABLE@")
set(GETTEXT_INCLUDE_DIR "@GETTEXT_INCLUDE_DIR@")
set(GETTEXT_LIBRARY "@GETTEXT_LIBRARY@")
set(GETTEXT_INTL_LIBRARY "@GETTEXT_INTL_LIBRARY@")
set(OTB_USE_PQXX "@OTB_USE_PQXX@")
set(OTB_USE_PATENTED "@OTB_USE_PATENTED@")
set(OTB_USE_LIBLAS "@OTB_USE_LIBLAS@")
set(OTB_USE_EXTERNAL_LIBLAS "@OTB_USE_EXTERNAL_LIBLAS@")
......
......@@ -106,11 +106,6 @@ if(OTB_USE_LIBLAS AND OTB_USE_EXTERNAL_LIBLAS)
include_directories(${LIBLAS_INCLUDE_DIRS})
endif()
if(OTB_USE_PQXX)
find_package(Pqxx REQUIRED)
include_directories(${PQXX_INCLUDE_DIRS})
endif()
if(OTB_USE_EXTERNAL_LIBKML)
find_package(LibKML REQUIRED)
include_directories(${LIBKML_INCLUDE_DIRS})
......
......@@ -78,11 +78,6 @@ if(WIN32)
${OTB_SOURCE_DIR}/Utilities/otbmsinttypes )
endif()
if(OTB_USE_PQXX)
set(OTB_INCLUDE_DIRS_BUILD_TREE ${OTB_INCLUDE_DIRS_BUILD_TREE}
${OTB_SOURCE_DIR}/Code/GeospatialAnalysis ${PQXX_INCLUDE_DIR})
endif()
if(OTB_USE_SIFTFAST)
set(OTB_INCLUDE_DIRS_BUILD_TREE ${OTB_INCLUDE_DIRS_BUILD_TREE}
${OTB_SOURCE_DIR}/Utilities/otbsiftfast)
......
......@@ -210,7 +210,6 @@ include(ImportITK)
include(ImportJPEG2000)
include(ImportFLTK) # depends on ImportGdal
include(ImportCurl)
include(ImportPqxx)
include(ImportBoost)
include(ImportMapnik) # depends on ImportBoost
include(ImportOpenThreads)
......@@ -391,7 +390,6 @@ if(NOT OTB_INSTALL_NO_DEVELOPMENT)
${OTB_SOURCE_DIR}/CMake/FindMercurial.cmake
${OTB_SOURCE_DIR}/CMake/FindMuParser.cmake
${OTB_SOURCE_DIR}/CMake/FindOpenThreads.cmake
${OTB_SOURCE_DIR}/CMake/FindPqxx.cmake
${OTB_SOURCE_DIR}/CMake/FindTinyXML.cmake
DESTINATION ${OTB_INSTALL_CMAKEMODULE_DIR}
COMPONENT Development)
......
......@@ -28,10 +28,6 @@ if(OTB_USE_VISU_GUI)
add_subdirectory(Visualization)
endif()
if(OTB_USE_PQXX)
add_subdirectory(GeospatialAnalysis)
endif()
if(BUILD_APPLICATIONS)
add_subdirectory(ApplicationEngine)
add_subdirectory(Wrappers)
......
......@@ -6,10 +6,6 @@ if( NOT OTB_USE_MAPNIK )
list(REMOVE_ITEM OTBCommon_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbVectorDataStyle.cxx" )
endif()
if( NOT OTB_USE_PQXX )
list(REMOVE_ITEM OTBCommon_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbPostGISConnectionImplementation.cxx" )
endif()
add_library(OTBCommon ${OTBCommon_SRCS})
#Apparently not supported by opensolaris at least
#set_target_properties(OTBCommon
......@@ -21,10 +17,6 @@ if(OTB_USE_MAPNIK)
target_link_libraries(OTBCommon ${MAPNIK_LIBRARY} ${ICUUC_LIBRARY})
endif()
if(OTB_USE_PQXX)
target_link_libraries(OTBCommon ${PQXX_LIBRARY})
endif()
if(OTB_I18N)
target_link_libraries(OTBCommon ${GETTEXT_LIBRARY})
if(APPLE OR WIN32)
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbPostGISConnectionImplementation.h"
#include <sstream>
#include <sstream>
#include <assert.h>
namespace otb
{
PostGISConnectionImplementation::PostGISConnectionImplementation()
{
m_Host = "localhost";
m_DBName = "";
m_User = "postgres";
m_Password = "";
m_Port = "5432";
m_Options = "";
}
PostGISConnectionImplementation::~PostGISConnectionImplementation()
{
}
void PostGISConnectionImplementation::ConnectToDB()
{
std::stringstream connstring;
connstring << "host=" << m_Host << " dbname=" << m_DBName << " user=" << m_User;
if (m_Password != "") connstring << " password=" << m_Password;
if (m_Port != "") connstring << " port=" << m_Port;
if (m_Options != "") connstring << " options=" << m_Options;
if (!m_PostGISConnection) delete m_PostGISConnection;
m_PostGISConnection = new BasicConnectionType(connstring.str().c_str());
}
void PostGISConnectionImplementation::PerformTransaction(const TransactorType& theTransaction) const
{
//assert(0); //do not use this method yet
//m_PostGISConnection->perform( theTransaction );
}
PostGISConnectionImplementation::BasicConnectionType* PostGISConnectionImplementation::GetConnection() const
{
return m_PostGISConnection;
}
void PostGISConnectionImplementation::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << std::endl;
os << "DB name: " << m_DBName << std::endl;
}
} // end namespace otb
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPostGISConnectionImplementation_h
#define __otbPostGISConnectionImplementation_h
#include "otbGISConnectionImplementation.h"
#include <pqxx/pqxx>
namespace otb
{
/** \class PostGISConnectionImplementation
* \brief this class represents a connection to a PostGIS data base.
*
*
*
*/
class ITK_EXPORT PostGISConnectionImplementation
: public GISConnectionImplementation<pqxx::transactor<pqxx::nontransaction> >
{
public:
/** Standard class typedefs */
typedef PostGISConnectionImplementation Self;
typedef pqxx::transactor<pqxx::nontransaction> PQXXTransactorType;
typedef GISConnectionImplementation<PQXXTransactorType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macros */
itkNewMacro(Self);
itkTypeMacro(PostGISConnectionImplementation, GISConnectionImplementation);
/** Typedefs */
typedef pqxx::basic_connection<pqxx::connect_direct> BasicConnectionType;
typedef PQXXTransactorType TransactorType;
/** Acessors */
itkGetMacro(Host, std::string);
itkSetMacro(Host, std::string);
itkGetMacro(DBName, std::string);
itkSetMacro(DBName, std::string);
itkGetMacro(User, std::string);
itkSetMacro(User, std::string);
itkGetMacro(Password, std::string);
itkSetMacro(Password, std::string);
itkGetMacro(Port, std::string);
itkSetMacro(Port, std::string);
itkGetMacro(Options, std::string);
itkSetMacro(Options, std::string);
/** Using the connection */
void ConnectToDB();
void PerformTransaction(const TransactorType& theTransaction) const;
BasicConnectionType* GetConnection() const;
protected:
/** Constructor */
PostGISConnectionImplementation();
/** Destructor */
virtual ~PostGISConnectionImplementation();
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
PostGISConnectionImplementation(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
std::string m_Host;
std::string m_DBName;
std::string m_User;
std::string m_Password;
std::string m_Port;
std::string m_Options;
BasicConnectionType* m_PostGISConnection;
};
} // end namespace otb
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPostGISTable_h
#define __otbPostGISTable_h
#include "otbGISTable.h"
#include "otbCorrectPolygonFunctor.h"
namespace otb
{
/** \class PostGISTable
* \brief this class represents a table of a geospatial database (PostGIS).
*
*
* \sa GISTableFileReader
* \sa GISTableFileWriter
*
*/
template <class TConnectionImplementation, class TPrecision = double, unsigned int TSpatialDimension = 2>
class ITK_EXPORT PostGISTable
: public GISTable <TConnectionImplementation, TPrecision, TSpatialDimension>
{
public:
/** Standard class typedefs */
typedef PostGISTable Self;
typedef GISTable <TConnectionImplementation, TPrecision, TSpatialDimension> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macros */
itkNewMacro(Self);
itkTypeMacro(PostGISTable, GISTable);
itkStaticConstMacro(Dimension, unsigned int, TSpatialDimension);
/** Some convenient typedefs */
typedef TConnectionImplementation ConnectionType;
typedef typename ConnectionType::Pointer ConnectionPointerType;
typedef itk::Point<TPrecision, TSpatialDimension> PointType;
typedef PolyLineParametricPathWithValue <TPrecision, TSpatialDimension> LineType;
typedef typename LineType::Pointer LinePointerType;
typedef Polygon <TPrecision> PolygonType;
typedef typename PolygonType::Pointer PolygonPointerType;
typedef typename PolygonType::ConstPointer PolygonConstPointerType;
typedef ObjectList<PolygonType> PolygonListType;
typedef typename PolygonListType::Pointer PolygonListPointerType;
typedef typename PolygonListType::ConstPointer PolygonListConstPointerType;
/** typedefs for correct polygon */
typedef otb::CorrectPolygonFunctor<PolygonType> CorrectFunctorType;
/** Acessors */
itkGetConstMacro(TableName, std::string);
itkSetMacro(TableName, std::string);
//itkGetConstObjectMacro(Connection, ConnectionType);
itkGetObjectMacro(Connection, ConnectionType);
itkSetObjectMacro(Connection, ConnectionType);
/** Clear the table not implemented yet*/
bool Clear();
/** Get attributes of the Table*/ //TODO implement
/** Get srid of the geometric column*/ //TODO implement
//virtual
/** Init basic SQL command*/
void InsertBegin(std::stringstream& sqlCmd);
/** Add Point content to the GIS Table*/
void InsertPoint(const PointType& pt, const std::string& attribute = 0);
//void InsertMultiPoint();
/** Add Polygons to the GIS Table (exterior and interior ring)*/
void InsertPolygons(PolygonConstPointerType polygonExtRing,
PolygonListConstPointerType polygonListInteriorRing = 0,
const std::string& attribute = 0);
/** Add Line to the GIS Table*/
void InsertLineString(LinePointerType l, const std::string& attribute = 0);
/** Execute the sqlCmd which add geometric rows to the gis table*/
void InsertGeometries(const std::string& sqlCmd);
/** Clean up SQL command*/
void EraseLastChar(std::stringstream& sqlCmd);
/** Effective Creation of the table*/
void CreateTable(bool dropExistingGISTable);
/** Get geometry column type Not implemented yet in progress */
void getGeometryType();
/** Get string connection usable by OGR library*/
std::string GetOGRStrConnection() const;
/** Get const string connection methos temp*/
//ConnectionPointerType GetConstConnection() const;
/** Add an alpha numeric column to the table */
// const std::string AddVarCharColumn(unsigned int size);
/** Insert Alpha Numeric Data in the Car char column */
// void AddStrDataToVarCharColumn(std::string data);
protected:
/** Constructor */
PostGISTable();
/** Destructor */
virtual ~PostGISTable() {}
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
PostGISTable(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
std::string m_TableName;
ConnectionPointerType m_Connection;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPostGISTable.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPostGISTable_txx
#define __otbPostGISTable_txx
#include "otbPostGISTable.h"
#include "itkPreOrderTreeIterator.h"
#include "otbMetaDataKey.h"
#include <iostream>
#include <sstream>
#include <string>
#include "otbPostGISFromStringTransactor.h"
#include "otbPostGISConnectionImplementation.h"
#include "otbPostGISCreateTableTransactor.h"
namespace otb
{
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::PostGISTable()
{
m_Connection = ConnectionType::New();
this->SetSrid(-1);
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << std::endl;
os << "Table name: " << m_TableName << std::endl;
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
bool
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::Clear()
{ //TODO implementation
return true;
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::InsertBegin(std::stringstream& sqlCmd)
{
sqlCmd.str("");
sqlCmd << "INSERT INTO \"" << this->GetTableName() << "\" ( \"the_geom\" , \"genre\" ) VALUES (";
sqlCmd << "GeometryFromText('";
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::InsertPoint(const PointType& pt, const std::string& attribute)
{
std::stringstream sqlCmd;
this->InsertBegin(sqlCmd);
sqlCmd << "POINT( ";
for (unsigned int i = 0; i < TSpatialDimension; ++i)
{
sqlCmd << pt[i] << " ";
}
//int this->GetSrid()=-1;
sqlCmd << ")'," << this->GetSrid() << ") ,'" << attribute << "');" << std::endl;
//Execute the query
this->InsertGeometries(sqlCmd.str());
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::InsertLineString(LinePointerType l, const std::string& attribute)
{
std::stringstream sqlCmd;
this->InsertBegin (sqlCmd);
sqlCmd << "LINESTRING( ";
typedef typename LineType::VertexListConstIteratorType VertexIterator;
VertexIterator itVertex = l->GetVertexList()->Begin();
while (itVertex != l->GetVertexList()->End())
{
for (unsigned int i = 0; i < TSpatialDimension; ++i)
{
sqlCmd << itVertex.Value()[i] << " ";
++itVertex;
}
sqlCmd << ",";
}
//Erase the last ','
EraseLastChar (sqlCmd);
//int this->GetSrid()=-1;
sqlCmd << ")'," << this->GetSrid() << ") ,'" << attribute << "');" << std::endl;
//Execute the query
this->InsertGeometries(sqlCmd.str());
/* Invalid (MULTI)Linestring */
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::InsertPolygons(PolygonConstPointerType polygonExtRing,
PolygonListConstPointerType polygonListInteriorRing,
const std::string& attribute)
{
/** correct polygon exterior ring */
CorrectFunctorType correct;
PolygonPointerType correctPolygonExtRing = correct(polygonExtRing);
std::stringstream sqlCmd;
this->InsertBegin (sqlCmd);
sqlCmd << "POLYGON( ( ";
//std::cout << "sqlcmd: " << sqlCmd.str() << std::endl;
typedef typename PolygonType::VertexListConstIteratorType VertexIterator;
VertexIterator itVertex = correctPolygonExtRing->GetVertexList()->Begin();
//std::cout << "sizeof ext poly: " << polygonExtRing->GetVertexList()->Size()<< std::endl;
while (itVertex != correctPolygonExtRing->GetVertexList()->End())
{
//polygon->line_to(itVertex.Value()[0], m_SensorModelFlip*itVertex.Value()[1]);
//std::cout << "vertex: " << itVertex.Value()<< std::endl;
for (unsigned int i = 0; i < TSpatialDimension; ++i)
{
sqlCmd << itVertex.Value()[i] << " ";
//++itVertex;
}
sqlCmd << ",";
++itVertex;
}
//Erase the last ','
//std::cout << "avt erase : " << sqlCmd.str() << std::endl;
EraseLastChar (sqlCmd);
//std::cout << "apres arase " << sqlCmd.str() << std::endl;
sqlCmd << "),";
//std::cout << "ext polygon: " << sqlCmd.str() << std::endl;
//Add interior polygons
if (!polygonListInteriorRing.IsNull())
{
//get holes
//sqlCmd << ",";
typedef typename PolygonListType::ConstIterator PolygonListConstIteratorType;
for (PolygonListConstIteratorType itPolygonList = polygonListInteriorRing->Begin();
itPolygonList != polygonListInteriorRing->End();
++itPolygonList)
{
/** correct current polygon interior ring */
CorrectFunctorType correctCurrentInt;
PolygonPointerType correctCurrentPolygonIntRing = correctCurrentInt(itPolygonList.Get());
sqlCmd << "(";
itVertex = correctCurrentPolygonIntRing->GetVertexList()->Begin();
while (itVertex != correctCurrentPolygonIntRing->GetVertexList()->End())
{
//polygon->line_to(itVertex.Value()[0], m_SensorModelFlip*itVertex.Value()[1]);
for (unsigned int i = 0; i < TSpatialDimension; ++i)
{
sqlCmd << itVertex.Value()[i] << " ";
++itVertex;
}
sqlCmd << ",";
++itVertex;
}
//Erase the last ','
EraseLastChar (sqlCmd);
sqlCmd << "),";
}
//std::cout << "int polygon: " << sqlCmd.str() << std::endl;
}
//Erase the last ','
EraseLastChar (sqlCmd);
//int this->GetSrid()=-1;
sqlCmd << ")'," << this->GetSrid() << ") ,'" << attribute << "');" << std::endl;
//std::cout << "sqlcmd polygon: " << sqlCmd.str() << std::endl;
//Insert the geometry
this->InsertGeometries(sqlCmd.str());
//std::cout << "geometries!!" << std::endl;
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::InsertGeometries(const std::string& sqlCmd)
{
typedef otb::PostGISFromStringTransactor TransactorType;
TransactorType myStringTransactor;
//std::cout << "transactor string" << sqlCmd<< std::endl;
myStringTransactor.SetTransactionString(sqlCmd);
//this->GetConnection()->ConnectToDB();
this->GetConnection()->GetConnection()->perform(myStringTransactor);
// this->GetConnection()->PerformTransaction( myStringTransactor );
//myStringTransactor ( *( this->GetConnection()->GetConnection() ) );
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::EraseLastChar(std::stringstream& sqlCmd)
{
std::string EraseCmd = sqlCmd.str();
EraseCmd.erase(EraseCmd.length() - 1);
sqlCmd.str("");
sqlCmd << EraseCmd;
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::CreateTable(bool dropExistingGISTable)
{
typedef otb::PostGISCreateTableTransactor TransactorType;
//Instantiation
TransactorType myTransactor;
myTransactor.SetDimension(TSpatialDimension);
//std::string name = "mytable";
myTransactor.SetTableName(this->GetTableName());
//int this->GetSrid() = -1;
myTransactor.SetSRID(this->GetSrid());
myTransactor.SetRemoveExistingTable(dropExistingGISTable);
this->GetConnection()->GetConnection()->perform(myTransactor);
//this->GetConnection()->PerformTransaction( myTransactor );
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
void
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::getGeometryType()
{
//the geomtric column name is the_geom
std::string query = "SELECT DISTINCT geometrytype(\"the_geom\") "
"FROM \"" + this->GetTableName() + "\" WHERE NOT geometrytype(\"the_geom\") IS NULL";
typedef otb::PostGISFromStringTransactor TransactorType;
TransactorType myStringTransactor;
//std::cout << "transactor string" << sqlCmd<< std::endl;
myStringTransactor.SetTransactionString(query);
//this->GetConnection()->ConnectToDB();
//typedef pqxx::result ResultType;
//ResultType R = this->GetConnection()->GetConnection()->perform( myStringTransactor );
}
template <class TConnectionImplementation, class TPrecision, unsigned int TSpatialDimension>
std::string
PostGISTable<TConnectionImplementation, TPrecision, TSpatialDimension>
::GetOGRStrConnection() const
{
//std::cout << "getOGR: " << m_Connection << std::endl;
std::string connectionSTR = "";
connectionSTR += "PG:";
connectionSTR += "dbname='";
connectionSTR += m_Connection->GetDBName();
connectionSTR += "' ";
connectionSTR += "host='";
connectionSTR += m_Connection->GetHost();
connectionSTR += "' ";
connectionSTR += "port='";
connectionSTR += m_Connection->GetPort();
connectionSTR += "' ";
connectionSTR += "user='";
connectionSTR += m_Connection->GetUser();
connectionSTR += "' ";
connectionSTR += "password='";
connectionSTR += m_Connection->GetPassword();
connectionSTR += "' ";
if (!m_TableName.empty())
{
connectionSTR += "tables=";
connectionSTR += m_TableName;
// connectionSTR += "' ";
}
otbGenericMsgDebugMacro(<< "OGR connection string " << connectionSTR);
return connectionSTR;
}
} // end namespace otb
#endif
# Sources of non-templated classes.
file(GLOB OTBGeospatialAnalysis_SRCS "*.cxx" )
add_library(OTBGeospatialAnalysis ${OTBGeospatialAnalysis_SRCS})
target_link_libraries(OTBGeospatialAnalysis OTBCommon ${PQXX_LIBRARY})
if(OTB_LIBRARY_PROPERTIES)
set_target_properties(OTBGeospatialAnalysis PROPERTIES ${OTB_LIBRARY_PROPERTIES})
endif()
if(NOT OTB_INSTALL_NO_LIBRARIES)
install(TARGETS OTBGeospatialAnalysis
RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR} COMPONENT Development)
endif()
if(NOT OTB_INSTALL_NO_DEVELOPMENT)
file(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
install(FILES ${__files1} ${__files2}
DESTINATION ${OTB_INSTALL_INCLUDE_DIR}/GeospatialAnalysis
COMPONENT Development)
endif()
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbGISTableFunction_h
#define __otbGISTableFunction_h
#include "itkFunctionBase.h"
#include "otbGISTable.h"
namespace otb
{
/** \class GISTableFunction
* \brief Evaluates a const transaction on a GISTable
*
* GISTableFunction is a baseclass for all objects that evaluate
* a const transaction on a GISTable.
*
* The input table is set via method SetInputTable().
*
*
* \sa GISTable
* \sa GISConnection
*
* \ingroup GISTableFunctions
*/
template <
class TInputTable,
class TOutput
>
class ITK_EXPORT GISTableFunction :
public FunctionBase<TInputTable,
TOutput>
{
public:
/** Dimension underlying input table. */
itkStaticConstMacro(TableDimension, unsigned int,
TInputTable::TSpatialDimension);
/** Standard class typedefs. */
typedef GISTableFunction Self;
typedef FunctionBase<
TInputTable,
TOutput> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(GISTableFunction, FunctionBase);
/** InputTableType typedef support. */
typedef TInputTable InputTableType;
/** Connection typedef support */
typedef typename InputTableType::ConnectionType ConnectionType;
/** InputTablePointer typedef support */
typedef typename InputTableType::ConstPointer InputTableConstPointer;
/** OutputType typedef support. */
typedef TOutput OutputType;
/** Set the input table. */
virtual void SetInputTable(const InputTableType* ptr);
/** Get the input Table. */
const InputTableType * GetInputTable() const
{ return m_Table.GetPointer(); }
/** Evaluate the function.
* Subclasses must provide this method. */
virtual TOutput Evaluate() const = 0;
protected:
GISTableFunction();
virtual ~GISTableFunction() {}
void PrintSelf(std::ostream& os, Indent indent) const;
/** Const pointer to the input table. */
InputTableConstPointer m_Table;
private:
GISTableFunction(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
};
} // end namespace otb
#if OTB_MANUAL_INSTANTIATION
# include "itkGISTableFunction.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbGISTableFunction_txx
#define __otbGISTableFunction_txx
#include "otbGISTableFunction.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputTable, class TOutput>
GISTableFunction<TInputTable, TOutput>
::GISTableFunction()
{
m_Table = NULL;
}
/**
* Standard "PrintSelf" method
*/
template <class TInputTable, class TOutput>
void
GISTableFunction<TInputTable, TOutput>
::PrintSelf(
std::ostream& os,
Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "InputTable: " << m_Table.GetPointer() << std::endl;
}
/**
* Initialize by setting the input table
*/
template <class TInputTable, class TOutput>
void
GISTableFunction<TInputTable, TOutput>
::SetInputTable(
const InputTableType* ptr)
{
// set the input table
m_Table = ptr;
}
} // end namespace itk
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbPostGISCreateTableTransactor.h"
#include <sstream>
#include <cassert>
#include "otbMacro.h"
namespace otb
{
PostGISCreateTableTransactor::PostGISCreateTableTransactor() : PostGISCreateTableTransactor::Superclass("CreateTable")
{
m_RemoveExistingTable = false;
}
PostGISCreateTableTransactor::PostGISCreateTableTransactor(const PostGISCreateTableTransactor& pgt)
: PostGISCreateTableTransactor::Superclass("CreateTable")
{
m_TableName = pgt.GetTableName();
m_SRID = pgt.GetSRID();
m_Dimension = pgt.GetDimension();
m_RemoveExistingTable = pgt.GetRemoveExistingTable();
}
PostGISCreateTableTransactor & PostGISCreateTableTransactor::operator =(const PostGISCreateTableTransactor& pgt)
throw()
{
m_TableName = pgt.GetTableName();
m_SRID = pgt.GetSRID();
m_Dimension = pgt.GetDimension();
m_RemoveExistingTable = pgt.GetRemoveExistingTable();
return *this;
}
void PostGISCreateTableTransactor::operator ()(pqxx::nontransaction& T)
{
if (m_RemoveExistingTable)
{
std::stringstream dropCommand;
//dropCommand << "DROP TABLE " << m_TableName;
dropCommand << "DROP TABLE IF EXISTS " << m_TableName << " CASCADE";
otbGenericMsgDebugMacro(<< "Drop Command " << dropCommand.str());
m_Result = T.exec(dropCommand.str());
}
std::stringstream createCommand;
createCommand << "CREATE TABLE " << m_TableName
<< " (id serial PRIMARY KEY, genre TEXT);";
otbGenericMsgDebugMacro(<< "Create Command " << createCommand.str());
m_Result = T.exec(createCommand.str());
std::stringstream addGeometryCommand;
addGeometryCommand << "SELECT AddGeometryColumn( '" << m_TableName <<
"', 'the_geom', " << m_SRID << ", 'GEOMETRY'," << m_Dimension << " );";
m_Result = T.exec(addGeometryCommand.str());
/** creation index GIST */
//FIXME not working yet
// std::stringstream addGISTIndexCommand;
//
// addGISTIndexCommand << "CREATE INDEX idx_" << m_TableName << "_the_geom ON " << m_TableName <<
// " USING gist( the_geom );";
//
// otbGenericMsgDebugMacro(<< "Create Command " << addGISTIndexCommand.str());
//
// m_Result = T.exec(addGISTIndexCommand.str());
}
void PostGISCreateTableTransactor::on_commit()
{
otbMsgDevMacro( "\t Table is created \t" );
//T.exec
}
std::string PostGISCreateTableTransactor::GetTableName() const
{
return m_TableName;
}
void PostGISCreateTableTransactor::SetTableName(const std::string& aName)
{
m_TableName = aName;
}
int PostGISCreateTableTransactor::GetSRID() const
{
return m_SRID;
}
void PostGISCreateTableTransactor::SetSRID(int aSRID)
{
m_SRID = aSRID;
}
unsigned short PostGISCreateTableTransactor::GetDimension() const
{
return m_Dimension;
}
void PostGISCreateTableTransactor::SetDimension(unsigned short aDim)
{
m_Dimension = aDim;
}
void PostGISCreateTableTransactor::SetRemoveExistingTable(bool val)
{
m_RemoveExistingTable = val;
}
bool PostGISCreateTableTransactor::GetRemoveExistingTable() const
{
return m_RemoveExistingTable;
}
PostGISCreateTableTransactor::ResultType PostGISCreateTableTransactor::GetResult() const
{
return m_Result;
}
void PostGISCreateTableTransactor::CreateGISTIndex(pqxx::nontransaction& T)
{
/*
std::stringstream addGISTIndexCmd;
addGISTIndexCmd << "CREATE INDEX idx_" << m_TableName << "_the_geom ON " << m_TableName << " USING gist( the_geom );";
otbGenericMsgDebugMacro(<<"Create Command " << addGISTIndexCmd.str());
T.exec(addGISTIndexCmd.str());
*/
assert(0);
}
} // end namespace otb
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPostGISCreateTableTransactor_h
#define __otbPostGISCreateTableTransactor_h
#include <pqxx/pqxx>
#include <string>
namespace otb
{
/** \class PostGISCreateTableTransactor
* \brief PQXX-based transactor for creating PostGIS tables
*
*
* The copy constructor and the "=" operator have to be defined for
* deep copy, so that libpqxx is able to get the values set for the
* class variables.
*
*
* \ingroup GISTransactors
*/
class PostGISCreateTableTransactor :
public pqxx::transactor<pqxx::nontransaction>
{
public:
typedef pqxx::result ResultType;
typedef pqxx::transactor<pqxx::nontransaction> Superclass;
PostGISCreateTableTransactor();
PostGISCreateTableTransactor(const PostGISCreateTableTransactor& pgt);
PostGISCreateTableTransactor& operator =(const PostGISCreateTableTransactor& pgt)
throw();
void operator ()(pqxx::nontransaction& T);
void on_commit();
std::string GetTableName() const;
void SetTableName(const std::string& aName);
int GetSRID() const;
void SetSRID(int aSRID);
unsigned short GetDimension() const;
void SetDimension(unsigned short aDim);
void SetRemoveExistingTable(bool val);
bool GetRemoveExistingTable() const;
ResultType GetResult() const;
void CreateGISTIndex(pqxx::nontransaction& T);
protected:
ResultType m_Result;
std::string m_TableName;
int m_SRID;
unsigned short m_Dimension;
bool m_RemoveExistingTable;
};
} // end namespace otb
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbPostGISFromStringTransactor.h"
#include <sstream>
#include "otbMacro.h"
namespace otb
{
PostGISFromStringTransactor::PostGISFromStringTransactor() : PostGISFromStringTransactor::Superclass(
"FromStringTransactor")
{
m_TransactionString = "";
}
PostGISFromStringTransactor::PostGISFromStringTransactor(const PostGISFromStringTransactor& pgt)
: PostGISFromStringTransactor::Superclass("FromStringTransactor")
{
m_TransactionString = pgt.GetTransactionString();
}
PostGISFromStringTransactor & PostGISFromStringTransactor::operator =(const PostGISFromStringTransactor& pgt)
throw()
{
m_TransactionString = pgt.GetTransactionString();
return *this;
}
void PostGISFromStringTransactor::operator ()(pqxx::nontransaction& T)
{
if (m_TransactionString != "")
{
otbGenericMsgDebugMacro(<< "Transaction Command " << m_TransactionString);
m_Result = T.exec(m_TransactionString);
}
}
void PostGISFromStringTransactor::on_commit()
{
otbMsgDevMacro( "\t Transaction \t\n\t" << m_TransactionString );
}
std::string PostGISFromStringTransactor::GetTransactionString() const
{
return m_TransactionString;
}
void PostGISFromStringTransactor::SetTransactionString(const std::string& aName)
{
m_TransactionString = aName;
}
PostGISFromStringTransactor::ResultType PostGISFromStringTransactor::GetResult() const
{
return m_Result;
}
} // end namespace otb
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbPostGISFromStringTransactor_h
#define __otbPostGISFromStringTransactor_h
#include <pqxx/pqxx>
#include <string>
namespace otb
{
/** \class PostGISFromStringTransactor
* \brief PQXX-based transactor for executing PostGIS queries.
*
*
* The copy constructor and the "=" operator have to be defined for
* deep copy, so that libpqxx is able to get the values set for the
* class variables.
*
*
* \ingroup GISTransactors
*/
class PostGISFromStringTransactor :
public pqxx::transactor<pqxx::nontransaction>
{
public:
typedef pqxx::result ResultType;
typedef pqxx::transactor<pqxx::nontransaction> Superclass;
PostGISFromStringTransactor();
PostGISFromStringTransactor(const PostGISFromStringTransactor& pgt);
PostGISFromStringTransactor& operator =(const PostGISFromStringTransactor& pgt)
throw();
void operator ()(pqxx::nontransaction& T);
void on_commit();
std::string GetTransactionString() const;
void SetTransactionString(const std::string& trans);
ResultType GetResult() const;
protected:
ResultType m_Result;
std::string m_TransactionString;
};
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment