OmniSciDB  16c4e035a1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geospatial::GDAL Class Reference

#include <GDAL.h>

Classes

struct  CoordinateTransformationDeleter
 
struct  DataSourceDeleter
 
struct  FeatureDeleter
 
struct  SpatialReferenceDeleter
 

Public Types

using DataSourceUqPtr = std::unique_ptr< OGRDataSource, DataSourceDeleter >
 
using FeatureUqPtr = std::unique_ptr< OGRFeature, FeatureDeleter >
 
using SpatialReferenceUqPtr = std::unique_ptr< OGRSpatialReference, SpatialReferenceDeleter >
 
using CoordinateTransformationUqPtr = std::unique_ptr< OGRCoordinateTransformation, CoordinateTransformationDeleter >
 

Static Public Member Functions

static void init ()
 
static bool supportsNetworkFileAccess ()
 
static bool supportsDriver (const std::string &driver_name)
 
static void setAuthorizationTokens (const std::string &s3_region, const std::string &s3_endpoint, const std::string &s3_access_key, const std::string &s3_secret_key, const std::string &s3_session_token)
 
static DataSourceUqPtr openDataSource (const std::string &name, const import_export::SourceType source_type)
 
static import_export::SourceType getDataSourceType (const std::string &name)
 
static std::vector< std::string > unpackMetadata (char **metadata)
 
static void logMetadata (GDALMajorObject *object)
 
static std::string getMetadataString (char **metadata, const std::string &key)
 

Static Private Attributes

static bool initialized_ = false
 
static std::mutex init_mutex_
 

Detailed Description

Definition at line 34 of file GDAL.h.

Member Typedef Documentation

using Geospatial::GDAL::CoordinateTransformationUqPtr = std::unique_ptr<OGRCoordinateTransformation, CoordinateTransformationDeleter>

Definition at line 65 of file GDAL.h.

using Geospatial::GDAL::DataSourceUqPtr = std::unique_ptr<OGRDataSource, DataSourceDeleter>

Definition at line 48 of file GDAL.h.

using Geospatial::GDAL::FeatureUqPtr = std::unique_ptr<OGRFeature, FeatureDeleter>

Definition at line 53 of file GDAL.h.

using Geospatial::GDAL::SpatialReferenceUqPtr = std::unique_ptr<OGRSpatialReference, SpatialReferenceDeleter>

Definition at line 59 of file GDAL.h.

Member Function Documentation

import_export::SourceType Geospatial::GDAL::getDataSourceType ( const std::string &  name)
static

Definition at line 211 of file GDAL.cpp.

References getMetadataString(), init(), import_export::kGeoFile, import_export::kRasterFile, import_export::kUnknown, import_export::kUnsupported, and openDataSource().

211  {
212  // lazy init
213  init();
214 
215  // attempt to open datasource as either vector or raster
217 
219 
220  // couldn't open it at all
221  if (!datasource) {
222  return source_type;
223  }
224 
225  // get the driver
226  auto* driver = datasource->GetDriver();
227  if (!driver) {
228  return source_type;
229  }
230 
231  // get capabilities
232  auto const is_vector = getMetadataString(driver->GetMetadata(), "DCAP_VECTOR") == "YES";
233  auto const is_raster = getMetadataString(driver->GetMetadata(), "DCAP_RASTER") == "YES";
234 
235  // analyze
236  if (is_vector && !is_raster) {
238  } else if (is_raster && !is_vector) {
240  }
241 
242  // done
243  return source_type;
244 }
string name
Definition: setup.in.py:72
static void init()
Definition: GDAL.cpp:67
std::unique_ptr< OGRDataSource, DataSourceDeleter > DataSourceUqPtr
Definition: GDAL.h:48
static DataSourceUqPtr openDataSource(const std::string &name, const import_export::SourceType source_type)
Definition: GDAL.cpp:181
static std::string getMetadataString(char **metadata, const std::string &key)
Definition: GDAL.cpp:276

+ Here is the call graph for this function:

std::string Geospatial::GDAL::getMetadataString ( char **  metadata,
const std::string &  key 
)
static

Definition at line 276 of file GDAL.cpp.

References CHECK, initialized_, and unpackMetadata().

Referenced by getDataSourceType(), and import_export::RasterImporter::getRawBandNamesForFormat().

276  {
277  CHECK(initialized_) << "GDAL not initialized!";
278  auto const key_len = key.length();
279  auto const strings = unpackMetadata(metadata);
280  for (auto const& str : strings) {
281  if (str.substr(0, key_len) == key) {
282  return str.substr(key_len + 1, std::string::npos);
283  }
284  }
285  return std::string();
286 }
static std::vector< std::string > unpackMetadata(char **metadata)
Definition: GDAL.cpp:246
static bool initialized_
Definition: GDAL.h:76
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Geospatial::GDAL::init ( )
static

Definition at line 67 of file GDAL.cpp.

References Geospatial::anonymous_namespace{GDAL.cpp}::gdal_error_handler(), omnisci::get_root_abs_path(), logger::INFO, init_mutex_, initialized_, and LOG.

