QGIS supports various capabilities for editing OGR, PostGIS and SpatiaLite vector layers.
Note
The procedure for editing GRASS layers is different - see Section Digitizing and editing a GRASS vector layer for details.
Tip
Concurrent Edits
This version of QGIS does not track if somebody else is editing a feature at the same time as you. The last person to save their edits wins.
Before we can edit vertices, we must set the snapping tolerance and search radius to a value that allows us an optimal editing of the vector layer geometries.
Snapping tolerance is the distance QGIS uses to search for the closest vertex and/or segment you are trying to connect when you set a new vertex or move an existing vertex. If you aren’t within the snapping tolerance, QGIS will leave the vertex where you release the mouse button, instead of snapping it to an existing vertex and/or segment. The snapping tolerance setting affects all tools which work with tolerance.
Note that this layer based snapping overrides the global snapping option set in the Digitizing tab. So if you need to edit one layer, and snap its vertices to another layer, then enable snapping only on the snap to layer, then decrease the global snapping tolerance to a smaller value. Furthermore, snapping will never occur to a layer which is not checked in the snapping options dialog, regardless of the global snapping tolerance. So be sure to mark the checkbox for those layers that you need to snap to.
Figure Edit 1:
Search radius is the distance QGIS uses to search for the closest vertex you are trying to move when you click on the map. If you aren’t within the search radius, QGIS won’t find and select any vertex for editing and it will pop up an annoying warning to that effect. Snap tolerance and search radius are set in map units or pixels, so you may find you need to experiment to get them set right. If you specify too big of a tolerance, QGIS may snap to the wrong vertex, especially if you are dealing with a large number of vertices in close proximity. Set search radius too small and it won’t find anything to move.
The search radius for vertex edits in layer units can be defined in the
Digitizing tab under Settings ‣
Options. The same place where you define the general, project
wide snapping tolerance.
Before editing a layer, you should zoom in to your area of interest. This avoids waiting while all the vertex markers are rendered across the entire layer.
Apart from using the pan and
zoom-in /
zoom-out icons on the toolbar
with the mouse, navigating can also be done with the mouse wheel, spacebar
and the arrow keys.
While digitizing you can press the mouse wheel to pan inside of the main
window and you can roll the mouse wheel to zoom in and out on the map.
For zooming place the mouse cursor inside the map area and roll it forward
(away from you) to zoom in and backwards (towards you) to zoom out. The mouse
cursor position will be the center of the zoomed area of interest. You can
customize the behavior of the mouse wheel zoom using the Map tools
tab under the Settings ‣
Options menu.
Panning the map during digitizing is possible with the arrow keys. Place the mouse cursor inside the map area and click on the right arrow key to pan east, left arrow key to pan west, up arrow key to pan north and down arrow key to pan south.
You can also use the spacebar to temporarily cause mouse movements to pan then map. The PgUp and PgDown keys on your keyboard will cause the map display to zoom in or out without interrupting your digitizing session.
Besides layer based snapping options you can also define some topological
functionalities in the Snapping options... dialog in the
Settings (or File) menu. Here you can
define Enable topological editing and/or for
polygon layers you can activate the column
Avoid Int. which avoids intersection of new polygons.
The option Enable topological editing is for editing
and maintaining common boundaries in polygon mosaics. QGIS ‘detects’ a
shared boundary in a polygon mosaic and you only have to move the vertex
once and QGIS will take care about updating the other boundary.
The second topological option in the Avoid Int.
column, called Avoid intersections of new polygons avoids
overlaps in polygon mosaics. It is for quicker digitizing of adjacent
polygons. If you already have one polygon, it is possible with this option
to digitise the second one such that both intersect and QGIS then cuts the
second polygon to the common boundary. The advantage is that users don’t
have to digitize all vertices of the common boundary.
By default, QGIS loads layers read-only: This is a safeguard to avoid accidentally editing a layer if there is a slip of the mouse. However, you can choose to edit any layer as long as the data provider supports it, and the underlying data source is writable (i.e. its files are not read-only). Layer editing is most versatile when used on PostgreSQL/PostGIS data sources.
In general, editing vector layers is divided into a digitizing and an advanced digitizing toolbar, described in Section Advanced digitizing. You can select and unselect both under Settings ‣ Toolbars ‣. Using the basic digitizing tools you can perform the following functions:
Table Editing: Vector layer basic editing toolbar
All editing sessions start by choosing the
Toggle editing option. This can be found in the context menu
after right clicking on the legend entry for that layer.
Alternately, you can use the Toggle Editing
Toggle editing button from the digitizing toolbar to start or stop the
editing mode. Once the layer is in edit mode, markers will appear at the
vertices, and additional tool buttons on the editing toolbar will become
available.
Tip
Save Regularly
Remember to Save Edits regularly. This will also
check that your data source can accept all the changes.
You can use the Add Feature,
Add Feature or
Add Feature icons on the toolbar to put the QGIS cursor into
digitizing mode.
For each feature, you first digitize the geometry, then enter its attributes. To digitize the geometry, left-click on the map area to create the first point of your new feature.
For lines and polygons, keep on left-clicking for each additional point you wish to capture. When you have finished adding points, right-click anywhere on the map area to confirm you have finished entering the geometry of that feature.
The attribute window will appear, allowing you to enter the information for
the new feature. Figure_edit_2 shows setting attributes for a fictitious new
river in Alaska. In the Digitizing tab under the
Settings ‣ Options menu, you can also activate
Suppress attributes pop-up windows after each created feature
Reuse last entered attribute values.
Figure Edit 2:
With the Move Feature(s) icon on the toolbar you can
move existing features.
Tip
Attribute Value Types
For editing the attribute types are validated during the entry. Because of this, it is not possible to enter a number into the text-column in the dialog Enter Attribute Values or vice versa. If you need to do so, you should edit the attributes in a second step within the Attribute table dialog.
For both PostgreSQL/PostGIS and shapefile-based layers, the
Node Tool provides manipulation capabilites of
feature vertices similar to CAD programs. It is possible to simply select
multiple vertices at once and to move, add or delete them alltogether.
The node tool also works with ‘on the fly’ projection turned on and supports
the topological editing feature. This tool is, unlike other tools in
Quantum GIS, persistent, so when some operation is done, selection stays
active for this feature and tool. If the node tool couldn’t find any
features, a warning will be displayed.
Important is to set the property Settings ‣
Options ‣ Digitizing ‣ Search Radius:
to a number greater than zero (i.e. 10). Otherwise QGIS will
not be able to tell which vertex is being edited.
Start by activating the Node Tool and selecting a
feature by clicking on it. Red boxes will appear at each vertex of this feature.
Each change made with the node tool is stored as a separate entry in the undo dialog. Remember that all operations support topological editing when this is turned on. On the fly projection is also supported, and the node tool provides tooltips to identify a vertex by hovering the pointer over it.
Selected features can be cut, copied and pasted between layers in the same
QGIS project, as long as destination layers are set to
Toggle editing beforehand.
Features can also be pasted to external applications as text: That is, the features are represented in CSV format with the geometry data appearing in the OGC Well-Known Text (WKT) format.
However in this version of QGIS, text features from outside QGIS cannot be pasted to a layer within QGIS. When would the copy and paste function come in handy? Well, it turns out that you can edit more than one layer at a time and copy/paste features between layers. Why would we want to do this? Say we need to do some work on a new layer but only need one or two lakes, not the 5,000 on our big_lakes layer. We can create a new layer and use copy/paste to plop the needed lakes into it.
As an example we are copying some lakes to a new layer:
What happens if the source and target layers have different schemas (field names and types are not the same)? QGIS populates what matches and ignores the rest. If you don’t care about the attributes being copied to the target layer, it doesn’t matter how you design the fields and data types. If you want to make sure everything - feature and its attributes - gets copied, make sure the schemas match.
Tip
Congruency of Pasted Features
If your source and destination layers use the same projection, then the pasted features will have geometry identical to the source layer. However if the destination layer is a different projection then QGIS cannot guarantee the geometry is identical. This is simply because there are small rounding-off errors involved when converting between projections.
If we want to delete an entire polygon, we can do that by first selecting the
polygon using the regular Select Single Feature tool. You
can select multiple features for deletion. Once you have the selection set,
use the
Delete Selected tool to delete the
features.
The Cut Features tool on the digitizing toolbar can
also be used to delete features. This effectively deletes the feature but
also places it on a “spatial clipboard”. So we cut the feature to delete.
We could then use the
Paste Features tool to put it back,
giving us a one-level undo capability. Cut, copy, and paste work on the
currently selected features, meaning we can operate on more than one at a time.
Tip
Feature Deletion Support
When editing ESRI shapefiles, the deletion of features only works if QGIS is linked to a GDAL version 1.3.2 or greater. The OS X and Windows versions of QGIS available from the download site are built using GDAL 1.3.2 or higher.
When a layer is in editing mode, any changes remain in the memory of QGIS.
Therefore they are not committed/saved immediately to the data source or disk.
If you want to save edits to the current layer but want to continue editing
without leaving the editing mode, you can click the
Save Edits button. When you turn editing mode off with the
Toggle editing (or quit QGIS for that matter),
you are also asked if you want to save your changes or discard them.
If the changes cannot be saved (e.g. disk full, or the attributes have values that are out of range), the QGIS in-memory state is preserved. This allows you to adjust your edits and try again.
Tip
Data Integrity
It is always a good idea to back up your data source before you start editing. While the authors of QGIS have made every effort to preserve the integrity of your data, we offer no warranty in this regard.
Table Advanced Editing: Vector layer advanced editing toolbar
The Undo and
Redo tools allow the
user to undo or redo vector editing operations. There is also a dockable
widget, which shows all operations in the undo/redo history (see
Figure_edit_3). This widget is not displayed by default; it can be
displayed by right clicking on the toolbar and activating the Undo/Redo
check box. Undo/Redo is however active, even if the widget is not displayed.
Figure Edit 3:
When Undo is hit, the state of all features and attributes are reverted to the state before the reverted operation happened. Changes other than normal vector editing operations (for example changes done by a plugin), may or may not be reverted, depending on how the changes were performed.
To use the undo/redo history widget simply click to select an operation in the history list; all features will be reverted to the state they were in after the selected operation.
The Simplify Feature tool allows to reduce the
number of vertices of a feature, as long as the geometry doesn’t change.
You need to select a feature, it will be highlighted by a red rubber band
and a slider appears. Moving the slider, the red rubber band is changing
its shape to show how the feature is being simplified. Clicking [OK]
the new, simplified geometry will be stored. If a feature cannot be simplified
(e.g. MultiPolygons), a message shows up.
You can create ring polygons using the
Add Ring icon in the toolbar. This means inside an existing area it
is possible to digitize further polygons, that will occur as a ‘hole’, so
only the area in between the boundaries of the outer and inner polygons remain
as a ring polygon.
You can add part polygons to a selected
multipolygon. The new part polygon has to be digitized outside
the selected multipolygon.
The Delete Ring tool allows to delete ring polygons
inside an existing area. This tool only works with polygon layers. It doesn’t
change anything when it is used on the outer ring of the polygon. This tool
can be used on polygon and multi-polygon features. Before you select the
vertices of a ring, adjust the vertex edit tolerance.
The Delete Part tool allows to delete parts from
multifeatures (e.g. to delete polygons from a multipolygon feature). It won’t
delete the last part of the feature, this last part will stay untouched. This
tool works with all multi-part geometries point, line and polygon. Before you
select the vertices of a part, adjust the vertex edit tolerance.
You can reshape line and polygon features using the
Reshape Features icon on the toolbar. It replaces the line or polygon
part from the first to the last intersection with the original line. With
polygons this can sometimes lead to unintended results. It is mainly useful
to replace smaller parts of a polygon, not major overhauls and the reshape
line is not allowed to cross several polygon rings as this would generate an
invalid polygon.
For example, you can edit the boundary of a polygon with this tool. First, click in the inner area of the polygon next to the point where you want to add a new vertex. Then, cross the boundary and add the vertices outside the polygon. To finish, right-click in the inner area of the polygon. The tool will automatically add a node where the new line crosses the border. It is also possible to remove part of the area from the polygon, starting the new line outside the polygon, adding vertices inside, and ending the line outside the polygon with a right click.
Note
The reshape tool may alter the starting position of a polygon ring or a closed line. So the point that is represented ‘twice’ will not be the same any more. This may not be a problem for most applications, but it is something to consider.
The Offset Curve tool is a new editing tool. It
creates parallel shifts of lines and polygon rings. The tool can be applied to
the edited layer (the geometries are modified) or also to background layers
(creates copies of the lines / rings and adds it to the the edited layer). It is
thus ideally suited for the creation of distance line layers.The displacement is
shown at the bottom left of the taskbar.
You can split features using the Split Features
icon on the toolbar. Just draw a line across the feature you want to split.
The Merge Selected Features tool allows to merge
features that have common boundaries and the same attributes.
The Merge Attributes of Selected Features tool
allows to merge attributes of features with common boundaries and
attributes without merging their boundaries.
The Rotate Point Symbols tool is currently
only supported by the old symbology engine. It allows to change the rotation
of point symbols in the map canvas, if you have defined a rotation column
from the attribute table of the point layer in the Style tab of
the Layer Properties. Otherwise the tool is inactive.
Figure Edit 4:
To change the rotation, select a point feature in the map canvas and rotate it holding the left mouse button pressed. A red arrow with the rotation value will be visualized (see Figure_edit_4). When you release the left mouse button again, the value will be updated in the attribute table.
Note
If you hold the Ctrl key pressed, the rotation will be done in 15 degree steps.
QGIS allows to create new Shapefile layers and new SpatiaLite layers. Creation of a new GRASS layer is supported within the GRASS-plugin. Please refer to section Creating a new GRASS vector layer for more information on creating GRASS vector layers.
To create a new Shape layer for editing, choose New ‣
New Shapefile Layer... from the
Layer menu. The New Vector Layer dialog will be
displayed as shown in Figure_edit_5. Choose the type of layer (point, line or
polygon) and the CRS (Coordinate Reference System).
Note that QGIS does not yet support creation of 2.5D features (i.e. features with X,Y,Z coordinates).
Figure Edit 5:
To complete the creation of the new Shapefile layer, add the desired attributes
by clicking on the [Add] button and specifying a name and type for the
attribute. A first ‘id’ column is added as default but can be removed, if not
wanted. Only Type: real , Type: integer
, and Type: string
attributes are
supported. Additionally and according to the attribute type you can also define
the width and precision of the new attribute column. Once you are happy with
the attributes, click [OK] and provide a name for the shapefile. QGIS will
automatically add a .shp extension to the name you specify. Once the
layer has been created, it will be added to the map and you can edit it in the
same way as described in Section Digitizing an existing layer above.
To create a new SpatiaLite layer for editing, choose New ‣
New SpatiaLite Layer... from the
Layer menu. The New SpatiaLite Layer dialog will
be displayed as shown in Figure_edit_6.
Figure Edit 6:
First step is to select an existing SpatiaLite database or to create a new
SpatiaLite database. This can be done with the browse button to
the right of the database field. Then add a name for the new layer and define
the layer type and the EPSG SRID. If desired you can select to
Create an autoincrementing primary key.
To define an attribute table for the new SpatiaLite layer, add the names of the attribute columns you want to create with the according column type and click on the [Add to attribute list] button. Once you are happy with the attributes, click [OK]. QGIS will automatically add the new layer to the legend and you can edit it in the same way as described in Section Digitizing an existing layer above.
Further management of SpatiaLite-Layers can be done with the DB Manager see DB Manager Plugin.
The attribute table displays features of a selected layer. Each row in the table represents one map feature and each column contains a particular piece of information about the feature. Features in the table can be searched, selected, moved or even edited.
To open the attribute table for a vector layer, make the layer active by
clicking on it in the map legend area. Then from the main menu
Layer choose Open Attribute
Table. It is also possible to rightclick on the layer and choose
Open Attribute Table from the dropdown menu.
This will open a new window which displays the feature attributes in the layer (figure_attributes_1). The number of features and the number of selected features are shown in the attribute table title.
Figure Attributes 1:
Each selected row in the attribute table displays the attributes of a selected feature in the layer. If the set of features selected in the main window is changed, the selection is also updated in the attribute table. Likewise, if the set of rows selected in the attribute table is changed, the set of features selected in the main window will be updated.
Rows can be selected by clicking on the row number on the left side of the row. Multiple rows can be marked by holding the Ctrl key. A continuous selection can be made by holding the Shift key and clicking on several row headers on the left side of the rows. All rows between the current cursor position and the clicked row are selected. Moving the cursor position in the attribute table, by clicking a cell in the table, does not change the row selection. Changing the selection in the main canvas does not move the cursor position in the attribute table.
The table can be sorted by any column, by clicking on the column header. A small arrow indicates the sort order (downward pointing means descending values from the top row down, upward pointing means ascending values from the top row down).
For a simple search by attributes on only one column the Look for
field can be used. Select the field (column) from which the search should be
performed from the dropdown menu and hit the [Search] button. The
matching rows will be selected and the total number of matching rows will
appear in the title bar of the attribute table, and in the status bar of
the main window. For more complex searches use the Advanced search button
, which will launch the Search Query Builder described in
Section Query Builder.
To show selected records only, use the checkbox
Show selected only.
To search selected records only, use the checkbox
Search selected only. The
Case sensitive
checkbox allows to select case sensitive.
The other buttons at the bottom left of the attribute table window provide
following functionality:
Tip
Skip WKT geometry
If you want to use attribute data in external programs (such as Excel) use the
Copy selected rows to clipboard button.
You can copy the information without vector geometries if you deactivate
Settings ‣ Options ‣ General tab
Copy geometry in WKT representation from attribute table.
The selected features can be saved as any OGR supported vector format and also transformed into another Coordinate Reference System (CRS). Just open the right mouse menu of the layer and click on Save selection as ‣ to define the name of the output file, its format and CRS (see Section Map Legend). It is also possible to specify OGR creation options within the dialog.
QGIS allows also to load non spatial tables. This includes currently tables
supported by OGR, delimited text and the PostgreSQL provider. The tables can
be used for field lookups or just generally browsed and edited using the table
view. When you load the table you will see it in the legend field. It can be
opened e.g. with the Open Attribute Table tool and
is then editable like any other layer attribute table.
As an example you can use columns of the non spatial table to define attribute values or a range of values that are allowed to be added to a specific vector layer during digitizing. Have a closer look at the edit widget in section Fields Tab to find out more.