gis data analysis: creating and editing vector data ...€¦ · 3/23/2020  · dr. vijendra kumar...

15
GIS DATA ANALYSIS: CREATDING AND EDITING VECTOR DATA Page 1 Department of Geography B.A. (Hons.) Geography, II Year Geographic Information System (Practical) - QGIS Manual Dr. Vijendra Kumar Pandey GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info: If you have a geo-referenced topographic sheet, tourist map, or any other map, and you would like to perform some spatial analysis on it. The first thing that we need to do is digitalize it using the appropriate vector layer, such as point, polyline, or polygon. A vector data can be created using QGIS in Shapefile format. What is a Shapefile? A shapefile is a file that keeps a geospatial vector data format and contains the position, format, and attributes of geographic elements. A shapefile must have at least four files associated with it. These are: > .shp – this file stores the geometry of the elements; > .shx – this file stores the geometry index; > .dbf – this file stores all the information about the attributes (city names, etc.). > .prj – contain projection information. All files described above must be saved in the same directory with the same name; otherwise, the shapefile will not be loaded. Being the shapefile of a simple file structure, it has as a principal advantage, comparing with other data sources, the possibility of edition. Creating Shapefile in QGIS This guide explains how to digitize geographic features or creating a point, line, and polygon shapefile layer and editing. Procedure: 1. Creation of Project i. Open QGIS software and click on tab <Project> and from dropdown click on >New

Upload: others

Post on 12-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 1

Department of Geography B.A. (Hons.) Geography, II Year

Geographic Information System (Practical) - QGIS Manual Dr. Vijendra Kumar Pandey

GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

If you have a geo-referenced topographic sheet, tourist map, or any other map, and you would like to perform some spatial analysis on it. The first thing that we need to do is digitalize it using the appropriate vector layer, such as point, polyline, or polygon.

A vector data can be created using QGIS in Shapefile format.

What is a Shapefile?

A shapefile is a file that keeps a geospatial vector data format and contains the position, format, and attributes of geographic elements. A shapefile must have at least four files associated with it. These are:

> .shp – this file stores the geometry of the elements;

> .shx – this file stores the geometry index;

> .dbf – this file stores all the information about the attributes (city names, etc.).

> .prj – contain projection information.

All files described above must be saved in the same directory with the same name; otherwise, the shapefile will not be loaded.

Being the shapefile of a simple file structure, it has as a principal advantage, comparing with other data sources, the possibility of edition.

Creating Shapefile in QGIS This guide explains how to digitize geographic features or creating a point, line, and polygon shapefile layer and editing.

Procedure:

1. Creation of Project i. Open QGIS software and click on tab <Project> and from dropdown click on >New

Page 2: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 2

ii. Now we need to save this project>save>select directory>name and click <ok>. A project will be created, and the name you have assigned will appear on the top left.

iii. Add your raster data (Georeferenced map) to this project. Click on Layer>Add layer>Add Raster layer.

iv. A new window will appear. You need to navigate to the folder and select raster data and click on add>close. The map is added to you project.

2. Creation of Vector layer (Shapefile)

Page 3: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 3

a) To create a new vector layer, click Layer >New >New Shapefile Layer.

b) Select the type of shapefile you wish to create; first, you need to choose a file name. Click on the right side <….> to navigate a directory and write your file name. Next is the selection of Geometry type, which in this example is a polygon (1). Select the appropriate projection for your shapefile by clicking ‘Specify CRS’ (2). As ‘WGS 84 / UTM zone 44N’, for Mirzapur (UP).

c) The next important point is the creation of an attribute table. In the ‘New Feild’ box, you can create new fields to add to the attributes list (3). Further attributes can be added later, so for now, just add ‘name’ and ‘description,’ both of type Text, and click OK.

Page 4: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 4

d) Click OK, and a new layer will be created and appear in the Layer panel.

e) Similarly, you can create a point and polyline layer.

3. Digitization of geographic features Initially, the layer which is created is locked. You cannot capture any features in the file. To enable it for digitization click on the file name to <select> it and then right click>toggle editing

