我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用osgeo.gdal.PushErrorHandler()。
def translate(self, params): if params is None: return params['callback'] = self.translate_callback dlg = QProgressDialog(self) dlg.setWindowTitle(plugin_name()) dlg.setLabelText('Operation in progress') dlg.setMinimum(0) dlg.setMaximum(100) dlg.setWindowModality(Qt.WindowModal) self.progress_dlg = dlg self.setCursor(Qt.WaitCursor) try: log("gdal.VectorTranslate({})".format(str(params))) gdal.PushErrorHandler(gdal_error_handler) with qgis_proxy_settings(): res = gdal.VectorTranslate(**params) gdal.PopErrorHandler() log(str(res)) finally: self.unsetCursor() self.progress_dlg.reset() self.progress_dlg = None
def _load(self, iface, max_tiles, serial_tile_processing_limit=None, merge_tiles=False, clip_tiles=False, apply_styles=False): conn = copy.deepcopy(MBTILES_CONNECTION_TEMPLATE) gdal.PushErrorHandler('CPLQuietErrorHandler') conn["name"] = "Unittest_Connection" conn["path"] = os.path.join(os.path.dirname(__file__), '..', 'sample_data', 'uster_zh.mbtiles') reader = VtReader(iface=iface, connection=conn) bounds = {'y_min': 10644, 'y_max': 10645, 'zoom': 14, 'height': 2, 'width': 3, 'x_max': 8589, 'x_min': 8587} reader.set_options(merge_tiles=merge_tiles, clip_tiles=clip_tiles, max_tiles=max_tiles, layer_filter=['landcover', 'place', 'water_name'], apply_styles=apply_styles) reader._loading_options["zoom_level"] = 14 reader._loading_options["bounds"] = bounds if serial_tile_processing_limit: reader._nr_tiles_to_process_serial = serial_tile_processing_limit reader._load_tiles() reader.shutdown()