@@ -229,6 +229,8 @@ const char *VRTDataset::GetMetadataItem(const char *pszName,
229
229
{
230
230
if (EQUAL (pszName, " MULTI_THREADED_RASTERIO_LAST_USED" ))
231
231
return m_bMultiThreadedRasterIOLastUsed ? " 1" : " 0" ;
232
+ else if (EQUAL (pszName, " CheckCompatibleForDatasetIO()" ))
233
+ return CheckCompatibleForDatasetIO () ? " 1" : " 0" ;
232
234
}
233
235
return GDALDataset::GetMetadataItem (pszName, pszDomain);
234
236
}
@@ -2147,6 +2149,7 @@ bool VRTDataset::CheckCompatibleForDatasetIO() const
2147
2149
2148
2150
m_nCompatibleForDatasetIO = false ;
2149
2151
2152
+ GDALDataset *poFirstBandSourceDS = nullptr ;
2150
2153
for (int iBand = 0 ; iBand < nBands; iBand++)
2151
2154
{
2152
2155
auto poVRTBand = static_cast <VRTRasterBand *>(papoBands[iBand]);
@@ -2176,8 +2179,12 @@ bool VRTDataset::CheckCompatibleForDatasetIO() const
2176
2179
return false ;
2177
2180
2178
2181
if (poSource->m_nBand != iBand + 1 ||
2179
- poSource->m_bGetMaskBand || poSource->m_osSrcDSName .empty ())
2182
+ poSource->m_bGetMaskBand ||
2183
+ (nSources > 1 && poSource->m_osSrcDSName .empty ()))
2180
2184
return false ;
2185
+ if (nSources == 1 && poSource->m_osSrcDSName .empty ())
2186
+ poFirstBandSourceDS =
2187
+ poSource->GetRasterBand ()->GetDataset ();
2181
2188
osResampling = poSource->GetResampling ();
2182
2189
}
2183
2190
}
@@ -2200,12 +2207,19 @@ bool VRTDataset::CheckCompatibleForDatasetIO() const
2200
2207
if (poSource->GetType () != VRTSimpleSource::GetTypeStatic ())
2201
2208
return false ;
2202
2209
if (poSource->m_nBand != iBand + 1 ||
2203
- poSource->m_bGetMaskBand || poSource->m_osSrcDSName .empty ())
2210
+ poSource->m_bGetMaskBand ||
2211
+ (nSources > 1 && poSource->m_osSrcDSName .empty ()))
2204
2212
return false ;
2205
2213
if (!poSource->IsSameExceptBandNumber (poRefSource))
2206
2214
return false ;
2207
2215
if (osResampling.compare (poSource->GetResampling ()) != 0 )
2208
2216
return false ;
2217
+ if (nSources == 1 && poSource->m_osSrcDSName .empty () &&
2218
+ poFirstBandSourceDS !=
2219
+ poSource->GetRasterBand ()->GetDataset ())
2220
+ {
2221
+ return false ;
2222
+ }
2209
2223
}
2210
2224
}
2211
2225
}
0 commit comments