CPLErr PDSDataset::IBuildOverviews( const char *pszResampling, int nOverviews, int *panOverviewList, int nListBands, int *panBandList, GDALProgressFunc pfnProgress, void * pProgressData ) { if( poCompressedDS != NULL ) return poCompressedDS->BuildOverviews( pszResampling, nOverviews, panOverviewList, nListBands, panBandList, pfnProgress, pProgressData ); else return RawDataset::IBuildOverviews( pszResampling, nOverviews, panOverviewList, nListBands, panBandList, pfnProgress, pProgressData ); }
void output_geotiff ( rgb_image & out ) { int i, r, c; int val; char s[2]; OGRSpatialReference ref; GDALDataset *df; char *wkt = NULL; GDALRasterBand *bd; double trans[6]; GDALDriver *gt; char **options = NULL; int ov[] = { 2, 4, 8, 16, 32 }; int nov; int n; int bands[] = { 1, 2, 3 }; char file[1000]; int block, ir, rows; options = CSLSetNameValue ( options, "TILED", "NO" ); options = CSLSetNameValue ( options, "BLOCKXSIZE", "256" ); options = CSLSetNameValue ( options, "BLOCKYSIZE", "256" ); options = CSLSetNameValue ( options, "COMPRESS", "LZW" ); gt = GetGDALDriverManager()->GetDriverByName("GTiff"); if ( !gt ) { fprintf(stderr,"Could not get GTiff driver\n"); exit(1); } strcpy ( file, p.value("output_file").c_str() ); df = gt->Create( file, out.cols, out.rows, 3, GDT_Byte, options ); if( df == NULL ) { fprintf(stderr,"Could not create %s\n", file ); exit(1); } trans[0] = p.dvalue("easting_left"); trans[1] = p.dvalue("output_cell_size"); trans[2] = 0.0; trans[3] = p.dvalue("northing_top"); trans[4] = 0.0; trans[5] = -p.dvalue("output_cell_size"); df->SetGeoTransform ( trans ); ref.SetUTM ( p.ivalue("utm_zone") ); ref.SetWellKnownGeogCS ( "NAD27" ); ref.exportToWkt ( &wkt ); df->SetProjection(wkt); CPLFree ( wkt ); for ( ir = 0; ir < out.rows; ir += bs ) { rows = out.rows - ir; if ( rows > bs ) rows = bs; //printf("Writer waiting for %d\n",ir ); pe.wait_for("data",ir); for ( i = 0; i < 3; i++ ) { bd = df->GetRasterBand(i+1); bd->RasterIO( GF_Write, 0, ir, out.cols, rows, out.img[i].data+ir*out.cols, out.cols, rows, GDT_Byte, 0, 0 ); } } delete df; df = (GDALDataset *)GDALOpen ( file, GA_Update ); if( df == NULL ) { fprintf(stderr,"Could not open for update %s\n", file ); exit(1); } nov = p.ivalue("overviews"); if ( nov > 5 ) nov = 5; if ( nov > 0 ) { df->BuildOverviews("NEAREST", nov, ov, 3, bands, NULL, NULL ); } }
void output_dist_geotiff ( image<float> & dist, image<unsigned char> & v ) { int r, c; int val; OGRSpatialReference ref; GDALDataset *df; char *wkt = NULL; GDALRasterBand *bd; double trans[6]; GDALDriver *gt; char **options = NULL; int ov[] = { 2, 4, 8, 16, 32 }; int nov; int n; char file[1000]; options = CSLSetNameValue ( options, "TILED", "NO" ); options = CSLSetNameValue ( options, "COMPRESS", "LZW" ); gt = GetGDALDriverManager()->GetDriverByName("GTiff"); if ( !gt ) { fprintf(stderr,"Could not get GTiff driver\n"); exit(1); } strcpy ( file, p.value("dist_file").c_str() ); df = gt->Create( file, dist.cols, dist.rows, 1, GDT_Byte, options ); if( df == NULL ) { fprintf(stderr,"Could not create %s\n", file ); exit(1); } trans[0] = p.dvalue("easting_left"); trans[1] = p.dvalue("output_cell_size"); trans[2] = 0.0; trans[3] = p.dvalue("northing_top"); trans[4] = 0.0; trans[5] = -p.dvalue("output_cell_size"); df->SetGeoTransform ( trans ); ref.SetUTM ( p.ivalue("utm_zone") ); ref.SetWellKnownGeogCS ( "NAD27" ); ref.exportToWkt ( &wkt ); df->SetProjection(wkt); CPLFree ( wkt ); for ( r=0; r < dist.rows; r++ ) { for ( c=0; c < dist.cols; c++ ) { val = int(sqrt(dist[r][c])+0.5); if ( val > 255 ) val = 255; v[r][c] = val; } } bd = df->GetRasterBand(1); bd->RasterIO( GF_Write, 0, 0, v.cols, v.rows, v.data, v.cols, v.rows, GDT_Byte, 0, 0 ); delete df; df = (GDALDataset *)GDALOpen ( file, GA_Update ); if( df == NULL ) { fprintf(stderr,"Could not open for update %s\n", file ); exit(1); } nov = p.ivalue("overviews"); if ( nov > 5 ) nov = 5; if ( nov > 0 ) { n = 1; df->BuildOverviews("NEAREST", nov, ov, 1, &n, NULL, NULL ); } }
bool wxGISGPCreateOverviewsTool::Execute(ITrackCancel* pTrackCancel) { if(!Validate()) { //add messages to pTrackCancel if(pTrackCancel) pTrackCancel->PutMessage(_("Unexpected error occurred"), -1, enumGISMessageErr); return false; } IGxObjectContainer* pGxObjectContainer = dynamic_cast<IGxObjectContainer*>(m_pCatalog); if(!pGxObjectContainer) { //add messages to pTrackCancel if(pTrackCancel) pTrackCancel->PutMessage(_("Error getting catalog object"), -1, enumGISMessageErr); return false; } wxString sSrcPath = m_paParam[0]->GetValue(); IGxObject* pGxObject = pGxObjectContainer->SearchChild(sSrcPath); if(!pGxObject) { //add messages to pTrackCancel if(pTrackCancel) pTrackCancel->PutMessage(_("Error getting source object"), -1, enumGISMessageErr); return false; } IGxDataset* pGxDataset = dynamic_cast<IGxDataset*>(pGxObject); if(!pGxDataset) { //add messages to pTrackCancel if(pTrackCancel) pTrackCancel->PutMessage(_("Source object is of incompatible type"), -1, enumGISMessageErr); return false; } wxGISRasterDatasetSPtr pSrcDataSet = boost::dynamic_pointer_cast<wxGISRasterDataset>(pGxDataset->GetDataset()); if(!pSrcDataSet) { //add messages to pTrackCancel if(pTrackCancel) pTrackCancel->PutMessage(_("Source dataset is of incompatible type"), -1, enumGISMessageErr); return false; } if(!pSrcDataSet->IsOpened()) if(!pSrcDataSet->Open(true)) return false; GDALDataset* poGDALDataset = pSrcDataSet->GetRaster(); if(!poGDALDataset) { //add messages to pTrackCancel if(pTrackCancel) pTrackCancel->PutMessage(_("Error getting raster"), -1, enumGISMessageErr); return false; } wxString sResampleMethod = m_paParam[1]->GetValue(); wxString sCompress = m_paParam[2]->GetValue(); CPLSetConfigOption( "COMPRESS_OVERVIEW", sCompress.mb_str() ); if(pSrcDataSet->GetSubType() == enumRasterImg) { CPLSetConfigOption( "USE_RRD", "YES" ); CPLSetConfigOption( "HFA_USE_RRD", "YES" ); } else CPLSetConfigOption( "USE_RRD", "NO" ); wxArrayString saLevels = m_paParam[3]->GetValue().GetArrayString(); int anOverviewList[25] = {0}; int nLevelCount = saLevels.GetCount(); for(size_t i = 0; i < saLevels.GetCount(); ++i) { int nLevel = wxAtoi(saLevels[i]); anOverviewList[i] = nLevel; } CPLErr eErr = poGDALDataset->BuildOverviews( sResampleMethod.mb_str(), nLevelCount, anOverviewList, 0, NULL, ExecToolProgress, (void*)pTrackCancel ); if(eErr != CE_None) { if(pTrackCancel) { const char* pszErr = CPLGetLastErrorMsg(); pTrackCancel->PutMessage(wxString::Format(_("BuildOverviews failed! GDAL error: %s"), wxString(pszErr, wxConvUTF8).c_str()), -1, enumGISMessageErr); } return false; } pSrcDataSet->SetHasOverviews(true); return true; }