QGIS 3.14|Earthquake data animation effect combat (1) data preparation

Some time ago, I searched for QGIS related information. I accidentally discovered that Nyall Dawson, a member of the QGIS development team and the author of the Temporal Controller plug-in, released a live video. Taking seismic data as an example, it demonstrated the time control and map animation of QGIS 3.14. Inspired, so the sorted out ideas came into being.

First look at the final animation effect:

Insert picture description here


Achieving the effect of the above picture requires a more complicated operation process. I disassembled it into three chapters: data preparation, animation setting, and progress bar setting. Through detailed steps, the seismic data animation effect in Nyall Dawson live broadcast is reproduced. This article is the first in a series, namely data preparation.

01 Obtain demo data


The demonstration data uses the seismic data provided by the National Oceanic and Atmospheric Administration (NOAA). The download address is:

http://www.ngdc.noaa.gov/nndc/struts/results?type_0=Exact&query_0=$ID&t=101650&s=13&d=189&dfn=signif.txt


02 Open the base map and import the data


  • Open the OpenStreetMap basemap

From the [Browse] panel, expand the [XYZ Tiles] node and double-click [OpenStreetMap] to add the base map of OpenStreetMap to the map window.


Insert picture description here


  • Import seismic data

1. Click the [Add Text Data Layer] button on the [Layer Management] toolbar to open the [Data Source Manager] dialog box.

2. Click the [...] button on the right side of [File name], browse to the seismic data TXT text file, and fill it in the text box.

3. [Layer name] can be set to any character, fill in "signif" here as the layer name, and the name will be displayed in the [Layer] panel.

4. [File Format] Select "Custom Separator" and check the "Tab" on the right.

5. In the [Geometric Definition], select "LONGITUDE" for [Horizontal Coordinate Field], and "LATITUDE" for [Vertical Coordinate Field].

6. Finally, click the [Add] button below to add the data to the map window.


Insert picture description here


QGIS will randomly select the rendering color for the newly added layer. If you are not satisfied with the default color, you can click the [Open Layer Style Panel] button above the [Layer] panel and set your favorite in the [Layer Style] panel colour.

Insert picture description here


03 Data extraction

  • Observe the attribute table of seismic data

In the [Layer] panel, right-click the "signif" layer, and select [Open Attribute Table] from the pop-up menu.

Insert picture description here


It can be seen that the layer contains a total of 6207 earthquake event points, and the six fields of "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", and "SECOND" constitute the time attribute of the earthquake. Due to the large time span and many elements, the time period of interest can be selected as the research interval. This article will use the earthquake points from January 1, 2018 to present as demonstration data.


Insert picture description here


  • Extract a subset of data

Click the [Use expression to select elements] button on the toolbar at the top of the attribute table window to call up the [Expression String Builder] dialog box.

Enter the following expression in the expression code editing area:

if ( to_int("year") >= 2018,1,0 )

Insert picture description here

This expression uses an if conditional statement to determine whether the "year" field is greater than 2018, if it is, it returns 1, otherwise it returns 0. "to_int" is a conversion function, which is used to convert the "year" field of the string type to a numeric type for easy comparison.

Click the [Select Elements] button in the lower right corner, a bubble will pop up at the top of the map window to show that 151 elements have been selected, and they will be highlighted in the map canvas with a yellow dot.

  • Export selection set

Next, export the selected features as a separate layer. Close the expression builder dialog box, right-click the "signif" layer in the [Layer] panel, and select [Export] -> [Save selected elements as...] in the pop-up menu, and open [Save vector layer as...] Dialog box.

Insert picture description here


Save format can choose Shapefile, SpatiaLite, Geojson, GML, MIF, GeoPackage, etc., this article chooses GeoPackage format to save. Click the [...] button on the right side of [File Name] to open the [Save Layer As] dialog box, set the file name to "quake2020", and click the [Save] button to close the dialog box.


Insert picture description here


Return to the [Save Vector Layer As...] dialog box, keep other default options, make sure to check the [Add the saved file to the map] below, click [OK] to complete the selection set export.


Insert picture description here


You can see that the exported layer "quake2020" is added to the map window. Uncheck the "signif" layer and keep the OpenStreetMap basemap and the "quake2020" layer in the map window.


Insert picture description here


04 Time data conversion

