重要

Translation is a community effort you can join. This page is currently translated at 32.77%.

16.3. 编辑

QGIS具有编辑 OGR、SpatiaLite、PostGIS、MS SQL Server 和 Oracle 空间矢量图层和表的各种功能,它们可以是2D或3D几何图形类型。

备注

编辑GRASS图层具有不同的步骤 - 详细信息请参阅 Digitizing and editing a GRASS vector layer

注意

并发编辑

QGIS不会跟踪其他人是否与您同时编辑同一要素,最终结果取决于最后保存编辑的人。

小技巧

验证编辑

可以在 图层属性 ► 数字化 选项卡中基于图层激活连续验证。详细信息请参阅 Digitizing Properties

16.3.1. 设置捕捉容差和搜索半径

设置 ► 选项... ► 数字化 菜单中,QGIS提供了许多参数来配置编辑工具的默认操作。更多信息请参阅 数字化设置

为了优化和准确编辑矢量图层几何图形,需要为要素顶点设置合适的捕捉容差和搜索半径的值。 捕捉 组提供了相关选项,即捕捉容差和搜索半径的处理。

  • 捕捉容差:当添加新顶点或移动现有顶点时,捕捉容差是QGIS用于搜索您试图连接到最近顶点或线段的距离。如果不在捕捉容差范围内,QGIS将把顶点放置在您松开鼠标按钮的位置,而不是将其捕捉到现有顶点或线段。

    容差设置将影响所有使用捕捉的工具,并且默认会应用于新建图层和工程。但是,它可以在图层级别被覆写 (请参阅 捕捉和数字化选项) 。

  • 搜索半径: 顶点编辑的搜索半径 是QGIS在单击地图时用于 搜索 要选择的顶点的距离。如果不在搜索半径内,QGIS将无法找到并选择任何顶点进行编辑。

捕捉容差和搜索半径是以 地图单位像素 进行设置的。您可能需要进行尝试才能最优设置。如果指定的容差太大,尤其是在处理大量非常邻近的顶点时,QGIS可能会捕捉到错误的顶点。搜索半径越小,就越难找到您想要移动的对象。

16.3.2. 捕捉和数字化选项

全局 捕捉和数字化设置 (捕捉模式、容差值和单位...) 优先于在工程中从 工程 ► 捕捉选项... 菜单的设置。在 捕捉和数字化选项 中,还可以配置一些其他属性 (捕捉图层、比例限制、拓扑…)。 捕捉工具栏 可以访问其中大部分功能。

默认情况下,在点击 snapping 启用捕捉 按钮或按 S 键之前,捕捉在工程中处于禁用状态。捕捉模式、容差值和单位也可以在此工具栏中进行配置。

16.3.2.1. 捕捉属性

有三个选项可用于选择要捕捉到的图层:

  • 所有图层: 工程中所有可见图层的快速设置,以便指针捕捉到所有顶点和/或线段。在多数情况下,使用这种捕捉模式就足够了,但在将其用于具有许多矢量图层的工程时要小心,因为这可能会影响性能。

  • 活动图层: 只作用于活动图层,这是确保正在编辑的图层内拓扑一致性的一种便捷方式。

  • 高级配置: 允许您在图层的基础上启用和调整捕捉模式、容差和单位、重叠和捕捉比例 (请参阅 图 16.78) 。如果需要编辑一个图层并将其顶点捕捉到另一个图层,请确保选中目标图层,并将捕捉容差增大到更高值。捕捉不会作用在捕捉选项对话框中未勾选的图层。

When moving or creating vertex, you can opt for the following snapping modes:

  • snappingVertex Vertex

  • snappingSegment Segment: snaps along a line or a polygon perimeter. If topological editing is enabled, then a new vertex is added at the snapping location.

  • snappingArea Area: guarantees that the snap point lies anywhere on a polygon's area, not necessarily on its boundary

  • snappingCentroid Centroid: snaps to the centroid of the geometry of a feature. In case of a multipart geometry, the target point may be distinct from the existing parts.

  • snappingMiddle Middle of Segments on line or polygon feature

  • snappingEndpoint Line Endpoints: snaps to the first or last vertex of every part of a line or polygon feature.

QGIS将根据 捕捉 类型显示不同的 捕捉 图标:

表 16.2 捕捉图标
../../../_images/snap_vertex_icon.png
../../../_images/snap_segment_icon.png
../../../_images/snap_intersection_icon.png

捕捉到顶点: 方框图标

捕捉到线段:沙漏图标

捕捉到相交点:十字图标

请注意,可以在全局设置的 数字化 选项卡中更改这些图标的颜色。

容差值可以使用工程的 地图单位像素 。选择 像素 的优点是在不同的地图比例下保持捕捉不变。10到12像素通常是一个不错的值,但这取决于屏幕的DPI。使用地图单位可以使容差与实际范围的距离相关。例如,如果元素之间的距离较近,此选项可用于确保添加的顶点不会彼此太近。

../../../_images/editProjectSnapping.png

图 16.78 捕捉选项 (高级配置模式)

备注

默认仅捕捉可见要素 (显示样式的要素,符号化为 "无符号" 的图层除外)。可以通过勾选 设置 ► 选项 ► 数字化 选项卡下的 unchecked 对不可见的要素 (未在地图画布中显示) 也启用捕捉 来启用不可见要素的捕捉。

小技巧

默认启用捕捉

您可以在 设置 ► 选项 ► 数字化 选项卡中将捕捉设置为默认在所有新建工程中启用。还可以设置默认捕捉模式、容差值和单位,这将填充 捕捉选项 对话框。

16.3.2.2. 启用相交处捕捉

另一个可用的选项是使用 snappingIntersection 相交处捕捉 ,这使您可以捕捉到启用捕捉的图层的几何图形相交点,即使相交处没有顶点。

16.3.2.3. 将捕捉限制在比例范围内

在某些情况下,捕捉可能会变得非常迟钝。这通常是由某些图层中的要素数量引起的,这些要素需要大量索引来计算和维护。某些参数仅在地图视图处于相关比例范围内才启用捕捉。这允许仅执行与绘制比例捕捉相关的价值高的索引计算。

捕捉的比例限制在 工程 ► 捕捉选项... 中配置。将捕捉限制为缩放仅在 高级配置 模式下可用。

要将捕捉限制在比例范围内,有三种可用模式:

  • 禁用: 无论当前地图比例是多少,都会启用捕捉。这是默认模式。

  • 全局: 捕捉是有限的,仅当地图的当前比例介于全局最小值和全局最大值之间时才会启用。选择此模式时,将有两个控件用于配置启用捕捉的比例范围。

  • 每个图层: 捕捉比例范围限制是为每个图层定义的。选择此模式时,将有两列可用于配置每个图层的最小和最大比例。

请注意,最小和最大比例遵循QGIS约定:最小比例是 "缩小" 比例的最小值,而最大比例是 "放大" 比例的最大值。设置为 "0" 或 "未设置" 的最小或最大比例被视为非限制性。

16.3.2.4. 自捕捉

snappingSelf 自捕捉 选项允许捕捉到正在编辑的几何图形。结合 高级数字化面板 ,提供了一种相对于之前边或顶点对新边进行数字化的便捷方式。自捕捉可能会导致无效的几何图形,请谨慎使用。

../../../_images/self_snapping.gif

图 16.79 使用自捕捉绘制要素

16.3.2.5. 在自定义网格上捕捉

还可以在图层属性对话框的 数字化 选项卡中基于图层自定义捕捉距离。通过设置 几何图形精度 距离,可以启用在地图画布处于相干比例时可见的点缀网格进行显示。然后对网格的点进行捕捉:添加或修改的几何图形的所有顶点将自动捕捉到网格的最近节点。更多信息,请参阅 Digitizing Properties

