def highlight_spatial_unit( self, spatial_unit, geom, map_canvas ): layer = self._iface.activeLayer() map_canvas.setExtent(layer.extent()) map_canvas.refresh() if self.spatial_unit_layer(spatial_unit, layer): self.clear_sel_highlight() qgis_geom = qgsgeometry_from_wkbelement(geom) self.sel_highlight = QgsHighlight( map_canvas, qgis_geom, layer ) rgba = selection_color() self.sel_highlight.setFillColor(rgba) self.sel_highlight.setWidth(3) self.sel_highlight.show() extent = qgis_geom.boundingBox() extent.scale(1.5) map_canvas.setExtent(extent) map_canvas.refresh() else: return
def multi_select_highlight(self, index): """ Highlights a feature with rubberBald class when selecting features are more than one. :param index: Selected QTreeView item index :type Integer :return: None """ map = self.iface.mapCanvas() try: # Get the selected item text using the index selected_item = self.model.itemFromIndex(index) # Use mutli-select only when more than 1 items are selected. if self.layer.selectedFeatures() < 2: return self.selected_root = selected_item # Split the text to get the key and value. selected_item_text = selected_item.text() selected_value = selected_item.data() # If the first word is feature, expand & highlight. if selected_item_text == format_name(self.spatial_unit.short_name): self.view.expand(index) # expand the item # Clear any existing highlight self.clear_sel_highlight() # Insert highlight # Create expression to target the selected feature expression = QgsExpression( "\"id\"='" + str(selected_value) + "'" ) # Get feature iteration based on the expression ft_iteration = self.layer.getFeatures( QgsFeatureRequest(expression) ) # Retrieve geometry and attributes for feature in ft_iteration: # Fetch geometry geom = feature.geometry() self.sel_highlight = QgsHighlight(map, geom, self.layer) self.sel_highlight.setFillColor(selection_color()) self.sel_highlight.setWidth(4) self.sel_highlight.setColor(QColor(212,95,0, 255)) self.sel_highlight.show() break except AttributeError: # pass attribute error on child items such as party pass except IndexError: pass
def _table_widget_row_selection(self): """ Set vertex color on row selection change """ # Remove highlighting gpx_view.row_selection_change(self.map_canvas, self.point_row_attr, self.prev_selected_rows) current_selected_rows = sorted( set([index.row() for index in self.table_widget.selectedIndexes()])) # Make selection gpx_view.row_selection_change(self.map_canvas, self.point_row_attr, current_selected_rows, selection_color()) if current_selected_rows: self.prev_selected_rows = [] self.prev_selected_rows.extend(current_selected_rows)
def _table_widget_row_selection(self): """ Set vertex color on row selection change """ # Remove highlighting gpx_view.row_selection_change( self.map_canvas, self.point_row_attr, self.prev_selected_rows ) current_selected_rows = sorted( set([index.row() for index in self.table_widget.selectedIndexes()]) ) # Make selection gpx_view.row_selection_change( self.map_canvas, self.point_row_attr, current_selected_rows, selection_color() ) if current_selected_rows: self.prev_selected_rows = [] self.prev_selected_rows.extend(current_selected_rows)