編集
目次
- 1 Editing
- 1.1 Setting the Snapping Tolerance and Search Radius
- 1.2 Topological editing
- 1.3 Editing an Existing Layer
- 1.3.1 Zooming and panning with the mouse wheel
- 1.3.2 Panning with the arrow keys
- 1.3.3 Adding Features
- 1.3.4 Move Feature
- 1.3.5 Split Feature
- 1.3.6 Editing Vertices of a Feature
- 1.3.7 Adding Vertices of a Feature
- 1.3.8 Moving Vertices of a Feature
- 1.3.9 Deleting Vertices of a Feature
- 1.3.10 Add Ring
- 1.3.11 Add Island
- 1.3.12 Cutting, Copying and Pasting Features
- 1.3.13 Deleting Selected Features
- 1.3.14 Snap Mode
- 1.3.15 Saving Edited Layers
- 1.4 Creating a New Layer
- 1.5 Working with the Attribute Table
Editing
QGIS supports basic capabilities for editing vector geometries. Before reading any further you should note that at this stage editing support is still preliminary. Before performing any edits, always make a backup of the dataset you are about to edit.
Note - the procedure for editing GRASS layers is different - see Section grass_digitising for details.
Setting the Snapping Tolerance and Search Radius
Before we can edit vertices, it is very important to set the snapping tolerance and search radius to a value that allows us an optimal editing of the vector layer geometries.
Snapping tolerance
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 snap tolerance, QGIS will leave the vertex where you release the mouse button, instead of snapping it to an existing vertex and/or segment.
- A general, project wide snapping tolerance can be defined choosing Settings > Options. (On Mac: go to QGIS > Preferences, on Linux: Edit > Options.) In the Digitizing tab you can select between to vertex, to segment or to vertex and segment as default snap mode. You can also define a default snapping tolerance and a search radius for vertex edits. The tolerance an be set either in map units or in pixels. In our digitizing project (working with the Alaska dataset), the units are in feet. Your results may vary, but something on the order of 300ft should be fine at a scale of 1:10 000 should be a reasonable setting.
- A layer based snapping tolerance can be defined by choosing Settings (or File) > Project Properties.... In the General tab, section Digitize you can click on Snapping options... to enable and adjust snapping mode and tolerance on a layer basis (see Figure 13).
Search radius
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.
Topological editing
Besides layer based snapping options the General tab in menu Settings -> Project Properties... also provides some topological functionalities. In the Digitizing option group you can Enable topological editing and/or activate Avoid intersections of new polygons.
Enable topological editing
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.
Avoid intersections of new polygons
The second topological option 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.
Editing an Existing Layer
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.
Tip 13 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.
Tip 14 Manipulating Attribute data
Currently only PostGIS layers are supported for adding or dropping attribute columns within this dialog. In future versions of QGIS, other datasources will be supported, because this feature was recently implemented in GDAL/OGR > 1.6.0
Tip 15 Save Regularly
Remember to toggle Toggle editing off regularly. This allows you to save your recent changes, and also confirms that your data source can accept all your changes.
Tip 16 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.
Tip 17 Zoom in Before Editing
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.
Tip 18 Vertex Markers
The current version of QGIS supports two kinds of vertex-markers - a semi-transparent circle or a cross. To change the marker style, choose Options from the Settings menu and click on the Digitizing tab and select the appropriate entry.
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 button from the 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.
Zooming and panning with the mouse wheel
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 with the arrow keys
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 digitising session.
You can perform the following editing functions:
- Add Features: Capture Point, Capture Line and Capture Polygon
- Add Ring
- Add Island
- Split Features
- Move Features
- Move Vertex
- Add Vertex
- Delete Vertex
- Delete Selected
- Cut Features
- Copy Features
- Paste Features
Adding Features
Before you start adding features, use the pan and zoom-in/ zoom-out tools to first navigate to the area of interest.
Then you can use the Capture point, Capture line or Capture polygon 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 fig:vector_digitising shows setting attributes for a fictitious new river in Alaska.
Tip 19 Attribute Value Types
At least for shapefile editing the attribue 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 vica versa. If you need to do so, you should edit the attributes in a second step within the Attribute table dialog.
Move Feature
You can move features using the Move Feature icon on the toolbar.
Split Feature
You can split features using the Split Features icon on the toolbar.
Editing Vertices of a Feature
For both PostgreSQL/PostGIS and shapefile-based layers, the vertices of features can be edited.
Vertices can be directly edited, that is, you don't have to choose which feature to edit before you can change its geometry. In some cases, several features may share the same vertex and so the following rules apply when the mouse is pressed down near map features:
- Lines - The nearest line to the mouse position is used as the target feature. Then (for moving and deleting a vertex) the nearest vertex on that line is the editing target.
- Polygons - If the mouse is inside a polygon, then it is the target feature; otherwise the nearest polygon is used. Then (for moving and deleting a vertex) the nearest vertex on that polygon is the editing target.
You will need to set the property Settings> Options>Digitizing>Search Radius10 to a number greater than zero. Otherwise QGIS will not be able to tell which feature is being edited.
Adding Vertices of a Feature
You can add new vertices to a feature by using the Add Vertex icon on the toolbar.
Note, it doesn't make sense to add more vertices to a Point feature!
In this version of QGIS, vertices can only be added to an existing line segment of a line feature. If you want to extend a line beyond its end, you will need to move the terminating vertex first, then add a new vertex where the terminus used to be.
Moving Vertices of a Feature
You can move vertices using the Move Vertex icon on the toolbar.
Deleting Vertices of a Feature
You can delete vertices by using the Delete Vertex icon on the toolbar.
Note, it doesn't make sense to delete the vertex of a Point feature! Delete the whole feature instead.
Similarly, a one-vertex line or a two-vertex polygon is also fairly useless and will lead to unpredictable results elsewhere in QGIS, so don't do that.
Warning: A vertex is identified for deletion as soon as you click the mouse near an eligible feature. To undo, you will need to toggle Editing off and then discard your changes. (Of course this will mean that other unsaved changes will be lost, too.)
Add Ring
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 'whole', so only the area in between the boundaries of the outer and inner polygons remain as a ring polygon.
Add Island
You can add island polygons to a selected multipolygon. The new island polygon has to be digitized outside the selected multipolygon.
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 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:
- Load the layer you want to copy from (source layer)
- Load or create the layer you want to copy to (target layer)
- Start editing for target layer
- Make the source layer active by clicking on it in the legend
- Use the Select tool to select the feature(s) on the source layer
- Click on the Copy Features tool
- Make the destination layer active by clicking on it in the legend
- Click on the Paste Features tool
- 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 - feature and its attributes - gets copied, make sure the schemas match.
Tip xx 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.
Deleting Selected Features
If we want to delete an entire polygon, we can do that by first selecting the polygon using the regular Select Features tool. You can select multiple features for deletion. Once you have the selection set, use the Delete Selected tool to delete the features. There is no undo function, but remember your layer isn't really changed until you stop editing and choose to save your changes. So if you make a mistake, you can always cancel the save.
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 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 xx 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.
Snap Mode
QGIS allows digitized vertices to be snapped to other vertices of the same layer. To set the snapping tolerance, go to Settings> Options->Digitizing. (On Mac: go to QGIS > Preferences, on Linux: Edit > Options.) Note that the snapping tolerance is in map units or pixels.
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. When you turn editing mode off (or quit QGIS for that matter), you are then 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.
Creating a New Layer
To create a new layer for editing, choose New Vector Layer from the Layer menu. The New Vector Layer dialog will be displayed as shown in Figure 15. Choose the type of layer (point, line or polygon).
Note that QGIS does not yet support creation of 2.5D features (i.e. features with X,Y,Z coordinates) or measure features. At this time, only shapefiles can be created. In a future version of QGIS, creation of any OGR or PostgreSQL layer type will be supported.
Creation of GRASS-layers is supported within the GRASS-plugin. Please refer to section sec:creating_new_grass_vectors for more information on creating GRASS vector layers.
To complete the creation of the new layer, add the desired attributes by clicking on the Add button and specifying a name and type for the attribute. Only Type real , Type integer , and Type string attributes are supported. 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 sec:edit_existing_layer above.
Working with the Attribute Table
To open the attribute table for a vector layer, make the layer active by clicking on it in the Map legend area. Then use Layer Layer from the main menu and and choose Open Attribute Table from the menu. It is also possible to rightlick on the layer and choose Open Attribute Table from the dropdown menu. This will open a new window which displays the attributes for every feature in the layer (figure fig:attributetable).
}caption} |
Each column can be sorted by clicking on its 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 rown down). For a simple selection 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. For more complex searches use the Advanced search ..., which will lauch the Search Query Builder described in Section sec:select_by_query.
To show selected records only, use the checkbox Show selected records only. Using the buttons at the bottom left of the window, selected fields can be removed, moved to the top of the table, or the selection can be inverted. Selected features can also be copied to the clipboard, which can also be done with Ctrl-C. You can also zoom into the selected features on the map. Toggle editing allows to edit single values of attributes.