OmniSciDB  91042dcc5b
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RasterImporter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * @file RasterImporter.h
19  * @author Simon Eves <simon.eves@omnisci.com>
20  * @brief GDAL Raster File Importer
21  */
22 
23 #pragma once
24 
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <vector>
29 
30 #include "Geospatial/GDAL.h"
32 #include "Shared/sqltypes.h"
33 
34 class GDALRasterBand;
35 class OGRCoordinateTransformation;
36 class OGRDataSource;
37 
38 namespace import_export {
39 
41  public:
43 
44  explicit GCPTransformer(OGRDataSource* datasource, const Mode mode = Mode::kPolynomial);
45  GCPTransformer() = delete;
47 
48  void transform(double& x, double& y);
49 
50  private:
53 };
54 
56  public:
57  RasterImporter() = default;
58  ~RasterImporter() = default;
59 
61  enum class PointTransform { kNone, kAuto, kFile, kWorld };
62 
63  void detect(const std::string& file_name,
64  const std::string& specified_band_names,
65  const std::string& specified_band_dimensions,
66  const PointType point_type,
67  const PointTransform point_transform,
68  const bool point_compute_angle,
69  const bool throw_on_error,
70  const MetadataColumnInfos& metadata_column_infos);
71 
72  void import(const uint32_t max_threads);
73 
74  using NamesAndSQLTypes = std::vector<std::pair<std::string, SQLTypes>>;
75  using RawPixels = std::vector<std::byte>;
76  using NullValue = std::pair<double, bool>;
77  using Coords = std::vector<std::tuple<double, double, float>>;
78 
79  const uint32_t getNumBands() const;
80  const PointTransform getPointTransform() const;
83  const int getBandsWidth() const { return bands_width_; }
84  const int getBandsHeight() const { return bands_height_; }
85  const NullValue getBandNullValue(const int band_idx) const;
86  const Coords getProjectedPixelCoords(const uint32_t thread_idx, const int y) const;
87  void getRawPixels(const uint32_t thread_idx,
88  const uint32_t band_idx,
89  const int y_start,
90  const int num_rows,
91  const SQLTypes column_sql_type,
92  RawPixels& raw_pixel_bytes);
93 
94  private:
95  struct ImportBandInfo {
96  std::string name;
97  std::string alt_name;
99  uint32_t datasource_idx;
100  int band_idx;
101  double null_value;
103  };
104 
105  std::vector<std::string> datasource_names_;
106  std::vector<std::vector<std::string>> raw_band_names_;
107  std::map<std::string, bool> specified_band_names_map_;
108  std::map<std::string, int> column_name_repeats_map_;
109  std::vector<ImportBandInfo> import_band_infos_;
110  std::array<double, 6> affine_transform_matrix_;
111  std::vector<std::vector<Geospatial::GDAL::DataSourceUqPtr>> datasource_handles_;
114 
115  int bands_width_{-1};
116  int bands_height_{-1};
119  std::vector<Geospatial::GDAL::CoordinateTransformationUqPtr>
121  std::vector<std::unique_ptr<GCPTransformer>> gcp_transformers_;
122  bool point_compute_angle_{false};
123 
125  void initializeFiltering(const std::string& specified_band_names,
126  const std::string& specified_band_dimensions,
127  const MetadataColumnInfos& metadata_column_infos);
128  bool shouldImportBandWithName(const std::string& name);
129  bool shouldImportBandWithDimensions(const int width, const int height);
130  std::string getBandName(const uint32_t datasource_idx, const int band_idx);
131  void checkSpecifiedBandNamesFound() const;
132 };
133 
134 } // namespace import_export
const NamesAndSQLTypes getBandNamesAndSQLTypes() const
SQLTypes
Definition: sqltypes.h:38
const int getBandsWidth() const
const NullValue getBandNullValue(const int band_idx) const
void getRawBandNamesForFormat(const Geospatial::GDAL::DataSourceUqPtr &datasource)
string name
Definition: setup.in.py:72
std::vector< std::tuple< double, double, float >> Coords
void transform(double &x, double &y)
Constants for Builtin SQL Types supported by OmniSci.
const uint32_t getNumBands() const
const PointTransform getPointTransform() const
std::vector< std::byte > RawPixels
bool shouldImportBandWithName(const std::string &name)
std::vector< std::vector< std::string > > raw_band_names_
std::vector< Geospatial::GDAL::CoordinateTransformationUqPtr > coordinate_transformations_
bool shouldImportBandWithDimensions(const int width, const int height)
const int getBandsHeight() const
const NamesAndSQLTypes getPointNamesAndSQLTypes() const
std::vector< ImportBandInfo > import_band_infos_
std::vector< std::string > datasource_names_
void getRawPixels(const uint32_t thread_idx, const uint32_t band_idx, const int y_start, const int num_rows, const SQLTypes column_sql_type, RawPixels &raw_pixel_bytes)
std::unique_ptr< OGRDataSource, DataSourceDeleter > DataSourceUqPtr
Definition: GDAL.h:48
std::map< std::string, bool > specified_band_names_map_
std::vector< std::vector< Geospatial::GDAL::DataSourceUqPtr > > datasource_handles_
std::pair< double, bool > NullValue
const Coords getProjectedPixelCoords(const uint32_t thread_idx, const int y) const
std::vector< std::pair< std::string, SQLTypes >> NamesAndSQLTypes
std::map< std::string, int > column_name_repeats_map_
std::array< double, 6 > affine_transform_matrix_
void initializeFiltering(const std::string &specified_band_names, const std::string &specified_band_dimensions, const MetadataColumnInfos &metadata_column_infos)
std::string getBandName(const uint32_t datasource_idx, const int band_idx)
void detect(const std::string &file_name, const std::string &specified_band_names, const std::string &specified_band_dimensions, const PointType point_type, const PointTransform point_transform, const bool point_compute_angle, const bool throw_on_error, const MetadataColumnInfos &metadata_column_infos)
std::vector< std::unique_ptr< GCPTransformer > > gcp_transformers_
std::vector< MetadataColumnInfo > MetadataColumnInfos