16.3.3. 拓扑编辑

除了这些捕捉选项之外, 捕捉选项... 对话框 (工程 ► 捕捉选项) 和 捕捉 工具栏允许您启用 / 禁用一些其他拓扑功能。

16.3.3.1. 启用拓扑编辑

topologicalEditing 拓扑编辑 按钮有助于编辑和维护具有公共边界的要素。启用此选项后,QGIS将 '检测' 共享边界。移动公共顶点/线段时,QGIS也会在相邻要素的几何图形中移动它们。

拓扑编辑适用于来自不同图层的要素,只要图层可见且处于编辑模式即可。

在具有 Z 或 M 值的图层中,拓扑编辑将根据用于连接的边的值对顶点的 Z 或 M 值进行插值。

16.3.3.2. 重叠控制

重叠可防止绘制与选定图层中现有要素相重叠的新要素,从而加快邻接多边形的数字化。可以通过重叠工具进行控制,并有三种模式可用:

  1. allowIntersections 允许重叠 (默认)

  2. avoidIntersectionsCurrentLayer 在活动图层避免重叠: 防止与正在编辑的图层中的其他要素发生重叠。数字化新几何图形,使其与相邻几何图形重叠,QGIS将剪切新几何图形的重叠部分,并将其捕捉到现有要素的边界。其优势是不必数字化边界上的公共顶点。

  3. avoidIntersectionsLayers 遵循高级配置: 允许在 高级配置 视图模式中以图层为基础设置重叠的相关参数。

备注

如果新几何图形完全被现有几何图形覆盖,会将其被清除,QGIS显示一条错误信息。

警告

请谨慎使用 避免重叠 选项

由于此选项将剪切任何多边形图层的新重叠几何图形,因此如果您在不再需要时忘记取消勾选,可能会得到意外的几何图形。

16.3.3.3. 自动追踪

通常,使用捕捉地图工具 (添加要素、添加部件、添加环、重塑和分割) 时,需要单击要素的每个顶点。使用自动追踪模式,可以加快数字化处理,因为在数字化过程中不再需要手动放置所有顶点:

  1. 通过按下图标或按 T 键启用 tracing 追踪 工具 (在 捕捉 工具栏中) 。

  2. 捕捉到 沿其追踪要素的顶点或线段。

  3. 将鼠标移动到要捕捉的另一个顶点或线段上,数字化橡皮筋表示从捕捉的最后一个点到当前位置的路径,而不是通常的直线。该工具也适用于曲线几何图形。

    QGIS实际是使用底层要素拓扑来构建两点之间的最短路径。追踪要求在可追踪图层中激活捕捉以构建路径。数字化时还应捕捉到现有顶点或线段,并确保两个节点可通过现有要素边进行拓扑连接,否则QGIS将无法进行连接,从而追踪单一直线。

  4. 单击,QGIS将中间顶点放置在显示的路径之后。

展开 tracing 启用追踪 图标,并设置 偏移 选项以数字化平行于要素的路径,而不是沿着要素进行追踪。正值将新图形移动到追踪方向的左侧,负值则相反。

备注

为实现最佳追踪请调整地图比例或捕捉设置

如果地图显示的要素过多,将禁用追踪,避免可能过长的追踪结构准备和大量内存占用。放大或禁用某些图层后,将再次启用追踪。

备注

不添加拓扑点

即使启用了 拓扑编辑 ,该工具也不会向现有多边形几何图形添加点。如果在编辑的图层激活了几何图形精度,则生成的几何图形可能不会完全遵循现有几何图形。

小技巧

按 ** :kbd:`T` ** 键可快速启用或禁用自动追踪

通过按 T 键,可以随时启用/禁用追踪 (即使在数字化要素时也是如此),因此可以在启用追踪时数字化要素的某些部分,而在禁用追踪的情况下数字化其他部分。禁用跟踪时,工具的行为恢复到正常状态。

小技巧

将追踪转换为曲线几何图形

通过使用 设置 ► 选项 ► 数字化 ► 追踪 ,可以在数字化的同时创建曲线几何图形。请参阅 数字化选项

16.3.4. 数字化现有图层

默认情况下,QGIS以只读方式加载图层。这是一种保护措施,可以避免在鼠标滑动时意外编辑图层。但是,只要数据提供程序支持,并且基础数据源是可写的 (其文件不是只读属性),就可以选择编辑任何图层 (请参阅 探索数据格式与字段) 。

小技巧

约束工程中图层的编辑权限

From the Project ► Properties... ► Data Sources ► Layers Capabilities table, you can choose to set any layer read-only regardless the provider permission. This can be a handy way, in a multi-users environment to avoid unauthorized users to mistakenly edit layers (e.g., Shapefile), hence potentially corrupt data. Note that this setting only applies inside the current project.

In general, tools for editing vector layers are divided into a digitizing and an advanced digitizing toolbar, described in section Advanced digitizing. You can select and unselect both under View ► Toolbars ►.

Using the basic digitizing tools, you can perform the following functions:

表 16.3 矢量图层基本编辑工具栏

工具

目标

工具

目标

allEdits

Access to save, rollback or cancel changes in all or selected layers simultaneously

toggleEditing

Turn on or off edit status of selected layer(s) based on the active layer status

saveEdits

Save edits to the active layer

digitizeWithSegment

Digitize using straight segments

digitizeWithCurve

Digitize using curve lines

streamingDigitize

Enable freehand digitizing

digitizeShape

Digitize polygon of regular shape

newTableRow

Add new record

capturePoint

Add Feature: Capture Point

captureLine

Add Feature: Capture Line

capturePolygon

Add Feature: Capture Polygon

vertexTool

Vertex Tool (All Layers)

vertexToolActiveLayer

Vertex Tool (Current Layer)

checkbox Show Vertex Editor

Set whether the vertex editor panel should auto-open

multiEdit

Modify the attributes of all selected features simultaneously

deleteSelectedFeatures

Delete Selected features from the active layer

editCut

Cut Features from the active layer

editCopy

Copy selected Features from the active layer

editPaste

Paste Features into the active layer

undo

Undo changes in the active layer

redo

Redo changes in active layer

Note that while using any of the digitizing tools, you can still zoom or pan in the map canvas without losing the focus on the tool.

All editing sessions start by choosing the toggleEditing Toggle editing option found in the context menu of a given layer, from the attribute table dialog, the digitizing toolbar or the Layer menu.

Once the layer is in edit mode, additional tool buttons on the editing toolbar will become available and markers will appear at the vertices of all features unless Show markers only for selected features option under Settings ► Options... ► Digitizing menu is checked.

小技巧

Save Regularly

Remember to saveEdits Save Layer Edits regularly. This will also check that your data source can accept all the changes.

16.3.4.1. Geometry editing techniques

When a geometry drawing tool (mainly the ones that add, split, reshape features) is enabled for a line or polygon based layer, you can select the technique for adding new vertices:

  • The digitizeWithSegment Digitize with Segment: draws straight segment whose start and end points are defined by left clicks.

  • The digitizeWithCurve Digitize with Curve: draws curve line based on three consecutive nodes defined by left clicks (start, point along the arc, end). If the geometry type does not support curves, then consecutive smaller segments are used to approximate the curvature.

  • The streamingDigitize Stream Digitizing: draws lines in freehand mode, i.e. nodes are added following cursor movement in the map canvas and a Streaming Tolerance. The streaming tolerance defines the spacing between consecutive vertices. Currently, the only supported unit is pixels (px). Only the starting left click and the ending right click are necessary in this mode.

  • The digitizeShape Digitize Shape: triggers tools on the Shape Digitizing Toolbar to draw a polygon of a regular shape.

