This chapter will provide you with more advanced ways to create vector and raster data. There is a great deal of spatial data held in tabular format. Readers will learn how to map coordinate- and address-based data. Other common sources of geospatial data are historic aerial photographs and maps in hard copy. Readers will learn how to georeference scanned imagery and transform it into a target coordinate reference system. The final portion of the chapter will cover testing topological relationships in vector data and correcting any errors via topological editing.
The topics that you will cover in this chapter are as follows:
There is a lot of data with spatial components stored in spreadsheets and tables. One of the most common forms of tabular spatial data is x and y coordinates that are stored in a delimited text file. The data may have been collected with a GPS receiver, it may have been generated by a surveyor, or it may have been transcribed off topographic maps. Regardless, QGIS can map these coordinates as points by using the Add Delimited Text Layer tool:
This tool can be found by navigating to Layer | Add Layer | Add Delimited Text Layer or on the Manage Layers toolbar.
Delimited text data is simply a table with column breaks that are identified by a specific character such as a comma. With this tool, QGIS can accept either x and y coordinates or Well-Known Text (WKT) representations of geometry. WKT can contain point, line, or polygon geometry. The following is sample data, cougar_sightings.csv
, viewed in a text editor. This is a comma-delimited file with x and y coordinate values:
In this example, the first row contains the column names and definitions for the data type in each column. The column names and definitions are enclosed in quotes and are separated by commas. The first column reads "SAMPID, C, 20"
. In this case, the field name is SAMPID
. It is a text field signified by the letter C
, which stands for character, with a width of 20
characters. The final two columns contain the coordinates. These are numeric fields signified by the N
character. They have a precision of 19
and a scale of 11
.
QGIS has three requirements for the delimited text file to be mapped:
The Create a Layer from a Delimited Text File tool is simple but robust enough to handle many file-format contingencies. The following is the workflow for mapping data held in such a file:
is the regular expression for the tab character.There is a setting that can affect the behavior of the Coordinate Reference System Selector for both new layers and layers that are loaded into QGIS without a defined CRS. By navigating to Settings | Options | CRS, you can choose how these situations are handled. The choices are Prompt for CRS, Use Project CRS, or Use default CRS displayed below. The default setting is Prompt for CRS. However, if you have this set to Use project CRS or Use default CRS displayed below, then you will not be prompted to define the CRS as described earlier.
The following screenshot shows an example of a completed Create a Layer from a Delimited Text File tool:
Once the tool has been run, a new point layer will be added to QGIS with all the attributes present in the original file (unless you chose to discard empty fields). However, this is not a standalone GIS layer yet. It is simply a rendering of the tabular data within the QGIS project. As such, it will behave like any other layer. It can be used as an input for other tools, records can be selected, and it can be styled. However, it cannot be edited. To convert the layer to a standalone shapefile or another vector format, click on Save as under Layer or right-click on the layer in the Layers panel and click on Save as. Here, you can choose any OGR-supported file format, along with an output CRS of your choice. The cougar_sightings.csv
sample data has coordinates in UTM zone 13 NAD83 or EPSG:26913.
The following screenshot shows the mapped data in the cougar_sightings.csv
sample data:
As mentioned earlier, the Add Delimited Text Layer tool can also be used to map WKT representations of geometry. WKT can be used to represent simple geometries such as Point, LineString, and Polygon, along with MultiPoint, MultiLineString, and MultiPolygon. It can also represent more complex geometry types such as geometry collections, 3D geometries, curves, triangular irregular networks, and polyhedral surfaces. WKT geometries use geometry primitives such as Point, LineString, and Polygon, followed by the coordinates of vertices that are separated by commas.
For example, LINESTRING (30 10, 20 20, 40 30)
would represent the line feature shown in the following screenshot:
To demonstrate how WKT can be mapped via the Add Delimited Text Layer tool, we will map the Parcels_WKT.csv
sample data file; this has WKT geometries for eight parcels (polygons):
Parcels_WKT.csv
file is being used.The following screenshot shows an example of a completed Create a Layer from a Delimited Text File tool set up to parse a WKT file:
The data layer will be added to the Layers list and will behave like any other vector layer. The following figure shows the resulting parcel boundaries:
Here is a tip describing a way to derive WKT geometries from loaded features.
13.58.39.23