Referenced by import_export::QueryExporterGDAL::beginExport(), import_export::Importer::gdalGetAllFilesInArchive(), import_export::Importer::gdalGetLayersInGeoFile(), import_export::Importer::gdalStatInternal(), import_export::Importer::gdalToColumnDescriptorsRaster(), getDataSourceType(), Geospatial::GeoBase::getTransformation(), openDataSource(), import_export::Importer::openGDALDataSource(), setAuthorizationTokens(), and supportsDriver().

67  {
68  // this should not be called from multiple threads, but...
69  std::lock_guard<std::mutex> guard(init_mutex_);
70 
71  // init under mutex
72  if (!initialized_) {
73  // FIXME(andrewseidl): investigate if CPLPushFinderLocation can be public
74 #ifdef _WIN32
75  _putenv_s(
76  "GDAL_DATA",
77  std::string(omnisci::get_root_abs_path() + "/ThirdParty/gdal-data").c_str());
78  _putenv_s(
79  "PROJ_LIB",
80  std::string(omnisci::get_root_abs_path() + "/ThirdParty/gdal-data/proj").c_str());
81 #else
82  setenv("GDAL_DATA",
83  std::string(omnisci::get_root_abs_path() + "/ThirdParty/gdal-data").c_str(),
84  true);
85  setenv(
86  "PROJ_LIB",
87  std::string(omnisci::get_root_abs_path() + "/ThirdParty/gdal-data/proj").c_str(),
88  true);
89 #endif
90 
91 #ifndef _MSC_VER // TODO
92  // configure SSL certificate path (per S3Archive::init_for_read)
93  // in a production build, GDAL and Curl will have been built on
94  // CentOS, so the baked-in system path will be wrong for Ubuntu
95  // and other Linux distros. Unless the user is deliberately
96  // overriding it by setting SSL_CERT_FILE explicitly in the server
97  // environment, we set it to whichever CA bundle directory exists
98  // on the machine we're running on
99  static constexpr std::array<const char*, 6> known_ca_paths{
100  "/etc/ssl/certs/ca-certificates.crt",
101  "/etc/pki/tls/certs/ca-bundle.crt",
102  "/usr/share/ssl/certs/ca-bundle.crt",
103  "/usr/local/share/certs/ca-root.crt",
104  "/etc/ssl/cert.pem",
105  "/etc/ssl/ca-bundle.pem"};
106  for (const auto& known_ca_path : known_ca_paths) {
107  if (boost::filesystem::exists(known_ca_path)) {
108  LOG(INFO) << "GDAL SSL Certificate path: " << known_ca_path;
109  setenv("SSL_CERT_FILE", known_ca_path, false); // no overwrite
110  break;
111  }
112  }
113 #endif
114 
115  GDALAllRegister();
116  OGRRegisterAll();
117  CPLSetErrorHandler(*gdal_error_handler);
118  LOG(INFO) << "GDAL Initialized: " << GDALVersionInfo("--version");
119  initialized_ = true;
120  }
121 }
void gdal_error_handler(CPLErr err_class, int err_no, const char *err_msg)
Definition: GDAL.cpp:39
#define LOG(tag)
Definition: Logger.h:205
static bool initialized_
Definition: GDAL.h:76
static std::mutex init_mutex_
Definition: GDAL.h:77
std::string get_root_abs_path()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Geospatial::GDAL::logMetadata ( GDALMajorObject *  object)
static

Definition at line 257 of file GDAL.cpp.

References CHECK, logger::INFO, initialized_, LOG, and unpackMetadata().

Referenced by import_export::RasterImporter::detect().

257  {
258  CHECK(initialized_) << "GDAL not initialized!";
259  CHECK(object);
260  LOG(INFO) << "DEBUG: Metadata domains for object '" << object->GetDescription() << "'";
261  LOG(INFO) << "DEBUG: (default)";
262  auto const default_metadata = unpackMetadata(object->GetMetadata());
263  for (auto const& str : default_metadata) {
264  LOG(INFO) << "DEBUG: " << str;
265  }
266  auto const metadata_domains = unpackMetadata(object->GetMetadataDomainList());
267  for (auto const& domain : metadata_domains) {
268  LOG(INFO) << "DEBUG: " << domain;
269  auto const metadata = unpackMetadata(object->GetMetadata(domain.c_str()));
270  for (auto const& str : metadata) {
271  LOG(INFO) << "DEBUG: " << str;
272  }
273  }
274 }
static std::vector< std::string > unpackMetadata(char **metadata)
Definition: GDAL.cpp:246
#define LOG(tag)
Definition: Logger.h:205
static bool initialized_
Definition: GDAL.h:76
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GDAL::DataSourceUqPtr Geospatial::GDAL::openDataSource ( const std::string &  name,
const import_export::SourceType  source_type 
)
static

Definition at line 181 of file GDAL.cpp.

References CHECK, init(), import_export::kGeoFile, import_export::kRasterFile, and import_export::kUnknown.

