otbOGRVersionProxy.h 5.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
18 19
#ifndef otbOGRVersionProxy_h
#define otbOGRVersionProxy_h
20 21

#include <string>
22
#include <vector>
23
#include "otbConfigure.h"
24
#include "itkMacro.h"
25

26 27 28 29 30 31 32 33 34 35
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4251 )
#include "ogr_core.h" // OGR enums
#pragma warning ( pop )
#else
#include "ogr_core.h" // OGR enums
#endif


36 37 38 39 40 41 42 43
#ifdef OTB_USE_GDAL_20
class GDALDataset;
class GDALDriver;
#else
class OGRDataSource;
class OGRSFDriver;
#endif

44 45
#include "OTBGdalAdaptersExport.h"

46 47
namespace otb
{
48 49 50 51 52
namespace ogr
{
namespace version_proxy
{

53 54 55 56 57 58
/**
* With Gdal >= 2.0, this function will test equality between type and
* OFTInteger64 enum. Otherwise, it returns false. 
*/
OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type);

59
/** 
60
 * This namespace holds proxy functions hiding interface changes in gdal 2.0 
61
 *
62
 * This namespace holds proxy functions hiding interface changes in OGR
63 64
 * dataset between gdal 1.x (x>10) and gdal 2.x. It defines a common
 * interface that should be used in place of calling directly the
65
 * wrapped gdal functions.
66 67 68
 * 
 * Whenever GDALDataset and GDALDriver have to be used to open a
 * vector dataset (or OGRDataSource an OGRSFDriver for gdal 1.x), one
69
 * should use ogr::version_proxy types GDALDatasetType and
70 71
 * GDALDriverType.
 * 
72
 * See function documentation for details.
73 74
 */

75 76 77 78 79 80 81
  #ifdef OTB_USE_GDAL_20
  typedef GDALDataset GDALDatasetType;
  typedef GDALDriver GDALDriverType;
  #else
  typedef OGRDataSource GDALDatasetType;
  typedef OGRSFDriver   GDALDriverType;
#endif
82 83

  /** 
84
   * This function opens a file, possibly in read-only mode, and returns
85 86 87 88 89 90 91 92
   * a dataset.
   *
   * Calls OGRSFDriverRegistrar::Open for gdal 1.x implementation and GDALopenEx for
   * gdal 2.x implementation.

   * \param filename Filename of the file to open
   * \param readOnly: If true, dataset is open in read-only mode.
   * \return NULL if file could not be open.
93 94
   */
  OTBGdalAdapters_EXPORT   
95
  GDALDatasetType * Open(const char * filename, bool readOnly = true);
96 97

  /**
98
   * This function closes a dataset.
99 100 101 102 103 104 105
   *
   * Calls OGRDataSource::DestroyDataSource for gdal 1.x
   * implementation and GDALClose for gdal 2.x implementation.
   *
   * \param dataset Pointer to the dataset to close. Will not be
   * checked for null pointer.
   */
106
  OTBGdalAdapters_EXPORT
107
  void Close(GDALDatasetType * dataset);
108 109

  /**
110
   * This function creates a new dataset.
111 112 113 114 115 116 117 118 119 120 121 122
   *
   * Calls OGRSFDriver::CreateDataSource for gdal 1.x implementation
   * and GDALDriver::Create with (0,0) raster size for gdal 2.x
   * implementation
   * 
   * \param driver Pointer to the driver used for creation. Will not
   * be checked for null pointer.
   *
   * \param name Name of the dataset to create.
   * 
   * \return NULL if dataset could not be created.
   */
123
  OTBGdalAdapters_EXPORT
124
  GDALDatasetType * Create(GDALDriverType * driver, const char * name);
125

126 127

  /**
128
   * This function physically deletes an existing dataset.
129 130 131 132 133
   * 
   * Calls OGRDataSource::DeleteDataSource for gdal 1.x implementation
   * and GDALDriver::Delete for gdal 2.x implementation.
   *
   * \param name Name of the dataset to destroy.
134 135
   */
  OTBGdalAdapters_EXPORT   
136
  bool Delete(const char * name);
137

138
  /**
139
   * This function returns a pointer to the driver from its name.
140 141 142 143 144 145 146 147 148 149
   * 
   * Calls OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName() for
   * gdal 1.x implementation and
   * GetGDALDriverManager()->GetDriverByName() for gdal 2.x
   * implementation.
   * 
   * \param name Name of the driver to retrieve
   * 
   * \return NULL if no driver could be retrieved.
   */
150
  OTBGdalAdapters_EXPORT 
151
  GDALDriverType *  GetDriverByName(const char * name);
152

153
  OTBGdalAdapters_EXPORT
154 155
  std::string GetDriverNameFromDataSource(const GDALDatasetType * ds);

156 157 158 159 160 161 162 163 164 165 166
  /**
   * Sync dataset to disk.
   *
   * Calls OGRDataSource::SyncToDisk() for gdal 1.x implementation and
   * GDALDataset::FlushCache() for gdal 2.x  implementation.
   *
   * \param dataset Pointer to the dataset to sync. Will not be
   * checked for null pointer.
   *
   * \return True if sync went on without any error.
   */
167 168
   OTBGdalAdapters_EXPORT
   bool SyncToDisk(GDALDatasetType * dataset);
169

170 171 172 173
  /**
   * \return The name of the dataset class behind the implementation
   * (OGRDataSource for gdal 1.x and GdalDataset for gdal 2.x)
   */
174
  OTBGdalAdapters_EXPORT
175
  std::string GetDatasetClassName();
176

177 178 179 180
  /**
   * \return The name of the driver class behind the implementation
   * (OGRSFDriver for gdal 1.x and GDALDriver for gdal 2.x)
   */
181
  OTBGdalAdapters_EXPORT 
182
  std::string GetDriverClassName();
183

184 185 186 187 188 189 190 191 192 193 194 195
  /**
   * Return the list of files composing the dataset.
   * 
   * Calls OGRDataSource::GetName() and wrap in string vector for gdal
   * 1.x implementation, and GDALDataset::GetFileList and wrap in
   * string vector for gdal 2.x implementation.
   *  
   * \param dataset Pointer to the dataset to get the file list from. Will not be
   * checked for null pointer.
   * 
   * \return A vector of string containing the list of files.
   */
196 197
   
  OTBGdalAdapters_EXPORT 
198
  std::vector<std::string> GetFileListAsStringVector(GDALDatasetType * dataset);
199 200 201 202 203 204 205 206 207 208

  /** 
   * Return the list of available drivers.
   *
   * Calls OGRSFDriverRegistrar::GetRegistrar() for gdal 1.x
   * implementation and GetGDALDriverManager() for gdal 2.x
   * implementation.
   *
   * \return A vector of string containing the list of available drivers.
   */  
209
  OTBGdalAdapters_EXPORT
210
  std::vector<std::string> GetAvailableDriversAsStringVector();
211

212 213
}
}
214 215 216
} // end namespace otb

#endif