Skip to content
Snippets Groups Projects
Commit 5640b6a3 authored by Luc Hermitte's avatar Luc Hermitte
Browse files

ENH: encapsulation of OGR

parent 6f22f577
No related branches found
No related tags found
No related merge requests found
Showing
with 960 additions and 0 deletions
......@@ -35,6 +35,7 @@ SET(OTB_INCLUDE_DIRS_BUILD_TREE ${OTB_INCLUDE_DIRS_BUILD_TREE}
${OTB_SOURCE_DIR}/Code/UtilitiesAdapters/CurlAdapters
${OTB_SOURCE_DIR}/Code/UtilitiesAdapters/OssimAdapters
${OTB_SOURCE_DIR}/Code/UtilitiesAdapters/TinyXMLAdapters
${OTB_SOURCE_DIR}/Code/UtilitiesAdapters/OGRAdapters
${OTB_SOURCE_DIR}/Code/Visu
${OTB_SOURCE_DIR}/Code/Visualization
${OTB_BINARY_DIR}/Code/Visualization
......
ADD_SUBDIRECTORY(CurlAdapters)
ADD_SUBDIRECTORY(OssimAdapters)
ADD_SUBDIRECTORY(TinyXMLAdapters)
ADD_SUBDIRECTORY(OGRAdapters)
# Sources of non-templated classes.
FILE(GLOB OTBOGRAdapters_SRCS "*.cxx" )
# IF(OTB_USE_EXTERNAL_OSSIM)
# INCLUDE_DIRECTORIES( ${OSSIM_INCLUDE_DIR} )
# ELSE(OTB_USE_EXTERNAL_OSSIM)
# INCLUDE_DIRECTORIES( ${OTB_SOURCE_DIR}/Utilities/otbossim/include
# ${OTB_BINARY_DIR}/Utilities/otbossim/include )
# ENDIF(OTB_USE_EXTERNAL_OSSIM)
ADD_LIBRARY(OTBOGRAdapters ${OTBOGRAdapters_SRCS})
TARGET_LINK_LIBRARIES (OTBOGRAdapters ${OGR_LIBRARY} ITKCommon ${Boost_FILESYSTEM_LIBRARY})
IF(OTB_LIBRARY_PROPERTIES)
SET_TARGET_PROPERTIES(OTBOGRAdapters PROPERTIES ${OTB_LIBRARY_PROPERTIES})
ENDIF(OTB_LIBRARY_PROPERTIES)
IF(NOT OTB_INSTALL_NO_LIBRARIES)
INSTALL(TARGETS OTBOGRAdapters
RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR_CM24} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR_CM24} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR_CM24} COMPONENT Development)
ENDIF(NOT OTB_INSTALL_NO_LIBRARIES)
# Note: no txx allowed here
IF(NOT OTB_INSTALL_NO_DEVELOPMENT)
FILE(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
# FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
# FILE(GLOB __files3 "${CMAKE_CURRENT_BINARY_DIR}/*.h")
# INSTALL(FILES ${__files1} ${__files2} ${__files3}
INSTALL(FILES ${__files1}
DESTINATION ${OTB_INSTALL_INCLUDE_DIR_CM24}/UtilitiesAdapters/OGRAdapters
COMPONENT Development)
ENDIF(NOT OTB_INSTALL_NO_DEVELOPMENT)
/*=========================================================================
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 "otbOGRDataSourceWrapper.h"
// standard includes
#include <cassert>
#include <boost/bind.hpp>
// ITK includes
#include "itkMacro.h" // itkExceptionMacro
#include "itkMetaDataObject.h"
#include "itkExceptionObject.h"
// OTB includes
#include "otbMacro.h"
#include "otbMetaDataKey.h"
#include "otbOGRDriversInit.h"
// OGR includes
#include "ogrsf_frmts.h"
void
otb::ogr::DataSource
::SetProjectionRef(const std::string& projectionRef)
{
itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
itk::EncapsulateMetaData<std::string>(
dict, MetaDataKey::ProjectionRefKey, projectionRef);
this->Modified();
}
std::string
otb::ogr::DataSource
::GetProjectionRef() const
{
const itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
std::string projectionRef;
itk::ExposeMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, projectionRef);
return projectionRef;
}
/*===========================================================================*/
/*=======================[ construction/destruction ]========================*/
/*===========================================================================*/
bool otb::ogr::DataSource::Clear()
{
Reset(0);
return true;
}
void otb::ogr::DataSource::Reset(OGRDataSource * source)
{
if (m_DataSource) {
// OGR makes a pointless check for non-nullity in
// OGRDataSource::DestroyDataSource (pointless because "delete 0" is
// perfectly valid -> it's a no-op)
OGRDataSource::DestroyDataSource(m_DataSource); // void, noexcept
}
m_DataSource = source;
}
otb::ogr::DataSource::DataSource()
: m_DataSource(0)
{
Drivers::Init();
OGRSFDriver * d = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("Memory");
assert(d && "OGR Memory driver not found");
m_DataSource = d->CreateDataSource("in-memory");
if (!m_DataSource) {
itkExceptionMacro(<< "Failed to create OGRMemDataSource");
}
m_DataSource->SetDriver(d);
}
otb::ogr::DataSource::DataSource(OGRDataSource * source)
: m_DataSource(source)
{
}
otb::ogr::DataSource::Pointer
otb::ogr::DataSource::New(std::string const& filename, Modes::type mode)
{
Drivers::Init();
const bool update = mode & Modes::write;
OGRDataSource * source = OGRSFDriverRegistrar::Open(filename.c_str(), update);
if (!source) {
itkGenericExceptionMacro(<< "Failed to open OGRDataSource file " << filename);
}
Pointer res = new DataSource(source);
return res;
}
/*static*/
otb::ogr::DataSource::Pointer
otb::ogr::DataSource::New(OGRDataSource * source)
{
Pointer res = new DataSource(source);
return res;
}
/*virtual*/ otb::ogr::DataSource::~DataSource()
{
Clear();
}
/*===========================================================================*/
/*================================[ layers ]=================================*/
/*===========================================================================*/
OGRLayer& otb::ogr::DataSource::GetLayerChecked(size_t i)
{
const int nb_layers = GetLayersCount();
if (int(i) >= nb_layers)
{
itkExceptionMacro(<< "Cannot fetch " << i << "th layer in the OGRDataSource as it contains only " << nb_layers << "layers.");
}
OGRLayer * layer_ptr = m_DataSource->GetLayer(int(i));
if (!layer_ptr)
{
itkExceptionMacro( << "Unexpected error: cannot fetch " << i << "th layer in the OGRDataSource.");
}
return *layer_ptr;
}
OGRLayer const& otb::ogr::DataSource::GetLayerChecked(size_t i) const
{
return const_cast <DataSource*>(this)->GetLayerChecked(i);
}
OGRLayer* otb::ogr::DataSource::GetLayerUnchecked(size_t i)
{
OGRLayer * layer_ptr = m_DataSource->GetLayer(int(i));
}
int otb::ogr::DataSource::GetLayersCount() const
{
assert(m_DataSource);
return m_DataSource->GetLayerCount();
}
/*===========================================================================*/
/*===============================[ features ]================================*/
/*===========================================================================*/
namespace { // Anonymous namespace
struct AccuLayersSizes
{
AccuLayersSizes(bool doForceComputation)
: m_doForceComputation(doForceComputation) { }
int operator()(OGRLayer& layer, int accumulated) const
{
const int loc_size = layer.GetFeatureCount(m_doForceComputation);
return loc_size < 0 ? loc_size : loc_size+accumulated;
}
private:
bool m_doForceComputation;
};
} // Anonymous namespace
int otb::ogr::DataSource::Size(bool doForceComputation) const
{
return AccumulateOnLayers(AccuLayersSizes(doForceComputation), 0);
}
/*===========================================================================*/
/*=================================[ Misc ]==================================*/
/*===========================================================================*/
/*virtual*/
void otb::ogr::DataSource::PrintSelf(
std::ostream& os, itk::Indent indent) const
{
// ForEachLayer(boost::bind(&OGRLayer::PrintSelf, _1, indent++));
}
/*virtual*/ void otb::ogr::DataSource::Graft(const itk::DataObject * data)
{
assert(! "Disabled to check if it makes sense...");
}
/*=========================================================================
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 __otbOGRDataSourceWrapper_h
#define __otbOGRDataSourceWrapper_h
#include <string>
#include <cassert>
#include "itkVector.h"
#include "itkPoint.h"
#include "itkDataObject.h"
#include "itkMacro.h" // itkNewMacro
#include "itkObjectFactory.h" // that should have been included by itkMacro.h
// class OGRDataSource;
#include "ogrsf_frmts.h" // OGRDataSource
class OGRLayer;
namespace otb { namespace ogr {
/**\ingroup Geometry
* \todo see how mix it with the \c otb::ogr::DataSource wrapper as it was
* with \c VectorData.
*/
template <typename TPrecision>
class ImageReference
{
public:
typedef TPrecision PrecisionType;
enum { Dimension = 2 };
/**\name Standard ITK typedefs */
//@{
//@}
/**\name Template-parameters typedefs */
//@{
typedef itk::Vector<PrecisionType, 2> SpacingType;
typedef itk::Point<PrecisionType, 2> OriginType;
typedef itk::Point<PrecisionType, 2> PointType;
//@}
/** Default constructor.
* @post <tt>m_Spacing = {1,1}</tt>
* @post <tt>m_Origin = {0,0}</tt>
*/
ImageReference()
{
m_Spacing.Fill(1);
m_Origin.Fill(0);
}
/** Init constructor.
* @post <tt>m_Spacing = spacing</tt>
* @post <tt>m_Origin = origin</tt>
*/
ImageReference(SpacingType const& spacing, OriginType const& origin)
: m_Spacing(spacing), m_Origin(origin)
{
}
/**\name Origin property
* Represents the origin of the geometries in the image coordinates system.
*/
//@{
itkGetConstReferenceMacro(Origin, OriginType); //!< Origin getter.
itkSetMacro(Origin, OriginType); //!< Origin setter.
void SetOrigin(const TPrecision origin[Dimension]) //!< Origin setter.
{
const OriginType p(origin);
this->SetOrigin(p);
}
//@}
/**\name Spacing property
* Spacing of the geometries to put in the corresponding image coordinates.
*/
//@{
itkGetConstReferenceMacro(Spacing, SpacingType); //!< Spacing getter.
void SetSpacing(const SpacingType& spacing) //!< Spacing setter.
{
itkDebugMacro("setting Spacing to " << spacing);
if (this->m_Spacing != spacing)
{
this->m_Spacing = spacing;
this->Modified();
}
}
void SetSpacing(const TPrecision spacing[Dimension]) //!< Spacing setter.
{
const SpacingType s(spacing);
this->SetSpacing(s);
}
//@}
/**
* Projects a point from the Data Source coordinates system to the image
* coordinates system.
* \param[in] point point in Data Source coordinates system
* \param[out] physicalPoint point in the image coordinates system.
* \throw None
*/
void TransformPointToPhysicalPoint(const PointType& point, PointType& physicalPoint) const
{
for (size_t i=0; i!=Dimension ; ++i)
physicalPoint[i] = point[i] * m_Spacing[i] + m_Origin[i];
}
/**
* Projects a point from the Data Source coordinates system to the image
* coordinates system.
* \param[in] point point in Data Source coordinates system
* \return the point projected in the image coordinates system.
* \throw None
*/
void TransformPointToPhysicalPoint(const PointType& point) const
{
// why no loop on VDimension ?
PointType physicalPoint;
for (size_t i=0; i!=Dimension ; ++i)
physicalPoint[i] = point[i] * m_Spacing[i] + m_Origin[i];
return physicalPoint;
}
private:
SpacingType m_Spacing;
OriginType m_Origin;
};
/**\ingroup Geometry
* Collection of geometric objects.
*
* This class is meant to supercede \c otb::VectorData class. It provides
* an encapsulation of OGR classes. In that particular case, it's an
* encapsulation of \c OGRDataSource.
*
* @note not meant to be inherited
* @note this class has an entity semantics: \em non-copyable, nor \em
* assignable.
* @note \c OGRRegisterAll() is implicitly called on construction
*/
class DataSource : public itk::DataObject
{
public:
/**\name Standard ITK typedefs */
//@{
typedef DataSource Self;
typedef itk::DataObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
//@}
/**\name Standard macros */
//@{
/** Default builder.
* This builder function creates a new \c DataSource() with its default
* constructor. The actual \c OGRDataSource is using the <em>in-memory</em>
* \c OGRSFDriver: \c OGRMemDriver.
*
* \throw itk::ExceptionObject if the inner \c OGRDataSource cannot be
* opened.
*
* @note \c OGRRegisterAll() is implicitly called on construction
* @see \c DataSource()
*/
itkNewMacro(Self);
itkTypeMacro(Layer, DataObject);
// itkStaticConstMacro(Dimension, unsigned int, VDimension);
//@}
/**\name Creation functions */
//@{
struct Modes { enum type { invalid, read=1, write=2, MAX__ }; };
/**
* Builder from an existing named data source.
* \param[in] filename filename of the data source
* \param[in] mode opening mode (read or read-write)
* \return a newly created \c DataSource.
* \throw itk::ExceptionObject if the inner \c OGRDataSource cannot be
* opened.
* @note \c OGRRegisterAll() is implicitly called on construction
* @see \c DataSource(OGRDataSource *)
*/
static Pointer New(std::string const& filename, Modes::type mode=Modes::read);
/**
* Builder from a built \c OGRDataSource.
* \param[in,out] source \c OGRDataSource already constructed.
* \return a newly created \c DataSource that assumes ownership of \c
* source.
* \throw Nothing
* @note \c OGRRegisterAll() is supposed to have been called before building
* \c source.
* @note no condition is assumed on the non-nullity of \c source.
* @see \c DataSource(OGRDataSource *)
*/
static Pointer New(OGRDataSource * source);
//@}
/**\name Projection Reference property */
//@{
/*virtual*/ void SetProjectionRef(const std::string& projectionRef);
/*virtual*/ std::string GetProjectionRef() const;
//@}
/** Clears the data source.
* @post the \c OGRDataSource owned is destroyed with the dedicated function
* from OGR %API.
* @post <tt>m_DataSource = 0</tt>
*/
/*virtual*/ bool Clear();
/**
* Applies a functor on all layers.
* \param[in] f functor (copied) to execute on each layer.
*
* \throw itk::ExceptionObject in case one layer can't be accessed.
* \throw * whatever the functor \c may throw.
* \note the functor is expected to receive an \c OGRLayer by reference.
* \sa std::for_each
*/
template <class Functor> void ForEachLayer(Functor f)
{
assert(m_DataSource && "OGRDataSource not initialized");
const int nbLayers = this->GetLayersCount();
for (int i=0; i!=nbLayers ; ++i)
{
OGRLayer * l = m_DataSource->GetLayer(i);
if (!l)
{
itkExceptionMacro(<< "Failed to fetch "<< i <<"th layer from OGRDataSource");
}
f(*l);
}
}
/**
* Accumulates the result of a functor on all layers.
* \param[in] f functor (copied) to execute on each layer.
*
* \return the result accumulated (with +)
* \throw itk::ExceptionObject in case one layer can't be accessed.
* \throw * whatever the functor \c may throw.
* \note the functor is expected to receive an \c OGRLayer by reference.
* \sa std::accumulate
*/
template <class Functor, typename V> V AccumulateOnLayers(Functor f, V v0) const
{
assert(m_DataSource && "OGRDataSource not initialized");
const int nbLayers = this->GetLayersCount();
for (int i=0; i!=nbLayers ; ++i)
{
OGRLayer * l = m_DataSource->GetLayer(i);
if (!l)
{
itkExceptionMacro(<< "Failed to fetch "<< i <<"th layer from OGRDataSource");
}
v0 = f(*l, v0);
}
return v0;
}
/** Returns the number of elements in the Data Source.
* \param[in] doForceComputation indicates whether the size shall be
* computed on each layer even so it's expensive to do so.
*
* \return the number of features in the Data Source, -1 if count is unknown
* \throw None
* \sa OGRLayer::GetFeatureCount
*/
int Size(bool doForceComputation) const;
/** Grafts data and information from one data source to another.
* \deprecated \c OGRLayer has an embedded input iterator. As a consequence,
* the layer cannot support multiple access to its elements.
*
* This is a convenience function to setup a second data source with all the
* meta information of another data source and use the same underlying \c
* OGRDataSource.
* \note this function is different than just using two SmartPointers to the
* same data source since separate «DataObjects» are still maintained. This
* function is similar to \c «LayerSource»::GraftOutput().
*/
virtual void Graft(const itk::DataObject *data);
/**
* Resets current data source with the one in parameter.
* \param[in,out] source source \c OGRDataSource that this instance will own.
* \throw None
* @post Assumes ownership of the \c source.
*/
void Reset(OGRDataSource * source);
/**\name Layers access
*@note as the following accessors are not inlined, they aren't optimized.
*/
//@{
/** Returns the number of layers.
*/
int GetLayersCount() const;
/**
* Unchecked Accessor to a given layer.
* \param[in] i index of the layer to access
* \return a reference to the layer requested.
* \pre <tt>i < GetLayersCount()</tt>, an assertion will abort the program
* otherwise.
* \pre the layer must available, an assertion will abort the program
* otherwise.
* \throw None
* @note Use \c GetLayerUnchecked() if invalid indices are programming
* errors, or if null layers are to be expected.
*/
OGRLayer& GetLayer(size_t i)
{
assert(int(i) < GetLayersCount());
OGRLayer * layer_ptr = GetLayerUnchecked(i);
assert(layer_ptr);
return *layer_ptr;
}
/**\copydoc otb::ogr::DataSource::GetLayer()
*/
OGRLayer const& GetLayer(size_t i) const
{
return const_cast <DataSource*>(this)->GetLayer(i);
}
/**
* Checked Accessor to a given layer.
* \param[in] i index of the layer to access
* \return a reference to the layer requested.
* \pre <tt>i < GetLayersCount()</tt>, an exception is raised otherwise.
* \pre the layer must available, an exception is raised otherwise.
* \note Use \c GetLayer() if invalid indices, and null layers, are expected
* to be programming errors.
* \throw None
*/
OGRLayer& GetLayerChecked(size_t i) ;
/**\copydoc otb::ogr::DataSource::GetLayerChecked()
*/
OGRLayer const& GetLayerChecked(size_t i) const ;
//@}
struct boolean{ int i;};
/** Can the data source be used (ie not null).
*
* Hack to provide a boolean operator that is convertible only to a
* boolean expression to be used in \c if tests.
* @see <em>Imperfect C++</em>, Matthew Wilson, Addisson-Welsey, §24.6
*/
operator int boolean ::* () const {
return m_DataSource ? &boolean::i : 0;
}
protected:
/** Default constructor.
* The actual \c OGRDataSource is using the <em>in-memory</em> \c
* OGRSFDriver: \c OGRMemDriver.
* \throw itk::ExceptionObject if the inner \c OGRDataSource cannot be
* opened.
*
* @note \c OGRRegisterAll() is implicitly called on construction
* @see \c DataSource::New()
*/
DataSource();
/** Init constructor.
* @post the newly constructed object owns the \c source parameter.
*/
DataSource(OGRDataSource * source);
/** Destructor.
* @post the \c OGRDataSource owned is released (if not null).
*/
virtual ~DataSource();
/** Prints self into stream. */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
/**
* Internal unchecked accessor to a given layer.
* \param[in] i index of the layer to access
* \return a reference to the layer requested.
* \pre <tt>i < GetLayersCount()</tt>, return 0 otherwise
* \pre the layer must available, 0 is returned otherwise.
* \throw None
* \internal this function is a simple encapsulation of \c
* OGRDataSource::GetLayer().
*/
OGRLayer* GetLayerUnchecked(size_t i);
DataSource(const Self&); //purposely not implemented
DataSource& operator =(const Self&); //purposely not implemented
private:
OGRDataSource *m_DataSource;
// ImageReference m_ImageReference;
}; // end class DataSource
} } // end namespace otb::ogr
#ifndef OTB_MANUAL_INSTANTIATION
// #include "otbOGRDataSourceWrapper.txx"
#endif
#endif // __otbOGRDataSourceWrapper_h
/*=========================================================================
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 "otbOGRDriversInit.h"
#include "ogr_api.h"
/*static*/
otb::ogr::Drivers & otb::ogr::Drivers::Init()
{
static Drivers theInstance;
return theInstance;
}
otb::ogr::Drivers::Drivers()
{
OGRRegisterAll();
}
otb::ogr::Drivers::~Drivers()
{
OGRCleanupAll();
}
/*=========================================================================
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 __otbOGRDriversInit_h
#define __otbOGRDriversInit_h
#include <boost/noncopyable.hpp>
namespace otb { namespace ogr {
/**\ingroup Geometry
* Singleton-like class to provide lazy-registering of all \c OGRDriver's.
*
* Call
* \code
* otb::ogr::Drivers::Init();
* \endcode
* before using classes wrapping OGR.
*
* <p><b>Properties</b><br>
* - Follows Meyer's Singleton design.
* - Implicitly initialized with a default constructor
* - MT-Safe in C++11, and some compilers like GCC (not on old releases of
* VC++)
* - Non-copyable
*/
class Drivers : private boost::noncopyable
{
/** \name Singleton related functions */
//@{
public:
static Drivers & Init() ;
private:
/** Constructor.
* Calls \c OGRRegisterAll().
*/
Drivers();
/** Destructor.
* Calls \c OGRCleanupAll().
*/
~Drivers();
//@}
};
} } // end namespace otb::ogr
#endif // __otbOGRDriversInit_h
/*=========================================================================
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 __otbOGR_h
#define __otbOGR_h
namespace otb {
/**\defgroup Geometry Geometry
* \ingroup Thematic
* Classes and functions aimed toward the manipulation of set of geometric
* objects.
* This module mainly provides an encapsulation of <a
* href="http://www.gdal.org/ogr/">OGR API</a>.
* @{
*/
namespace ogr { }
//@}
} // namespace otb
#include "otbOGRDriversInit.h"
#include "otbOGRDataSourceWrapper.h"
/**\ingroup Geometry
* \file otbOGR.h
* How to include all include files dedicated to OGR encapsulation in OTB...
*/
#endif // __otbOGR_h
IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
ADD_SUBDIRECTORY(OGRAdapters)
SET(UtilitiesAdapters_TESTS1 ${CXX_TEST_PATH}/otbUtilitiesAdaptersTests1)
......
IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
SET(OGR_TESTS ${CXX_TEST_PATH}/otbOGRTests)
SET(OGRCommon_SRC
otbOGRDataSourceWrapperNew.cxx
# otbOGRDataSourceWrapperIO.cxx
)
find_package(Boost COMPONENTS filesystem unit_test_framework)
IF(Boost_FOUND)
MESSAGE(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
MESSAGE(STATUS "Boost_FILESYSTEM_LIBRARY: ${Boost_FILESYSTEM_LIBRARY}")
MESSAGE(STATUS "Boost_UNIT_TEST_FRAMEWORK_LIBRARY: ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}")
# MESSAGE(STATUS "Boost_DATE_TIME_LIBRARY: ${Boost_DATE_TIME_LIBRARY}")
ELSE(Boost_FOUND)
MESSAGE(FATAL_ERROR
"Cannot build OTB/OGR UT without Boost. Please set Boost_DIR.")
ENDIF(Boost_FOUND)
OTB_ADD_EXECUTABLE(otbOGRTests "${OGRCommon_SRC}" "OTBIO;OTBTesting")
# TARGET_LINK_LIBRARIES(otbOGRTests OTBOGRAdapters OTBTesting itkvcl)
TARGET_LINK_LIBRARIES(otbOGRTests OTBOGRAdapters OTBTesting
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
)
# ------------- otb::OGRDataSourceWrapper ----------------------------
ADD_TEST(coTuOGRDataSourceWrapperNew ${OGR_TESTS}
otbOGRDataSourceWrapperNew
)
# ADD_TEST(coTuOGRDataSourceWrapperIO ${OGR_TESTS}
# otbOGRDataSourceWrapperIO
# )
ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
/*=========================================================================
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.
=========================================================================*/
/*===========================================================================*/
/*===============================[ Includes ]================================*/
/*===========================================================================*/
#include "otbOGRDataSourceWrapper.h"
using namespace otb;
/*===========================================================================*/
/*==============================[ other stuff ]==============================*/
/*===========================================================================*/
/*=========================================================================
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.
=========================================================================*/
/*===========================================================================*/
/*===============================[ Includes ]================================*/
/*===========================================================================*/
#include "otbOGRDataSourceWrapper.h"
#include <cstdlib> // EXIT_FAILURE
#include <iostream>
using namespace otb;
/*===========================================================================*/
/*==============================[ other stuff ]==============================*/
/*===========================================================================*/
int otbOGRDataSourceNew (int argc, char **argv)
// int main(int argc, char **argv)
{
if (argc <1)
{
std::cerr << "otbOGRDataSourceNew <shape-file>\n";
return EXIT_FAILURE;
}
ogr::DataSource::Pointer ds = ogr::DataSource::New(argv[1]);
std::cout << "file:\t" << argv[1] << std::endl;
std::cout << "nb layers:\t" << ds->GetLayersCount() << std::endl;
std::cout << "nb features(0):\t" << ds->Size(false) << std::endl;
std::cout << "nb features(1):\t" << ds->Size(true) << std::endl;
return EXIT_SUCCESS;
}
/*=========================================================================
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.
=========================================================================*/
/*===========================================================================*/
/*===============================[ Includes ]================================*/
/*===========================================================================*/
#define BOOST_TEST_MODULE "otb::org::DataSource creation unit testing"
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "otbOGRDataSourceWrapper.h"
using namespace otb;
#if 0
#if defined(BOOST_TEST_DYN_LINK)
#error BOOST_TEST_DYN_LINK defined
#else
#error BOOST_TEST_DYN_LINK not defined
#endif
#if defined(BOOST_TEST_MAIN)
#error BOOST_TEST_MAIN defined
#else
#error BOOST_TEST_MAIN not defined
#endif
#if defined(BOOST_TEST_NO_MAIN)
#error BOOST_TEST_NO_MAIN defined
#else
#error BOOST_TEST_NO_MAIN not defined
#endif
#endif
/*===========================================================================*/
/*==============================[ other stuff ]==============================*/
/*===========================================================================*/
BOOST_AUTO_TEST_CASE(OGRDataSource_new)
{
ogr::DataSource::Pointer ds = ogr::DataSource::New();
BOOST_ASSERT(ds);
BOOST_CHECK_EQUAL(ds->GetLayersCount(), 0);
BOOST_CHECK_EQUAL(ds->Size(false), 0);
BOOST_CHECK_EQUAL(ds->Size(true), 0);
BOOST_CHECK_THROW(ds->GetLayerChecked(0), itk::ExceptionObject);
}
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