Attribute Table

Overview

To view information about all the GPS data as a table, we'll use the attribute table. In addition we'll practice creating new fields using the field calculator.

  1. Right click the layer from the layers panel and select Attribute table. This will open a new window that displays the feature attributes for the layer

  1. In table view, each row in the attribute table displays the attributes of a unique feature in the layer. Selecting a row selects the feature and likewise, selecting a feature in the map canvas (in case of geometry enabled layer) selects the row in the attribute table. If the set of features selected in the map canvas (or attribute table) is changed, then the selection is also updated in the attribute table (or map canvas) accordingly.

Editing Attribute Table

To edit features in the table, add/delete fields, first toggle on edit mode found in the upper left hand corner of the attribute table (pencil icon).

  1. In the tool bar, select Open field calculator

  1. In the expression builder use the following code to calculate time difference between points. All functions can be found in the function list and is modeled off of a SQL-like style and uses its own simple expression language. The following expression uses several functions age, to_datetime and hour to calculate the time difference. Since the timestamp field is a string we need to convert it to datetime.

hour(age(
 to_datetime(attribute($currentfeature,'timestamp')),
 to_datetime(attribute(get_feature_by_id('points_projected',$id-1),'timestamp'))
))
  1. Go back to the attribute table and you'll see a new field called TimeDiff. This is only applied to

The next part will show you how to add a season field to your GPS data. This won't be covered in the workshop unless time allows. Feel free to try it out on your own!

  1. First, convert the date/time field to just a date field. Toggle on Create New Field > set the output field type to Date > enter the following in the expression to_date(timestamp)

  1. Click OK

  2. The next field we'll make is a month field. We'll extract this from the date field using the month function. Repeat steps 1 -3 and change the output field to Integer and the expression to month(Date)

  1. Finally, we'll create a season field. Repeat steps 1 - 3 except change the output field name to season, field type to Text (string) and enter the following expression:

CASE WHEN DateMonth BETWEEN 1 AND 2 THEN 'winter' WHEN DateMonth BETWEEN 9 AND 11 THEN 'fall' WHEN DateMonth = 12 THEN 'winter' WHEN DateMonth BETWEEN 6 AND 8 THEN 'summer' WHEN DateMonth BETWEEN 3 AND 5 THEN 'spring'

END

  1. In the attribute table menu click Save Edits and toggle off editing mode.

Last updated