diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h index 0a37948fab58167d9426007187279e5468497bd8..03fa62c64affa2493eee88df6621288eae96d9ae 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h @@ -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 diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.txx b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.txx index d9f240e07872467c2eb34c996e016326cbe6a740..b14e3ac4f01e8e212713c94552cc271987308575 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.txx +++ b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.txx @@ -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; } diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h b/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h index 007229fc9ac2224b0ee822afe9250c0c86ad1bc7..da7ed61bd4ef1f89a96a8a45583182aedc71db9a 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h @@ -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 */ diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx index d2be6f3652f70946a75a90cfb77183908f23c247..f0943171d6401fd914afee1714a553f1f903a40b 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx @@ -45,13 +45,15 @@ bool otb::ogr::DataSource::Clear() return true; } -void otb::ogr::DataSource::Reset(OGRDataSource * source) +void otb::ogr::DataSource::Reset(GDALDataset * source) { if (m_DataSource) { // OGR makes a pointless check for non-nullity in - // OGRDataSource::DestroyDataSource (pointless because "delete 0" is + // GDALDataset::DestroyDataSource (pointless because "delete 0" is // perfectly valid -> it's a no-op) - OGRDataSource::DestroyDataSource(m_DataSource); // void, noexcept + // JML: GDALClose is said to be better for windows than calling + // delete operator + GDALClose(m_DataSource); // void, noexcept } m_DataSource = source; } @@ -119,16 +121,15 @@ otb::ogr::DataSource::DataSource() { Drivers::Init(); - OGRSFDriver * d = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("Memory"); + GDALDriver * d = GetGDALDriverManager()->GetDriverByName("Memory"); assert(d && "OGR Memory driver not found"); - m_DataSource = d->CreateDataSource("in-memory"); + m_DataSource = d->Create("in-memory",0,0,0,GDT_Unknown,NULL); if (!m_DataSource) { itkExceptionMacro(<< "Failed to create OGRMemDataSource: " << CPLGetLastErrorMsg()); } - m_DataSource->SetDriver(d); } -otb::ogr::DataSource::DataSource(OGRDataSource * source, Modes::type mode) +otb::ogr::DataSource::DataSource(GDALDataset * source, Modes::type mode) : m_DataSource(source), m_OpenMode(mode), m_FirstModifiableLayerID(0) @@ -140,14 +141,14 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c { bool update = (mode != Modes::Read); - OGRDataSource * source = OGRSFDriverRegistrar::Open(datasourceName.c_str(), update); + GDALDataset * source = (GDALDataset *)GDALOpen(datasourceName.c_str(), (update?GA_Update:GA_ReadOnly)); if (!source) { // In read mode, this is a failure // In write mode (Overwrite and Update), create the data source transparently if (mode == Modes::Read) { - itkGenericExceptionMacro(<< "Failed to open OGRDataSource file " + itkGenericExceptionMacro(<< "Failed to open GDALDataset file " << datasourceName<<" : " << CPLGetLastErrorMsg()); } @@ -159,19 +160,18 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c <<datasourceName<<">."); } - OGRSFDriver * d = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driverName); + GDALDriver * d = GetGDALDriverManager()->GetDriverByName(driverName); if(!d) { itkGenericExceptionMacro(<<"Could not create OGR driver "<<driverName<<", check your OGR configuration for available drivers."); } - source = d->CreateDataSource(datasourceName.c_str()); + source = d->Create(datasourceName.c_str(),0,0,0,GDT_Unknown,NULL); if (!source) { - itkGenericExceptionMacro(<< "Failed to create OGRDataSource <"<<datasourceName + itkGenericExceptionMacro(<< "Failed to create GDALDataset <"<<datasourceName <<"> (driver name: <" << driverName<<">: " << CPLGetLastErrorMsg()); } - source->SetDriver(d); } return otb::ogr::DataSource::New(source, mode); } @@ -179,27 +179,30 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c void DeleteDataSource(std::string const& datasourceName) { // Attempt to delete the datasource if it already exists - OGRDataSource * poDS = OGRSFDriverRegistrar::Open(datasourceName.c_str(), TRUE); + GDALDataset * poDS = (GDALDataset *)GDALOpen(datasourceName.c_str(), GA_Update); if (poDS != NULL) { - OGRSFDriver * ogrDriver = poDS->GetDriver(); - OGRDataSource::DestroyDataSource(poDS); + GDALDriver * ogrDriver = poDS->GetDriver(); + //Erase the data if possible - if (ogrDriver->TestCapability(ODrCDeleteDataSource)) + if (poDS->TestCapability(ODrCDeleteDataSource)) { //Delete datasource - OGRErr ret = ogrDriver->DeleteDataSource(datasourceName.c_str()); + OGRErr ret = ogrDriver->Delete(datasourceName.c_str()); if (ret != OGRERR_NONE) { + GDALClose(poDS); itkGenericExceptionMacro(<< "Deletion of data source " << datasourceName << " failed: " << CPLGetLastErrorMsg()); } } else { + GDALClose(poDS); itkGenericExceptionMacro(<< "Cannot delete data source " << datasourceName); } + GDALClose(poDS); } // if (poDS != NULL) } @@ -223,7 +226,7 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode) /*static*/ otb::ogr::DataSource::Pointer -otb::ogr::DataSource::New(OGRDataSource * source, Modes::type mode) +otb::ogr::DataSource::New(GDALDataset * source, Modes::type mode) { Pointer res = new DataSource(source, mode); res->UnRegister(); @@ -271,7 +274,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer( if (m_OpenMode == Modes::Read) { otb::ogr::Layer l = GetLayerChecked(name); // will throw if not existing - itkGenericOutputMacro(<< "Requesting layer creation in read-only OGRDataSource. Returning the existing layer"); + itkGenericOutputMacro(<< "Requesting layer creation in read-only GDALDataset. Returning the existing layer"); return l; } @@ -294,7 +297,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer( if (!ol) { itkGenericExceptionMacro(<< "Failed to create the layer <"<<name - << "> in the OGRDataSource file <" << m_DataSource->GetName() + << "> in the GDALDataset file <" << GetFileListAsString() <<">: " << CPLGetLastErrorMsg()); } @@ -315,9 +318,9 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer( OGRLayer * ol = m_DataSource->CreateLayer( name.c_str(), poSpatialRef, eGType, otb::ogr::StringListConverter(papszOptions).to_ogr()); if (!ol) - { + { itkGenericExceptionMacro(<< "Failed to create the layer <"<<name - << "> in the OGRDataSource file <" << m_DataSource->GetName() + << "> in the GDALDataset file <" << GetFileListAsString() <<">: " << CPLGetLastErrorMsg()); } @@ -329,7 +332,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer( case Modes::Update_LayerCreateOnly: { // The layer exists. Returns it - // It will be non-modifiable if already existing at OGRDataSource creation time + // It will be non-modifiable if already existing at GDALDataset creation time if (layer) { return layer; @@ -340,8 +343,9 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer( name.c_str(), poSpatialRef, eGType, otb::ogr::StringListConverter(papszOptions).to_ogr()); if (!ol) { + itkGenericExceptionMacro(<< "Failed to create the layer <"<<name - << "> in the OGRDataSource file <" << m_DataSource->GetName() + << "> in the GDALDataset file <" << GetFileListAsString() <<">: " << CPLGetLastErrorMsg()); } @@ -351,11 +355,11 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer( break; default : assert(false && "Should never be there"); - itkGenericExceptionMacro(<< "OGRDataSource opening mode not supported"); + itkGenericExceptionMacro(<< "GDALDataset opening mode not supported"); break; } - itkGenericExceptionMacro(<< "OGRDataSource opening mode not supported"); + itkGenericExceptionMacro(<< "GDALDataset opening mode not supported"); return Layer(0, false); // keep compiler happy } @@ -369,11 +373,11 @@ otb::ogr::Layer otb::ogr::DataSource::CopyLayer( switch (m_OpenMode) { case Modes::Invalid: - assert(false && "Invalid OGRDataSource opening mode"); - itkGenericExceptionMacro(<< "Invalid OGRDataSource opening mode"); + assert(false && "Invalid GDALDataset opening mode"); + itkGenericExceptionMacro(<< "Invalid GDALDataset opening mode"); break; case Modes::Read: - itkGenericExceptionMacro(<< "OGRDataSource is opened in Read mode : cannot create a layer"); + itkGenericExceptionMacro(<< "GDALDataset is opened in Read mode : cannot create a layer"); break; default: break; @@ -382,10 +386,10 @@ otb::ogr::Layer otb::ogr::DataSource::CopyLayer( OGRLayer * l0 = &srcLayer.ogr(); OGRLayer * ol = m_DataSource->CopyLayer(l0, newName.c_str(), papszOptions); if (!ol) - { + { itkGenericExceptionMacro(<< "Failed to copy the layer <" << srcLayer.GetName() << "> into the new layer <" <<newName - << "> in the OGRDataSource file <" << m_DataSource->GetName() + << "> in the GDALDataset file <" << GetFileListAsString() <<">: " << CPLGetLastErrorMsg()); } const bool modifiable = true; @@ -400,14 +404,14 @@ void otb::ogr::DataSource::DeleteLayer(size_t i) switch (m_OpenMode) { case Modes::Invalid: - assert(false && "Invalid OGRDataSource opening mode"); - itkGenericExceptionMacro(<< "Invalid OGRDataSource opening mode"); + assert(false && "Invalid GDALDataset opening mode"); + itkGenericExceptionMacro(<< "Invalid GDALDataset opening mode"); break; case Modes::Read: - itkGenericExceptionMacro(<< "OGRDataSource is opened in Read mode : cannot delete a layer"); + itkGenericExceptionMacro(<< "GDALDataset is opened in Read mode : cannot delete a layer"); break; case Modes::Update_LayerCreateOnly: - itkGenericExceptionMacro(<< "OGRDataSource is opened in Update_LayerCreateOnly mode : cannot delete a layer"); + itkGenericExceptionMacro(<< "GDALDataset is opened in Update_LayerCreateOnly mode : cannot delete a layer"); break; default: break; @@ -416,14 +420,16 @@ void otb::ogr::DataSource::DeleteLayer(size_t i) const int nb_layers = GetLayersCount(); if (int(i) >= nb_layers) { - itkExceptionMacro(<< "Cannot delete " << i << "th layer in the OGRDataSource <" - << m_DataSource->GetName() << "> as it contains only " << nb_layers << "layers."); + + itkExceptionMacro(<< "Cannot delete " << i << "th layer in the GDALDataset <" + << GetFileListAsString() << "> as it contains only " << nb_layers << "layers."); } const OGRErr err = m_DataSource->DeleteLayer(int(i)); if (err != OGRERR_NONE) { - itkExceptionMacro(<< "Cannot delete " << i << "th layer in the OGRDataSource <" - << m_DataSource->GetName() << ">: " << CPLGetLastErrorMsg()); + + itkExceptionMacro(<< "Cannot delete " << i << "th layer in the GDALDataset <" + << GetFileListAsString() << ">: " << CPLGetLastErrorMsg()); } } @@ -480,7 +486,7 @@ size_t otb::ogr::DataSource::GetLayerID(std::string const& name) const if (id < 0) { itkExceptionMacro( << "Cannot fetch any layer named <" << name - << "> in the OGRDataSource <" << m_DataSource->GetName() << ">: " + << "> in the GDALDataset <" << GetFileListAsString() << ">: " << CPLGetLastErrorMsg()); } return 0; // keep compiler happy @@ -492,14 +498,14 @@ otb::ogr::Layer 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 <" - << m_DataSource->GetName() << "> as it contains only " << nb_layers << "layers."); + itkExceptionMacro(<< "Cannot fetch " << i << "th layer in the GDALDataset <" + << GetFileListAsString() << "> 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 <" - << m_DataSource->GetName() << ">: " << CPLGetLastErrorMsg()); + itkExceptionMacro( << "Unexpected error: cannot fetch " << i << "th layer in the GDALDataset <" + << GetFileListAsString() << ">: " << CPLGetLastErrorMsg()); } return otb::ogr::Layer(layer_ptr, IsLayerModifiable(i)); } @@ -525,7 +531,7 @@ otb::ogr::Layer otb::ogr::DataSource::GetLayerChecked(std::string const& name) if (!layer_ptr) { itkExceptionMacro( << "Cannot fetch any layer named <" << name - << "> in the OGRDataSource <" << m_DataSource->GetName() << ">: " + << "> in the GDALDataset <" << GetFileListAsString() << ">: " << CPLGetLastErrorMsg()); } return otb::ogr::Layer(layer_ptr, IsLayerModifiable(name)); @@ -550,10 +556,10 @@ otb::ogr::Layer otb::ogr::DataSource::ExecuteSQL( { #if defined(PREFER_EXCEPTION) itkExceptionMacro( << "Unexpected error: cannot execute the SQL request <" << statement - << "> in the OGRDataSource <" << m_DataSource->GetName() << ">: " << CPLGetLastErrorMsg()); + << "> in the GDALDataset <" << GetFileListAsString() << ">: " << CPLGetLastErrorMsg()); #else // Cannot use the deleter made for result sets obtained from - // OGRDataSource::ExecuteSQL because it checks for non-nullity.... + // GDALDataset::ExecuteSQL because it checks for non-nullity.... // *sigh* return otb::ogr::Layer(0, modifiable); #endif @@ -699,10 +705,24 @@ bool otb::ogr::DataSource::HasCapability(std::string const& capabilityName) cons void otb::ogr::DataSource::SyncToDisk() { assert(m_DataSource && "Datasource not initialized"); - const OGRErr res= m_DataSource->SyncToDisk(); - if (res != OGRERR_NONE) + m_DataSource->FlushCache(); +} + +std::string otb::ogr::DataSource::GetFileListAsString() const +{ + char ** files = m_DataSource->GetFileList(); + + std::string files_str=""; + + if(files) { - itkExceptionMacro( << "Cannot flush the pending of the OGRDataSource <" - << m_DataSource->GetName() << ">: " << CPLGetLastErrorMsg()); + unsigned int i = 0; + while(files[i]!=NULL) + { + files_str+=std::string(files[i])+" "; + ++i; + } + CSLDestroy(files); } + return files_str; } diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx index 6942ef41a8b4f1916fd99592736d58468a4511f2..777bfa518e6f6b00a7433ac2df31cfd2603bc231 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx @@ -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) {