We need to fill hazard class when it's empty.

    :param layer: The vector layer.
    :type layer: QgsVectorLayer

    :return: The updated vector layer.
    :rtype: QgsVectorLayer

    .. versionadded:: 4.0
323690
def fill_hazard_class(layer):
    
    hazard_field = layer.keywords['inasafe_fields'][hazard_class_field['key']]

    expression = '"%s" is NULL OR  "%s" = \'\'' % (hazard_field, hazard_field)
    index = layer.fields().lookupField(hazard_field)
    request = QgsFeatureRequest().setFilterExpression(expression)
    layer.startEditing()

    for feature in layer.getFeatures(request):
        layer.changeAttributeValue(
            feature.id(),
            index,
            not_exposed_class['key'])
    layer.commitChanges()

    return layer
348026
def get_layer(self, class_: Type[L], became: bool=True) -> L:
        

        try:
            return self._index[class_][0]
        except KeyError:
            if became:
                return self._transformed[class_][0]
            else:
                raise
645712
def potentiallayers(self, x, y, layers, aq=None):
        ''''''
        if aq is None: aq = self.model.aq.find_aquifer_data(x, y)
        pot = np.sum(self.potential(x, y, aq) * aq.eigvec, 1 )
        return pot[layers]
1055157
def hazard_extra_keyword(keyword, feature, parent):
    
    _ = feature, parent  # NOQA
    hazard_layer_path = QgsExpressionContextUtils. \
        projectScope(QgsProject.instance()).variable(
          'hazard_layer')
    hazard_layer = load_layer(hazard_layer_path)[0]
    keywords = KeywordIO.read_keywords(hazard_layer)
    extra_keywords = keywords.get('extra_keywords')
    if extra_keywords:
        value = extra_keywords.get(keyword)
        if value:
            value_definition = definition(value)
            if value_definition:
                return value_definition['name']
            return value
        else:
            return tr('Keyword %s is not found' % keyword)
    return tr('No extra keywords found')
1076564
def layer(self, queryset, stylename=None):
        
        cls = RasterLayer if hasattr(queryset, 'image') else VectorLayer
        layer = cls(queryset, style=stylename)
        try:
            style = self.map.find_style(layer.stylename)
        except KeyError:
            self.map.append_style(layer.stylename, layer.style())
        layer.styles.append(layer.stylename)
        self.map.layers.append(layer._layer)
        return layer
1304329
def load(self, _=None):
        
        for k, v in self.layer.iteritems():
            self.add(k, v['module'], v.get('package'))
575191
def get_descriptor_for_layer(self, layer):
        
        if not layer in self._layer_descriptor_cache:
            params = {'f': 'pjson'}
            if self.token:
                params['token'] = self.token
            response = requests.get(self._build_request(layer), params=params)
            self._layer_descriptor_cache[layer] = response.json()
        return self._layer_descriptor_cache[layer]
1023569
function (layer) {
		var id = this.getLayerId(layer);

		this._layers[id] = layer;

		if (this._map) {
			this._proxyMcgLayerSupportGroup.addLayer(layer);
		} else {
			this._proxyMcgLayerSupportGroup.checkIn(layer);
		}

		return this;
	}