QGIS 3.14 uses the built-in Temporal Controller plug-in instead of TimeManager to implement time series animation. Due to the different implementation methods of animation, the time field of Temporal Controller currently only supports Date/DateTime, while the time attribute in seismic data is It consists of six character string fields: "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", and "SECOND". Therefore, these six fields need to be synthesized and converted to Date or DateTime.

(For Temporal Controller's support for temporal attributes, please refer to: https://qgis.org/en/site/forusers/visualchangelog314/#feature-cumulative-temporal-range-setting-in-temporal-controller .)

  • Handling abnormal data

Right-click the "quake2020" layer in the [Layer] panel, and select [Open Attribute Table] from the pop-up menu to open the attribute table window of the layer.

Insert picture description here


In order to check whether there is abnormal data, click the column names of "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", and "SECOND" in order to sort them in ascending order. Obviously, the "HOUR", "MINUTE" and "SECOND" fields have null values ​​(NULL), and the "SECOND" field has spaces. These are abnormal data. It is known from the knowledge of expressions that the participation of abnormal data in expression operations may cause expression errors.

In this article, if the hour, minute, and second of the earthquake are unknown (NULL value), it is acceptable for the time to be accurate to the day, so the abnormal data of "HOUR", "MINUTE" and "SECOND" can be processed as 0 in advance. That is to say, for the unknown "HOUR", "MINUTE" and "SECOND" earthquake events, the default occurs at 00:00:00 of the day.


Insert picture description here


Click the [Open Field Calculator] button on the toolbar of the attribute table window to pop up the [Field Calculator] dialog box.


Insert picture description here


Check [Update existing field], select the field "HOUR" in the drop-down box, and enter the following expression in the expression code editing area:


if (NOT  "HOUR" IS NULL , "HOUR" ,0)

Insert picture description here

This expression uses an if conditional statement to determine whether the "HOUR" field is NULL, if "HOUR" is NULL, then "HOUR" is assigned a value of 0, otherwise, the original value is still retained.


Note that before any update operations on the layer, the layer should be set to editable status, otherwise a prompt message will appear under the expression builder: You are editing the information in the layer, but the layer is currently in a non-editable state. Edit mode.


Click the [OK] button to close the [Field Calculator] dialog box. It can be seen that the [Switch Edit Mode] in the toolbar of the attribute table window is in the selected state, which means that the current layer is automatically opened for editing. Click the "HOUR" field name again and make sure that NULL has been updated to 0.


Insert picture description here


Repeat the previous step, change the updated field to "MINUTE", and deal with the NULL situation in the "MINUTE" field.


if (NOT  "MINUTE" IS NULL , "MINUTE" ,0)

Insert picture description here


The "SECOND" field has abnormal data with spaces, so in addition to the need to determine whether it is NULL, it is added to determine whether the string is composed of spaces. The specific implementation logic is: first use the trim function to remove the spaces before and after the value of the "SECOND" field, and then use the length function to determine the length of the string after removing the spaces. If the length is 0, it means that the "SECOND" field of the current element is all If it is composed of spaces, update the value to '0', otherwise keep the original "SECOND" value.


if( "SECOND" is NULL  OR  length(  trim("SECOND" ))=0,0,"SECOND")

Insert picture description here


  • Generate time field

Check the attribute data table again to ensure that the relevant fields have no abnormal data, and click the [Open Field Calculator] button in the toolbar to construct the expression generation time field.


Insert picture description here


In the [Field Calculator] dialog box, check [New Field], [Output Field Name] fill in "time", [Output Field Type] select "Date and Time", and enter in the expression code editing area:


make_datetime(  "YEAR" , "MONTH" , "DAY" , "HOUR" , "MINUTE" , "SECOND" )

Insert picture description here


The above expression uses the make_datetime function to merge the six fields "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", and "SECOND" into a time field. Click the [OK] button to return to the attribute table window.


As you can see, a date and time type field named "time" has been added to the attribute table, and the time corresponds to "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", and "SECOND".


Insert picture description here


At this point, the preparation of seismic data is complete, and the next article will explain the animation settings of seismic data.


Wu Jianling

August 25, 2020


Copyright Notice


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


This article is compiled with reference to Nyall Dawson's video. Nyall Dawson is a member of the QGIS development team. He has 10 years of QGIS development experience. His live broadcast is clearly organized and innovative. Interested friends can watch related videos at: https://www.youtube.com/watch? v=vgDg5cRwPRw.

Insert picture description here

Guess you like

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