The selected technique remains while switching among the digitizing tools. You can combine any of the first three methods while drawing the same geometry.

16.3.4.2. Adding Features

Depending on the layer type, you can use the newTableRow Add Record, capturePoint Add Point Feature, captureLine Add Line Feature or capturePolygon Add Polygon Feature icons on the toolbar to add new features into the current layer.

To add a geometryless feature, click on the newTableRow Add Record button and you can enter attributes in the feature form that opens.

To create features with the spatially enabled tools, you first digitize the geometry then enter its attributes. To digitize the geometry:

  1. (Optional as it is the default) Select the digitizeWithSegment Digitize With Segment geometry drawing method

  2. Left-click on the map area to create the first point of your new feature. For point features, this should be enough and trigger, if required, the feature form to fill in their attributes.

  3. For line or polygon geometries, keep on left-clicking for each additional point you wish to capture. You can rely on the snapping to features options, the snap-to-grid or the advanced digitizing panel to accurately position each vertex.

    Along with drawing straight segments between nodes you click one by one, lines and polygons can be:

    • traced automatically, accelerating the digitization. This will create consecutive straight lines between the vertices you place, following existing features.

    • free-hand digitized, pressing R or activating streamingDigitize Stream Digitizing.

    • drawn as curve, pressing Ctrl+Shift+G or activating digitizeWithCurve Digitize with Curve.

    备注

    While digitizing line or polygon geometries, you can switch back and forth between the geometry drawing methods, allowing you to create features mixing straight segments, free-hand ones and curved parts.

  4. Press Delete or Backspace key to revert the last node(s) you may wrongly add.

  5. When you have finished adding points, right-click anywhere on the map area to confirm you have finished entering the geometry of that feature.

    小技巧

    Customize the digitizing rubber band

    While capturing polygon, the by-default red rubber band can hide underlying features or places you'd like to capture a point. This can be fixed by setting a lower opacity (or alpha channel) to the rubber band's Fill Color in Settings ► Options ► Digitizing menu. You can also avoid the use of the rubber band by checking Don't update rubber band during node editing.

  6. For line feature pressing Shift + right-click will close the line automatically.

  7. The attribute window will appear, allowing you to enter the information for the new feature. 图 16.80 shows setting attributes for a fictitious new river. However, in the Digitizing menu under the Settings ► Options menu, you can also:

    • checkbox Suppress attributes pop-up windows after each created feature to avoid the form opening;

    • or checkbox Reuse last entered attribute values to have fields automatically filled at the opening of the form and just have to type changing values.

../../../_images/editDigitizing.png

图 16.80 Enter Attribute Values Dialog after digitizing a new vector feature

16.3.4.3. 顶点工具

QGIS provides two tools to interact with vector features vertices:

  • vertexToolActiveLayer Vertex Tool (Current Layer): only overlaid features in the active layer (in the Layers panel) are affected

  • vertexTool Vertex Tool (All Layers): any overlaid features in all editable layers are affected. This allows you to edit features without switching the active layer or edit multiple layers at once (e.g., country and their regions boundaries)

For any editable vector layer, the vertex tools provide manipulation capabilities of feature vertices similar to CAD programs. It is possible to select multiple vertices at once and to move, add or delete them altogether. The vertex tools also support the topological editing feature. They are selection persistent, so when some operation is done, selection stays active for this feature and tool.

It is important to set the property Settings ► options Options ► Digitizing ► Search Radius: selectNumber to a number greater than zero. Otherwise, QGIS will not be able to tell which vertex is being edited and will display a warning.

小技巧

Vertex Markers

QGIS supports different kinds of vertex markers: 'Semi-transparent circle', 'Cross' and 'None'. To change the marker style, choose options Options from the Settings menu, click on the Digitizing tab and select the appropriate entry.

Basic operations

Given a layer in edit mode, start by activating the vertex tool. Red circles will appear when hovering vertices.

  • Selecting vertices: You can select vertices by:

    • Clicking on them one at a time holding Shift key pressed

    • Click-and-dragging a rectangle surrounding the target vertices

    • Drawing a polygon surrounding the target vertices: Hold Alt and click using the vertex tool to start digitizing a polygon. Each subsequent click adds a new vertex to the rubberband polygon. Backspace or Delete removes last added rubberband vertex. Esc cancels the polygon selection mode, as also does backspacing/deleting all of the rubberband's vertices. Right click finalizes the polygon digitizing and selects all vertices within the rubberband polygon.

    When a vertex is selected, its color changes to blue. To add more vertices to the current selection, hold down the Shift key while proceeding as above. To remove vertices from the selection, hold down Ctrl.

    小技巧

    Feature selection bounds vertex tool

    Vertices can be selected accross different features (or layers). If you are looking for vertices of a specific feature in a crowded place, first select that feature. Then draw the rectangle or polygon selector with the vertex tool around the vertices: only the selected feature's vertices are selected.

    This is also the case if you display the feature in the vertex editor panel.

  • Batch vertex selection mode: The batch selection mode can be activated by pressing Shift+R. Select a first node with one single click, and then hover without clicking another vertex. This will dynamically select all the nodes in between using the shortest path (for polygons).

    ../../../_images/vertex_batch_selection_mode.png

    图 16.81 Batch vertex selection using Shift+R

    Press Ctrl will invert the selection, selecting the longest path along the feature boundary. Ending your node selection with a second click, or pressing Esc will escape the batch mode.

  • Adding vertices: To add a vertex to a line or polygon geometry, hold Shift and double-click the place on the segment.

    When hovering a segment, a virtual new node appears on the center. Click on it, move the cursor to a new location and click again to add a new vertex. For lines, a virtual node is also proposed at both extremities: click on it, do subsequent clicks and finish with a right-click; this allows to easily extend an existing line.

    ../../../_images/vertex_add_node.png

    图 16.82 Virtual nodes for adding vertices

  • Deleting vertices: Select the vertices and click the Delete key. Deleting all the vertices of a feature generates, if compatible with the datasource, a geometryless feature. Note that this doesn't delete the complete feature, just the geometry part. To delete a complete feature use the deleteSelectedFeatures Delete Selected tool.

  • Moving vertices: Select all the vertices you want to move, click on a selected vertex or edge, and click on the desired new location. You can use the snapping to feature capabilities and the Advanced Digitizing Panel constraints for distance, angles, exact X and Y location before the second click. All the selected vertices will be translated.

    However, if the snap-to-grid option is enabled, selected vertices are snapped to the closest grid intersection to their translated position. Unselected vertices are also moved to their closest grid intersection. There is no simple translation.

    ../../../_images/vertex_snap_to_grid.png

    图 16.83 Moving the top vertex snaps all the vertices to the grid

  • Converting adjacent segments to/from curve: Select the center vertex of the segment you want to convert, hit the O letter key. If the vertex was in a curve, the curve is converted into straight lines. If the vertex was between two straight lines, they are converted into a curve. A first or a last vertex of a line can't be converted to a center vertex curve. The layer must be compatible with curve geometry type.

    ../../../_images/vertex_convert_curve.png

    图 16.84 Switch from curve to straight lines with O letter

Each change made with the vertex 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.

The Vertex Editor Panel

With enabling a vertex tool, you also open the Vertex Editor panel. Right-clicking over a feature fills the panel with the list of all the vertices of the feature with their x, y (z, m if applicable) coordinates and r (for the radius, in case of circular geometry). The feature is also made exclusive for editing, meaning that the edit of any other features is disabled:

  • Selecting a row in the table does select the corresponding vertex in the map canvas, and vice versa.

  • Clicking or dragging over the map canvas will only select or move vertices and segments of that feature

  • Change a coordinate in the table and the vertex position is updated. This is a convenient way to edit Z coordinate or M value on vertices.

  • You can also select multiple rows and delete them altogether.

  • New vertices can only be added to the bound feature

