示例#1
0
    def sendMap(self):
        """Function to send all visible layers to gison3dmap"""
        visible_layers = self.canvas.layers()
        commands = list()

        if self.cfg.clear_before_draw_map:
            commands.append(u'CLEAR')

        # Since last defined layer will be projected above the other, we need to iterate the
        # Visible layer at the inverse order,i.e., bottom to top. That's why [::-1] was used
        for layer in visible_layers[::-1]:
            try:
                layer_legend = get_layer_legend(layer)
            except AttributeError:
                layer_legend = None

            if layer.type() == layer.VectorLayer and layer_legend:
                commands.append(u'DEFINELAYER ' + define_layer(layer))
                commands.append(u'LEGEND ' + layer_legend)
                commands.append(u'LAYERSQL ' + layer.name() + u', ' + get_layer_filter(layer))

            elif layer.type() == layer.RasterLayer and layer_legend:
                commands.append(u'DEFINEGRID ' + layer.name() + ',' + layer_legend)
                commands.append(u'GRID ' + layer.name())

            else:
                error_msg = "The following layer is not compatible with gison3dmap: " + layer.name()
                self.iface.messageBar().pushMessage("gison3dmap",error_msg,0,10)

        commands.append(u'DRAW')

        # Check if list of commands are more that just CLEAR and DRAW and a DEFINE LAYER
        # Meaning that there are no valid layers to project
        if len(commands)>2:
            tocontroller.send_messages(commands)
示例#2
0
    def sendLayer(self):
        """Function to send active layer or layer group to gison3dmap"""
        current_node = self.tree_view.currentNode()

        if current_node.nodeType() == 1:
            #In this case the node is a QgsLayerTree
            #One single layer will be projected
            layer = current_node.layer()
            group_layers = [layer]

        elif current_node.nodeType() == 0:
            #In this case the node is a QgsLayerGroup
            #All visible layers with the group should be projected
            layers_tree = current_node.findLayers()
            group_layers = [layer.layer() for layer in layers_tree if layer.isVisible()]

        else:
            group_layers = None

        commands = list()

        if self.cfg.clear_before_draw_map:
            commands.append(u'CLEAR')

        for layer in group_layers[::-1]: # [::-1] is used to reverse the order of layers to project
            # Try to get the legend form layer
            try:
                layer_legend = get_layer_legend(layer)
            except AttributeError:
                layer_legend = None

            if layer.type() == layer.VectorLayer and layer_legend:
                commands.append(u'DEFINELAYER ' + define_layer(layer))
                commands.append(u'LEGEND ' + layer_legend)
                commands.append(u'LAYERSQL ' + layer.name() + u', ' + get_layer_filter(layer))

            elif layer.type() == layer.RasterLayer and layer_legend:
                commands.append(u'DEFINEGRID ' + layer.name() + ',' + layer_legend)
                commands.append(u'GRID ' + layer.name())
            else:
                error_msg = "The following layer is not compatible with gison3dmap: " + layer.name()
                self.iface.messageBar().pushMessage("gison3dmao",error_msg,0,10)

        commands.append(u'DRAW')

        tocontroller.send_messages(commands)