Referenced by import_export::RasterImporter::detect(), getDataSourceType(), import_export::RasterImporter::import(), and import_export::Importer::openGDALDataSource().

182  {
183  // lazy init
184  init();
185 
186  // how should we try to open it?
187  unsigned int open_flags{0u};
188  switch (source_type) {
190  open_flags = GDAL_OF_VECTOR | GDAL_OF_RASTER;
191  break;
193  open_flags = GDAL_OF_VECTOR;
194  break;
196  open_flags = GDAL_OF_RASTER;
197  break;
198  default:
199  CHECK(false) << "Invalid datasource source type";
200  }
201 
202  // attempt to open datasource
203  // error will simply log and return null to be trapped later
204  auto* datasource = static_cast<OGRDataSource*>(
205  GDALOpenEx(name.c_str(), open_flags | GDAL_OF_READONLY, nullptr, nullptr, nullptr));
206 
207  // done
208  return DataSourceUqPtr(datasource);
209 }
string name
Definition: setup.in.py:72
static void init()
Definition: GDAL.cpp:67
std::unique_ptr< OGRDataSource, DataSourceDeleter > DataSourceUqPtr
Definition: GDAL.h:48
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Geospatial::GDAL::setAuthorizationTokens ( const std::string &  s3_region,
const std::string &  s3_endpoint,
const std::string &  s3_access_key,
const std::string &  s3_secret_key,
const std::string &  s3_session_token 
)
static

Definition at line 138 of file GDAL.cpp.

References init().

Referenced by import_export::Importer::gdalGetAllFilesInArchive(), import_export::Importer::gdalGetLayersInGeoFile(), import_export::Importer::gdalStatInternal(), import_export::Importer::gdalToColumnDescriptorsRaster(), and import_export::Importer::openGDALDataSource().

142  {
143  // lazy init
144  init();
145 
146  // set tokens
147  if (s3_region.size()) {
148  CPLSetConfigOption("AWS_REGION", s3_region.c_str());
149  } else {
150  CPLSetConfigOption("AWS_REGION", nullptr);
151  }
152  if (s3_endpoint.size()) {
153  CPLSetConfigOption("AWS_S3_ENDPOINT", s3_endpoint.c_str());
154  } else {
155  CPLSetConfigOption("AWS_S3_ENDPOINT", nullptr);
156  }
157  if (s3_access_key.size()) {
158  CPLSetConfigOption("AWS_ACCESS_KEY_ID", s3_access_key.c_str());
159  } else {
160  CPLSetConfigOption("AWS_ACCESS_KEY_ID", nullptr);
161  }
162  if (s3_secret_key.size()) {
163  CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", s3_secret_key.c_str());
164  } else {
165  CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", nullptr);
166  }
167  if (s3_session_token.size()) {
168  CPLSetConfigOption("AWS_SESSION_TOKEN", s3_session_token.c_str());
169  } else {
170  CPLSetConfigOption("AWS_SESSION_TOKEN", nullptr);
171  }
172 
173  // if we haven't set keys, we need to disable signed access
174  if (s3_access_key.size() || s3_secret_key.size()) {
175  CPLSetConfigOption("AWS_NO_SIGN_REQUEST", nullptr);
176  } else {
177  CPLSetConfigOption("AWS_NO_SIGN_REQUEST", "YES");
178  }
179 }
static void init()
Definition: GDAL.cpp:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Geospatial::GDAL::supportsDriver ( const std::string &  driver_name)
static

Definition at line 131 of file GDAL.cpp.

References init().

131  {
132  // lazy init
133  init();
134 
135  return GetGDALDriverManager()->GetDriverByName(driver_name.c_str()) != nullptr;
136 }
static void init()
Definition: GDAL.cpp:67

+ Here is the call graph for this function:

bool Geospatial::GDAL::supportsNetworkFileAccess ( )
static

Definition at line 123 of file GDAL.cpp.

Referenced by anonymous_namespace{DBHandler.cpp}::add_vsi_network_prefix().

123  {
124 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 2)
125  return true;
126 #else
127  return false;
128 #endif
129 }

+ Here is the caller graph for this function:

std::vector< std::string > Geospatial::GDAL::unpackMetadata ( char **  metadata)
static

Definition at line 246 of file GDAL.cpp.

Referenced by import_export::RasterImporter::detect(), getMetadataString(), and logMetadata().

246  {
247  std::vector<std::string> strings;
248  if (metadata) {
249  while (*metadata) {
250  strings.emplace_back(*metadata);
251  metadata++;
252  }
253  }
254  return strings;
255 }

+ Here is the caller graph for this function:

Member Data Documentation

std::mutex Geospatial::GDAL::init_mutex_
staticprivate

Definition at line 77 of file GDAL.h.

Referenced by init().

bool Geospatial::GDAL::initialized_ = false
staticprivate

Definition at line 76 of file GDAL.h.

Referenced by getMetadataString(), init(), and logMetadata().


The documentation for this class was generated from the following files: