May I please ask for assistance with this code? I'm trying to close a dataset with subdatasets and then reopen if the requested subdataset is found.
It segfaults for all but the last subdataset name ... and I'm at a loss for what I'm doing wrong. Thank you. Code below, and this gist documents it with a little more details: https://gist.github.com/mdsumner/2ffc9b4746454fa0152b4a250900e535 Cheers, Mike #include "gdal.h" #include "gdal_priv.h" #include <iostream> int main(int argc, char **argv) { GDALAllRegister(); auto poSrcDS = GDALDataset::Open(argv[1], GDAL_OF_RASTER, nullptr, nullptr, nullptr); if (poSrcDS == nullptr) { return 0; } char **papszSubdatasets = poSrcDS->GetMetadata("SUBDATASETS"); int nSubdatasets = CSLCount(papszSubdatasets); char *pszSubdatasetSource = nullptr; if (nSubdatasets > 0) { for (int j = 0; j < nSubdatasets; j += 2) { pszSubdatasetSource = CPLStrdup(strstr(papszSubdatasets[j], "=") + 1); GDALSubdatasetInfoH info = GDALGetSubdatasetInfo(pszSubdatasetSource); if ( EQUAL(argv[2], GDALSubdatasetInfoGetSubdatasetComponent(info))) { std::cout << pszSubdatasetSource << "\n"; poSrcDS->ReleaseRef(); poSrcDS = GDALDataset::Open(pszSubdatasetSource, GDAL_OF_RASTER, nullptr, nullptr, nullptr); CPLFree(pszSubdatasetSource); GDALDestroySubdatasetInfo(info); } } } poSrcDS->ReleaseRef(); return 1; } -- Michael Sumner Software and Database Engineer Australian Antarctic Division Hobart, Australia e-mail: mdsum...@gmail.com
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev