Kyle,

you didn't mention which driver was in question. I guess this is GeoTIFF ? 
I've looked at the code of the driver and it appears that it loads the .rpb 
and .imd files at least since GDAL 1.6.0. The new thing in GDAL 1.8.0 is that 
it also tries to load the _rpc.txt file. Is it that small difference which 
causes the slowdown you observe ?

In fact, setting GDAL_DISABLE_READDIR_ON_OPEN = TRUE might make things 
actually worse (w.r.t to that aspect of loading rpb/rpc/imd) since the driver 
has to really test the filesystem to look for the existence of the files, 
whereas by default it would rely on the papszSiblingsFile list.

Anyway, I've attached a patch (against SVN trunk) that differs the loading of 
RPC and IMD until necessary (that is to say when GetMetadata() or 
GetMetadataItem() is called with "RPC" or "IMD" metadata domain, or when 
GetFileList() is called).

Could you try it and report if it makes things better for you ?

Another idea to solve the performance problem would be to use an alternate 
GDALOpen() where you could provide the papszSiblingFile list. If you read 
several files in the same directory, you could build the list one and provide 
it multiple times afterwards.

Best regards,

Even

> Often, we need to open many raster files over a network connection with
> thousands of other files residing in the same directory.
> 
> 
> 
> Previously, we were using version 1.7.0 of GDAL (from FW Tools), and we
> used SetConfigOption("GDAL_DISABLE_READDIR_ON_OPEN", "TRUE")
> 
> to suppress the automatic search for sibling files.  This approach served
> us well.
> 
> 
> 
> We upgraded to 1.8.0.  It was quite a bit slower opening the raster files.
> I was able to get GDAL built in debug and stepped through the code and
> discovered the following:
> 
> 
> 
> 1.       It searches for several files containing RPC metadata.
> 
> 2.       It searches for files for PAM as well.
> 
> 
> 
> I was able to use SetConfigOption("GDAL_PAM_ENABLED", "NO") to suppress
> searching for PAM files.
> 
> 
> 
> However, I do not see a way to suppress searching for RPC metadata.  Does
> anyone know of a way to do this or other workarounds? If there is no way to
> currently do this, is the community open to adding this option?
> 
> 
> 
> I apologize if this question has been posted previously, but I haven't yet
> found a convenient way to search the archives.
> 
> 
> 
> Thanks,
> 
> Kyle
Index: frmts/gtiff/geotiff.cpp
===================================================================
--- frmts/gtiff/geotiff.cpp	(révision 21957)
+++ frmts/gtiff/geotiff.cpp	(copie de travail)
@@ -331,6 +331,11 @@
     int           FindRPCFile(char** papszSiblingFiles);
     CPLString     osIMDFile;
     int           FindIMDFile(char** papszSiblingFiles);
+    int           bSiblingFilesAreNull;
+    int           bHasSearchedRPC;
+    void          LoadRPC();
+    int           bHasSearchedIMD;
+    void          LoadIMD();
 
     int           bHasWarnedDisableAggressiveBandCaching;
 
@@ -2796,6 +2801,10 @@
     bDebugDontWriteBlocks = CSLTestBoolean(CPLGetConfigOption("GTIFF_DONT_WRITE_BLOCKS", "NO"));
 
     bIsFinalized = FALSE;
+
+    bSiblingFilesAreNull = FALSE;
+    bHasSearchedRPC = FALSE;
+    bHasSearchedIMD = FALSE;
 }
 
 /************************************************************************/
@@ -5561,6 +5570,8 @@
 
     this->eAccess = eAccess;
 
+    bSiblingFilesAreNull = (papszSiblingFiles == NULL);
+
 /* -------------------------------------------------------------------- */
 /*      Capture some information from the file that is of interest.     */
 /* -------------------------------------------------------------------- */
@@ -6216,45 +6227,14 @@
 
     bMetadataChanged = FALSE;
 
-/* -------------------------------------------------------------------- */
-/*      Check for RPC metadata in an RPB or _rpc.txt file.              */
-/* -------------------------------------------------------------------- */
-    if( bBaseIn )
+    if( bBaseIn && papszSiblingFiles != NULL)
     {
-        char **papszRPCMD = NULL;
-        /* Read Digital Globe .RPB file */
-        if (FindRPBFile(papszSiblingFiles))
-            papszRPCMD = GDALLoadRPBFile( osRPBFile.c_str(), NULL );
-        /* Read GeoEye _rpc.txt file */
-        if(papszRPCMD == NULL && FindRPCFile(papszSiblingFiles))
-            papszRPCMD = GDALLoadRPCFile( osRPCFile.c_str(), NULL );
-
-        if( papszRPCMD != NULL )
-        {
-            oGTiffMDMD.SetMetadata( papszRPCMD, "RPC" );
-            CSLDestroy( papszRPCMD );
-            bMetadataChanged = FALSE;
-        }
-        else
-            ReadRPCTag();
+        FindRPBFile(papszSiblingFiles);
+        FindRPCFile(papszSiblingFiles);
+        FindIMDFile(papszSiblingFiles);
     }
 
 /* -------------------------------------------------------------------- */