If you do not want the Vertex Editor panel to immediately show each time you interact with vertex tools (and potentially hide other panels or disturb panels placement), uncheck the Auto-open table entry in the hamburgerMenu Options menu at the top of the panel. You can then also close the panel. To reopen the panel, you would need to right-click over a panel or toolbar and select it in the list or tick the Show vertex editor entry in the Digitizing toolbar.

../../../_images/vertex_editor_panel.png

图 16.85 Vertex editor panel showing selected nodes

16.3.4.4. Rules of Z coordinate or M value assignment

Digitizing 3D vector features or features with M value is not that different from (X,Y) 2D layers'. Tools and options described in this chapter are still available and help you place the vertex or point in a planar environment. Then you may need to handle the Z coordinate (or M value) assignment:

  • By default, QGIS will assign to new vertices the Default Z value (respectively Default M value) set in the Settings ► Options ► Digitizing tab. If the Advanced Digitizing Panel is in use, then the value is taken from its z (respectively m) widget.

  • When snapping to a vertex, the new or moved vertex takes the snapped one's Z or M value.

  • When snapping to a segment while the topological editing is on, then the new vertex Z or M value is interpolated along the segment.

  • If the z (respectively m) widget of the Advanced Digitizing Panel is locked locked, then its value is applied to the vertex, taking precedence over any snapped vertex or segment Z or M value.

To edit Z or M values of an existing feature, you can use the Vertex editor panel. To create features with custom Z or M values you may want to rely on the Advanced Digitizing Panel.

16.3.4.5. Cutting, Copying and Pasting Features

Selected features can be cut, copied and pasted between layers in the same QGIS project, as long as destination layers are set to toggleEditing Toggle editing beforehand.

小技巧

Transform polygon into line and vice-versa using copy/paste

Copy a line feature and paste it in a polygon layer: QGIS pastes in the target layer a polygon whose boundary corresponds to the closed geometry of the line feature. This is a quick way to generate different geometries of the same data.

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. WKT and GeoJSON features from outside QGIS can also 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 will copy some lakes to a new layer:

  1. Load the layer you want to copy from (source layer)

  2. Load or create the layer you want to copy to (target layer)

  3. Start editing for target layer

  4. Make the source layer active by clicking on it in the legend

  5. Use the selectRectangle Select Features by area or single click tool to select the feature(s) on the source layer

  6. Click on the editCopy Copy Features tool

  7. Make the destination layer active by clicking on it in the legend

  8. Click on the editPaste Paste Features tool

  9. Stop editing and save the changes

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 - the feature and its attributes - gets copied, make sure the schemas match.

备注

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.

小技巧

Copy string attribute into another

If you have created a new column in your attribute table with type 'string' and want to paste values from another attribute column that has a greater length the length of the column size will be extended to the same amount. This is because the GDAL Shapefile driver knows to auto-extend string and integer fields to dynamically accommodate for the length of the data to be inserted.

16.3.4.6. Deleting Selected Features

If we want to delete an entire feature (attribute and geometry), we can do that by first selecting the geometry using the regular selectRectangle Select Features by area or single click tool. Selection can also be done from the attribute table. Once you have the selection set, press Delete or Backspace key or use the deleteSelectedFeatures Delete Selected tool to delete the features. Multiple selected features can be deleted at once.

The editCut 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 editPaste 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.

16.3.4.7. Undo and Redo

The undo Undo and redo Redo tools allows you to undo or redo vector editing operations. There is also a dockable widget, which shows all operations in the undo/redo history (see 图 16.86). This widget is not displayed by default; it can be displayed by right-clicking on the toolbar and activating the Undo/Redo Panel checkbox. The Undo/Redo capability is however active, even if the widget is not displayed.

../../../_images/redo_undo.png

图 16.86 Redo and Undo digitizing steps

When Undo is hit or Ctrl+Z (or Cmd+Z) pressed, 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.

16.3.4.8. Saving Edited Layers

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 saveEdits Save Layer Edits button. When you turn editing mode off with toggleEditing 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.

小技巧

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.

Saving multiple layers at once

This feature allows the digitization of multiple layers. Choose fileSaveAs Save for Selected Layers to save all changes you made in multiple layers. You also have the opportunity to rollbackEdits Rollback for Selected Layers, so that the digitization may be withdrawn for all selected layers. If you want to stop editing the selected layers, cancelEdits Cancel for Selected Layer(s) is an easy way.

The same functions are available for editing all layers of the project.

小技巧

Use transaction group to edit, save or rollback multiple layers changes at once

When working with layers from the same PostGreSQL database, activate the Automatically create transaction groups where possible option in Project ► Properties... ► Data Sources to sync their behavior (enter or exit the edit mode, save or rollback changes at the same time).

16.3.5. Advanced digitizing

表 16.4 Vector layer advanced editing toolbar

Icon

目标

Icon

目标

cad

Enable Advanced Digitizing Tools

moveFeature moveFeatureLine moveFeaturePoint

Move Feature(s)

moveFeatureCopy moveFeatureCopyLine moveFeatureCopyPoint

Copy and Move Feature(s)

rotateFeature

Rotate Feature(s)

simplify

Simplify Feature

scaleFeature

Scale Feature

addRing

Add Ring

addPart

Add Part

fillRing

Fill Ring

reverseLine

Swap direction

deleteRing

Delete Ring

deletePart

Delete Part

offsetCurve

Offset Curve

reshape

Reshape Features

splitParts

Split Parts

splitFeatures

Split Features

mergeFeatureAttributes

合并(merge)选中要素的属性

mergeFeatures

合并(merge)选中的要素

rotatePointSymbols

Rotate Point Symbols

offsetPointSymbols

Offset Point Symbols

trimExtend

Trim or Extend Feature

16.3.5.1. Move Feature(s)

The moveFeature Move Feature(s) tool allows you to move existing features:

  1. Select the feature(s) to move.

  2. Click on the map canvas to indicate the origin point of the displacement; you can rely on snapping capabilities to select an accurate point.

    You can also take advantages of the advanced digitizing constraints to accurately set the origin point coordinates. In that case:

    1. First click on the cad button to enable the panel.

    2. Type x and enter the corresponding value for the origin point you'd like to use. Then press the locked button next to the option to lock the value.

    3. Do the same for the y coordinate.

    4. Click on the map canvas and your origin point is placed at the indicated coordinates.

  3. Move over the map canvas to indicate the destination point of the displacement, still using snapping mode or, as above, use the advanced digitizing panel which would provide complementary distance and angle placement constraints to place the end point of the translation.

  4. Click on the map canvas: the whole features are moved to new location.

Likewise, you can create a translated copy of the feature(s) using the moveFeatureCopy Copy and Move Feature(s) tool.

备注

If no feature is selected when you first click on the map canvas with any of the Move Feature(s) or Copy and Move Feature(s) tools, then only the feature under the mouse is affected by the action. So, if you want to move several features, they should be selected first.

16.3.5.2. Rotate Feature(s)

Use the rotateFeature Rotate Feature(s) tool to rotate one or multiple features in the map canvas:

  1. Press the rotateFeature Rotate Feature(s) icon

  2. Then click on the feature to rotate. The feature's centroid is referenced as rotation center, a preview of the rotated feature is displayed and a widget opens showing the current Rotation angle.

  3. Click on the map canvas when you are satisfied with the new placement or manually enter the rotation angle in the text box. You can also use the Snap to ° box to constrain the rotation values.

  4. If you want to rotate several features at once, they shall be selected first, and the rotation is by default around the centroid of their combined geometries.

