[Gdal-dev] BuildOverviews()

Chapman, Martin MChapman at sanz.com
Fri Nov 19 00:40:29 EST 2004


Gao,

I've built overviews successfully before for a tif but I can't remember if it was tiled or stripped.  I think I've done both before though.  See the code snippets below if it's any help:

Let me know if it works.
Martin

// this goes some where in your code...
GDALAllRegister();

GDALDataset* m_pDataset = (GDALDataset*) GDALOpen(m_sFileName.c_str(), GA_ReadOnly);
GDALDefaultOverviews* m_pGDALDefaultOverviews = new GDALDefaultOverviews();

if( m_pDataset == NULL )
{
	const char* pszError = CPLGetLastErrorMsg();
	AfxMessageBox(pszError);
	return false;
}
//........


// I use this function to generate the ovr file

void CImagePortDoc::GenerateOverViewFile()
{
	try
	{
		if (!m_pDataset)
			return;
	
		string ovr_file;
		string ovr_name;
		string file = m_sFileName;
		string::size_type pos = file.find('.');

		if (pos == string::npos)
		{
			ovr_file = file + ".ovr";
			ovr_name = file;
		}
		else
		{
			ovr_file.insert(0, file.begin(), &file[pos]);
			ovr_name = ovr_file;
			ovr_file += ".ovr";
		}

		CMainFrame* pMainFrame = (CMainFrame*) AfxGetMainWnd();
		if (pMainFrame->FileExists(ovr_file))
		{
			CString sMessage = _T("The file ");
			sMessage += ovr_file.c_str();
			sMessage += _T(" exists.\nDo you want to overwrite it?");
			if (AfxMessageBox(sMessage, MB_YESNO|MB_ICONQUESTION) == IDNO)
				return;

			DeleteFile(ovr_file.c_str());
		}
		else
		{
			if (AfxMessageBox("Build the overviews?", MB_YESNO|MB_ICONQUESTION) == IDNO)
				return;
		}

		BeginWaitCursor();

		if (!m_pGDALDefaultOverviews->IsInitialized())
			m_pGDALDefaultOverviews->Initialize(m_pDataset, ovr_file.c_str());

		int nOverviewCount = m_pGDALDefaultOverviews->GetOverviewCount(1);

		int* pOverviewList = NULL;
		nOverviewCount = 12;
		pOverviewList = new int[nOverviewCount];
		int nNumberOfBands = m_vBandList.size();
		
		pOverviewList[0] = 2;
		pOverviewList[1] = 4;
		pOverviewList[2] = 8;
		pOverviewList[3] = 16;
		pOverviewList[4] = 32;
		pOverviewList[5] = 64;
		pOverviewList[6] = 128;
		pOverviewList[7] = 256;
		pOverviewList[8] = 512;
		pOverviewList[9] = 1024;
		pOverviewList[10] = 2048;
		pOverviewList[11] = 4096;

		int* pBandList = new int[nNumberOfBands];
		for (int n = 0; n < nNumberOfBands; n++)
			pBandList[n] = n + 1;

		CPLErr err = m_pGDALDefaultOverviews->BuildOverviews(ovr_name.c_str(), "NEAREST", nOverviewCount, pOverviewList, nNumberOfBands, pBandList, GDALDummyProgress, NULL);

		if (pBandList) delete pBandList;
		if (pOverviewList) delete pOverviewList;

		if (err != CE_None)
			return;

		m_vResLevels.clear();
		for (int k = 0; k < nOverviewCount; k++)
			m_vResLevels.push_back(k);

		UpdateAllViews(NULL);

		EndWaitCursor();
	
	}
	catch(...)
	{
		AfxMessageBox("An unspecified error occurred");
	}
}



-----Original Message-----
From:	Gao, Peng [mailto:pgao at esri.com]
Sent:	Thu 11/18/2004 4:40 PM
To:	gdal-dev at remotesensing.org
Cc:	
Subject:	[Gdal-dev] BuildOverviews()
I tried to build the overviews on a tiff image, and it failed because
the format does not support building of overviews. What formats are
currently supporting building the overviews (pyramid)? I understand
the overviews if built, are stored in a tiff image with a special
extension .ovr. Are these overview tiffs tiled or scanline based?

Gao, Peng

_______________________________________________
Gdal-dev mailing list
Gdal-dev at xserve.flids.com
http://xserve.flids.com/mailman/listinfo/gdal-dev






More information about the Gdal-dev mailing list