~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to gcore/gdaldefaultoverviews.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: gdaldefaultoverviews.cpp 18333 2009-12-18 15:50:43Z warmerdam $
 
2
 * $Id: gdaldefaultoverviews.cpp 22381 2011-05-16 21:14:22Z rouault $
3
3
 *
4
4
 * Project:  GDAL Core
5
5
 * Purpose:  Helper code to implement overview and mask support for many 
31
31
#include "gdal_priv.h"
32
32
#include "cpl_string.h"
33
33
 
34
 
CPL_CVSID("$Id: gdaldefaultoverviews.cpp 18333 2009-12-18 15:50:43Z warmerdam $");
 
34
CPL_CVSID("$Id: gdaldefaultoverviews.cpp 22381 2011-05-16 21:14:22Z rouault $");
35
35
 
36
36
/************************************************************************/
37
37
/*                        GDALDefaultOverviews()                        */
66
66
    CPLFree( pszInitName );
67
67
    CSLDestroy( papszInitSiblingFiles );
68
68
 
 
69
    CloseDependentDatasets();
 
70
}
 
71
 
 
72
/************************************************************************/
 
73
/*                       CloseDependentDatasets()                       */
 
74
/************************************************************************/
 
75
 
 
76
int GDALDefaultOverviews::CloseDependentDatasets()
 
77
{
 
78
    int bHasDroppedRef = FALSE;
69
79
    if( poODS != NULL )
70
80
    {
 
81
        bHasDroppedRef = TRUE;
71
82
        poODS->FlushCache();
72
83
        GDALClose( poODS );
73
84
        poODS = NULL;
77
88
    {
78
89
        if( bOwnMaskDS )
79
90
        {
 
91
            bHasDroppedRef = TRUE;
80
92
            poMaskDS->FlushCache();
81
93
            GDALClose( poMaskDS );
82
94
        }
83
95
        poMaskDS = NULL;
84
96
    }
 
97
 
 
98
    return bHasDroppedRef;
85
99
}
86
100
 
87
101
/************************************************************************/
189
203
 
190
204
        if( bExists )
191
205
        {
192
 
            poODS = (GDALDataset*) GDALOpen( osOvrFilename, poDS->GetAccess() );
 
206
            GDALOpenInfo oOpenInfo(osOvrFilename, poDS->GetAccess(),
 
207
                                   papszInitSiblingFiles);
 
208
            poODS = (GDALDataset*) GDALOpenInternal( oOpenInfo, NULL );
193
209
        }
194
210
    }
195
211
 
203
219
/* -------------------------------------------------------------------- */
204
220
    if( !poODS && !EQUAL(pszInitName,":::VIRTUAL:::") )