You can also use an anchor point different from the default feature centroid: press the Ctrl button, click on the map canvas and that point will be used as the new rotation center.

If you hold Shift before clicking on the map, the rotation will be done in 45 degree steps, which can be modified afterwards in the user input widget.

To abort feature rotation, press the ESC button or click on the rotateFeature Rotate Feature(s) icon.

16.3.5.3. Scale Feature

The scaleFeature Scale Feature tool is similar to the Rotate feature. Though instead of performing a rotation of selected features, it rescales their geometry. The change is performed in relation to the anchor point and the scale ratio can be manually specified in the widget that appears in the upper corner of the canvas.

16.3.5.4. Simplify Feature

The simplify Simplify Feature tool allows you to interactively reshape a line or polygon geometry by reducing or densifying the number of vertices, as long as the geometry remains valid:

  1. Select the simplify Simplify Feature tool.

  2. Click on the feature or drag a rectangle over the features.

  3. A dialog pops up allowing you to define the Method to apply, ie whether you would like to:

    • simplify the geometry, meaning less vertices than the original. Available methods are Simplify by distance, Simplify by snapping to grid or simplify by area (Visvalingam). You'd then need to indicate the value of Tolerance in Layer units, Pixels or map units to use for simplification. The higher the tolerance is the more vertices can be deleted.

    • or densify the geometries with new vertices thanks to the Smooth option: for each existing vertex, two vertices are placed on each of the segments originated from it, at an Offset distance representing the percentage of the segment length. You can also set the number of Iterations the placement would be processed: the more iterations, the more vertices and smoother is the feature.

    Settings that you used will be saved when leaving a project or an edit session. So you can go back to the same parameters the next time you simplify a feature.

  4. A summary of the modifications that would apply is shown at the bottom of the dialog, listing number of features and number of vertices (before and after the operation and the ratio the change represents). Also, in the map canvas, the expected geometry is displayed over the existing one, using the rubberband color.

  5. When the expected geometry fits your needs, click OK to apply the modification. Otherwise, to abort the operation, you can either press Cancel or right-click in the map canvas.

备注

Unlike the feature simplification option in Settings ► Options ► Rendering menu which simplifies the geometry just for rendering, the simplify Simplify Feature tool permanently modifies feature's geometry in data source.

16.3.5.5. Add Part

You can addPart Add Part to a selected feature generating a multipoint, multiline or multipolygon feature. The new part must be digitized outside the existing one which should be selected beforehand.

The addPart Add Part can also be used to add a geometry to a geometryless feature. First, select the feature in the attribute table and digitize the new geometry with the addPart Add Part tool.

16.3.5.6. Delete Part

The deletePart Delete Part tool allows you to delete parts from multifeatures (e.g., to delete polygons from a multi-polygon feature). This tool works with all multi-part geometries: point, line and polygon. Furthermore, it can be used to totally remove the geometric component of a feature. To delete a part, simply click within the target part.

16.3.5.7. Add Ring

You can create ring polygons using the addRing Add Ring icon in the toolbar. This means that inside an existing area, it is possible to digitize further polygons that will occur as a 'hole', so only the area between the boundaries of the outer and inner polygons remains as a ring polygon.

16.3.5.8. Fill Ring

The fillRing Fill Ring tool helps you create polygon feature that totally falls within another one without any overlapping area; that is the new feature covers a hole within the existing one. To create such a feature:

  1. Select the fillRing Fill Ring tool.

  2. Draw a new polygon over the existing feature: QGIS adds a ring to its geometry (like if you used the addRing Add Ring tool) and creates a new feature whose geometry matches the ring (like if you traced over the interior boundaries with the capturePolygon Add polygon feature tool).

  3. Or alternatively, if the ring already exists on the feature, place the mouse over the ring and left-click while pressing Shift: a new feature filling the hole is drawn at that place.

    The Feature Attributes form of the new feature opens, pre-filled with values of the "parent" feature and/or fields constraints.

16.3.5.9. Delete Ring

The deleteRing Delete Ring tool allows you to delete rings within an existing polygon, by clicking inside the hole. This tool only works with polygon and multi-polygon features. It doesn't change anything when it is used on the outer ring of the polygon.

16.3.5.10. Reshape Features

You can reshape line and polygon features using the reshape Reshape Features tool on the toolbar. For lines, it replaces the line part from the first to the last intersection with the original line.

../../../_images/reshape_lines.png

图 16.87 Reshape line

小技巧

Extend linestring geometries with reshape tool

Use the reshape Reshape Features tool to extend existing linestring geometries: snap to the first or last vertex of the line and draw a new one. Validate and the feature's geometry becomes the combination of the two lines.

For polygons, it will reshape the polygon's boundary. For it to work, the reshape tool's line must cross the polygon's boundary at least twice. To draw the line, click on the map canvas to add vertexes. To finish it, just right-click. Like with the lines, only the segment between the first and the last intersections is considered. The reshape line's segments that are inside the polygon will result in cropping it, where the ones outside the polygon will extend it.

../../../_images/reshape_polygon.png

图 16.88 Reshape polygon

With polygons, reshaping can sometimes lead to unintended results. It is mainly useful to replace smaller parts of a polygon, not for major overhauls, and the reshape line is not allowed to cross several polygon rings, as this would generate an invalid polygon.

备注

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.

16.3.5.11. Offset Curves

The offsetCurve Offset Curve tool creates parallel shifts of line layers. The tool can be applied to the edited layer (the geometries are modified) or also to background layers (in which case it creates copies of the lines / rings and adds them to the edited layer). It is thus ideally suited for the creation of distance line layers. The User Input dialog pops-up, showing the displacement distance.

To create a shift of a line layer, you must first go into editing mode and activate the offsetCurve Offset Curve tool. Then click on a feature to shift it. Move the mouse and click where wanted or enter the desired distance in the user input widget. Holding Ctrl during the 2nd click will make an offset copy. Your changes may then be saved with the saveEdits Save Layer Edits tool.

QGIS options dialog (Digitizing tab then Curve offset tools section) allows you to configure some parameters like Join style, Quadrant segments, Miter limit.

16.3.5.12. Reverse Line

Changing the direction of a line geometry can be useful for cartographical purposes or when preparing for network analysis.

To change a line direction:

  1. Activate the reverse line tool by clicking reverseLine Reverse line.

  2. Click on the line. The direction of the line is reversed.

16.3.5.13. Split Features

Use the splitFeatures Split Features tool to split a feature into two or more new and independent features, ie. each geometry corresponding to a new row in the attribute table.

To split line or polygon features:

  1. Select the splitFeatures Split Features tool.

  2. Draw a line across the feature(s) you want to split. If a selection is active, only selected features are split. Fields of resulting features are filled according to their splitting policy.

  3. You can then as usual modify any of the attributes of any resulting feature.

小技巧

Split a polyline into new features in one-click

Using the splitFeatures Split Features tool, snap and click on an existing vertex of a polyline feature to split that feature into two new features.

16.3.5.14. Split parts

In QGIS it is possible to split the parts of a multi part feature so that the number of parts is increased. Just draw a line across the part you want to split using the splitParts Split Parts icon.

小技巧

Split a polyline into new parts in one-click

Using the splitParts Split Parts tool, snap and click on an existing vertex of a polyline feature to split the feature into two new polylines belonging to the same feature.

16.3.5.15. Merge selected features

