[gdal-dev] Gdalinfo.exe is magic, why not bindings ?

Even Rouault even.rouault at mines-paris.org
Mon Nov 28 13:58:09 EST 2011


Le lundi 28 novembre 2011 12:09:13, Florent JITIAUX a écrit :
> Hi all,
> 
> well i found the little error from my files. In fact blanks before the name
> of type of the file in the header (GENERAL_INFORMATION_FILE for example)
> missed. That's why i had :
> ERROR 1: Unrecognised data_struct_code value G.
> Field 000 initialization incorrect.
> ERROR 1: Unrecognised data_type_code value E.
> Field 000 initialization incorrect.
> 
> But the size of the control record was correct and size and offset of
> subfields too. Then it's possible to read data after the control record.

OK, exact error messages do help ! So the error is in the generic iso8211 lib, 
not in the SRP driver. If you are in position of compiling GDAL yourself, you 
can try the following patch that turns the error into a warning :

Index: frmts/iso8211/ddffielddefn.cpp
===================================================================
--- frmts/iso8211/ddffielddefn.cpp	(révision 23420)
+++ frmts/iso8211/ddffielddefn.cpp	(copie de travail)
@@ -281,7 +281,7 @@
         break;
 
       default:
-        CPLError( CE_Failure, CPLE_AppDefined, 
+        CPLError( CE_Warning, CPLE_AppDefined,
                   "Unrecognised data_struct_code value %c.\n"
                   "Field %s initialization incorrect.",
                   pachFieldArea[0], pszTag );
@@ -320,7 +320,7 @@
         break;
 
       default:
-        CPLError( CE_Failure, CPLE_AppDefined, 
+        CPLError( CE_Warning, CPLE_AppDefined,
                   "Unrecognised data_type_code value %c.\n"
                   "Field %s initialization incorrect.",
                   pachFieldArea[1], pszTag );



It would be interesting if you could share the .gen file so we can better 
investigate.

In any case a ticket in Trac would be welcome so that action can follow.

> 
> I still have a problem to understand how gdalinfo.exe works.
> In the Gdalinfo.class, if the dataset can't be read the dataset = null.
> Getting the driver is done by calling the method ".GetDriver()" from the
> Dataset class. Well if the dataset is null it's impossible to get the
> driver. And in the Gdalinfo.class (in the Gdalinfo.c too) if the dataset is
> null the program exit.
> But as I say I can get the driver with "gdal.IdentifyDriver(pszFilename)".

The IdentifyDriver() doesn't check for the error status, so if the dataset 
return is non null, it will work.

> 
> Then, for me gdalinfo.exe is still magic.

Well, as I said previously, the Open() method of the Java/Python/... bindings 
has extra logic to check for the error status, that a GDALOpen() doesn't do. 
Hence the difference of behaviour between the C/C++ utilities and the Java 
code.

> 
> About Qgis, I download the source to understand how it works. I found in
> the GdalTools_utils.py functions that call gdalinfo with Qprocess. If I
> understand correctly, this is a Qt class "used to start external programs
> and to communicate with them". After Qgis get the output and splits it to
> get information like information giving by gdalinfo.exe.
> That's why I said Qgis use gdalinfo.exe.

The GdalTools do indeed fork GDAL command line utilities. But the core of qgis 
directly uses the GDAL C API. In both cases, the GDAL python bindings are not 
used.

> 
> There's no way to get information with bindings like gdalinfo.exe when
> files contains errors ?

Not without changing code.

I'm wondering if a more general alternative to the ad-hoc fix I proposed above 
would be to alter the binding code to just reset the error status flag if the 
dataset is not null.

Index: swig/include/gdal.i
===================================================================
--- swig/include/gdal.i	(révision 23420)
+++ swig/include/gdal.i	(copie de travail)
@@ -670,9 +670,7 @@
   GDALDatasetShadow *ds = GDALOpen( utf8_path, eAccess );
   if( ds != NULL && CPLGetLastErrorType() == CE_Failure )
   {
-      if ( GDALDereferenceDataset( ds ) <= 0 )
-          GDALClose(ds);
-      ds = NULL;
+      CPLErrorReset();
   }
   return (GDALDatasetShadow*) ds;
 }
@@ -692,9 +690,7 @@
   GDALDatasetShadow *ds = GDALOpen( utf8_path, eAccess );
   if( ds != NULL && CPLGetLastErrorType() == CE_Failure )
   {
-      if ( GDALDereferenceDataset( ds ) <= 0 )
-          GDALClose(ds);
-      ds = NULL;
+      CPLErrorReset();
   }
   return (GDALDatasetShadow*) ds;
 }
@@ -708,9 +704,7 @@
   GDALDatasetShadow *ds = GDALOpenShared( utf8_path, eAccess );
   if( ds != NULL && CPLGetLastErrorType() == CE_Failure )
   {
-      if ( GDALDereferenceDataset( ds ) <= 0 )
-          GDALClose(ds);
-      ds = NULL;
+      CPLErrorReset();
   }
   return (GDALDatasetShadow*) ds;
 }





More information about the gdal-dev mailing list