otbOGRLayerWrapper.h 19.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20

21 22
#ifndef otbOGRLayerWrapper_h
#define otbOGRLayerWrapper_h
23 24

// #include <iosfwd> // std::ostream&
25 26 27
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
28
#include <boost/shared_ptr.hpp>
29 30
#include <boost/iterator/iterator_facade.hpp>
#include <boost/utility/enable_if.hpp>
31 32 33 34 35 36
#pragma GCC diagnostic pop
#else
#include <boost/shared_ptr.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/utility/enable_if.hpp>
#endif
37
// #include "itkIndent.h", included from field
38
#include "otbOGRFeatureWrapper.h"
39
#include "otbOGRVersionProxy.h"
40
#include <string>
41

42
// #include "ogr_core.h" // OGRwkbGeometryType, included from feature -> field
Luc Hermitte's avatar
Luc Hermitte committed
43 44
// Forward declarations
class OGRLayer;
45
class OGRGeometry;
46
class OGRFeatureDefn;
47

48 49
namespace otb { namespace ogr {
class DataSource;
50 51
class Layer;

52 53 54 55
/**\ingroup gGeometry
 * Compares layers identities.
 * \return whether the two layers are in fact the same.
 */
56
 OTBGdalAdapters_EXPORT
57 58
bool operator==(Layer const& lhs, Layer const& rhs);

59
/**\ingroup gGeometry
60 61
 * \class Layer
 * \brief %Layer of geometric objets.
62 63 64 65
 *
 * It provides an encapsulation of OGR classes. In that particular case, it's an
 * encapsulation of \c OGRLayer.
 *
66 67
 * \note This class is a proxy class on top of an \c OGRLayer.
 * \note It can be copied, and assigned. New instances will share the underlying
Luc Hermitte's avatar
Luc Hermitte committed
68
 * \c OGRLayer.
69
 * \note When created from a \c otb::ogr::DataSource::ExecuteSQL(), it will
70
 * automatically manage the release of the underlying \c OGRLayer.
71 72
 * \note The default constructor is disabled on purpose.
 * \note The destructor automatically generated does everything that is
73 74
 * expected.
 *
75 76
 * \todo Find a way to be notified when the related \c OGRDataSource is released
 * \since OTB v 3.14.0
77 78
 *
 * \ingroup OTBGdalAdapters
79
 */
80
class OTBGdalAdapters_EXPORT Layer
81 82
  {
public:
83
  /**\name ITK standard definitions */
84 85
  //@{
  typedef Layer                         Self;
OTB Bot's avatar
OTB Bot committed
86
  const char *GetNameOfClass() const {return "Layer"; }
87 88
  //@}

89
#if 0
90
  typedef itk::SmartPointer<DataSource> DataSourcePtr;
91
#endif
92

93 94
  /**\name Construction */
  //@{
Luc Hermitte's avatar
Luc Hermitte committed
95 96 97
  /**
   * Init constructor with a layer owned by a DataSource.
   * \param layer \c OGRLayer instance that is owned by a DataSource.
98
   * \param datasource Pointer to the actual data source.
Luc Hermitte's avatar
Luc Hermitte committed
99 100 101
   * \throw None
   * On destruction of the proxy class, the internal \c OGRLayer is left alone.
   *
102
   * \warning If the datasource hosting the layer (built with this constructor)
103
   * is deleted, the layer won't be usable anymore. Unfortunately, there is no
Luc Hermitte's avatar
Luc Hermitte committed
104 105
   * mean to report this to this layer proxy.
   */
106
  Layer(OGRLayer* layer, bool modifiable);
Luc Hermitte's avatar
Luc Hermitte committed
107 108 109 110

  /**
   * Init constructor for layers that need to be released.
   * \param layer  \c OGRLayer owned by the client code.
111
   * \param sourceInChargeOfLifeTime  reference to the actual \c GDALDataset
Luc Hermitte's avatar
Luc Hermitte committed
112
   * that knows how to release the layer.
113 114
   * \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).
Luc Hermitte's avatar
Luc Hermitte committed
115 116 117 118 119 120 121
   *
   * \throw None
   * \internal
   * This constructor is meant to be used for wrapping layers coming from \c
   * OGRDataSource::ExecuteSQL(). It's actually the constructor called by \c
   * DataSource::ExecuteSQL().
   */
122
    Layer(OGRLayer* layer, GDALDataset& sourceInChargeOfLifeTime, bool modifiable);
123
  //@}
124 125 126

  /**\name Features collection */
  //@{
127 128 129 130 131 132
  /** Returns the number of elements in the layer.
   * \param[in] doForceCompuation  indicates whether the size shall be computed
   * even so it's expensive to do so.
   *
   * \return the number of features in the layer, -1 if count is unknown
   * \throw None
133
   * \sa \c OGRLayer::GetFeatureCount()
134 135 136
   */
  int GetFeatureCount(bool doForceComputation) const;

Luc Hermitte's avatar
Luc Hermitte committed
137 138 139 140 141 142
  /**
   * 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.
143
   * \sa \c OGRLayer::CreateFeature()
Luc Hermitte's avatar
Luc Hermitte committed
144 145 146 147 148 149
   * \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.
   */
150
  void CreateFeature(Feature feature);
Luc Hermitte's avatar
Luc Hermitte committed
151 152 153 154 155 156

  /**
   * 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.
157
   * \warning Calls to this function will invalidate any feature iterator
Luc Hermitte's avatar
Luc Hermitte committed
158
   * previously obtained.
159
   * \sa \c OGRFeature::DeleteFeature()
Luc Hermitte's avatar
Luc Hermitte committed
160
   */
161
  void DeleteFeature(long nFID);
Luc Hermitte's avatar
Luc Hermitte committed
162 163 164 165 166 167 168 169 170 171

  /**
   * 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
172 173
   * \post Result's \c GetFID() equals \c nFID
   * \warning Calls to this function will invalidate any feature iterator
Luc Hermitte's avatar
Luc Hermitte committed
174
   * previously obtained.
175
   * \sa \c OGRFeature::GetFeature()
Luc Hermitte's avatar
Luc Hermitte committed
176 177 178
   * \internal
   * The feature obtained is owned by the \c Feature instance.
   */
179
  Feature GetFeature(long nFID);
Luc Hermitte's avatar
Luc Hermitte committed
180 181 182 183 184 185

  /**
   * 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)
   *
Luc Hermitte's avatar
Luc Hermitte committed
186
   * \throw itk::ExceptionObject if the feature can't be set.
Luc Hermitte's avatar
Luc Hermitte committed
187
   * \pre The Layer needs to support <em>OLCRandomWrite</em> capability.
188
   * \sa \c OGRLayer::SetFeature()
189 190
   * \warning Calls to this function may invalidate any feature iterator
   * previously obtained depending on the actual \c OGRDriver.
Luc Hermitte's avatar
Luc Hermitte committed
191 192 193 194 195 196
   * \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.
   */
197 198 199 200 201
  void SetFeature(Feature feature);
  //@}

  /** Returns the name given to the layer, if any.
  */
202 203
  std::string GetName() const;

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
  /** Retrieves the extent of the layer.
   *  \param[in] force Force computation of the extent if not available. May
   *  force the driver to walk all geometries to compute the extent.
   *  \return the extent of the layer
   *  \throw itk::ExceptionObject if the extent can not be retrieved.
  */
  OGREnvelope GetExtent(bool force = false) const;

  /** Retrieves the extent of the layer.
   *  \param[out] ulx reference to upper-left x coordinate of the extent
   *  \param[out] uly reference to upper-left y coordinate of the extent
   *  \param[out] lrx reference to lower-right x coordinate of the extent
   *  \param[out] uly reference to lower-right y coordinate of the extent
   *  \param[in] force Force computation of the extent if not available. May
   *  force the driver to walk all geometries to compute the extent.
219
   *  \throw itk::ExceptionObject if the extent can not be retrieved.
OTB Bot's avatar
OTB Bot committed
220
  */
221 222
  void GetExtent(double & ulx, double & uly, double & lrx, double & lry, bool force = false) const;

223 224 225 226
  /** Prints self into stream. */
  void PrintSelf(std::ostream& os, itk::Indent indent) const;


227 228
  /**\copydoc operator int boolean ::* () const
  */
OTB Bot's avatar
OTB Bot committed
229
  struct boolean{ int i; };
230
  /** Can the layer be used (ie not null).
OTB Bot's avatar
OTB Bot committed
231
   *
232 233 234 235
   * Hack to provide a boolean operator that is convertible only to a
   * boolean expression to be used in \c if tests.
   * @see <em>Imperfect C++</em>, Matthew Wilson, Addisson-Welsey, par 24.6
   */
236 237
  operator int boolean ::* () const
    {
238
    return m_Layer ? &boolean::i : nullptr;
239
    }
240 241 242 243

  /** Access to raw \c OGRLayer.
   * This function provides an abstraction leak in case deeper control on the
   * underlying \c OGRLayer is required.
244
   * \pre The underlying \c OGRLayer must be valid, i.e.
245
   * <tt>m_Layer != 0</tt>, an assertion is fired otherwise.
246
   * \warning You must under no circumstance try to delete the \c OGRLayer
247 248 249 250
   * obtained this way.
   */
  OGRLayer & ogr();

251
  /**\name Spatial filter property
252
   * \todo We'll see later if a Geometry capsule is defined, or a
253
   * \c nondeletable<> pointer type.
Luc Hermitte's avatar
Luc Hermitte committed
254 255 256
   * \internal
   * The I/O geometry is an undeletable pointer, that may be null (hence the
   * need of pointers instead of references).
257 258
   */
  //@{
Luc Hermitte's avatar
Luc Hermitte committed
259 260 261 262 263 264 265
  /**
   * Returns a reference to the current spatial filter, if any.
   *
   * \return a reference to the current spatial filter. Spatial filter that isn't
   * supposed to be modified this way. Use \c SetSpatialFilter or \c
   * SetSpatialFilterRect for this purpose.
   * \throw None
266
   * \sa \c OGRLayer::GetSpatialFilter()
Luc Hermitte's avatar
Luc Hermitte committed
267 268 269 270 271 272
   */
  OGRGeometry const* GetSpatialFilter() const;

  /**
   * Sets the current spatial filter.
   * Replaces the current spatial filter with a clone of the one passed as
273
   * parameter. Thus the parameter remains of the responsibility of the caller.
Luc Hermitte's avatar
Luc Hermitte committed
274 275 276
   *
   * The spatial filter is used to filter the \c Feature's obtained when iterating
   * on the layer.
277 278 279
   * \param[in] spatialFilter  new spatial filter definition, NULL clears the
   * filter.
   * \throw None
Luc Hermitte's avatar
Luc Hermitte committed
280 281
   * \note OGR warns us that the test may be incorrectly implemented, and that
   * we may have false-positives, but no missed shapes.
282
   * \sa \c OGRLayer::SetSpatialFilter()
Luc Hermitte's avatar
Luc Hermitte committed
283 284 285 286 287 288 289
   */
  void SetSpatialFilter(OGRGeometry const* spatialFilter);
  /** Sets a new rectangular spatial filter.
   * Defines the new filter as a rectangular shape.
   *
   * The coordinates used shall be in the same referential as the layer as the
   * whole (as returned by \c GetSpatialRef()).
290
   * \sa \c OGRLayer::SetSpatialFilterRect()
Luc Hermitte's avatar
Luc Hermitte committed
291
   */
292 293 294
  void SetSpatialFilterRect(double dfMinX, double dfMinY, double dfMaxX, double dfMaxY);
  //@}

295 296 297
  /** Spatial Reference property.
   * \note Read-only property. In order to set this property, you'll have to
   * create a new layer with a spatial reference.
298 299 300
   * \internal the I/O spatial reference is an undeletable pointer, that may be null.
   */
  OGRSpatialReference const* GetSpatialRef() const;
301

302
  /** Returns the projection ref associated with the layer.
303 304 305 306
   * \return The projection ref (wkt string) associated with the layer
   */
  std::string GetProjectionRef() const;

307 308
  /**\name Iteration */
  //@{
309
  /**\ingroup gGeometry
310
   * \class feature_iter
311
   * \brief Implementation class for \c Feature iterator.
Luc Hermitte's avatar
Luc Hermitte committed
312 313
   * This iterator is a single <em>pass iterator</em>. We may fetch the \c
   * Feature referenced by an iterator previously stored, but never resume the
314
   * iteration after a call to \c Layer::begin(), \c Layer::start_at(), \c
Luc Hermitte's avatar
Luc Hermitte committed
315 316 317 318 319 320 321
   * Layer::CreateFeature(), \c Layer::DeleteFeature(), \c Layer::GetFeature(),
   * \c Layer::SetFeature(), nor fork the iteration.
   * \code
   * iterator b = begin();
   * iterator i = std::advance(b, 1);
   * b++; // this is invalid
   * \endcode
322
   * \internal
323 324
   * \sa \c otb::ogr::Layer::iterator
   * \sa \c otb::ogr::Layer::const_iterator
325 326 327 328
   * \note Naming policy is compliant with C++ standard as the iterator
   * functions are as well. This will permit transparent integration with all
   * standard and boost algorithms, and C++11 <em>for-range loops</em> for
   * instance.
329
   * \see http://www.boost.org/doc/libs/1_49_0/libs/iterator/doc/iterator_facade.html#tutorial-example
330
   * \since OTB v 3.14.0
331 332
 *
 * \ingroup OTBGdalAdapters
333
   */
334 335 336 337 338 339
  template <class Value> class feature_iter
    : public boost::iterator_facade<feature_iter<Value>, Value, boost::single_pass_traversal_tag>
    {
    struct enabler {};
  public:
    feature_iter()
340
      : m_Layer(nullptr), m_Crt(nullptr) {}
341 342 343 344
    explicit feature_iter(otb::ogr::Layer & layer)
      : m_Layer(&layer), m_Crt(layer.GetNextFeature()) {}
    template <class OtherValue> feature_iter(
      feature_iter<OtherValue> const& other,
345
      typename boost::enable_if<boost::is_convertible<OtherValue*,Value*> >::type* = nullptr
346 347 348 349 350 351 352 353 354 355
    )
      : m_Layer(other.m_Layer), m_Crt(other.m_Crt)
      {}
  private:
    friend class boost::iterator_core_access;
    template <class> friend class feature_iter;

    template <class OtherValue> bool equal(feature_iter<OtherValue> const& other) const
      { return other.m_Crt == m_Crt; }
    void increment()
OTB Bot's avatar
OTB Bot committed
356
      {
357 358 359
      assert(m_Layer && "cannot increment end()");
      m_Crt = m_Layer->GetNextFeature();
      }
OTB Bot's avatar
OTB Bot committed
360
    Value & dereference() const
361 362
      { return m_Crt; }

363 364
    otb::ogr::Layer         * m_Layer;
    otb::ogr::Feature mutable m_Crt;
365 366 367
    };

  template <class> friend class feature_iter;
Luc Hermitte's avatar
Luc Hermitte committed
368
  /// Features %iterator.
369
  typedef feature_iter<Feature      > iterator;
Luc Hermitte's avatar
Luc Hermitte committed
370
  /// Features const %iterator.
371 372
  typedef feature_iter<Feature const> const_iterator;

Luc Hermitte's avatar
Luc Hermitte committed
373
  /** Returns a <em>single-pass</em> %iterator to the start of the sequence.
374
   * \sa \c feature_iter
Luc Hermitte's avatar
Luc Hermitte committed
375
   */
OTB Bot's avatar
OTB Bot committed
376
  const_iterator cbegin() const;
Luc Hermitte's avatar
Luc Hermitte committed
377 378
  /** Returns the %end %iterator of the sequence.
   */
379
  const_iterator cend  () const { return iterator(); }
Luc Hermitte's avatar
Luc Hermitte committed
380 381 382 383 384
  /**\copydoc cbegin */
  const_iterator begin () const { return cbegin(); }
  /**\copydoc cend */
  const_iterator end   () const { return cend  (); }
  /**\copydoc cbegin */
OTB Bot's avatar
OTB Bot committed
385
  iterator       begin ();
Luc Hermitte's avatar
Luc Hermitte committed
386
  /**\copydoc cend */
387
  iterator       end   () { return iterator(); }
388

Luc Hermitte's avatar
Luc Hermitte committed
389 390
  /** Returns a <em>single-pass</em> %iterator to the i-th \c Feature of the
   * sequence.
391
   * \sa \c feature_iter
Luc Hermitte's avatar
Luc Hermitte committed
392 393
   * Depending of the actual driver (i.e. \c OGRDriver), this may be done in O(N).
   */
394
  const_iterator cstart_at(GIntBig index) const;
Luc Hermitte's avatar
Luc Hermitte committed
395
  /** \copydoc cstart_at */
396
  const_iterator start_at (GIntBig index) const { return cstart_at(index); }
Luc Hermitte's avatar
Luc Hermitte committed
397
  /** \copydoc cstart_at */
398
  iterator       start_at (GIntBig index);
399
  //@}
400

Luc Hermitte's avatar
Luc Hermitte committed
401
  /**\name Features definition
402
   * \todo Shall we instead inhibit the declaration of the functions when GDAL
Luc Hermitte's avatar
Luc Hermitte committed
403 404
   * version does not match?
   */
405
  //@{
Luc Hermitte's avatar
Luc Hermitte committed
406
  /** Returns a reference to the layer definition.
407
   * \warning The definition obtained shall not be modified. Use the \c *Field
Luc Hermitte's avatar
Luc Hermitte committed
408 409
   * functions instead.
   * \internal
410
   * The return type shall have been const, but unfortunately \c OGRFeatureDefn
Luc Hermitte's avatar
Luc Hermitte committed
411
   * is not const-correct.
412
   * \sa \c OGRLayer::GetLayerDefn()
Luc Hermitte's avatar
Luc Hermitte committed
413
   */
414 415
  OGRFeatureDefn & GetLayerDefn() const;

Luc Hermitte's avatar
Luc Hermitte committed
416 417 418 419 420 421 422
  /**
   * Adds a new field given its definition.
   * \param[in] field  field definition
   * \param[in] bApproxOK  If true, the field may be created in a slightly
   * different form depending on the limitations of the format driver.
   *
   * \pre This function shall not be called while there are \c Feature in
423
   * existence that were obtained or created with the previous layer definition.
Luc Hermitte's avatar
Luc Hermitte committed
424
   * \throw itk::ExceptionObject if the new field cannot be created
425
   * \sa \c OGRLayer::CreateField()
426 427
   * \warning Calls to this function may invalidate any feature iterator
   * previously obtained depending on the actual \c OGRDriver.
428
   * \todo Move to use \c otb::ogr::FieldDefn
Luc Hermitte's avatar
Luc Hermitte committed
429
   */
430
  void CreateField(FieldDefn const& field, bool bApproxOK = true);
Luc Hermitte's avatar
Luc Hermitte committed
431 432 433 434 435 436

  /**
   * Deletes a field.
   * \param[in] fieldIndex  index of the field to remove.
   *
   * \pre This function shall not be called while there are \c Feature in
437
   * existence that were obtained or created with the previous layer definition.
Luc Hermitte's avatar
Luc Hermitte committed
438
   * \throw itk::ExceptionObject if the new field cannot be deleted
439 440
   * \sa \c OGRLayer::DeleteField()
   * \pre To be available, this function requires OTB to be compiled against OGR
Luc Hermitte's avatar
Luc Hermitte committed
441 442
   * v1.9.0 at least.
   */
443
  void DeleteField(int fieldIndex);
Luc Hermitte's avatar
Luc Hermitte committed
444 445 446 447 448 449 450 451 452 453 454

  /**
   * Changes the definition of the i-th field.
   * \param[in] fieldIndex  index of the field to change
   * \param[in,out] newFieldDefn  definition of the new field.
   * \param[in] nFlags  combination of \c ALTER_NAME_FLAG, \c ALTER_TYPE_FLAG
   * and \c ALTER_WIDTH_PRECISION_FLAG to indicate which of the name and/or type
   * and/or width and precision fields from the new field definition must be
   * taken into account.
   *
   * \pre This function shall not be called while there are \c Feature in
455
   * existence that were obtained or created with the previous layer definition.
Luc Hermitte's avatar
Luc Hermitte committed
456
   * \throw itk::ExceptionObject if the new field cannot be modified
457 458
   * \sa \c OGRLayer::AlterFieldDefn()
   * \pre To be available, this function requires OTB to be compiled against OGR
Luc Hermitte's avatar
Luc Hermitte committed
459
   * v1.9.0 at least.
460
   * \todo Move to use \c otb::ogr::FieldDefn
Luc Hermitte's avatar
Luc Hermitte committed
461
   */
462
  void AlterFieldDefn(size_t fieldIndex, FieldDefn const& newFieldDefn, int nFlags);
Luc Hermitte's avatar
Luc Hermitte committed
463 464 465 466 467 468 469

  /**
   * Moves a field from one position to another.
   * \param[in] oldPos  old field index position
   * \param[in] newPos  new field index position
   *
   * \pre This function shall not be called while there are \c Feature in
470
   * existence that were obtained or created with the previous layer definition.
Luc Hermitte's avatar
Luc Hermitte committed
471
   * \throw itk::ExceptionObject if the new field cannot be modified
472 473
   * \sa \c OGRLayer::ReorderField()
   * \pre To be available, this function requires OTB to be compiled against OGR
Luc Hermitte's avatar
Luc Hermitte committed
474 475
   * v1.9.0 at least.
   */
476
  void ReorderField(size_t oldPos, size_t newPos);
Luc Hermitte's avatar
Luc Hermitte committed
477 478 479 480 481 482

  /**
   * Reorder all the fields of the layer.
   * \param[in] map array that tells the new position of each field.
   *
   * \pre This function shall not be called while there are \c Feature in
483
   * existence that were obtained or created with the previous layer definition.
Luc Hermitte's avatar
Luc Hermitte committed
484
   * \throw itk::ExceptionObject if the new field cannot be modified
485 486
   * \sa \c OGRLayer::ReorderFields()
   * \pre To be available, this function requires OTB to be compiled against OGR
Luc Hermitte's avatar
Luc Hermitte committed
487 488
   * v1.9.0 at least.
   */
489
  void ReorderFields(int *map);
Luc Hermitte's avatar
Luc Hermitte committed
490 491 492 493 494 495 496 497 498 499 500 501 502

  /**
   * Sets which fields can be omitted when retrieving features from the layer.
   * \param[in] fieldNames 0-terminated array of the field names to ignore when
   * fetching features from the layer. 0 to clear the list.
   * end
   *
   * Besides field names of the layers, the following special fields can be
   * passed: "OGR_GEOMETRY" to ignore geometry and "OGR_STYLE" to ignore layer
   * style.
   *
   * By default, no fields are ignored.
   * \throw itk::ExceptionObject if the new field cannot be modified
503
   * \sa \c OGRLayer::SetIgnoredFields()
Luc Hermitte's avatar
Luc Hermitte committed
504 505
   */
  void SetIgnoredFields(char const** fieldNames);
506
  //@}
507

Luc Hermitte's avatar
Luc Hermitte committed
508
  /** Returns the type of the geometry stored.
509
   * \sa \c OGRLayer::GetGeomType()
Luc Hermitte's avatar
Luc Hermitte committed
510
   */
511
  OGRwkbGeometryType GetGeomType() const;
512

513 514 515 516 517
  friend bool operator==(Layer const& lhs, Layer const& rhs)
  {
    const bool equal = lhs.m_Layer.get() == rhs.m_Layer.get();
    return equal;
  }
518

519
private:
520 521 522 523 524 525 526 527 528
  /**
   * Internal encapsulation of \c OGRLayer::GetNextFeature().
   *
   * \return the next \c OGRFeature of the layer, encapsulated in a \c Feature.
   * \throw None
   * \internal
   * Required to implement iterators without exposing/including \c OGRFeature
   * class definition.
   */
529
  Feature GetNextFeature();
530 531

  /** Data implementation.
532 533
   * \internal
   * The actual %layer implementation belongs to the \c otb::Layer object,
534
   * unless this is the result of \c ExecuteSQL(). In that case a deleter is set
535
   * to correctly release the layer.
536 537
   */
  boost::shared_ptr<OGRLayer> m_Layer;
538

539 540
  bool m_Modifiable;

541
#if 0
542
  /** Related DataSource.
543
   * Needed to access OTB meta information.
544 545
   */
  DataSourcePtr m_DataSource;
546
#endif
547 548
  };

549 550 551 552 553
inline bool operator!=(Layer const& lhs, Layer const& rhs)
  {
  return ! (lhs == rhs);
  }

554 555 556
} } // end namespace otb::ogr

#ifndef OTB_MANUAL_INSTANTIATION
557
// #include "otbLayerWrapper.hxx"
558 559
#endif

560
#endif // otbOGRLayerWrapper_h