def add_impact_layers_to_canvas(impact_function, group=None, iface=None):
    """Helper method to add impact layer to QGIS from impact function.

    :param impact_function: The impact function used.
    :type impact_function: ImpactFunction

    :param group: An existing group as a parent, optional.
    :type group: QgsLayerTreeGroup

    :param iface: QGIS QgisAppInterface instance.
    :type iface: QgisAppInterface
    """
    layers = impact_function.outputs
    name = impact_function.name

    if group:
        group_analysis = group
    else:
        # noinspection PyArgumentList
        root = QgsProject.instance().layerTreeRoot()
        group_analysis = root.insertGroup(0, name)
        group_analysis.setItemVisibilityChecked(True)

    group_analysis.setExpanded(group is None)

    for layer in layers:
        # noinspection PyArgumentList
        QgsProject.instance().addMapLayer(layer, False)
        layer_node = group_analysis.addLayer(layer)

        # set layer title if any
        try:
            title = layer.keywords['title']
            if qgis_version() >= 21800:
                layer.setName(title)
            else:
                layer.setLayerName(title)
        except KeyError:
            pass

        visible_layers = [impact_function.impact.id()]
        print_atlas = setting('print_atlas_report', False, bool)
        if print_atlas:
            visible_layers.append(impact_function.aggregation_summary.id())
        # Let's enable only the more detailed layer. See #2925
        if layer.id() in visible_layers:
            layer_node.setItemVisibilityChecked(True)
        else:
            layer_node.setItemVisibilityChecked(False)

        # we need to set analysis_impacted as an active layer because we need
        # to get all qgis variables that we need from this layer for
        # infographic.
        if iface:
            iface.setActiveLayer(impact_function.analysis_impacted)
def add_impact_layers_to_canvas ( impact_function , group = None , iface = None ) : layers = impact_function . outputs name = impact_function . name if group : group_analysis = group else : root = QgsProject . instance ( ) . layerTreeRoot ( ) group_analysis = root . insertGroup ( 0 , name ) group_analysis . setItemVisibilityChecked ( True ) group_analysis . setExpanded ( group is None ) for layer in layers : QgsProject . instance ( ) . addMapLayer ( layer , False ) layer_node = group_analysis . addLayer ( layer ) try : title = layer . keywords [ 'title' ] if qgis_version ( ) >= 21800 : layer . setName ( title ) else : layer . setLayerName ( title ) except KeyError : pass visible_layers = [ impact_function . impact . id ( ) ] print_atlas = setting ( 'print_atlas_report' , False , bool ) if print_atlas : visible_layers . append ( impact_function . aggregation_summary . id ( ) ) if layer . id ( ) in visible_layers : layer_node . setItemVisibilityChecked ( True ) else : layer_node . setItemVisibilityChecked ( False ) if iface : iface . setActiveLayer ( impact_function . analysis_impacted )
Helper method to add impact layer to QGIS from impact function.

    :param impact_function: The impact function used.
    :type impact_function: ImpactFunction

    :param group: An existing group as a parent, optional.
    :type group: QgsLayerTreeGroup

    :param iface: QGIS QgisAppInterface instance.
    :type iface: QgisAppInterface