The mergeFeatures Merge Selected Features tool allows you to create a new feature by merging existing ones: their geometries are merged to generate a new one. If features don't have common boundaries, a multipolygon/multipolyline/multipoint feature is created.

  1. First, select the features you'd like to combine.

  2. Then press the mergeFeatures Merge Selected Features button.

  3. In the new dialog, the Merge line at the bottom of the table shows the attributes of the resulting feature. You can alter any of these values either by:

    • manually replacing the value in the corresponding cell;

    • selecting a row in the table and pressing Take attributes from selected feature to use the values of this initial feature;

    • pressing the Take attributes from the largest geometry to use the attributes from the longest line feature, the largest polygon, or the multipoints with the most parts;

    • pressing Skip all fields to use empty attributes;

    • expanding the drop down menu at the top of the table, select any of the above options to apply to the corresponding field only. There, you can also choose to aggregate the initial features attributes (Minimum, Maximum, Median, Sum, Count, Concatenation... depending on the type of the field. see 统计摘要面板 for the full list of functions).

    备注

    If the layer has default values or clauses present on fields, these are used as the initial value for the merged feature.

  4. Press OK to apply the modifications. A single (multi)feature is created in the layer, replacing the previously selected ones.

16.3.5.16. Merge attributes of selected features

The mergeFeatureAttributes Merge Attributes of Selected Features tool allows you to apply same attributes to features without merging their boundaries. The dialog is the same as the Merge Selected Features tool's except that unlike that tool, selected objects are kept with their geometry while some of their attributes are made identical.

16.3.5.17. Rotate Point Symbols

The rotatePointSymbols Rotate Point Symbols allows you to individually change the rotation of point symbols in the map canvas.

  1. First, you need to indicate the field to store the rotation value in. This is made by assigning a field to the symbol data-defined rotation property:

    1. In the Layer Properties ► Symbology dialog, browse to the symbol editor dialog.

    2. Click the dataDefine Data-defined override widget near the Rotation option of the top Marker level (preferably) of the symbol layers.

    3. Choose a field in the Field Type combobox. Values of this field are hence used to rotate each feature's symbol accordingly.

      You can also check the Store data in project entry to generate an auxiliary data storage field to control the rotation value.

    备注

    Make sure that the same field is assigned to all the symbol layers

    Setting the data-defined rotation field at the topmost level of the symbol tree automatically propagates it to all the symbol layers, a prerequisite to perform graphical symbol rotation with the Rotate Point Symbols tool. Indeed, if a symbol layer does not have the same field attached to its rotation property, the tool will not work.

    ../../../_images/rotatepointsymbol.png

    图 16.89 Rotating a point symbol

  2. Then click on a point symbol in the map canvas with the rotatePointSymbols Rotate Point Symbols tool

  3. Move the mouse around. A red arrow with the rotation value will be visualized (see 图 16.89). If you hold the Ctrl key while moving, the rotation will be done in 15 degree steps.

  4. When you get the expected angle value, click again. The symbol is rendered with this new rotation and the associated field is updated accordingly.

    You can right-click to abort symbol rotation.

16.3.5.18. Offset Point Symbols

The offsetPointSymbols Offset Point Symbols allows you to interactively change the rendered position of point symbols in the map canvas. This tool behaves like the rotatePointSymbols Rotate Point Symbols tool except that it requires you to connect a field to the data-defined Offset (X,Y) property of each layer of the symbol. The field will then be populated with the offset coordinates for the features whose symbol is moved in the map canvas.

  1. Associate a field to the data-defined widget of the Offset (X,Y) property of the symbol. If the symbol is made with many layers, you may want to assign the field to each of them

  2. Select the offsetPointSymbols Offset Point Symbols tool

  3. Click a point symbol

  4. Move to a new location

  5. Click again. The symbol is moved to the new place. Offset values from the original position are stored in the linked field.

    You can right-click to abort symbol offset.

备注

The offsetPointSymbols Offset Point Symbols tool doesn't move the point feature itself; you should use the vertexToolActiveLayer Vertex Tool (Current Layer) or moveFeaturePoint Move Feature tool for this purpose.

16.3.5.19. Trim/Extend Feature

The trimExtend Trim/Extend tool allows you to shorten or lengthen segments of a (multi)line or (multi)polygon geometry to converge with a selected segment (the cutting line). This results in a modified geometry with a vertex snapped to the target segment or in its prolongation. Depending on how the selected geometries are placed in relation to each other, the tool will either:

  • Trim: removes parts of the line segment or polygon boundary, beyond the cutting line

  • Extend: extends polygon boundaries or line segments so that they can snap to the cutting line.

In order to trim or extend existing geometries:

  1. Enable appropriate snapping settings on segment for the involved layer(s)

  2. Select the trimExtend Trim/Extend tool

  3. Click the target limit segment, i.e. the segment with respect to which you want to extend or trim another segment. It appears highlighted.

  4. Move to the segment you want to trim or extend. It does not need to be the last segment of the geometry, but has to be on the active layer.

  5. Hover over the segment, and QGIS displays a preview of what the feature's geometry would be. If OK, click the segment. In the case of a trim, you must select the part that should be shortened.

  6. When both segments are in 3D, the tool performs an interpolation on the limit segment to get the Z value.

注意

Pay attention to the modified geometry while using the trimExtend Trim/Extend tool. Depending on the inputs, it can create invalid geometries, potentially resulting in failure at layer saving.

16.3.6. Shape digitizing

The Shape Digitizing toolbar offers a set of tools to draw lines or polygons features of regular shape. It is synchronized with the digitizeShape Digitize Shape geometry drawing method you can select on the Digitizing Toolbar. To use it:

  1. Display the toolbar: View ► Toolbars ► Shape Digitizing

  2. Select a tool that creates or modifies the shape of a geometry, e.g. captureLine Add line feature, capturePolygon Add polygon feature, addPart Add part, addRing Add ring, reshape Reshape Features, ...

  3. The digitizeWithSegment Digitize with segment button on the Digitizing Toolbar is enabled. The first time, you may need to switch it to the digitizeShape Digitize Shape in order to enable tools on the Shape Digitizing toolbar.

  4. Pick a shape digitizing tool and draw.

16.3.6.1. Circular string by radius

The circularStringRadius Circular string by radius button allows to add line or polygon features with a circular geometry, given two nodes on the curve and a radius:

  1. Left click twice to place the two points on the geometry.

  2. A Radius widget in the top right corner of the map canvas displays current radius (corresponding to distance between the points). Edit that field to the value you want.

  3. An overview of the arcs matching these constraints is displayed while moving around the cursor. Right-click to validate when the expected arc is shown.

  4. Add a new point to start shaping another arc.

备注

Curved geometries are stored as such only in compatible data provider

Although QGIS allows to digitize curved geometries within any editable data format, you need to be using a data provider (e.g. PostGIS, memory layer, GML or WFS) that supports curves to have features stored as curved, otherwise QGIS segmentizes the circular arcs.

16.3.6.2. Draw Circles

There is a set of tools for drawing circles. The tools are described below.

Circles are converted into circular strings. Therefore, as explained in Circular string by radius, if allowed by the data provider, it will be saved as a curved geometry, if not, QGIS will segmentize the circular arcs.

  • circle2Points Circle from 2 points: The two points define the diameter and the orientation of the circle. (Left-click, right-click)

  • circle3Points Circle from 3 points: Draws a circle from three known points on the circle. (Left-click, left-click, right-click)

  • circleCenterPoint Circle by a center point and another point: Draws a circle with a given center and a point on the circle (Left-click, right-click). When used with the The Advanced Digitizing panel this tool can become a "Add circle from center and radius" tool by setting and locking the distance value after first click.

  • circle3Tangents Circle from 3 tangents: Draws a circle that is tangential to three segments. Note that you must activate snapping to segments (See 设置捕捉容差和搜索半径). Click on a segment to add a tangent. If two tangents are parallel, the coordinates of the click on the first parallel tangent are used to determine the positioning of the circle. If three tangents are parallel, an error message appears and the input is cleared. (Left-click, left-click, right-click)

  • circle2TangentsPoint Circle from 2 tangents and a point: Similar to circle from 3 tangents, except that you have to select two tangents, enter a radius and select the desired center.

