otbOGRVersionProxy1x.cxx 2.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*=========================================================================

  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.

=========================================================================*/
#include "otbOGRVersionProxy.h"

20
#if defined(__GNUC__) || defined(__clang__)
21 22
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
23
#include "ogrsf_frmts.h"
24 25 26 27
#pragma GCC diagnostic pop
#else
#include "ogrsf_frmts.h"
#endif
28 29 30

namespace otb
{
31 32 33 34
namespace ogr
{
namespace version_proxy
{
35

36 37 38 39 40 41
OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type)
{
  return false;
}


42
GDALDatasetType * Open(const char * filename, bool readOnly)
43 44 45 46
{
  return OGRSFDriverRegistrar::Open(filename,!readOnly);
}

47
void Close(GDALDatasetType * dataset)
48 49 50
{
  OGRDataSource::DestroyDataSource(dataset);
}
51

52
GDALDatasetType * Create(GDALDriverType * driver, const char * name)
53
{
54 55
  GDALDatasetType * ds = driver->CreateDataSource(name);

56
  if(ds)
57
    ds->SetDriver(driver);
58

59
  return ds;
60 61
}

62
bool Delete(const char * name)
63
{
64 65
  // Open dataset
  GDALDatasetType * poDS = Open(name,false);
66
  GDALDriverType * poDriver = ITK_NULLPTR;
67 68 69 70 71 72 73 74
  if(poDS)
    {
    poDriver = poDS->GetDriver();
    Close(poDS);
    }

  if(poDriver && poDriver->TestCapability(ODrCDeleteDataSource))
    {
75

76 77 78
    OGRErr ret = poDriver->DeleteDataSource(name);
    return (ret == OGRERR_NONE);
    }
79

80
  return false;
81 82
}

83
GDALDriverType *  GetDriverByName(const char * name)
84 85 86 87
{
  return OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(name);
}

88
std::string GetDatasetClassName()
89 90 91 92
{
  return std::string("OGRDataSource");
}

93
std::string GetDriverClassName()
94 95 96 97
{
  return std::string("OGRSFDriver");
}

98
std::vector<std::string> GetFileListAsStringVector(GDALDatasetType * dataset)
99
{
100 101 102
  std::vector<std::string> ret;

  ret.push_back(std::string(dataset->GetName()));
103

104
  return ret;
105 106
}

107
bool SyncToDisk(GDALDatasetType * dataset)
108 109 110 111 112 113
{
  const OGRErr res= dataset->SyncToDisk();

  return (res == OGRERR_NONE);
}

114
std::vector<std::string> GetAvailableDriversAsStringVector()
115 116
{
  std::vector<std::string> ret;
117

118
  int nbDrivers = OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount();
119

120 121 122 123 124 125 126 127
  for(int i = 0; i < nbDrivers;++i)
    {
    ret.push_back(OGRSFDriverRegistrar::GetRegistrar()->GetDriver(i)->GetName());
    }

  return ret;
}

128 129 130 131 132
std::string GetDriverNameFromDataSource(const GDALDatasetType * ds)
{
  return std::string(const_cast<GDALDatasetType *>(ds)->GetDriver()->GetName());
}

133 134
}
}
135
} // end namespace