def log_error_handler(err_class, err_no, msg): logging.error('{} - {}: {}'.format( pb.get_gdal_constant_name('CE', err_class), pb.get_gdal_constant_name('CPLE', err_no), msg))
logging.error('{} - {}: {}'.format( pb.get_gdal_constant_name('CE', err_class), pb.get_gdal_constant_name('CPLE', err_no), msg)) # Use your custom error handler to print messages to the screen. import logging gdal.PushErrorHandler(log_error_handler) ds1 = gdal.Open(os.path.join(data_dir, 'Switzerland', 'dem_class.tif')) ds2 = gdal.Open( os.path.join(data_dir, 'Landsat', 'Washington', 'nat_color.tif')) do_something(ds1, ds2) del ds1, ds2 # Or use it to write to a file (change to file path!). import logging logging.basicConfig(filename='d:/temp/log.txt') gdal.PushErrorHandler(log_error_handler) ds1 = gdal.Open(os.path.join(data_dir, 'Switzerland', 'dem_class.tif')) ds2 = gdal.Open( os.path.join(data_dir, 'Landsat', 'Washington', 'nat_color.tif')) do_something(ds1, ds2) del ds1, ds2 ###################### Get constant names with ospybook ##################### import ospybook as pb # Get the GDT constant that has a value of 5. print(pb.get_gdal_constant_name('GDT', 5))
logging.error('{} - {}: {}'.format( pb.get_gdal_constant_name('CE', err_class), pb.get_gdal_constant_name('CPLE', err_no), msg)) # Use your custom error handler to print messages to the screen. import logging gdal.PushErrorHandler(log_error_handler) ds1 = gdal.Open(os.path.join(data_dir, 'Switzerland', 'dem_class.tif')) ds2 = gdal.Open(os.path.join(data_dir, 'Landsat', 'Washington', 'nat_color.tif')) do_something(ds1, ds2) del ds1, ds2 # Or use it to write to a file (change to file path!). import logging logging.basicConfig(filename='d:/temp/log.txt') gdal.PushErrorHandler(log_error_handler) ds1 = gdal.Open(os.path.join(data_dir, 'Switzerland', 'dem_class.tif')) ds2 = gdal.Open(os.path.join(data_dir, 'Landsat', 'Washington', 'nat_color.tif')) do_something(ds1, ds2) del ds1, ds2 ###################### Get constant names with ospybook ##################### import ospybook as pb # Get the GDT constant that has a value of 5. print(pb.get_gdal_constant_name('GDT', 5))