16.3.6.3. Draw Ellipses

There is a set of tools for drawing ellipses. The tools are described below.

Ellipses cannot be converted as circular strings, so they will always be segmented.

  • ellipseCenter2Points Ellipse from center and two points: Draws an ellipse with a given center, major axis and minor axis. (Left-click, left-click, right-click)

  • ellipseCenterPoint Ellipse from center and a point: Draws an ellipse into a bounding box with the center and a corner. (Left-click, right-click)

  • ellipseExtent Ellipse from extent: Draws an ellipse into a bounding box with two opposite corners. (Left-click, right-click)

  • ellipseFoci Ellipse from foci: Draws an ellipse by 2 points for foci and a point on the ellipse. (Left-click, left-click, right-click)

16.3.6.4. Draw Rectangles

There is a set of tools for drawing rectangles. The tools are described below.

  • rectangleCenter Rectangle from center and a point: Draws a rectangle from the center and a corner. (Left-click, right-click)

  • rectangleExtent Rectangle from extent: Draws a rectangle from two opposite corners. (Left-click, right-click)

  • rectangle3PointsDistance Rectangle from 3 points (distance): Draws an oriented rectangle from three points. The first and second points determine the length and angle of the first edge. The third point determines the length of the other edge. One can use The Advanced Digitizing panel to set the length of the edges. (Left-click, left-click, right-click)

  • rectangle3PointsProjected Rectangle from 3 points (projected): Same as the preceding tool, but the length of the second edge is computed from the projection of the third point on the first edge. (Left-click, left-click, right-click)

    ../../../_images/draw_rectangles_3_points.png

    图 16.90 Draw rectangle from 3 points using distance (right) and projected (left)

16.3.6.5. Draw Regular Polygons

There is a set of tools for drawing regular polygons. The tools are described below. Left-click to place the first point. A dialog appears, where you can set the number of polygon edges. Right-click to finish the regular polygon.

  • regularPolygon2Points Regular polygon from two points: Draws a regular polygon where the two points determine the length and angle of the first edge.

  • regularPolygonCenterPoint Regular polygon from center and a point: Draws a regular polygon from the provided center point. The second point determines the angle and distance to the middle of an edge.

  • regularPolygonCenterCorner Regular polygon from center and a corner: Same as the preceding tool, but the second point determines the angle and distante to a vertex.

16.3.7. The Advanced Digitizing panel

When capturing, reshaping, splitting new or existing geometries you also have the possibility to use the Advanced Digitizing panel. You can digitize lines exactly parallel or perpendicular to a particular angle or lock lines to specific angles. Furthermore, you can make a precise definition of your new geometry by entering X and Y coordinates as well as Z for 3D features, or M values.

../../../_images/advanced_digitizing.png

图 16.91 The Advanced Digitizing panel

The Advanced Digitizing panel can be opened either with a right-click on the toolbar, from View ► Panels ► menu or pressing Ctrl+4. Once the panel is visible, click the cad Enable advanced digitizing tools button to activate the set of tools.

备注

The tools are not enabled if the map view is in geographic coordinates.

The aim of the Advanced Digitizing tool is to lock coordinates, lengths, and angles when moving the mouse during the digitalizing in the map canvas.

You can also create constraints with relative or absolute reference. Relative reference means that the next vertex constraints' values will be relative to the previous vertex or segment.

16.3.7.1. The toolbar

At the top of the Digitizing panel, you find the following buttons:

  • cad Enable advanced digitizing tools

  • cadConstruction Construction mode: allows to capture the clicks' positions to reuse as reference points to lock distance, angle, X, Y, Z or M relative values. More details at Construction mode.

  • cadParallel Parallel to draw a line parallel to an existing one (more at Parallel and perpendicular lines)

  • cadPerpendicular Perpendicular to draw a line perpendicular to an existing one (more at Parallel and perpendicular lines)

  • settings Snap to common angles: when moving the cursor, displays a virtual line that you can snap to to add the next vertex. The snapping line is defined by the last added vertex and an (absolute or relative to previous segment) angle from a preset list (following steps of 0.1°, 0.5°, 1°, 5°, 10°, 15°, 18°, 22.5°, 30°, 45° or 90°). Choose Do not snap to common angles to disable this feature.

    Snapping to features can be used along with snapping to common angles for accurate digitizing. For a fine-grained control on how the target element to snap to is retained, you can indicate whether to prioritize snapping to features over common angles, and vice-versa under the Snapping priority entry. You can switch from one method to the other during the digitizing operation, and this avoids disabling any of the snapping options in the meantime. Press N (or Shift+N) during a digitizing operation to cycle through the angles list.

  • floater Floater settings: if the Show floater item is checked, a contextual menu with digitizing information follows the cursor during digitizing. The values can be accessed using the panel's shortcuts, edited and locked Locked after validation (pressing Enter). The type of information to display can be selected in the bottom part of the menu:

    • Show distance

    • Show angle

    • Show XY coordinates

    • Show Z value

    • Show M value

    • Show bearing/azimuth

    • Show common snapping angle

  • extractVertices Construction Tools provides a couple of options that constrain the vertices placement based on extrapolated coordinates of existing elements:

    • unchecked Line Extension: hover over a segment and you get a purple dotted line extending the segment across the map canvas. You can snap the vertex anywhere on this virtual line.

    • unchecked X/Y Point: hover over a vertex and you get a purple dotted line along its X or Y coordinate, across the map canvas. You can snap the vertex anywhere on this virtual line. It is even possible to hover over two different vertices, generating virtual coordinate lines for both, and snap to their intersection.

Below the toolbar, you will find a number of text boxes whose value reflects by default the position or movement of the cursor in the map canvas. Editing these values helps you constrain the position of the items you edit:

  • d for the distance from a reference position, usually the last edited vertex

  • a for the angle (absolute or relative) from a reference position, usually the last edited segment

  • x for the X coordinate of the pointer

  • y for the Y coordinate of the pointer

  • z for the default Z value or the Z coordinate of the vertex or segment under the pointer

  • m for the default M value or the M value of the vertex or segment under the pointer

16.3.7.2. Keyboard shortcuts

To speed up the use of Advanced Digitizing Panel, there are a couple of keyboard shortcuts available:

表 16.5 Keyboard shortcuts of the Advanced Digitizing Panel tools

Key

Simple

Ctrl+ or Alt+

Shift+

D

Set distance

Lock distance

A

Set angle

Lock angle

Toggle relative angle to last segment

X

Set X coordinate

Lock X coordinate

Toggle relative X to last vertex

Y

Set Y coordinate

Lock Y coordinate

Toggle relative Y to last vertex

Z

Set Z coordinate

Lock Z coordinate

Toggle relative Z to last vertex

M

Set M value

Lock M value

Toggle relative M to last vertex

C

Toggle construction mode

P

Toggle perpendicular and parallel modes

备注

Z coordinate and M value options are available only if compatible with the layer geometry dimension.

16.3.7.3. Absolute reference digitizing

When drawing a new geometry from scratch, it is very useful to have the possibility to start digitizing vertexes at given coordinates.

