Commit 6b3d8240 authored by Luc Hermitte's avatar Luc Hermitte

DOC: OTB-134/OGR -> feature

parent fbe6bd80
......@@ -393,7 +393,7 @@ void otb::ogr::DataSource::PrintSelf(
assert(! "Disabled to check if it makes sense...");
}
bool otb::ogr::DataSource::HasCapability(std::string const& capabilityName)
bool otb::ogr::DataSource::HasCapability(std::string const& capabilityName) const
{
assert(m_DataSource && "Datasource not initialized");
return m_DataSource->TestCapability(capabilityName.c_str());
......
......@@ -50,7 +50,7 @@ otb::ogr::Feature::~Feature()
{
}
otb::ogr::Feature otb::ogr::Feature::clone() const
otb::ogr::Feature otb::ogr::Feature::Clone() const
{
CheckInvariants();
const Feature res(m_Feature->Clone());
......@@ -60,14 +60,22 @@ otb::ogr::Feature otb::ogr::Feature::clone() const
void otb::ogr::Feature::SetFrom(Feature const& rhs, bool mustForgive)
{
CheckInvariants();
m_Feature->SetFrom(&rhs.ogr(), mustForgive);
const OGRErr res = m_Feature->SetFrom(&rhs.ogr(), mustForgive);
if (res != OGRERR_NONE)
{
itkGenericExceptionMacro(<<"Cannot assign from another feature: " << CPLGetLastErrorMsg());
}
}
void otb::ogr::Feature::SetFrom(Feature const& rhs, int * map, bool mustForgive)
{
CheckInvariants();
#if GDAL_VERSION_NUM >= 1900
m_Feature->SetFrom(&rhs.ogr(), map, mustForgive);
const OGRErr res = m_Feature->SetFrom(&rhs.ogr(), map, mustForgive);
if (res != OGRERR_NONE)
{
itkGenericExceptionMacro(<<"Cannot assign from another feature: " << CPLGetLastErrorMsg());
}
#else
itkGenericExceptionMacro("OGRLayer::SetFrom(feature, fieldmap, forgive) is not supported by OGR v"
<< GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.")
......@@ -127,12 +135,7 @@ otb::ogr::Field const otb::ogr::Feature::operator[](size_t index) const
otb::ogr::Field otb::ogr::Feature::operator[](std::string const& name)
{
CheckInvariants();
int index = m_Feature->GetFieldIndex(name.c_str());
if (index < 0)
{
itkGenericExceptionMacro(<<"No field named <"<<name<<"> in feature");
}
const int index = GetFieldIndex(name);
return this->operator[](index);
}
......@@ -148,14 +151,20 @@ otb::ogr::FieldDefn otb::ogr::Feature::GetFieldDefn(size_t index) const
}
otb::ogr::FieldDefn otb::ogr::Feature::GetFieldDefn(std::string const& name) const
{
const int index = GetFieldIndex(name);
return this->GetFieldDefn(index);
}
int otb::ogr::Feature::GetFieldIndex(std::string const& name) const
{
CheckInvariants();
int index = m_Feature->GetFieldIndex(name.c_str());
const int index = m_Feature->GetFieldIndex(name.c_str());
if (index < 0)
{
itkGenericExceptionMacro(<<"No field named <"<<name<<"> in feature");
}
return this->GetFieldDefn(index);
return index;
}
/*===========================================================================*/
......@@ -173,7 +182,7 @@ void otb::ogr::Feature::SetFID(long fid)
const OGRErr res = m_Feature->SetFID(fid);
if (res != OGRERR_NONE)
{
itkGenericExceptionMacro(<<"Cannot Set FID to "<<fid<<" for feature: " << res);
itkGenericExceptionMacro(<<"Cannot Set FID to "<<fid<<" for feature: " << CPLGetLastErrorMsg());
}
}
......@@ -190,8 +199,14 @@ OGRFeatureDefn& otb::ogr::Feature::GetDefn() const
void otb::ogr::Feature::SetGeometryDirectly(UniqueGeometryPtr geometry)
{
CheckInvariants();
OGRGeometry * g = geometry.release();
m_Feature->SetGeometryDirectly(g);
OGRGeometry * g = geometry.get();
const OGRErr res = m_Feature->SetGeometryDirectly(g);
if (res != OGRERR_NONE)
{
itkGenericExceptionMacro(<<"Cannot set (directly) the geometry: " << CPLGetLastErrorMsg());
}
assert(m_Feature->GetGeometryRef() == g);
geometry.release(); // success => commit the transaction (after any exception thrown)
assert(! geometry);
}
......@@ -208,8 +223,11 @@ void otb::ogr::Feature::SetGeometry(OGRGeometry const* geometry)
{
CheckInvariants();
// OGR copies the input geometry => should have been const
m_Feature->SetGeometryDirectly(const_cast <OGRGeometry*>(geometry));
assert(m_Feature->GetGeometryRef() == geometry);
const OGRErr res = m_Feature->SetGeometry(const_cast <OGRGeometry*>(geometry));
if (res != OGRERR_NONE)
{
itkGenericExceptionMacro(<<"Cannot set the geometry: " << CPLGetLastErrorMsg());
}
}
OGRGeometry const* otb::ogr::Feature::GetGeometry() const
......
......@@ -71,6 +71,7 @@ BOOST_STATIC_ASSERT((boost::is_array<int[42]>::value));
BOOST_STATIC_ASSERT(!(boost::is_array<boost::array<int, 42> >::value));
BOOST_STATIC_ASSERT(!(boost::is_array<std::vector<int> >::value));
BOOST_STATIC_ASSERT((boost::is_contiguous<int*>::value));
BOOST_STATIC_ASSERT((boost::is_contiguous<int[42]>::value));
BOOST_STATIC_ASSERT((boost::is_contiguous<boost::array<int, 42> >::value));
BOOST_STATIC_ASSERT((boost::is_contiguous<std::vector<int> >::value));
......
......@@ -26,7 +26,6 @@
#include <boost/mpl/int.hpp>
#include <boost/mpl/at.hpp>
// #include <boost/mpl/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/range/size.hpp>
#include <boost/type_traits/is_same.hpp>
......@@ -37,29 +36,20 @@ class OGRFieldDefn;
#include "ogr_core.h" // OGR enums
#include "itkIndent.h"
#include <cassert>
#include <boost/type_traits/is_array.hpp>
namespace boost {
template <typename Range> struct is_contiguous
{ enum {value = is_array<Range>::value}; };
// todo: other vector params
template <typename T> struct is_contiguous<std::vector<T> >
{ enum {value = true}; };
template <typename T, std::size_t N> class array;
template <typename T, std::size_t N> struct is_contiguous<boost::array<T, N> >
{ enum {value = true}; };
} // boost namespace
// #include "boost/type_traits/is_contiguous.h" // from OTB actually
#include "is_contiguous.h" // from OTB actually
namespace otb { namespace ogr {
/**\ingroup Geometry
* \defgroup GeometryInternals Geometry Internals
* \since OTB v 3.14.0
*/
/**\ingroup GeometryInternals
* Namespace used to host internal meta-prog definitions.
* \since OTB v 3.14.0
*/
namespace metaprog { // namespace metaprog
using namespace boost::mpl;
......@@ -67,6 +57,7 @@ using namespace boost::mpl;
/**\ingroup GeometryInternals
* Associative map of C++ types to OGR field types (\c OGRFieldType).
* \internal Relies on Boost.MPL
* \since OTB v 3.14.0
*/
typedef boost::mpl::map
< pair<int, int_<OFTInteger> >
......@@ -92,6 +83,7 @@ typedef boost::mpl::map
*
* \internal
* This is a hack to pass a member function pointer as template-parameter.
* \since OTB v 3.14.0
*/
template
< typename T
......@@ -116,6 +108,7 @@ template
*
* \internal
* This is a hack to pass a member function pointer as template-parameter.
* \since OTB v 3.14.0
*/
template
< typename T
......@@ -140,6 +133,7 @@ template
*
* \internal
* This is a hack to pass a member function pointer as template-parameter.
* \since OTB v 3.14.0
*/
template
< typename T
......@@ -205,6 +199,7 @@ template
*
* \internal
* This is a hack to pass a member function pointer as template-parameter.
* \since OTB v 3.14.0
*/
template
< typename T
......@@ -228,6 +223,7 @@ template
* Associative map of OGR field types (\c OGRFieldType) to their associated
* getters.
* \internal Relies on Boost.MPL
* \since OTB v 3.14.0
*/
typedef map
< pair<int_<OFTInteger>, MemberGetterPtr<int, &OGRFeature::GetFieldAsInteger> >
......@@ -242,6 +238,7 @@ typedef map
* Associative map of OGR field types (\c OGRFieldType) to their associated
* setters.
* \internal Relies on Boost.MPL
* \since OTB v 3.14.0
*/
typedef map
< pair<int_<OFTInteger>, MemberSetterPtr<int, &OGRFeature::SetField> >
......@@ -261,6 +258,7 @@ typedef map
* \invariant \c m_definition lifetime is of the responsability of the owning \c
* \c OGRFeatureDefn.
* \sa OGRFieldDefn
* \since OTB v 3.14.0
*/
class FieldDefn
{
......@@ -317,12 +315,14 @@ template <> struct FieldDecodingTraitsGetter<std::string>
/*=================================[ Field ]=================================*/
/*===========================================================================*/
class Feature;
/**\ingroup Geometry
* \class Field
* \brief Encapsulation of \c OGRField
* Instances of \c Field are expected to be built from an existing \c Feature
* with which they'll share their owning \c OGRFeature.
* \sa OGRField
* \since OTB v 3.14.0
*/
class Field
{
......
......@@ -31,7 +31,9 @@
/*===========================================================================*/
void otb::ogr::internal::GeometryDeleter::operator()(OGRGeometry* p)
{
OGRGeometryFactory::destroyGeometry (p);
if (p) { // OGR refuses delete 0...
OGRGeometryFactory::destroyGeometry (p);
}
}
/*===========================================================================*/
......
......@@ -30,9 +30,9 @@ using namespace otb;
/**\ingroup Geometry
* \file otbOGRDataSourceWrapperNew.cxx
*
*\todo test: CopyLayer from one datasource to another
*\todo test: read datasource
*\todo test: write datasource
*\todo Test: CopyLayer from one datasource to another
*\todo Test: read datasource
*\todo Test: write datasource
*/
/*===========================================================================*/
......@@ -46,6 +46,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_new_empty)
BOOST_CHECK_EQUAL(ds->GetLayersCount(), 0);
BOOST_CHECK_EQUAL(ds->Size(false), 0);
BOOST_CHECK_EQUAL(ds->Size(true), 0);
BOOST_CHECK_EQUAL(ds->GetLayerChecked(0),otb::ogr::Layer(0));
BOOST_CHECK_THROW(ds->GetLayerChecked(0), itk::ExceptionObject);
}
......
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