205
221
    {
206
 
        poODS = GDALFindAssociatedAuxFile( pszInitName, poDS->GetAccess(),
207
 
                                           poDS );
 
222
        int bTryFindAssociatedAuxFile = TRUE;
 
223
        if( papszInitSiblingFiles )
 
224
        {
 
225
            CPLString osAuxFilename = CPLResetExtension( pszInitName, "aux");
 
226
            int iSibling = CSLFindString( papszInitSiblingFiles,
 
227
                                        CPLGetFilename(osAuxFilename) );
 
228
            if( iSibling < 0 )
 
229
            {
 
230
                osAuxFilename = pszInitName;
 
231
                osAuxFilename += ".aux";
 
232
                iSibling = CSLFindString( papszInitSiblingFiles,
 
233
                                        CPLGetFilename(osAuxFilename) );
 
234
                if( iSibling < 0 )
 
235
                    bTryFindAssociatedAuxFile = FALSE;
 
236
            }
 
237
        }
 
238
 
 
239
        if (bTryFindAssociatedAuxFile)
 
240
        {
 
241
            poODS = GDALFindAssociatedAuxFile( pszInitName, poDS->GetAccess(),
 
242
                                            poDS );
 
243
        }
208
244
 
209
245
        if( poODS )
210
246
        {
410
446
    GDALProgressFunc pfnProgress, void * pProgressData)
411
447
 
412
448
{
413
 
    if( osOvrFilename.length() == 0 )
 
449
    if( osOvrFilename.length() == 0 && nOverviews > 0 )
414
450
    {
415
451
        int iSequence = 0;
416
452
        VSIStatBufL sStatBuf;
418
454
        for( iSequence = 0; iSequence < 100; iSequence++ )
419
455
        {
420
456
            osOvrFilename.Printf( "%s_%d.ovr", pszPhysicalFile, iSequence );
421
 
            if( VSIStatL( osOvrFilename, &sStatBuf ) != 0 )
 
457
            if( VSIStatExL( osOvrFilename, &sStatBuf, VSI_STAT_EXISTS_FLAG ) != 0 )
422
458
            {
423
459
                CPLString osAdjustedOvrFilename;
424
460
 
482
518
 
483
519
            osOvrFilename = CPLResetExtension(poDS->GetDescription(),"aux");
484
520
 
485
 
            if( VSIStatL( osOvrFilename, &sStatBuf ) == 0 )
 
521
            if( VSIStatExL( osOvrFilename, &sStatBuf, VSI_STAT_EXISTS_FLAG ) == 0 )
486
522
                osOvrFilename.Printf( "%s.aux", poDS->GetDescription() );
487
523
        }
488
524
    }
544
580
        {
545
581
            int    nOvFactor;
546
582
            GDALRasterBand * poOverview = poBand->GetOverview( j );
 
583
            if (poOverview == NULL)
 
584
                continue;
547
585
 
548
586
            nOvFactor = (int) 
549
587
                (0.5 + poBand->GetXSize() / (double) poOverview->GetXSize());
653
691
            {
654
692
                int    nOvFactor;
655
693
                GDALRasterBand * poOverview = poBand->GetOverview( j );
 
694
                if (poOverview == NULL)
 
695
                    continue;
656
696
 
657
697
                int bHasNoData;
658
698
                double noDataValue = poBand->GetNoDataValue(&bHasNoData);
664
704
                    (0.5 + poBand->GetXSize() / (double) poOverview->GetXSize());
665
705
 
666
706
                if( nOvFactor == - panOverviewList[i] 
667
 
                    || nOvFactor == GDALOvLevelAdjust( -panOverviewList[i], 
668
 
                                                       poBand->GetXSize() ) )
 
707
                    || (panOverviewList[i] < 0 &&
 
708
                        nOvFactor == GDALOvLevelAdjust( -panOverviewList[i],
 
709
                                                       poBand->GetXSize() )) )
669
710
                {
670
711
                    papoOverviewBands[nNewOverviews++] = poOverview;
671
712
                    break;
915
956
        for( iOver = 0; iOver < nOverviewCount; iOver++ )
916
957
        {
917
958
            GDALRasterBand *poOverBand = poBaseMask->GetOverview( iOver );
 
959
            if (poOverBand == NULL)
 
960
                continue;
918
961
            
919
962
            if( poOverBand->GetXSize() == poDS->GetRasterXSize() 
920
963
                && poOverBand->GetYSize() == poDS->GetRasterYSize() )
949
992
        pszBasename = poDS->GetDescription();
950
993
 
951
994
    // Don't bother checking for masks of masks. 
952
 
    if( EQUAL(CPLGetExtension(pszBasename),".msk") )
 
995
    if( EQUAL(CPLGetExtension(pszBasename),"msk") )
953
996
        return FALSE;
954
997
 
955
998
    osMskFilename.Printf( "%s.msk", pszBasename );
972
1015
/* -------------------------------------------------------------------- */
973
1016
/*      Open the file.                                                  */
974
1017
/* -------------------------------------------------------------------- */
975
 
    poMaskDS = (GDALDataset *) GDALOpen( osMskFilename, poDS->GetAccess() );
 
1018
    GDALOpenInfo oOpenInfo(osMskFilename, poDS->GetAccess(),
 
1019
                           papszInitSiblingFiles);
 
1020
    poMaskDS = (GDALDataset *) GDALOpenInternal( oOpenInfo, NULL );
976
1021
    CPLAssert( poMaskDS != poDS );
977
1022
 
978
1023
    if( poMaskDS == NULL )