diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx index ab798e9f6646e869a1a7b5d503cb3dc655d37129..9d2697c8ad582dd58e656d98f9ec809b9e10645c 100644 --- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx +++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.cxx @@ -100,18 +100,30 @@ otb::ogr::Layer::const_iterator otb::ogr::Layer::cstart(size_t index) const void otb::ogr::Layer::CreateFeature(Feature feature) { assert(m_Layer && "OGRLayer not initialized"); - m_Layer->CreateFeature(&feature.ogr()); + const OGRErr res = m_Layer->CreateFeature(&feature.ogr()); + if (res != OGRERR_NONE) + { + itkGenericExceptionMacro(<< "Cannot create a new feature in the layer <"<<GetName()<<">:" << CPLGetLastErrorMsg()); + } } void otb::ogr::Layer::DeleteFeature(long nFID) { assert(m_Layer && "OGRLayer not initialized"); - m_Layer->DeleteFeature(nFID); + const OGRErr res = m_Layer->DeleteFeature(nFID); + if (res != OGRERR_NONE) + { + itkGenericExceptionMacro(<< "Cannot delete the feature <"<<nFID<<"> in the layer <"<<GetName()<<">:" << CPLGetLastErrorMsg()); + } } otb::ogr::Feature otb::ogr::Layer::GetFeature(long nFID) { assert(m_Layer && "OGRLayer not initialized"); + if (nFID == OGRNullFID) + { + itkGenericExceptionMacro(<< "Invalid feature null id GetFeature() in the layer <"<<GetName()<<">."); + } const Feature feat = m_Layer->GetFeature(nFID); return feat; } @@ -119,7 +131,11 @@ otb::ogr::Feature otb::ogr::Layer::GetFeature(long nFID) void otb::ogr::Layer::SetFeature(Feature feature) { assert(m_Layer && "OGRLayer not initialized"); - m_Layer->SetFeature(&feature.ogr()); + const OGRErr res = m_Layer->SetFeature(&feature.ogr()); + if (res != OGRERR_NONE) + { + itkGenericExceptionMacro(<< "Cannot update a feature in the layer <"<<GetName()<<">:" << CPLGetLastErrorMsg()); + } } /*===========================================================================*/ @@ -206,7 +222,7 @@ void otb::ogr::Layer::CreateField( const OGRErr res = m_Layer->CreateField(const_cast <OGRFieldDefn*>(&field), bApproxOK); if (res != OGRERR_NONE) { - itkGenericExceptionMacro(<< "Cannot create a new field in the layer <"<<GetName()<<">."); + itkGenericExceptionMacro(<< "Cannot create a field in the layer <"<<GetName()<<">:" << CPLGetLastErrorMsg()); } } diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h index 7a8d4be67fef5ca5a59238d2437abd9be8be98c4..25682b90609a58868965822d899bb38a08718539 100644 --- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h +++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRLayerWrapper.h @@ -20,14 +20,14 @@ PURPOSE. See the above copyright notices for more information. // #include <iosfwd> // std::ostream& #include <boost/shared_ptr.hpp> -// #include <boost/iterator/iterator_adaptor.hpp> #include <boost/iterator/iterator_facade.hpp> #include <boost/utility/enable_if.hpp> #include "itkIndent.h" #include "otbOGRFeatureWrapper.h" #include "ogr_core.h" // OGRwkbGeometryType -class OGRLayer; // fwd declarations +// Forward declarations +class OGRLayer; class OGRDataSource; class OGRGeometry; class OGRFeatureDefn; @@ -55,18 +55,9 @@ class Layer // : public itk::DataObject { public: - /**\name Standard class typedefs */ + /**\name ITK class typedefs */ //@{ typedef Layer Self; - // typedef itk::DataObject Superclass; - // typedef itk::SmartPointer<Self> Pointer; - // typedef itk::SmartPointer<const Self> ConstPointer; - //@} - - /**\name Standard macros */ - //@{ - // itkNewMacro(Self); - // itkTypeMacro(Layer, DataObject); //@} /**\name Construction */ @@ -87,9 +78,64 @@ public: */ int GetFeatureCount(bool doForceComputation) const; + /** + * Adds a pre-existing \c Feature to the layer. + * \param[in,out] feature feature to add. Upon successful completion, the feature + * id will be updated (unless it was previously set) + * + * \throw itk::ExceptionObject if the feature can't be added. + * \sa OGRLayer::CreateFeature + * \internal + * Whilst the \c Feature id is updated, it is not the same feature than the + * one stored in the layer. In other words, \c Feature is still in charge of + * the actual \c OGRFeature (in case it was), and the feature added is of the + * responsibility of the layer. + */ void CreateFeature(Feature feature); + + /** + * Removes a feature identified by its id from the \c Layer. + * \param[in] nFID feature id. + * + * \throw itk::ExceptionObject if the feature can't be added. + * \warning calls to this function will invalidate any feature iterator + * previously obtained. + * \sa OGRFeature::DeleteFeature + */ void DeleteFeature(long nFID); + + /** + * Finds a feature from its id. + * \param[in] nFID feature id. + * + * \return a RAII capsule around the \c OGRFeature stored in the layer and + * that matches the requested id. + * \throw itk::ExceptionObject if nFID is null + * + * \pre \c nFID value cannot be \c OGRNullFID + * \post result's \c GetFID() equals \c nFID + * \warning calls to this function will invalidate any feature iterator + * previously obtained. + * \sa OGRFeature::GetFeature + * \internal + * The feature obtained is owned by the \c Feature instance. + */ Feature GetFeature(long nFID); + + /** + * Changes a \c Feature in the Layer. + * \param[in,out] feature feature to set. Upon successful completion, the feature + * id will be updated (in case it was previously set) + * + * \throw itk::ExceptionObject if the feauture can't be set. + * \pre the Layer need to support <em>OLCRandomWrite</em> capability. + * \sa OGRLayer::SetFeature + * \internal + * Whilst the \c Feature id is updated, it is not the same feature than the + * one stored in the layer. In other words, \c Feature is still in charge of + * the actual \c OGRFeature (in case it was), and the feature added is of the + * responsibility of the layer. + */ void SetFeature(Feature feature); //@}