Commit 04412a3b authored by Julien Michel's avatar Julien Michel

ENH: Updating OGRDataSourceWrapper and OGRLayerWrapper to use the new C++ API of GDAL 2.0

parent dcf83b70
......@@ -33,7 +33,7 @@
#include "otbOGRLayerWrapper.h"
class OGRDataSource;
class GDALDataset;
class OGRLayer;
class OGRSpatialReference;
class OGRGeometry;
......@@ -46,7 +46,7 @@ namespace otb { namespace ogr {
*
* 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.
* encapsulation of \c GDALDataset.
*
* \note Not meant to be inherited.
* \note This class has an entity semantics: \em non-copyable, nor \em
......@@ -77,10 +77,10 @@ public:
//@{
/** 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>
* constructor. The actual \c GDALDataset is using the <em>in-memory</em>
* \c OGRSFDriver: \c OGRMemDriver.
*
* \throw itk::ExceptionObject if the inner \c OGRDataSource cannot be
* \throw itk::ExceptionObject if the inner \c GDALDataset cannot be
* opened.
*
* \note \c OGRRegisterAll() is implicitly called on construction.
......@@ -130,24 +130,24 @@ public:
* \param[in] datasourcename OGR identifier 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
* \throw itk::ExceptionObject if the inner \c GDALDataset cannot be
* opened.
* \note \c OGRRegisterAll() is implicitly called on construction
* \see \c DataSource(OGRDataSource *)
* \see \c DataSource(GDALDataset *)
*/
static Pointer New(std::string const& datasourcename, Modes::type mode = Modes::Read);
/**
* Builder from a built \c OGRDataSource.
* \param[in,out] source \c OGRDataSource already constructed.
* Builder from a built \c GDALDataset.
* \param[in,out] source \c GDALDataset 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 *)
* \see \c DataSource(GDALDataset *)
*/
static Pointer New(OGRDataSource * sourcemode, Modes::type mode = Modes::Read);
static Pointer New(GDALDataset * sourcemode, Modes::type mode = Modes::Read);
//@}
/**\name Projection Reference property */
......@@ -159,7 +159,7 @@ public:
//@}
/** Clears the data source.
* \post The \c OGRDataSource owned is destroyed with the dedicated function
* \post The \c GDALDataset owned is destroyed with the dedicated function
* from OGR %API.
* \post <tt>m_DataSource = 0</tt>
*/
......@@ -274,17 +274,17 @@ public:
*
* 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.
* GDALDataset.
*/
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.
* \param[in,out] source source \c GDALDataset that this instance will own.
* \throw None
* \post Assumes ownership of the \c source.
*/
void Reset(OGRDataSource * source);
void Reset(GDALDataset * source);
/**\name Layers modification */
//@{
......@@ -309,7 +309,7 @@ public:
* with \c CreateLayer(), you must use \c DeleteLayer().
* \note The \c papszOptions parameter may later become a \c
* std::vector<std::string>.
* \sa \c OGRDataSource::CreateLayer()
* \sa \c GDALDataset::CreateLayer()
*/
Layer CreateLayer(
std::string const& name,
......@@ -327,7 +327,7 @@ public:
*
* \pre The data source must support the delete operation.
* \pre The index \c i must be in range [0, GetLayersCount()).
* \sa \c OGRDataSource::DeleteLayer()
* \sa \c GDALDataset::DeleteLayer()
*/
void DeleteLayer(size_t i);
......@@ -348,7 +348,7 @@ public:
* with \c CreateLayer(), you must use \c DeleteLayer().
* \note The \c papszOptions parameter may later become a \c
* std::vector<std::string>.
* \sa \c OGRDataSource::CopyLayer()
* \sa \c GDALDataset::CopyLayer()
*/
Layer CopyLayer(
Layer & srcLayer,
......@@ -361,7 +361,7 @@ public:
*/
//@{
/** Returns the number of layers.
* \sa \c OGRDataSource::GetLayersCount()
* \sa \c GDALDataset::GetLayersCount()
*/
int GetLayersCount() const;
......@@ -437,8 +437,8 @@ public:
* neither this wrapping.
* \note The returned \c Layer will be automatically collected on its
* destruction; i.e. unlike OGR API, no need to explicitly call \c
* OGRDataSource::ReleaseResultSet().
* \sa \c OGRDataSource::ExecuteSQL()
* GDALDataset::ReleaseResultSet().
* \sa \c GDALDataset::ExecuteSQL()
*/
Layer ExecuteSQL(
std::string const& statement,
......@@ -461,32 +461,32 @@ public:
/** Flushes all changes to disk.
* \throw itd::ExceptionObject in case the flush operation failed.
* \sa \c OGRDataSource::SyncToDisk()
* \sa \c GDALDataset::SyncToDisk()
*/
void SyncToDisk();
/** Returns whether a capability is avalaible.
* \param[in] capabilityName name of the capability to check.
* \throw None
* \sa \c OGRDataSource::TestCapability()
* \sa \c GDALDataset::TestCapability()
*/
bool HasCapability(std::string const& capabilityName) const;
/** Access to raw \c OGRDataSource.
/** Access to raw \c GDALDataset.
* This function provides an abstraction leak in case deeper control on the
* underlying \c OGRDataSource is required.
* \pre The underlying \c OGRDataSource must be valid, i.e.
* underlying \c GDALDataset is required.
* \pre The underlying \c GDALDataset must be valid, i.e.
* <tt>m_DataSource != 0</tt>, an assertion is fired otherwise.
* \warning You must under no circonstance try to delete the \c OGRDataSource
* \warning You must under no circonstance try to delete the \c GDALDataset
* obtained this way.
*/
OGRDataSource & ogr();
GDALDataset & ogr();
protected:
/** Default constructor.
* The actual \c OGRDataSource is using the <em>in-memory</em> \c
* The actual \c GDALDataset is using the <em>in-memory</em> \c
* OGRSFDriver: \c OGRMemDriver.
* \throw itk::ExceptionObject if the inner \c OGRDataSource cannot be
* \throw itk::ExceptionObject if the inner \c GDALDataset cannot be
* opened.
*
* \note \c OGRRegisterAll() is implicitly called on construction
......@@ -496,9 +496,9 @@ protected:
/** Init constructor.
* \post The newly constructed object owns the \c source parameter.
*/
DataSource(OGRDataSource * source, Modes::type mode);
DataSource(GDALDataset * source, Modes::type mode);
/** Destructor.
* \post The \c OGRDataSource owned is released (if not null).
* \post The \c GDALDataset owned is released (if not null).
*/
virtual ~DataSource();
......@@ -516,7 +516,7 @@ private:
* \pre The layer must available, 0 is returned otherwise.
* \throw None
* \internal this function is a simple encapsulation of \c
* OGRDataSource::GetLayer().
* GDALDataset::GetLayer().
*/
OGRLayer* GetLayerUnchecked(size_t i);
/** @copydoc OGRLayer* otb::ogr::DataSource::GetLayerUnchecked(size_t i)
......@@ -529,8 +529,12 @@ private:
size_t GetLayerID(std::string const& name) const;
int GetLayerIDUnchecked(std::string const& name) const;
/** Return a string containing space separated items retrieved by
the GetFileList() method in GDALDataset (for error reporting) */
std::string GetFileListAsString() const;
private:
OGRDataSource *m_DataSource;
GDALDataset *m_DataSource;
Modes::type m_OpenMode;
int m_FirstModifiableLayerID;
}; // end class DataSource
......
......@@ -38,9 +38,9 @@
// to the compilation mode of the client code.
inline
OGRDataSource & otb::ogr::DataSource::ogr()
GDALDataset & otb::ogr::DataSource::ogr()
{
assert(m_DataSource && "OGRDataSource not initialized");
assert(m_DataSource && "GDALDataset not initialized");
return *m_DataSource;
}
......
......@@ -28,7 +28,7 @@ PURPOSE. See the above copyright notices for more information.
// #include "ogr_core.h" // OGRwkbGeometryType, included from feature -> field
// Forward declarations
class OGRLayer;
class OGRDataSource;
class GDALDataset;
class OGRGeometry;
class OGRFeatureDefn;
......@@ -94,7 +94,7 @@ public:
/**
* Init constructor for layers that need to be released.
* \param layer \c OGRLayer owned by the client code.
* \param sourceInChargeOfLifeTime reference to the actual \c OGRDataSource
* \param sourceInChargeOfLifeTime reference to the actual \c GDALDataset
* that knows how to release the layer.
* \post In this case, \c m_datasource is left null: we suppose (for now, that
* the layer won't need access to the datasource meta-information).
......@@ -105,7 +105,7 @@ public:
* OGRDataSource::ExecuteSQL(). It's actually the constructor called by \c
* DataSource::ExecuteSQL().
*/
Layer(OGRLayer* layer, OGRDataSource& sourceInChargeOfLifeTime, bool modifiable);
Layer(OGRLayer* layer, GDALDataset& sourceInChargeOfLifeTime, bool modifiable);
//@}
/**\name Features collection */
......
......@@ -27,10 +27,10 @@
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#include "ogrsf_frmts.h" // OGRDataSource & OGRLayer
#include "gdal_priv.h"// GDALDataset
#pragma GCC diagnostic pop
#else
#include "ogrsf_frmts.h" // OGRDataSource & OGRLayer
#include "gdal_priv.h" // GDALDataset
#endif
#include "otbOGRDataSourceWrapper.h"
......@@ -60,7 +60,7 @@ otb::ogr::Layer::Layer(OGRLayer* layer, bool modifiable)
{
}
otb::ogr::Layer::Layer(OGRLayer* layer, OGRDataSource& sourceInChargeOfLifeTime, bool modifiable)
otb::ogr::Layer::Layer(OGRLayer* layer, GDALDataset& sourceInChargeOfLifeTime, bool modifiable)
: m_Layer(layer, boost::bind(&OGRDataSource::ReleaseResultSet, boost::ref(sourceInChargeOfLifeTime), _1))
, m_Modifiable(modifiable)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment