diff --git a/CMakeLists.txt b/CMakeLists.txt index 858a49c5b795bd6b09864457dc520854070e07f0..316e1e35bd7edeca6f0a595e0237ae509d7d325f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,6 +360,43 @@ IF(OTB_USE_MAPNIK) ENDIF(OTB_USE_MAPNIK) +#------------------------------- +# Pqxx Library +#------------------------------- +OPTION(OTB_USE_PQXX "Use pqxx library (EXPERIMENTAL)." OFF) +MARK_AS_ADVANCED(OTB_USE_PQXX) +IF(OTB_USE_PQXX) + + FIND_PATH(PQXX_INCLUDE_DIR pqxx/pqxx PATHS) + MARK_AS_ADVANCED(PQXX_INCLUDE_DIR) + IF (NOT PQXX_INCLUDE_DIR) + MESSAGE(FATAL_ERROR + "Cannot find PQXX include directory. Please set PQXX_INCLUDE_DIR or SET OTB_USE_PQXX OFF.") + ENDIF (NOT PQXX_INCLUDE_DIR) + + + FIND_LIBRARY(PQXX_LIBRARY pqxx ) + MARK_AS_ADVANCED(PQXX_LIBRARY) + IF (NOT PQXX_LIBRARY) + MESSAGE(FATAL_ERROR + "Cannot find PQXX library. Please set PQXX_LIBRARY or SET OTB_USE_PQXX OFF.") + ENDIF (NOT PQXX_LIBRARY) + + FIND_LIBRARY(PQ_LIBRARY pq ) + MARK_AS_ADVANCED(PQ_LIBRARY) + IF (NOT PQ_LIBRARY) + MESSAGE(FATAL_ERROR + "Cannot find PQ library. Please set PQ_LIBRARY or SET OTB_USE_PQXX OFF.") + ENDIF (NOT PQ_LIBRARY) + + +# Add compiler option + ADD_DEFINITIONS(-DOTB_USE_PQXX) + + INCLUDE_DIRECTORIES(${PQXX_INCLUDE_DIR}) + +ENDIF(OTB_USE_PQXX) + #------------------------------- # Boost Library diff --git a/Code/Common/CMakeLists.txt b/Code/Common/CMakeLists.txt index d6ac37d2afb9dea75f0c83fe28218ac9fabc9402..e2b6028744d04b66589015066c61bfcde325ed5f 100644 --- a/Code/Common/CMakeLists.txt +++ b/Code/Common/CMakeLists.txt @@ -6,12 +6,22 @@ IF( NOT OTB_USE_MAPNIK ) LIST(REMOVE_ITEM OTBCommon_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbVectorDataStyle.cxx" ) ENDIF( NOT OTB_USE_MAPNIK ) +IF( NOT OTB_USE_PQXX ) + LIST(REMOVE_ITEM OTBCommon_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbGISConnection.cxx" ) +ENDIF( NOT OTB_USE_PQXX ) + + ADD_LIBRARY(OTBCommon ${OTBCommon_SRCS}) TARGET_LINK_LIBRARIES (OTBCommon ITKAlgorithms ITKStatistics ITKCommon) IF (OTB_USE_MAPNIK) #TODO this line should be refined when we will like to have this capability with windows TARGET_LINK_LIBRARIES(OTBCommon ${MAPNIK_LIBRARY}/libmapnik.so) ENDIF(OTB_USE_MAPNIK) +IF (OTB_USE_PQXX) +#TODO this line should be refined when we will like to have this capability with windows + TARGET_LINK_LIBRARIES(OTBCommon pq pqxx) +ENDIF(OTB_USE_PQXX) + IF(OTB_LIBRARY_PROPERTIES) SET_TARGET_PROPERTIES(OTBCommon PROPERTIES ${OTB_LIBRARY_PROPERTIES}) diff --git a/Code/Common/otbGISConnection.hxx b/Code/Common/otbGISConnection.hxx new file mode 100644 index 0000000000000000000000000000000000000000..1d79a7f2ababadcc41dde514e6401a29825513ec --- /dev/null +++ b/Code/Common/otbGISConnection.hxx @@ -0,0 +1,80 @@ +/*========================================================================= + + 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 __otbGISConnection_h +#define __otbGISConnection_h + + +#include <pqxx/pqxx> + +namespace otb +{ +/** \class GISConnection + * \brief this class represents a connection to a geospatial database (ie. PostGIS). + * + * + * \sa GISConnectionFileReader + * \sa GISConnectionFileWriter + * + */ +class GISConnection : public itk::DataObject +{ +public: + /** Standard class typedefs */ + typedef GISConnection Self; + typedef itk::DataObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + + + /** Standard macros */ + itkNewMacro(Self); + itkTypeMacro(GISConnection,DataObject); + + /** Typedefs */ + typedef pqxx::basic_connection<pqxx::connect_direct> BasicConnectionType; + + /** Acessors */ + + + + +protected: + /** Constructor */ + GISConnection(); + /** Destructor */ + virtual ~GISConnection() {}; + /** PrintSelf method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + GISConnection(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + + std::string m_TableName; + + +}; +}// end namespace otb + + + + +#endif + diff --git a/Code/Common/otbGISTable.hxx b/Code/Common/otbGISTable.hxx new file mode 100644 index 0000000000000000000000000000000000000000..a3f7b0ed198d09945d7b168d069c7be20b10ca7f --- /dev/null +++ b/Code/Common/otbGISTable.hxx @@ -0,0 +1,95 @@ +/*========================================================================= + + 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 __otbGISTable_h +#define __otbGISTable_h + + +#include "otbGISConnection.hxx" + +namespace otb +{ +/** \class GISTable + * \brief this class represents a table of a geospatial database (ie. PostGIS). + * + * + * \sa GISTableFileReader + * \sa GISTableFileWriter + * + */ +template <unsigned int VDimension =2> +class GISTable + : public itk::DataObject +{ +public: + /** Standard class typedefs */ + typedef GISTable Self; + typedef itk::DataObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + + + /** Standard macros */ + itkNewMacro(Self); + itkTypeMacro(GISTable,DataObject); + itkStaticConstMacro(Dimension, unsigned int, VDimension); + + /** Typedefs */ + typedef otb::GISConnection ConnectionType; + + /** Acessors */ + + itkGetMacro(TableName, std::string); + itkSetMacro(TableName, std::string); + + itkGetObjectMacro(Connection, ConnectionType); + itkSetObjectMacro(Connection, ConnectionType); + + + + /** Clear the table contents */ + virtual bool Clear(); + + +protected: + /** Constructor */ + GISTable(); + /** Destructor */ + virtual ~GISTable() {}; + /** PrintSelf method */ + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + GISTable(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + + std::string m_TableName; + ConnectionType m_Connection; + + +}; +}// end namespace otb + + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbGISTable.txx" +#endif + +#endif +