-/*      Check for RPC metadata in an RPB file.                          */
-/* -------------------------------------------------------------------- */
-    if( bBaseIn && FindIMDFile(papszSiblingFiles) )
-    {
-        char **papszIMDMD = GDALLoadIMDFile( osIMDFile.c_str(), NULL );
-
-        if( papszIMDMD != NULL )
-        {
-            oGTiffMDMD.SetMetadata( papszIMDMD, "IMD" );
-            CSLDestroy( papszIMDMD );
-            bMetadataChanged = FALSE;
-        }
-    }
-
-/* -------------------------------------------------------------------- */
 /*      Check for NODATA                                                */
 /* -------------------------------------------------------------------- */
     if( TIFFGetField( hTIFF, TIFFTAG_GDAL_NODATA, &pszText ) )
@@ -8232,6 +8212,58 @@
 }
 
 /************************************************************************/
+/*                              LoadRPC()                               */
+/************************************************************************/
+
+void GTiffDataset::LoadRPC()
+{
+    if (bHasSearchedRPC)
+        return;
+
+    bHasSearchedRPC = TRUE;
+
+    char **papszRPCMD = NULL;
+    /* Read Digital Globe .RPB file */
+    if (osRPBFile.size() != 0 || (bSiblingFilesAreNull && FindRPBFile(NULL)))
+        papszRPCMD = GDALLoadRPBFile( osRPBFile.c_str(), NULL );
+    /* Read GeoEye _rpc.txt file */
+    if(papszRPCMD == NULL &&
+        (osRPCFile.size() != 0 || (bSiblingFilesAreNull && FindRPCFile(NULL))))
+        papszRPCMD = GDALLoadRPCFile( osRPCFile.c_str(), NULL );
+
+    if( papszRPCMD != NULL )
+    {
+        oGTiffMDMD.SetMetadata( papszRPCMD, "RPC" );
+        CSLDestroy( papszRPCMD );
+    }
+    else
+        ReadRPCTag();
+}
+
+/************************************************************************/
+/*                              LoadIMD()                               */
+/************************************************************************/
+
+void GTiffDataset::LoadIMD()
+{
+    if (bHasSearchedIMD)
+        return;
+
+    bHasSearchedIMD = TRUE;
+
+    if (osIMDFile.size() != 0 || (bSiblingFilesAreNull && FindIMDFile(NULL)))
+    {
+        char **papszIMDMD = GDALLoadIMDFile( osIMDFile.c_str(), NULL );
+
+        if( papszIMDMD != NULL )
+        {
+            oGTiffMDMD.SetMetadata( papszIMDMD, "IMD" );
+            CSLDestroy( papszIMDMD );
+        }
+    }
+}
+
+/************************************************************************/
 /*                            GetMetadata()                             */
 /************************************************************************/
 
@@ -8241,6 +8273,12 @@
     if( pszDomain != NULL && EQUAL(pszDomain,"ProxyOverviewRequest") )
         return GDALPamDataset::GetMetadata( pszDomain );
 
+    else if( pszDomain != NULL && EQUAL(pszDomain,"RPC") )
+        LoadRPC();
+
+    else if( pszDomain != NULL && EQUAL(pszDomain,"IMD") )
+        LoadIMD();
+
     /* FIXME ? Should we call LookForProjection() to load GDALMD_AREA_OR_POINT ? */
     /* This can impact performances */
 
@@ -8285,7 +8323,13 @@
     if( pszDomain != NULL && EQUAL(pszDomain,"ProxyOverviewRequest") )
         return GDALPamDataset::GetMetadataItem( pszName, pszDomain );
 
-    if( (pszDomain == NULL || EQUAL(pszDomain, "")) &&
+    else if( pszDomain != NULL && EQUAL(pszDomain,"RPC") )
+        LoadRPC();
+
+    else if( pszDomain != NULL && EQUAL(pszDomain,"IMD") )
+        LoadIMD();
+
+    else if( (pszDomain == NULL || EQUAL(pszDomain, "")) &&
         pszName != NULL && EQUAL(pszName, GDALMD_AREA_OR_POINT) )
     {
         LookForProjection();
@@ -8459,6 +8503,12 @@
 {
     char **papszFileList = GDALPamDataset::GetFileList();
 
+    if (bSiblingFilesAreNull)
+    {
+        LoadRPC();
+        LoadIMD();
+    }
+
     if (osIMDFile.size() != 0)
         papszFileList = CSLAddString( papszFileList, osIMDFile );
     if (osRPBFile.size() != 0)
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to