@@ -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
0 commit comments