272444
def hazard_preparation(self):
        """"""
        LOGGER.info('ANALYSIS : Hazard preparation')

        use_same_projection = (
            self.hazard.crs().authid() == self._crs.authid())
        self.set_state_info(
            'hazard',
            'use_same_projection_as_aggregation',
            use_same_projection)

        if is_raster_layer(self.hazard):

            extent = self._analysis_impacted.extent()
            if not use_same_projection:
                transform = QgsCoordinateTransform(
                    self._crs, self.hazard.crs(), QgsProject.instance())
                extent = transform.transform(extent)

            self.set_state_process(
                'hazard', 'Clip raster by analysis bounding box')
            # noinspection PyTypeChecker
            self.hazard = clip_by_extent(self.hazard, extent)
            self.debug_layer(self.hazard)

            if self.hazard.keywords.get('layer_mode') == 'continuous':
                self.set_state_process(
                    'hazard', 'Classify continuous raster hazard')
                # noinspection PyTypeChecker
                self.hazard = reclassify_raster(
                    self.hazard, self.exposure.keywords['exposure'])
                self.debug_layer(self.hazard)

            self.set_state_process(
                'hazard', 'Polygonize classified raster hazard')
            # noinspection PyTypeChecker
            self.hazard = polygonize(self.hazard)
            self.debug_layer(self.hazard)

        if not use_same_projection:
            self.set_state_process(
                'hazard',
                'Reproject hazard layer to aggregation CRS')
            # noinspection PyTypeChecker
            self.hazard = reproject(self.hazard, self._crs)
            self.debug_layer(self.hazard, check_fields=False)

        self.set_state_process(
            'hazard',
            'Clip and mask hazard polygons with the analysis layer')
        self.hazard = clip(self.hazard, self._analysis_impacted)
        self.debug_layer(self.hazard, check_fields=False)

        self.set_state_process(
            'hazard',
            'Cleaning the vector hazard attribute table')
        # noinspection PyTypeChecker
        self.hazard = prepare_vector_layer(self.hazard)
        self.debug_layer(self.hazard)

        if self.hazard.keywords.get('layer_mode') == 'continuous':
            # If the layer is continuous, we update the original data to the
            # inasafe hazard class.
            self.set_state_process(
                'hazard',
                'Classify continuous hazard and assign class names')
            self.hazard = reclassify_vector(
                self.hazard, self.exposure.keywords['exposure'])
            self.debug_layer(self.hazard)
        else:
            # However, if it's a classified dataset, we only transpose the
            # value map using inasafe hazard classes.
            self.set_state_process(
                'hazard', 'Assign classes based on value map')
            self.hazard = update_value_map(
                self.hazard, self.exposure.keywords['exposure'])
            self.debug_layer(self.hazard)
45511
private void deselectLayer(Layer<?> layer) {
		if (layer != null) {
			layer.setSelected(false);
			handlerManager.fireEvent(new LayerDeselectedEvent(layer));
		}
	}
1209393
def validate_input(self):
        
        self.exposure_layer = layer_from_combo(self.dock.exposure_layer_combo)
        self.hazard_layer = layer_from_combo(self.dock.hazard_layer_combo)
        self.aggregation_layer = layer_from_combo(
            self.dock.aggregation_layer_combo)

        is_valid = True
        warning_message = None
        if self.exposure_layer is None:
            warning_message = tr(
                'Exposure layer is not found, can not save scenario. Please '
                'add exposure layer to do so.')
            is_valid = False

        if self.hazard_layer is None:
            warning_message = tr(
                'Hazard layer is not found, can not save scenario. Please add '
                'hazard layer to do so.')
            is_valid = False

        return is_valid, warning_message
1357832
def setCurrentLayer(self, layer):
        
        if self._currentLayer == layer:
            return False
        
        old = self._currentLayer
        self._currentLayer = layer
        
        if old is not None:
            old.sync()
        if layer is not None:
            layer.sync()
        
        self.selectionFinished.emit()
        self.invalidate()
        
        return True
897671
def add_layer(self, layer):
        
        assert (
            isinstance(layer,
                       (TiledTileLayer, TiledImageLayer, TiledObjectGroup)))

        self.layers.append(layer)
        self.layernames[layer.name] = layer
67774
def _search_inasafe_layer(self):
        
        selected_nodes = self.iface.layerTreeView().selectedNodes()
        for selected_node in selected_nodes:
            tree_layers = [
                child for child in selected_node.children() if (
                    isinstance(child, QgsLayerTreeLayer))]
            for tree_layer in tree_layers:
                layer = tree_layer.layer()
                keywords = self.keyword_io.read_keywords(layer)
                if keywords.get('inasafe_fields'):
                    return layer
653848
public void setLayer(VectorLayer layer) {
		this.layer = layer;
		Object value = layerSelect.getValue();
		if (value == null || !value.equals(layer.getLabel())) {
			layerSelect.setValue(layer.getLabel());
		}
		empty();
	}
722055
def layerFromSource(source):
    '''
    
    '''
    layers =_layerreg.mapLayers().values()
    for layer in layers:
        if layer.source() == source:
            return layer
    raise WrongLayerSourceException()
517884
function(layer, attributes) {
    if(attributes === undefined) {
      attributes = layer;
      layer = 0;
    }

    if(layer >= this.getLayerCount() && layer < 0) {
      throw new Error("layer does not exist");
    }

    if(typeof(attributes) == 'string') {
      attributes = attributes.split(',');
    }

    for(var i = 0; i < attributes.length; ++i) {
      attributes[i] = attributes[i].replace(/ /g, '');
    }

    this.layers[layer].options.interactivity = attributes;
    this._definitionUpdated();
    return this;
  }