# 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.&#x20;

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

<figure><img src="https://2205741137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9cMAMCb5DcFjpDJPHG1T%2Fuploads%2FOv5QpV6V95gKzjTDLj9b%2Fattribute.JPG?alt=media&#x26;token=c459fc59-a1bf-4473-a3cf-e968585180ee" alt=""><figcaption></figcaption></figure>

2. 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).&#x20;

1. In the tool bar, select `Open field calculator`

<figure><img src="https://2205741137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9cMAMCb5DcFjpDJPHG1T%2Fuploads%2FBJmgvb6NUYCsiEz6LDBN%2Ffieldcalculator.JPG?alt=media&#x26;token=a6bc5b58-551c-4061-9b68-45d45d5f4528" alt=""><figcaption></figcaption></figure>

2. 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.&#x20;

<pre><code><strong>hour(age(
</strong> to_datetime(attribute($currentfeature,'timestamp')),
 to_datetime(attribute(get_feature_by_id('points_projected',$id-1),'timestamp'))
))
</code></pre>

<figure><img src="https://2205741137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9cMAMCb5DcFjpDJPHG1T%2Fuploads%2FFrms2U55pdW74kkLaJaf%2Fhour_age_calc.JPG?alt=media&#x26;token=85067df5-8104-4b0c-97af-c3578fd9c391" alt=""><figcaption></figcaption></figure>

3. Go back to the attribute table and you'll see a new field called TimeDiff. This is only applied to&#x20;

<figure><img src="https://2205741137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9cMAMCb5DcFjpDJPHG1T%2Fuploads%2Fpab9Vhq6xDSwBjPUI6c2%2FTimeDiff.JPG?alt=media&#x26;token=d3ec16c5-3a4b-4b5f-a744-eac7376c3cf9" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
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!
{% endhint %}

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)`

<figure><img src="https://2205741137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9cMAMCb5DcFjpDJPHG1T%2Fuploads%2FIKXnVLMG94n7zzs8dTI5%2Fdatefield.JPG?alt=media&#x26;token=c906ac74-32ae-4523-854c-55235afc4edc" alt=""><figcaption></figcaption></figure>

2. Click `OK`
3. 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)`

<figure><img src="https://2205741137-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9cMAMCb5DcFjpDJPHG1T%2Fuploads%2FtJCOje9hpwvqJDRnSjac%2FDateMonth.JPG?alt=media&#x26;token=25a4c51f-8032-475c-8617-68da05823e8b" alt=""><figcaption></figcaption></figure>

6. 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:&#x20;

`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`

7. In the attribute table menu click `Save Edits` and toggle off editing mode.&#x20;
