26 #include <vsg/io/ReaderWriter.h>
27 #include <vsgXchange/Version.h>
31 #include <unordered_set>
36 class VSGXCHANGE_DECLSPEC
GDAL :
public vsg::Inherit<vsg::ReaderWriter, GDAL>
40 vsg::ref_ptr<vsg::Object> read(
const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options)
const override;
42 bool getFeatures(Features& features)
const override;
48 Implementation* _implementation;
55 #ifdef vsgXchange_GDAL
57 # include "gdal_priv.h"
58 # include "ogr_spatialref.h"
60 # include <vsg/core/Data.h>
61 # include <vsg/io/Path.h>
62 # include <vsg/maths/vec4.h>
70 extern VSGXCHANGE_DECLSPEC
bool initGDAL();
73 inline std::shared_ptr<GDALDataset> openDataSet(
const vsg::Path& filename, GDALAccess access)
76 return std::shared_ptr<GDALDataset>(
static_cast<GDALDataset*
>(GDALOpen(filename.string().c_str(), access)), [](GDALDataset* dataset) { GDALClose(dataset); });
80 inline std::shared_ptr<GDALDataset> openSharedDataSet(
const vsg::Path& filename, GDALAccess access)
83 return std::shared_ptr<GDALDataset>(
static_cast<GDALDataset*
>(GDALOpenShared(filename.string().c_str(), access)), [](GDALDataset* dataset) { GDALClose(dataset); });
87 extern VSGXCHANGE_DECLSPEC
bool compatibleDatasetProjections(
const GDALDataset& lhs,
const GDALDataset& rhs);
90 extern VSGXCHANGE_DECLSPEC
bool compatibleDatasetProjectionsTransformAndSizes(
const GDALDataset& lhs,
const GDALDataset& rhs);
93 extern VSGXCHANGE_DECLSPEC vsg::ref_ptr<vsg::Data> createImage2D(
int width,
int height,
int numComponents, GDALDataType dataType, vsg::dvec4 def = {0.0, 0.0, 0.0, 1.0});
96 extern VSGXCHANGE_DECLSPEC
bool copyRasterBandToImage(GDALRasterBand& band, vsg::Data& image,
int component);
99 extern VSGXCHANGE_DECLSPEC
bool assignMetaData(GDALDataset& dataset, vsg::Object&
object);
102 template<
class Iterator,
class BinaryPredicate>
103 bool all_equal(Iterator first, Iterator last, BinaryPredicate compare)
105 if (first == last)
return true;
106 Iterator itr = first;
109 for (; itr != last; ++itr)
111 if (!compare(**first, **itr))
return false;
118 inline std::set<GDALDataType> dataTypes(GDALDataset& dataset)
120 std::set<GDALDataType> types;
121 for (
int i = 1; i <= dataset.GetRasterCount(); ++i)
123 GDALRasterBand* band = dataset.GetRasterBand(i);
124 types.insert(band->GetRasterDataType());
131 template<
class Iterator>
132 std::set<GDALDataType> dataTypes(Iterator first, Iterator last)
134 std::set<GDALDataType> types;
135 for (Iterator itr = first; itr != last; ++itr)
137 GDALDataset& dataset = **itr;
138 for (
int i = 1; i <= dataset.GetRasterCount(); ++i)
140 GDALRasterBand* band = dataset.GetRasterBand(i);
141 types.insert(band->GetRasterDataType());
148 extern VSGXCHANGE_DECLSPEC
bool getEXIF_LatitudeLongitudeAlititude(GDALDataset& dataset,
double& latitude,
double& longitude,
double& altitude);
151 extern VSGXCHANGE_DECLSPEC
bool getEXIF_LatitudeLongitudeAlititude(
const vsg::Object&
object,
double& latitude,
double& longitude,
double& altitude);
162 std::istream& operator>>(std::istream& input, in_brackets<T> field)
164 while (input.peek() ==
' ') input.get();
167 if (input.peek() ==
'(')
171 input >> field.value;
173 if constexpr (std::is_same_v<T, std::string>)
175 if (!field.value.empty() && field.value[field.value.size() - 1] ==
')')
177 field.value.erase(field.value.size() - 1);
182 while (input.peek() !=
')')
185 if (input.eof())
return input;
187 field.value.push_back(c);
192 if (input.peek() ==
')')
199 input >> field.value;
210 struct dms_in_brackets
212 dms_in_brackets(
double& angle) :
217 inline std::istream& operator>>(std::istream& input, dms_in_brackets field)
219 double degrees = 0.0, minutes = 0.0, seconds = 0.0;
220 input >> in_brackets(degrees) >> in_brackets(minutes) >> in_brackets(seconds);
221 field.value = degrees + (minutes + seconds / 60.0) / 60.0;
optional GDAL ReaderWriter
Definition: gdal.h:37