// static function- pointer set in driver GDALDataset *KEADataset::Create( const char * pszFilename, int nXSize, int nYSize, int nBands, GDALDataType eType, char ** papszParmList ) { H5::H5File *keaImgH5File = CreateLL( pszFilename, nXSize, nYSize, nBands, eType, papszParmList ); if( keaImgH5File == NULL ) return NULL; bool bThematic = CPLTestBool(CSLFetchNameValueDef( papszParmList, "THEMATIC", "FALSE" )); try { // create our dataset object KEADataset *pDataset = new KEADataset( keaImgH5File, GA_Update ); pDataset->SetDescription( pszFilename ); // set all to thematic if asked if( bThematic ) { for( int nCount = 0; nCount < nBands; nCount++ ) { GDALRasterBand *pBand = pDataset->GetRasterBand(nCount+1); pBand->SetMetadataItem("LAYER_TYPE", "thematic"); } } return pDataset; } catch (kealib::KEAIOException &e) { CPLError( CE_Failure, CPLE_OpenFailed, "Attempt to create file `%s' failed. Error: %s\n", pszFilename, e.what() ); return NULL; } }
GDALDataset *KEADataset::CreateCopy( const char * pszFilename, GDALDataset *pSrcDs, CPL_UNUSED int bStrict, char ** papszParmList, GDALProgressFunc pfnProgress, void *pProgressData ) { // get the data out of the input dataset int nXSize = pSrcDs->GetRasterXSize(); int nYSize = pSrcDs->GetRasterYSize(); int nBands = pSrcDs->GetRasterCount(); GDALDataType eType = (nBands == 0) ? GDT_Unknown : pSrcDs->GetRasterBand(1)->GetRasterDataType(); H5::H5File *keaImgH5File = CreateLL( pszFilename, nXSize, nYSize, nBands, eType, papszParmList ); if( keaImgH5File == NULL ) return NULL; bool bThematic = CSLTestBoolean(CSLFetchNameValueDef( papszParmList, "THEMATIC", "FALSE" )); try { // create the imageio kealib::KEAImageIO *pImageIO = new kealib::KEAImageIO(); // open the file pImageIO->openKEAImageHeader( keaImgH5File ); // copy file if( !KEACopyFile( pSrcDs, pImageIO, pfnProgress, pProgressData) ) { delete pImageIO; return NULL; } // close it try { pImageIO->close(); } catch (kealib::KEAIOException &e) { } delete pImageIO; // now open it again - because the constructor loads all the info // in we need to copy the data first.... keaImgH5File = kealib::KEAImageIO::openKeaH5RW( pszFilename ); // and wrap it in a dataset KEADataset *pDataset = new KEADataset( keaImgH5File, GA_Update ); pDataset->SetDescription( pszFilename ); // set all to thematic if asked - overrides whatever set by CopyFile if( bThematic ) { for( int nCount = 0; nCount < nBands; nCount++ ) { GDALRasterBand *pBand = pDataset->GetRasterBand(nCount+1); pBand->SetMetadataItem("LAYER_TYPE", "thematic"); } } for( int nCount = 0; nCount < nBands; nCount++ ) { pDataset->GetRasterBand(nCount+1)->SetColorInterpretation( pSrcDs->GetRasterBand(nCount+1)->GetColorInterpretation()); } // KEA has no concept of per-dataset mask band for now. for( int nCount = 0; nCount < nBands; nCount++ ) { if( pSrcDs->GetRasterBand(nCount+1)->GetMaskFlags() == 0 ) // Per-band mask { pDataset->GetRasterBand(nCount+1)->CreateMaskBand(0); GDALRasterBandCopyWholeRaster( (GDALRasterBandH)pSrcDs->GetRasterBand(nCount+1)->GetMaskBand(), (GDALRasterBandH)pDataset->GetRasterBand(nCount+1)->GetMaskBand(), NULL, NULL, NULL); } } return pDataset; } catch (kealib::KEAException &e) { CPLError( CE_Failure, CPLE_OpenFailed, "Attempt to create file `%s' failed. Error: %s\n", pszFilename, e.what() ); return NULL; } }