Page 5: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 5

Now you can see all the icons shown above are enabled/ highlighted.

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:

Page 6: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 6

Table Editing: Vector layer basic editing toolbar

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.

Enabling editing can also be started by choosing the Toggle editing option found in the context menu of a given layer, from the attribute table dialog, the digitizing toolbar, or the Edit menu.

Tip

Save Regularly

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

Adding Features

You can use the Add Feature, Add Feature or Add Feature icons on the toolbar to add a new feature (point, line, and polygon) into the current layer.

In this example, we will use Add Feature tool to digitize polygon features.

Page 7: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 7

To begin digitization, click on the above-said tool and zoom the desired feature to capture the accurate shape. Digitization can begin with the left click a <node> will be created and now trace the entire feature. Click regularly to add <vertex> and finally right-click to end the capturing feature.

For linear or curved geometries, keep on left-clicking for each additional point you wish to capture or use the automatic tracing capability to accelerate the digitization. You can switch back and forth between linear Add feature tool and curved Add circular string... tools to create compound curved geometry. Pressing Delete or Backspace key reverts the last node you add. When you have finished adding points, right-click anywhere on the map area to confirm you have finished entering the geometry of that feature.

Adding Attributes

Once you have right-clicked in the polygon digitization, a new window will appear that will enable you to input feature attribute data.

Editing Features If you have completed the digitization of various features in the dataset and noticed that the geometry of a feature is not correct. It needs to be corrected.

Here, advance editing tools come to the rescue. We can correct as well as reshape the features.

1. Reshape Features Reshape features tools enable large-scale changes in the feature's geometry. It is a simple process. Identify the section of a feature, which needs to be corrected, zoom it properly and

click on <reshape feature tool> and trace the new geometry.

Page 8: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 8

2. Node Tool Node tool is another option to correct the geometry of a feature. This tool works when the

target feature is selected. To select the feature use the tool.

Basic operations

Start by activating the Node Tool and selecting a feature by clicking on it. Red boxes will appear at each vertex of this feature.

• Selecting vertices: You can select vertices by clicking on them one at a time, by clicking on edge to select the vertices at both ends, or by clicking and dragging a rectangle around some vertices. When a vertex is selected, its color changes to blue. To add more vertices to the current selection, hold down the Ctrl key while clicking. Hold down Ctrl when clicking to toggle the selection state of vertices (vertices that are currently unselected will be selected as usual, but also vertices that are already selected will become unselected).

• Adding vertices: To add a vertex, simply double click near an edge, and a new vertex will appear on edge near to the cursor. Note that the vertex will appear on edge, not at the cursor position; therefore, it should be moved if necessary.

• Deleting vertices: Select the vertices and click the Delete key. Deleting all the vertices of a feature generates, if compatible with the data source, geometry less feature. Note that this doesn’t delete the complete feature, just the geometry part; To delete a complete feature, use the Delete Selected tool.

• Moving vertices: Select all the vertices you want to move, click on a selected vertex or edge and drag in the direction you wish to move. All the selected vertices will move together. If snapping is enabled, the whole selection can jump to the nearest vertex or line.

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.

Page 9: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 9

Move features with precision

The Move Feature tool doesn’t currently allow to snap features while moving. Using the Node Tool, select ALL the vertices of the feature, click a vertex, drag and snap it to a target

vertex: the whole feature is moved and snapped to the other feature.

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.

Tip

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.

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)

Page 10: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 10

3. Start editing for the target layer 4. Make the source layer active by clicking on it in the legend

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

6. Click on the Copy Features tool 7. Make the destination layer active by clicking on it in the legend

8. Click on the 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.

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 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 Delete Selected tool to delete the features. Multiple selected features can be deleted at once.

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.

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 Save Layer Edits button. When you turn editing mode off with Toggle editing (or quit QGIS for that matter), you are also asked if you want to save your changes or discard them.

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.

Page 11: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 11

Advanced digitizing Icon Purpose Icon Purpose

Enable Advanced Digitizing Tools

Enable Tracing