For example, to add a new feature to a polygonal layer, click the capturePolygon button. You can enter the exact coordinates where you want to start editing the feature, i.e.:

  1. Click the x text box (or use the X keyboard shortcut).

  2. Type the X coordinate value you want and press Enter or click the locked button to their right to lock the mouse to the X axis on the map canvas.

  3. Click the y text box (or use the Y keyboard shortcut).

  4. Type the Y coordinate value you want and press Enter or click the locked button to their right to lock the mouse to the Y axis on the map canvas.

  5. If the layer has Z coordinate or M values, the corresponding z or m widget is enabled and displays its default value, as set in Settings ► Options ► Digitizing tab.

    1. Click the z or m text box (or use respectively the Z or M keyboard shortcut).

    2. Type the coordinate value you want and press Enter or click the locked button to their right to lock the value in the widget.

    备注

    Read Rules of Z coordinate or M value assignment for details on how Z coordinate and M values are automatically determined from existing features.

  6. Two blue dotted lines and a green cross identify the exact coordinates you entered. Click on the map canvas to add a vertex at the green cross position.

    ../../../_images/advanced_digitizing_coordinates.png

    图 16.92 Start drawing at given coordinates

  7. You can proceed as above, adding a new set of coordinates for the next vertex, or switch to another mode of digitizing (e.g. segment, curve or stream).

  8. If you want to draw a segment of a given length:

    1. Click the d (distance) text box (keyboard shortcut D)

    2. Type the distance value (in map units)

    3. Press Enter or click the locked button on the right to lock the mouse in the map canvas to the length of the segment. In the map canvas, the latest vertex is surrounded by a circle whose radius is the value entered in the distance text box. A cross on the circle shows the position of the next vertex if you click.

    ../../../_images/advanced_digitizing_distance.png

    图 16.93 Fixed length segment

  9. You can also constrain the vertex position, setting the angle of the segment. As described before:

    1. Click the a (angle) text box (keyboard shortcut A)

    2. Type the angle value (in degrees)

    3. Press Enter or click the locked button on the right to lock it. A line going through the latest vertex and rotated based on the set angle appears in the map canvas and a cross on it shows the next vertex position if you click.

    ../../../_images/advanced_digitizing_angle.png

    图 16.94 Fixed angle segment

提示

Pressing Ctrl+<key> or Alt+<key> automatically locks the target property and puts its value into edit. Modify, press Enter and you are done. Combined with the floater Toggle floater, this can be a real time saver, with keyboard digitizing.

16.3.7.4. Relative reference digitizing

Instead of using absolute values of angles or coordinates, you can also use values relative to the last digitized vertex or segment.

For angles, you can click the delta button on the left of the a text box (or press Shift+A) to toggle relative angles to the previous segment. With that option on, angles are measured between the last segment and the mouse pointer.

For coordinates, click the delta buttons to the left of the x, y, z or m text boxes (or press Shift+<key>) to toggle relative coordinates to the previous vertex. With these options on, coordinates measurement will consider the last vertex to be the origin of the set coordinates.

16.3.7.5. Continuous lock

Both in absolute or relative reference digitizing, angle, distance, X, Y, Z and M constraints can be locked continuously by clicking the lockRepeating Continuous lock buttons. Using continuous lock allows you to digitize several points or vertexes using the same constraints.

16.3.7.6. Parallel and perpendicular lines

All the tools described above can be combined with the cadPerpendicular Perpendicular and cadParallel Parallel tools. These two tools allow drawing segments perfectly perpendicular or parallel to another segment. The target segment can be on another layer, another feature within the layer or the feature being digitized (requires self-snapping option).

To draw a perpendicular segment:

  1. First add one of the segment vertices.

  2. Click the cadPerpendicular Perpendicular icon (keyboard shortcut P) to activate it.

  3. Click on the segment that you want to be perpendicular to.

  4. A virtual dotted line perpendicular to the segment through the previous vertex appears. The angle property is locked, constraining the next vertex on that line and, a cross indicates the projected position of the cursor on the line. Click to place the new vertex.

    ../../../_images/advanced_digitizing_perpendicular.png

    图 16.95 Perpendicular digitizing

To draw a parallel segment, the steps are the same except that you need to click on the cadParallel Parallel icon (keyboard shortcut P twice).

../../../_images/advanced_digitizing_parallel.png

图 16.96 Parallel digitizing

These two tools just find the right angle of the perpendicular and parallel angle and lock this parameter during your editing. Unlock the angle parameter to cancel their use in the middle of the process.

16.3.7.7. Construction mode

You can enable and disable construction mode by clicking on the cadConstruction Construction mode icon or with the C keyboard shortcut. While in construction mode, clicking the map canvas won't add new vertexes, but will capture the clicks' positions so that you can use them as reference points to then lock distance, angle or X, Y, Z, M relative values.

As an example, the construction mode can be used to draw some point at an exact distance from an existing point.

With an existing point in the map canvas and the snapping mode correctly activated, you can easily draw other points at given distances and angles from it. In addition to the cad button, you have to activate also the construction mode by clicking the cadConstruction Construction mode icon or with the C keyboard shortcut.

Click next to the point from which you want to calculate the distance and click on the d box (D shortcut) type the desired distance and press Enter to lock the mouse position in the map canvas:

../../../_images/advanced_digitizing_distance_point.png

图 16.97 Distance from point

Before adding the new point, press C to exit the construction mode. Now, you can click on the map canvas, and the point will be placed at the distance entered.

You can also use the angle constraint to, for example, create another point at the same distance of the original one, but at a particular angle from the newly added point. Click the cadConstruction Construction mode icon or with the C keyboard shortcut to enter construction mode. Click the recently added point, and then the other one to set a direction segment. Then, click on the d text box (D shortcut) type the desired distance and press Enter. Click the a text box (A shortcut) type the angle you want and press Enter. The mouse position will be locked both in distance and angle.

../../../_images/advanced_digitizing_distance_angle_point.png

图 16.98 Distance and angle from points

Before adding the new point, press C to exit the construction mode. Now, you can click on the map canvas, and the point will be placed at the distance and angle entered. Repeating the process, several points can be added.

../../../_images/advanced_digitizing_distance_point_final.png

图 16.99 Points at given distance and angle

16.3.8. The Processing in-place layer modifier

The Processing menu provides access to a large set of tools to analyze and create new features based on the properties of the input features or their relations with other features (within the same layer or not). While the common behavior is to create new layers as outputs, some algorithms also allow modifications to the input layer. This is a handy way to automate multiple features modification using advanced and complex operations.

To edit features in-place:

  1. Select the layer to edit in the Layers panel.

  2. Select the concerned features. You can skip this step, in which case the modification will apply to the whole layer.

  3. Press the processSelected Edit Features In-Place button at the top of the Processing toolbox. The list of algorithms is filtered, showing only those compatible with in-place modifications, i.e.:

    • They work at the feature source and not at the layer level.

    • They do not change the layer structure, e.g. adding or removing fields.

    • They do not change the geometry type, e.g. from line to point layer.

    ../../../_images/edit_inplace_algorithms.png

    图 16.100 Processing algorithms: all (left) vs polygon in-place editors (right)

  4. Find the algorithm you'd like to run and double-click it.

    备注

    If the algorithm does not need any additional user-set parameters (excluding the usual input and output layer parameters), then the algorithm is run immediately without any dialog popup.

    1. If parameters other than the usual input or output layers are needed, the algorithm dialog pops up. Fill in the required information.

    2. Click Modify Selected Features or Modify All Features depending on whether there's an active selection.

    Changes are applied to the layer and placed in the edit buffer: the layer is indeed toggled to editing mode with unsaved modification as indicated by the editableEdits icon next to the layer name.

  5. As usual, press saveEdits Save layer edits to commit the changes in the layer. You can also press undo Undo to rollback the whole modification.