Quickly review all the features one by one in QGIS
You can use the following script. It creates a toolbar containing Zoom Previous
, Zoom Next
actions and ID
text box. When you click the action it zooms to next/previous feature (in active layer) with next/previous ID
(means feauture.id()
) in text box.
Run the script in QGIS Python Editor.
layer = iface.activeLayer()
canvas = iface.mapCanvas()
ID = 0
def zoom_next():
global ID
ID += 1
zoom(ID)
def zoom_prev():
global ID
ID -= 1
zoom(ID)
def zoom(ID):
canvas.zoomToFeatureIds(layer, [ID])
text_id.setText(str(ID))
def reset_id():
global ID
global layer
ID = 0
text_id.setText('0')
layer = iface.activeLayer()
canvas.zoomToFeatureIds(layer, [ID])
## ACTIONS
zoom_next_action = QAction("Zoom Next")
zoom_next_action.triggered.connect(zoom_next)
zoom_prev_action = QAction("Zoom Previous")
zoom_prev_action.triggered.connect(zoom_prev)
label = QLabel("ID:")
text_id = QLineEdit()
text_id.setMaximumSize(QSize(40, 100))
text_id.setText('0')
## TOOLBAR
zoom_toolbar = iface.addToolBar("Zoom Features")
zoom_toolbar.addAction(zoom_prev_action)
zoom_toolbar.addAction(zoom_next_action)
zoom_toolbar.addWidget(label)
zoom_toolbar.addWidget(text_id)
iface.layerTreeView().currentLayerChanged.connect(reset_id)
Several ways of doing this, which is good :)
Here is another one using the Space bar (from another answer):
Steps
Download the script iterate_features.py and save it in the same folder as your QGIS project.
Open the QGIS Python console and enter the following line:
import iterate_features
Close the QGIS Python console.
Select a layer in the
Layers
panel and press the Space bar to start iterating features. Press Escape to reset the iteration.
Notes
- You can change the active layer anytime and start iterating its features.
- Iterating points is a special case, so you set the scale that works for you and after pressing the Space bar, the script pans to the next feature. For other geometry types, the script zooms to them.
- Press Shift+F6 (and embed the attribute table) to visualize also the selected feature attributes.
- This works also for geometryless tables. Specially if they have relations with other layers. See it in action:
There is no "Next" and "Previous" buttons,
You could however dock your table for easier viewing of both table and canvas,
and then use the "zoom to selection" keyboard shortcut (Ctrl+J).