Undo

Redo

Rotate Feature(s)

Simplify Feature

Add Ring

Add Part

Fill Ring

Delete Ring

Delete Part

Offset Curve

Reshape Features

Split Parts

Split Features

Merge Attributes of Selected Features

Merge Selected Features

Rotate Point Symbols

Offset Point Symbols

Table Advanced Editing: Vector layer advanced editing toolbar

Undo and Redo

The Undo and Redo tools allow you 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_undo). 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.

Page 12: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 12

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.

Rotate Feature(s)

Use Rotate Feature(s) to rotate one or multiple features in the map canvas. Press the Rotate

Feature(s) icon and then click on the feature to rotate. Either click on the map to place the rotated feature or enter an angle in the user input widget. If you want to rotate several features, they shall be selected first.

If you enable the map tool with feature(s) selected, its (their) centroid appears and will be the rotation anchor point. If you want to move the anchor point, hold the Ctrl button, and click on the map to place it.

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

To abort feature rotation, you need to click on Rotate Feature(s) icon.

Simplify Feature

The Simplify Feature tool allows you to reduce the number of vertices of a feature, as long as the geometry remains valid. With the tool, you can also simplify many features at once or multi-part features.

First, click on the feature or drag a rectangle over the features. A dialog where you can define tolerance in map units, layer units, or pixels pops up, and a colored and simplified

Page 13: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 13

copy of the feature(s), using the given tolerance, appears over them. QGIS calculates the amount of vertices that can be deleted while maintaining the geometry. The higher the tolerance is, the more vertices can be deleted. When the expected geometry fits your needs, just click the [OK] button. The tolerance you used will be saved when leaving a project or when leaving an edit session. So you can go back to the same tolerance the next time when simplifying a feature.

To abort feature simplification, you need to click on Simplify Feature icon.

Note

Unlike the feature simplification option in Settings ‣ Options ‣ Rendering menu, which

simplifies the geometry just for rendering, the Simplify Feature tool permanently modifies feature’s geometry in the data source.

Add Part

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

The Add Part can also be used to add geometry to a geometry less feature. First, select the

feature in the attribute table and digitize the new geometry with the Add Part tool.

Delete Part

The Delete Part tool allows you to delete parts from multi-features (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.

Add Ring

You can create ring polygons using the 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.

Fill Ring

You can use the Fill Ring function to add a ring to a polygon and add a new feature to the layer at the same time. Using this tool, you simply have to digitize a polygon within an

existing one. Thus you need not first use the Add Ring icon, and then the Add feature function anymore.

Page 14: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 14

Delete Ring

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

Reshape Features

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

Reshape line

Tip

Extend linestring geometries with reshape tool

Use the 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.

Page 15: GIS Data Analysis: Creating and Editing Vector Data ...€¦ · 3/23/2020  · Dr. Vijendra Kumar Pandey . GIS Data Analysis: Creating and Editing Vector Data (Shapefile) Brief Info:

G I S D A T A A N A L Y S I S : C R E A T D I N G A N D E D I T I N G V E C T O R D A T A

Page 15

Split Features

You can split features using the Split Features icon on the toolbar. Just draw a line across the feature you want to split.

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 Split Parts icon.

Tip

Split a polyline feature in one-click

A single click on a snapped vertex of a line feature with the Split Features or Split Parts tool is enough to have it split into new features or parts.

Merge selected features

The 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 multi polygon/multipolyline/multipoint feature is created.

First, select several features. Then press the Merge Selected Features button. In the new dialog, you can select at the top of the dialog which value to apply to each field of the new feature. That value can be:

• picked from the attributes of the initial features, • an aggregation of the initial features attributes (Minimum, Maximum, Median, Sum,

Count Concatenation... depending on the type of the field. see Statistical Summary Panel for the full list of functions),

• skipped, meaning that the field will be empty, • or manually entered, at the bottom of the rows.

Merge attributes of selected features

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

The Offset Point Symbols tool doesn’t move the point feature itself; you should use the Node Tool or Move Feature tool for this purpose.