QGIS Basic Skills Serial | 10 How to open a text file with coordinates

 01 delimited text file

 

Text files include txt, csv, dat, wkt and other file formats. Use the [Delimited Text File] tab in [Data Source Manager] to open the text file with spatial location information and restore its spatial graphics to display on the map Window.

 

The following takes the QGIS sample data qgis_sample_data\csv\elevp.csv as an example to demonstrate the process of opening a text file.

 

Open qgis_sample_data\csv\elevp.csv with Notepad and observe that the original data is a semicolon-separated text file with three columns: X, Y coordinates and elevation ELEV.

 

 

Click the [Open Data Source Manager] button to open the Data Source Manager dialog box. Switch to the separated text file tab and click the [...] browse button to the right of the file name.


 

Navigate to the directory where qgis_sample_data\csv\elevp.csv is located and select the file, click the [Open] button, close the dialog box and return to the data source manager.

 

 

It can be seen that [File name] is filled with the path of the imported file. Fill in the name in [Layer Name], such as "elevp", the layer name will be displayed in the [Layer] panel. [Code] Keep the default.

 

 

 02 Set file format

 

After setting the file path and name, QGIS parses the file according to the most recently used separator. For example, the most recent imported text file used a custom delimiter, this option will expand the check box of the predefined delimiter, such as comma, tab, semicolon, colon, space, etc. The elevp.csv file is parsed according to the checked "tab" and "comma". From the [Data Sample] table, it can be seen that the elevp.csv file is not parsed correctly.

 

 

 

At this time, if you check "Semicolon", you can see in the [Data Sample] area that the text file will be correctly divided into three columns.

 

 

If you select the CSV format (only separated by commas) option, although elevp.csv is a CSV format file, it is not comma separated, so it cannot be parsed correctly.

 

 

Select the delimiter as a regular expression. Regular expression is a very flexible and free string matching mode. Using regular expressions, complex separator patterns can be constructed. When we know that the separator of the text file is a semicolon, directly filling in the semicolon in the [Expression] text box can also parse the text content correctly.

 

 

 03 record and field options

 

In order to easily identify the field data in the file, QGIS sets the following options:

 

[Number of lines ignored from the beginning of the file]: If the first line or the first few lines of the imported file are blank lines, or the format is not uniform and cannot be recognized, you can set to ignore.

 

[The first line contains the field name]: If checked, the first line of text will be used as the field name, otherwise, QGIS will use the default column names: "Field 1", "Field 2"...

 

[Detection field type]: If checked, QGIS will automatically recognize the field type, otherwise, set all fields to text type.

 

[Decimal point is a comma]: Force the decimal point separator to be a comma.

 

[Cut the spaces before and after the field]: Automatically crop the spaces before and after the field when importing.

 

[Ignore empty fields]: Ignore empty fields in the record.

 

 

 04 Geometry definition

 

Based on the correct analysis of the text file, you can start to set the imported geometry type:

 

 

When the delimited text file contains X, Y, Z coordinates (elevation coordinates in three dimensions), or M fields (measurement dimensions), they should be represented by point layers in the map.

 

Select the point coordinates, set [Horizontal Coordinate Field] and [Vertical Coordinate Field], if there is an elevation value, set it to [Z Field], and set other measurement values ​​to [M Field]. If the coordinates are composed of degrees/minutes/seconds, check [Degrees, minutes, and seconds format coordinates].

 

Finally, click the Select Coordinate Reference System button to set the correct coordinate reference system and complete the geometrical figure definition settings of the point coordinates.

 

 

 05 WKT text

 

When the text file uses the WKT format to provide geometric information, select the WKT text option and set the [Geometric Field] and [Geometric Type].

 

 

[Geometric Field]: The name of the field storing WKT geometric figures.

 

【Geometric Figure Type】: Including point, line and surface types. The default is "Detect", that is, QGIS will automatically detect the geometry type based on the field content.

 

Let's take a look at some examples of text files in WKT format.

 

The WKT format of point data is as shown below:

 

 

To import the above WKT format point data, set the following settings on the [Delimited Text File] tab page:

 

  1. [File name]: The path to store the WKT file, such as: D:\MyData\WKT sample\Point.txt.

  2. [Layer name]: The default is OK.

  3. [File Format]: Select "Custom Separator", and then check "Colon".

  4. [Record and field options]: Check "The first line contains field names" and "Detect field type".

  5. [Geometry definition]: Select WKT text, [Geometry field] select the "point" field, and [Geometry type] select "Detection".

  6. [Geometric Coordinate Reference System]: Click the Select Coordinate Reference System button and select WGS84.

  7. Finally, click the [Add] button, click [Close] to close the dialog box and return to the main QGIS window.

 

 

After importing, the effect is as shown in the figure below. In order to facilitate observation, set the imported points to big red here, and set the label to display the name of the point.

 

 

The WKT format of line elements is as follows:

 

 

The import settings of line elements are basically the same as those of points, as shown in the figure below:

 

 

Import effect, you can see that the layer contains two line elements, for the convenience of observation, the same label is set.

 

 

The WKT format of polygon features is:

 

 

The settings of each parameter are:

 

 

After opening the WKT text of the above area element, the display effect in the QGIS map window is as follows:

 

 

If the text file you want to import has no geometric figures, you can select the [No Geometry (Pure Attribute Table)] option.

 

Delimited text files are a common data source of GIS, but for most GIS software, text files cannot be edited directly. Therefore, the text file layer can be set for visualization, but elements cannot be added and edited. If you really need to edit the file, it is recommended to export the layer as a data source in other formats, such as Shapefile, GeoPackage, etc.

 


Copyright Notice

 

This article welcomes reprinting, please indicate the source when reprinting.

 

 

Guess you like

Origin blog.csdn.net/QGISClass/article/details/108994098