@@ -1020,80 +1020,92 @@ namespace Isis {
1020
1020
1021
1021
isiscube.addObject (core);
1022
1022
1023
- if (dataset->GetSpatialRef ()) {
1024
- char ** projStr = new char *[1 ];
1025
- const OGRSpatialReference &oSRS = *dataset->GetSpatialRef ();
1026
- oSRS.exportToProj4 (projStr);
1027
- QString qProjStr = QString::fromStdString (std::string (projStr[0 ]) + " +type=crs" );
1028
- delete[] projStr[0 ];
1029
- delete[] projStr;
1030
-
1031
- char ** projJsonStr = new char *[1 ];
1032
- oSRS.exportToPROJJSON (projJsonStr, nullptr );
1033
- nlohmann::json projJson = nlohmann::json::parse (projJsonStr[0 ]);
1034
- CPLFree (projJsonStr);
1035
-
1036
- PvlGroup mappingGroup (" Mapping" );
1037
- mappingGroup.addKeyword (PvlKeyword (" ProjectionName" , " IProj" ));
1038
- mappingGroup.addKeyword (PvlKeyword (" EquatorialRadius" , toString (oSRS.GetSemiMajor ()), " meters" ));
1039
- mappingGroup.addKeyword (PvlKeyword (" PolarRadius" , toString (oSRS.GetSemiMinor ()), " meters" ));
1040
-
1041
- if (projJson.contains (" base_crs" )) {
1042
- projJson = projJson[" base_crs" ];
1043
- }
1023
+ m_label->addObject (isiscube);
1024
+ }
1044
1025
1045
- std::string direction = projJson[" coordinate_system" ][" axis" ][1 ][" direction" ];
1046
- if (direction == " east" ) {
1047
- mappingGroup.addKeyword (PvlKeyword (" LongitudeDirection" , " PositiveEast" ));
1048
- }
1049
- else if (direction == " west" ) {
1050
- mappingGroup.addKeyword (PvlKeyword (" LongitudeDirection" , " PositiveWest" ));
1051
- }
1052
- else {
1053
- QString msg = " Unknown direction [" + QString::fromStdString (direction) + " ]" ;
1054
- throw IException (IException::Programmer, msg, _FILEINFO_);
1055
- }
1056
- mappingGroup.addKeyword (PvlKeyword (" LongitudeDomain" , " 180" ));
1026
+ if (dataset->GetSpatialRef ()) {
1027
+ char ** projStr = new char *[1 ];
1028
+ const OGRSpatialReference &oSRS = *dataset->GetSpatialRef ();
1029
+ oSRS.exportToProj4 (projStr);
1030
+ QString qProjStr = QString::fromStdString (std::string (projStr[0 ]) + " +type=crs" );
1031
+ delete[] projStr[0 ];
1032
+ delete[] projStr;
1033
+
1034
+ char ** projJsonStr = new char *[1 ];
1035
+ oSRS.exportToPROJJSON (projJsonStr, nullptr );
1036
+ nlohmann::json projJson = nlohmann::json::parse (projJsonStr[0 ]);
1037
+ CPLFree (projJsonStr);
1038
+
1039
+ PvlGroup mappingGroup (" Mapping" );
1040
+ mappingGroup.addKeyword (PvlKeyword (" ProjectionName" , " IProj" ));
1041
+ mappingGroup.addKeyword (PvlKeyword (" EquatorialRadius" , toString (oSRS.GetSemiMajor ()), " meters" ));
1042
+ mappingGroup.addKeyword (PvlKeyword (" PolarRadius" , toString (oSRS.GetSemiMinor ()), " meters" ));
1043
+
1044
+ if (projJson.contains (" base_crs" )) {
1045
+ projJson = projJson[" base_crs" ];
1046
+ }
1047
+
1048
+ std::string direction = projJson[" coordinate_system" ][" axis" ][1 ][" direction" ];
1049
+ if (direction == " east" ) {
1050
+ mappingGroup.addKeyword (PvlKeyword (" LongitudeDirection" , " PositiveEast" ));
1051
+ }
1052
+ else if (direction == " west" ) {
1053
+ mappingGroup.addKeyword (PvlKeyword (" LongitudeDirection" , " PositiveWest" ));
1054
+ }
1055
+ else {
1056
+ QString msg = " Unknown direction [" + QString::fromStdString (direction) + " ]" ;
1057
+ throw IException (IException::Programmer, msg, _FILEINFO_);
1058
+ }
1059
+
1060
+ if (oSRS.GetSemiMajor () == oSRS.GetSemiMinor ()) {
1057
1061
mappingGroup.addKeyword (PvlKeyword (" LatitudeType" , " Planetocentric" ));
1058
- mappingGroup.addKeyword (PvlKeyword (" ProjStr" , qProjStr));
1059
-
1060
- // Read the GeoTransform and get the elements we care about
1061
- double *padfTransform = new double [6 ];
1062
- dataset->GetGeoTransform (padfTransform);
1063
- if (abs (padfTransform[1 ]) != abs (padfTransform[5 ])) {
1064
- delete[] padfTransform;
1065
- QString msg = " Vertical and horizontal resolution do not match" ;
1066
- throw IException (IException::Io, msg, _FILEINFO_);
1067
- }
1062
+ }
1063
+ else {
1064
+ mappingGroup.addKeyword (PvlKeyword (" LatitudeType" , " Planetographic" ));
1065
+ }
1068
1066
1069
- double dfScale;
1070
- double dfRes;
1071
- double upperLeftX;
1072
- double upperLeftY;
1073
- dfRes = padfTransform[1 ] * oSRS.GetLinearUnits ();
1074
- upperLeftX = padfTransform[0 ];
1075
- upperLeftY = padfTransform[3 ];
1076
- if (oSRS.IsProjected ()) {
1077
- const double dfDegToMeter = oSRS.GetSemiMajor () * M_PI / 180.0 ;
1078
- dfScale = dfDegToMeter / dfRes;
1079
- mappingGroup.addKeyword (PvlKeyword (" PixelResolution" , toString (dfRes), " meters/pixel" ));
1080
- }
1081
- else if (oSRS.IsGeographic ()) {
1082
- dfScale = 1.0 / dfRes;
1083
- mappingGroup.addKeyword (PvlKeyword (" PixelResolution" , toString (dfRes), " degrees/pixel" ));
1084
- }
1085
- else {
1086
- QString msg = " Gdal spatial reference is not Geographic or Projected" ;
1087
- throw IException (IException::Io, msg, _FILEINFO_);
1088
- }
1089
- mappingGroup.addKeyword (PvlKeyword (" Scale" , toString (dfScale), " pixels/degree" ));
1090
- mappingGroup.addKeyword (PvlKeyword (" UpperLeftCornerX" , toString (upperLeftX)));
1091
- mappingGroup.addKeyword (PvlKeyword (" UpperLeftCornerY" , toString (upperLeftY)));
1067
+ mappingGroup.addKeyword (PvlKeyword (" LongitudeDomain" , " 180" ));
1068
+ mappingGroup.addKeyword (PvlKeyword (" ProjStr" , qProjStr));
1069
+
1070
+ // Read the GeoTransform and get the elements we care about
1071
+ double *padfTransform = new double [6 ];
1072
+ dataset->GetGeoTransform (padfTransform);
1073
+ if (abs (padfTransform[1 ]) != abs (padfTransform[5 ])) {
1092
1074
delete[] padfTransform;
1075
+ QString msg = " Vertical and horizontal resolution do not match" ;
1076
+ throw IException (IException::Io, msg, _FILEINFO_);
1077
+ }
1093
1078
1094
- isiscube.addGroup (mappingGroup);
1079
+ double dfScale;
1080
+ double dfRes;
1081
+ double upperLeftX;
1082
+ double upperLeftY;
1083
+ dfRes = padfTransform[1 ] * oSRS.GetLinearUnits ();
1084
+ upperLeftX = padfTransform[0 ];
1085
+ upperLeftY = padfTransform[3 ];
1086
+ if (oSRS.IsProjected ()) {
1087
+ const double dfDegToMeter = oSRS.GetSemiMajor () * M_PI / 180.0 ;
1088
+ dfScale = dfDegToMeter / dfRes;
1089
+ mappingGroup.addKeyword (PvlKeyword (" PixelResolution" , toString (dfRes), " meters/pixel" ));
1095
1090
}
1096
- m_label->addObject (isiscube);
1091
+ else if (oSRS.IsGeographic ()) {
1092
+ dfScale = 1.0 / dfRes;
1093
+ mappingGroup.addKeyword (PvlKeyword (" PixelResolution" , toString (dfRes), " degrees/pixel" ));
1094
+ }
1095
+ else {
1096
+ QString msg = " Gdal spatial reference is not Geographic or Projected" ;
1097
+ throw IException (IException::Io, msg, _FILEINFO_);
1098
+ }
1099
+ mappingGroup.addKeyword (PvlKeyword (" Scale" , toString (dfScale), " pixels/degree" ));
1100
+ mappingGroup.addKeyword (PvlKeyword (" UpperLeftCornerX" , toString (upperLeftX)));
1101
+ mappingGroup.addKeyword (PvlKeyword (" UpperLeftCornerY" , toString (upperLeftY)));
1102
+ delete[] padfTransform;
1103
+
1104
+ PvlObject &isiscube = m_label->findObject (" IsisCube" );
1105
+ if (isiscube.hasGroup (" Mapping" )) {
1106
+ isiscube.deleteGroup (" Mapping" );
1107
+ }
1108
+ isiscube.addGroup (mappingGroup);
1097
1109
}
1098
1110
GDALClose (dataset);
1099
1111
@@ -1122,7 +1134,7 @@ namespace Isis {
1122
1134
*
1123
1135
*/
1124
1136
void Cube::reopen (QString access) {
1125
- if (!m_labelFile ) {
1137
+ if (!isOpen () ) {
1126
1138
QString msg = " Cube has not been opened yet. The filename to re-open is "
1127
1139
" unknown" ;
1128
1140
throw IException (IException::Programmer, msg, _FILEINFO_);
@@ -3024,7 +3036,6 @@ namespace Isis {
3024
3036
// update metadata
3025
3037
nlohmann::ordered_json jsonblob = this ->label ()->toJson ()[" Root" ];
3026
3038
nlohmann::ordered_json jsonOut;
3027
- // std::cout << jsonblob << std::endl;
3028
3039
for (auto & [key, val] : jsonblob.items ()) {
3029
3040
if (!val.contains (" Bytes" ) || key == " Label" ) {
3030
3041
jsonOut[key] = val;
@@ -3033,6 +3044,31 @@ namespace Isis {
3033
3044
std::string jsonblobstr = jsonOut.dump ();
3034
3045
std::string name = " CubeLabel" ;
3035
3046
gdalDataset ()->SetMetadataItem (name.c_str (), jsonblobstr.c_str (), " USGS" );
3047
+
3048
+ if (this ->label ()->findObject (" IsisCube" ).hasGroup (" Mapping" )) {
3049
+ PvlGroup &mappingGroup = this ->label ()->findObject (" IsisCube" ).findGroup (" Mapping" );
3050
+
3051
+ if (mappingGroup.hasKeyword (" ProjStr" )) {
3052
+ OGRSpatialReference *oSRS = new OGRSpatialReference ();
3053
+ oSRS->SetFromUserInput (mappingGroup.findKeyword (" ProjStr" )[0 ].toStdString ().c_str ());
3054
+
3055
+ gdalDataset ()->SetSpatialRef (oSRS);
3056
+
3057
+ double dfRes = (double )mappingGroup.findKeyword (" PixelResolution" ) / oSRS->GetLinearUnits ();
3058
+ double upperLeftX = (double ) mappingGroup.findKeyword (" UpperLeftCornerX" );
3059
+ double upperLeftY = (double ) mappingGroup.findKeyword (" UpperLeftCornerY" );
3060
+ double *padfTransform = new double [6 ];
3061
+ padfTransform[1 ] = dfRes;
3062
+ padfTransform[5 ] = -dfRes;
3063
+ padfTransform[0 ] = upperLeftX;
3064
+ padfTransform[3 ] = upperLeftY;
3065
+ gdalDataset ()->SetGeoTransform (padfTransform);
3066
+ delete oSRS;
3067
+ delete[] padfTransform;
3068
+ }
3069
+ }
3070
+
3071
+
3036
3072
return ;
3037
3073
}
3038
3074
0 commit comments