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)
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)
def sendSelection(self): """Function to send selected features on the active layer to gison3dmap""" layer = self.canvas.currentLayer() commands = list() if self.cfg.clear_before_draw_map: commands.append(u'CLEAR') # Try to get the legend form layer layer_legend = get_layer_legend(layer) if layer_legend: # Get IDs from selected Features ids = layer.selectedFeaturesIds() ids = [id + 1 for id in ids] #convert the list to a string to use in LAYERID command ids_str = ",".join(map(str,ids)) # Replace all colors in legend by project selection color qcolor = self.canvas.mapSettings().selectionColor() s_color = ",".join(map(str,qcolor.getRgb())) s_color = utils.rgba2argb(s_color,1.0) layer_legend = re.sub(r'\d{1,3},\d{1,3},\d{1,3},\d{1,3}', s_color, layer_legend) commands.append(u'DEFINELAYER ' + define_layer(layer)) commands.append(u'LEGEND ' + layer_legend) commands.append(u'LAYERID ' + layer.name() + "," + ids_str) commands.append(u'DRAW') if len(commands)>2: tocontroller.send_messages(commands) else: error_msg = "The following layer is not compatible with gison3dmap: " + layer.name() self.iface.messageBar().pushMessage("gison3dmao",error_msg,0,10)