def GetOutputDriversFor(filename: PathLike, is_raster=True): drv_list = [] ext = get_extension(filename) if ext.lower() == 'vrt': return ['VRT'] for i in range(gdal.GetDriverCount()): drv = gdal.GetDriver(i) if (drv.GetMetadataItem(gdal.DCAP_CREATE) is not None or drv.GetMetadataItem(gdal.DCAP_CREATECOPY) is not None) and \ drv.GetMetadataItem(gdal.DCAP_RASTER if is_raster else gdal.DCAP_VECTOR) is not None: if ext and DoesDriverHandleExtension(drv, ext): drv_list.append(drv.ShortName) else: prefix = drv.GetMetadataItem(gdal.DMD_CONNECTION_PREFIX) if prefix is not None and filename.lower().startswith( prefix.lower()): drv_list.append(drv.ShortName) # GMT is registered before netCDF for opening reasons, but we want # netCDF to be used by default for output. if ext.lower() == 'nc' and not drv_list and \ drv_list[0].upper() == 'GMT' and drv_list[1].upper() == 'NETCDF': drv_list = ['NETCDF', 'GMT'] return drv_list
def GetOutputDriverFor(filename: PathLike, is_raster=True, default_raster_format='GTiff', default_vector_format='ESRI Shapefile'): if not filename: return 'MEM' drv_list = GetOutputDriversFor(filename, is_raster) ext = get_extension(filename) if not drv_list: if not ext: return default_raster_format if is_raster else default_vector_format else: raise Exception("Cannot guess driver for %s" % filename) elif len(drv_list) > 1: print("Several drivers matching %s extension. Using %s" % (ext if ext else '', drv_list[0])) return drv_list[0]
def read(self, filename_or_strings: ColorPaletteOrPathOrStrings): if isinstance(filename_or_strings, ColorPalette): self.assign(filename_or_strings) else: filename, temp_filename = get_file_from_strings(filename_or_strings) ext = base.get_extension(filename).lower() if ext == 'qlr': self.read_qlr(filename) elif ext == 'txt': self.read_color_file(filename) else: return False if temp_filename: os.remove(temp_filename) return True
def is_supported_format(self, filename): if base.is_path_like(filename): ext = base.get_extension().lower() return ext in self.get_supported_extenstions() return False