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;
41 vsg::ref_ptr<vsg::Object> read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options = {})
const override;
42 vsg::ref_ptr<vsg::Object> read(
const uint8_t* ptr,
size_t size, vsg::ref_ptr<const vsg::Options> options = {})
const override;
44 bool getFeatures(Features& features)
const override;
50 Implementation* _implementation;
59# include "gdal_priv.h"
60# include "ogr_spatialref.h"
62# include <vsg/core/Data.h>
63# include <vsg/io/Path.h>
64# include <vsg/maths/vec4.h>
72 extern VSGXCHANGE_DECLSPEC
bool initGDAL();
75 inline std::shared_ptr<GDALDataset> openDataSet(
const vsg::Path& filename, GDALAccess access)
78 return std::shared_ptr<GDALDataset>(
static_cast<GDALDataset*
>(GDALOpen(filename.string().c_str(), access)), [](GDALDataset* dataset) { GDALClose(dataset); });
82 inline std::shared_ptr<GDALDataset> openSharedDataSet(
const vsg::Path& filename, GDALAccess access)
85 return std::shared_ptr<GDALDataset>(
static_cast<GDALDataset*
>(GDALOpenShared(filename.string().c_str(), access)), [](GDALDataset* dataset) { GDALClose(dataset); });
89 extern VSGXCHANGE_DECLSPEC
bool compatibleDatasetProjections(
const GDALDataset& lhs,
const GDALDataset& rhs);
92 extern VSGXCHANGE_DECLSPEC
bool compatibleDatasetProjectionsTransformAndSizes(
const GDALDataset& lhs,
const GDALDataset& rhs);
95 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});
98 extern VSGXCHANGE_DECLSPEC
bool copyRasterBandToImage(GDALRasterBand& band, vsg::Data& image,
int component);
101 extern VSGXCHANGE_DECLSPEC
bool assignMetaData(GDALDataset& dataset, vsg::Object&
object);
104 template<
class Iterator,
class BinaryPredicate>
105 bool all_equal(Iterator first, Iterator last, BinaryPredicate compare)
107 if (first == last)
return true;
108 Iterator itr = first;
111 for (; itr != last; ++itr)
113 if (!compare(**first, **itr))
return false;
120 inline std::set<GDALDataType> dataTypes(GDALDataset& dataset)
122 std::set<GDALDataType> types;
123 for (
int i = 1; i <= dataset.GetRasterCount(); ++i)
125 GDALRasterBand* band = dataset.GetRasterBand(i);
126 types.insert(band->GetRasterDataType());
133 template<
class Iterator>
134 std::set<GDALDataType> dataTypes(Iterator first, Iterator last)
136 std::set<GDALDataType> types;
137 for (Iterator itr = first; itr != last; ++itr)
139 GDALDataset& dataset = **itr;
140 for (
int i = 1; i <= dataset.GetRasterCount(); ++i)
142 GDALRasterBand* band = dataset.GetRasterBand(i);
143 types.insert(band->GetRasterDataType());
150 extern VSGXCHANGE_DECLSPEC
bool getEXIF_LatitudeLongitudeAlititude(GDALDataset& dataset,
double& latitude,
double& longitude,
double& altitude);
153 extern VSGXCHANGE_DECLSPEC
bool getEXIF_LatitudeLongitudeAlititude(
const vsg::Object&
object,
double& latitude,
double& longitude,
double& altitude);
164 std::istream& operator>>(std::istream& input, in_brackets<T> field)
166 while (input.peek() ==
' ') input.get();
169 if (input.peek() ==
'(')
173 input >> field.value;
175 if constexpr (std::is_same_v<T, std::string>)
177 if (!field.value.empty() && field.value[field.value.size() - 1] ==
')')
179 field.value.erase(field.value.size() - 1);
184 while (input.peek() !=
')')
187 if (input.eof())
return input;
189 field.value.push_back(c);
194 if (input.peek() ==
')')
201 input >> field.value;
212 struct dms_in_brackets
214 dms_in_brackets(
double& angle) :
219 inline std::istream& operator>>(std::istream& input, dms_in_brackets field)
221 double degrees = 0.0, minutes = 0.0, seconds = 0.0;
222 input >> in_brackets(degrees) >> in_brackets(minutes) >> in_brackets(seconds);
223 field.value = degrees + (minutes + seconds / 60.0) / 60.0;
optional GDAL ReaderWriter
Definition gdal.h:37