23 #include <boost/bind.hpp>
24 #include <boost/make_shared.hpp>
25 #include "ogr_feature.h"
26 #include "cpl_error.h"
35 OGRFeature::CreateFeature(&definition),
36 boost::bind(&OGRFeature::DestroyFeature, _1))
45 m_Feature.reset(feature, boost::bind(&OGRFeature::DestroyFeature, _1));
56 const Feature res(m_Feature->Clone());
62 const OGRErr res = m_Feature->SetFrom(&rhs.
ogr(), mustForgive);
63 if (res != OGRERR_NONE)
65 itkGenericExceptionMacro(<<
"Cannot assign from another feature: " << CPLGetLastErrorMsg());
71 #if GDAL_VERSION_NUM >= 1900
72 const OGRErr res = m_Feature->SetFrom(&rhs.
ogr(), map, mustForgive);
73 if (res != OGRERR_NONE)
75 itkGenericExceptionMacro(<<
"Cannot assign from another feature: " << CPLGetLastErrorMsg());
78 itkGenericExceptionMacro(
"OGRLayer::SetFrom(feature, fieldmap, forgive) is not supported by OGR v"
79 << GDAL_VERSION_NUM <<
". Upgrade to a version >= 1.9.0, and recompile OTB.")
88 const size_t nbFields = m_Feature->GetFieldCount();
90 os <<
" " << nbFields <<
" fields\n";
92 for (
size_t i=0; i!=nbFields; ++i)
94 assert(ogr().GetFieldDefnRef(i) &&
"No definition associated to the i-th field");
95 Field const& field = (*this)[i];
98 OGRGeometry
const* g = GetGeometry();
106 OGRFeature * l =
const_cast<OGRFeature*
>(lhs.
m_Feature.get());
107 OGRFeature * r =
const_cast<OGRFeature*
>(rhs.
m_Feature.get());
111 (l && r && l->Equal(r))
119 return ogr().GetFieldCount();
124 Field field(*
this, index);
130 const int index = GetFieldIndex(name);
131 return this->operator[](index);
136 return FieldDefn(*m_Feature->GetFieldDefnRef(index));
141 const int index = GetFieldIndex(name);
144 itkGenericExceptionMacro(<<
"no field named <"<<name<<
">");
146 return this->GetFieldDefn(index);
151 const int index = m_Feature->GetFieldIndex(name.c_str());
154 itkGenericExceptionMacro(<<
"No field named <"<<name<<
"> in feature");
164 return m_Feature->GetFID();
169 const OGRErr res = m_Feature->SetFID(fid);
170 if (res != OGRERR_NONE)
172 itkGenericExceptionMacro(<<
"Cannot Set FID to "<<fid<<
" for feature: " << CPLGetLastErrorMsg());
178 return *m_Feature->GetDefnRef();
187 OGRGeometry * g = geometry.get();
188 const OGRErr res = m_Feature->SetGeometryDirectly(g);
189 if (res != OGRERR_NONE)
191 itkGenericExceptionMacro(<<
"Cannot set (directly) the geometry: " << CPLGetLastErrorMsg());
198 OGRGeometry * g = m_Feature->StealGeometry();
205 const OGRErr res = m_Feature->SetGeometry(const_cast <OGRGeometry*>(geometry));
206 if (res != OGRERR_NONE)
208 itkGenericExceptionMacro(<<
"Cannot set the geometry: " << CPLGetLastErrorMsg());
214 return m_Feature->GetGeometryRef();