Skip to content

Commit 7f8ec1e

Browse files
authored
Merge pull request #3 from acpaquette/gdalchanges
Gdal 3.12 Changes
2 parents 287063e + 898642b commit 7f8ec1e

5 files changed

Lines changed: 61 additions & 33 deletions

File tree

isis/src/base/objs/Blob/Blob.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ namespace Isis {
252252

253253
void Blob::ReadGdal(GDALDataset *dataset) {
254254
try {
255-
std::string key = QString(p_type + "_" + p_blobName).toStdString();
256-
255+
std::string key = p_type.toStdString() + "_" + p_blobName.toStdString();
256+
257257
CPLStringList metadata = CPLStringList(dataset->GetMetadata("json:ISIS3"), false);
258-
const char *metadataItem = CPLParseNameValue(metadata[0], nullptr);
259-
ordered_json jsonblob = nlohmann::ordered_json::parse(metadataItem);
258+
const char *metadataJsonString = metadata[0];
259+
ordered_json jsonblob = nlohmann::ordered_json::parse(metadataJsonString);
260260

261261
if (jsonblob.find(key) == jsonblob.end()) {
262262
QString msg = "The key [" + QString::fromStdString(key) + "] does not exist on the geodata set.";
263-
throw IException( IException::Io, msg, _FILEINFO_);
263+
throw IException(IException::Io, msg, _FILEINFO_);
264264
}
265265

266266
std::string blobData = jsonblob[key]["_data"];
@@ -270,7 +270,9 @@ namespace Isis {
270270
Pvl::readObject(pvl, jsonblob);
271271

272272
p_blobName = QString::fromStdString(jsonblob[key]["Name"]);
273-
p_type = QString::fromStdString(jsonblob[key]["_container_name"]);
273+
if (jsonblob[key].contains("_container_name")) {
274+
p_type = QString::fromStdString(jsonblob[key]["_container_name"]);
275+
}
274276

275277
Find(pvl);
276278
ReadData(blobData);
@@ -481,12 +483,25 @@ namespace Isis {
481483
}
482484

483485
// update metadata
484-
string jsonblobstr = pvl.toJson()["Root"].dump();
485-
string key = this->Type().toStdString() + "_" + this->Name().toStdString();
486-
dataset->SetMetadataItem(key.c_str(), jsonblobstr.c_str(), "json:ISIS3");
486+
std::string key = this->Type().toStdString() + "_" + (this->Name().toStdString());
487+
488+
CPLStringList metadata = CPLStringList(dataset->GetMetadata("json:ISIS3"), false);
489+
ordered_json jsonblob = {};
490+
if (metadata[0] != nullptr) {
491+
const char *metadataJsonString = metadata[0];
492+
jsonblob = nlohmann::ordered_json::parse(metadataJsonString);
493+
}
494+
jsonblob[key] = pvl.toJson()["Root"][key];
495+
string jsonblobstr = jsonblob.dump();
496+
497+
char **outputMetadata = new char*[1];
498+
outputMetadata[0] = jsonblobstr.data();
499+
dataset->SetMetadata(outputMetadata, "json:ISIS3");
500+
delete []outputMetadata;
487501
}
488502
catch(exception &e) {
489-
cout << "Failed to write blob [" + p_blobName + "]: " << e.what() << endl;
503+
QString msg = "Failed to write blob [" + p_blobName + "]: " + QString(e.what());
504+
throw IException(IException::Unknown, msg, _FILEINFO_);
490505
}
491506
}
492507

isis/src/base/objs/Blob/Blob.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ namespace Isis {
7272
const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>());
7373
virtual void Read(const Pvl &pvl, std::istream &is,
7474
const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>());
75-
void ReadData(std::string &hexdata);
76-
7775
void Write(const QString &file);
7876
void Write(Pvl &pvl, std::fstream &stm,
7977
const QString &detachedFileName = "", bool overwrite=true, bool inline_data=true);
@@ -88,9 +86,10 @@ namespace Isis {
8886
void Find(const Pvl &pvl, const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>());
8987
virtual void ReadInit();
9088
virtual void ReadData(std::istream &is);
89+
void ReadData(std::string &hexdata);
9190
virtual void WriteInit();
9291
virtual void WriteData(std::fstream &os);
93-
virtual void WriteData(std::stringstream &os);
92+
void WriteData(std::stringstream &os);
9493

9594
PvlObject p_blobPvl; //!< Pvl Blob object
9695
QString p_blobName; //!< Name of the Blob object

isis/src/base/objs/Cube/Cube.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ namespace Isis {
703703
band->SetOffset(base());
704704
band->SetNoDataValue(noDataValue);
705705
band->Fill(noDataValue);
706+
band->CreateMaskBand(GMF_ALPHA);
707+
band->GetMaskBand()->Fill(255);
706708
}
707709
GDALClose(dataset);
708710
CSLDestroy( papszOptions );
@@ -969,19 +971,10 @@ namespace Isis {
969971
CPLStringList metadata = CPLStringList(dataset->GetMetadata("json:ISIS3"), false);
970972

971973
m_label = new Pvl();
972-
if (metadata) {
973-
for (int i = 0; i < metadata.size(); i++) {
974-
const char *metadataItem = CPLParseNameValue(metadata[i], nullptr);
975-
nlohmann::ordered_json metadataAsJson = nlohmann::ordered_json::parse(metadataItem);
976-
Pvl pvl;
977-
Pvl::readObject(pvl, metadataAsJson);
978-
for (int i = 0; i < pvl.objects(); i++) {
979-
m_label->addObject(pvl.object(i));
980-
}
981-
for (int i = 0; i < pvl.groups(); i++) {
982-
m_label->addGroup(pvl.group(i));
983-
}
984-
}
974+
if (metadata[0] != nullptr) {
975+
const char *metadataJsonString = metadata[0];
976+
nlohmann::ordered_json metadataAsJson = nlohmann::ordered_json::parse(metadataJsonString);
977+
Pvl::readObject(*m_label, metadataAsJson);
985978
}
986979
else {
987980
// Setup the PVL
@@ -3031,9 +3024,27 @@ namespace Isis {
30313024
jsonOut[key] = val;
30323025
}
30333026
}
3034-
std::string jsonblobstr = jsonOut.dump();
3035-
std::string name = "CubeLabel";
3036-
gdalDataset()->SetMetadataItem(name.c_str(), jsonblobstr.c_str(), "json:ISIS3");
3027+
3028+
char ** outputMetadata = new char*[1];
3029+
// Check for existing data, if there is data then only update the label
3030+
CPLStringList metadata = CPLStringList(gdalDataset()->GetMetadata("json:ISIS3"), false);
3031+
3032+
std::string jsonblobstr = "";
3033+
if (metadata[0] != nullptr) {
3034+
const char *metadataJsonString = metadata[0];
3035+
nlohmann::ordered_json metadataAsJson = nlohmann::ordered_json::parse(metadataJsonString);
3036+
for (auto& [key, val] : jsonOut.items()) {
3037+
metadataAsJson[key] = val;
3038+
}
3039+
jsonblobstr = metadataAsJson.dump();
3040+
}
3041+
else {
3042+
jsonblobstr = jsonOut.dump();
3043+
}
3044+
3045+
outputMetadata[0] = jsonblobstr.data();
3046+
gdalDataset()->SetMetadata(outputMetadata, "json:ISIS3");
3047+
delete []outputMetadata;
30373048

30383049
if (this->label()->findObject("IsisCube").hasGroup("Mapping")) {
30393050
PvlGroup &mappingGroup = this->label()->findObject("IsisCube").findGroup("Mapping");

isis/src/base/objs/ImageIoHandler/GdalIoHandler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ namespace Isis {
4747

4848
// Check if we need to create the mask band
4949
if ((m_geodataSet->GetAccess() == GA_Update) && (m_driverName != "ISIS3")) {
50-
m_geodataSet->CreateMaskBand(8);
51-
m_geodataSet->GetRasterBand(1)->GetMaskBand()->Fill(255);
50+
for (int i = 1; i <= m_bands; i++) {
51+
GDALRasterBand *band = m_geodataSet->GetRasterBand(i);
52+
band->CreateMaskBand(GMF_ALPHA);
53+
band->GetMaskBand()->Fill(255);
54+
}
5255
}
5356

5457
GDALRasterBand *band = m_geodataSet->GetRasterBand(1);

isis/tests/TiffFixtures.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ namespace Isis {
6464
band->SetScale(1);
6565
band->SetOffset(0);
6666
band->SetNoDataValue(noDataValue);
67+
band->CreateMaskBand(GMF_ALPHA);
68+
band->GetMaskBand()->Fill(255);
6769
}
68-
dataset->CreateMaskBand(GMF_ALPHA);
69-
dataset->GetRasterBand(1)->GetMaskBand()->Fill(255);
7070
dataset->Close();
7171
}
7272
}

0 commit comments

Comments
 (0)