# Calculating distance to the sea ice edge in QGIS

## Introduction

This exercise presents a method to calculate the distance from a point location to the sea ice edge, using QGIS.

The exercise will begin by outlining the input sea ice edge data source. It will also explain some fundamental set up considerations regarding projections and distance calculation before getting into the process itself.

The operations will be executed using the QGIS user interface.

## Learning outcomes

#### GIS based functions

* Awareness of projections and distance calculation&#x20;
* Geometry calculations on line features
* Vector data re-projection

#### Datasets

* Sea ice data products derived from remote sensing instruments
* A set of sample point data representing sample point locations

## Tools required

QGIS Desktop v3.x with GRASS GIS functions installed.

## The datasets

### Sea Ice edges

Download and unzip this dataset of the median sea ice edge for January, for the years 1981 - 2010:

{% file src="/files/ajzwSBiUAninhTnWgOEp" %}

This data was sourced from NSIDC Sea Ice Index, version 3. For further details, see <https://doi.org/10.7265/N5K072F8>.

*Fetterer, F., Knowles, K., Meier, W. N., Savoie, M. & Windnagel, A. K. (2017). Sea Ice Index. (G02135, Version 3). \[Data Set]. Boulder, Colorado USA. National Snow and Ice Data Center. <https://doi.org/10.7265/N5K072F8>. \[Median sea ice extent polyline for January, 1981-2010]. Date Accessed 10-07-2024.*

{% hint style="info" %}
This data is derived from sea ice concentration data, with the edge being delineated where the sea ice concentration is at 15%.  Sea ice concentration is derived using [passive microwave radiometer](https://nsidc.org/cryosphere/seaice/study/passive_remote_sensing.html) data. Objects on the earths surface emit microwave radiation at relatively low energy levels. The structure of ice typically emits more microwave radiation than the surrounding liquid water in the sea. Therefore, microwave radiometers can be used to detect the presence of sea ice.
{% endhint %}

### Sample point data

You will also need this .csv file of some point data in WGS84, latitude/longitude:

{% file src="/files/5c2Wkc1DIMZrHJ0bw7kd" %}
Sample points csv data
{% endfile %}

## The exercise

### Step 1: Open a new QGIS project and load in the datasets

Open a new QGIS project and drag and drop the `median_extent_S_01_1981-2010_polyline_v3.0.shp` file into the project.&#x20;

You will notice that in QGIS, the projection of the project will be set according to the first dataset you load in to a new project. In this case, the projection is [NSIDC Sea Ice Polar Stereographic South](https://spatialreference.org/ref/epsg/3412/), or EPSG:3412.&#x20;

You may also want to download the latest coastline from the [Antarctic Digital Database (ADD)](https://add.scar.org/) to provide some context to you project, which can be downloaded via the [ADD data catalogue](https://data.bas.ac.uk/collections/e74543c0-4c4e-4b41-aa33-5bb2f67df389/).

If you drag and drop the coastline data in to the project as well, you should get something like this:

<figure><img src="/files/XDqUNQuHl9q8LXk7tOYF" alt=""><figcaption></figcaption></figure>

Next you need to add in the point dataset. This is in the form of a csv with two columns, one for latitude and one for longitude. The projection of the data is WGS84.

In order to add these to the QGIS project, find the Add delimited Text Layer icon on the left hand side of the interface. Alternatively, go to the **Layer** Menu and select **Data Source Manager**, then choose the option of Delimited text. The dialogue box allows you to select the csv file, check it assigns the correct columns to lat and lon, and that the projection matches that of the coordinates in the csv.&#x20;

<figure><img src="/files/HVirWPKVcSXaRxXK781X" alt=""><figcaption><p>Data Source Manager - adding sample_points.csv</p></figcaption></figure>

### Step 2: Create lines representing the shortest distance between each point and the sea ice edge

For this step, we will need to use the [**v.distance** tool](https://grass.osgeo.org/grass78/manuals/v.distance.html), which is a GRASS GIS tool which comes bundled with QGIS. But first, a note on projections.

#### Re-projecting `sample_points`

The `sample_points` data we just imported is in WGS84, lat/lon. However, the sea ice edge data is on a cartesian projection, NSIDC Polar Stereographic South, with coordinates in metres away from the South Pole. Unfortunately, the v.distance tool will give very odd results if we do not make sure the `sample_points` data is in the same projection as the sea ice edge data. We therefore need to re-project it.&#x20;

To re-project vector data in QGIS, we can right click it in the layer menu and select Export. In the Export dialogue, we need to save the data as a shapefile or Geopackage, and change the output CRS (coordinate reference system) to EPSG 3412. The output dialogue should look like this:

![](/files/ts4bHtbWGOdk2exFbSeg)

This new layer, will be added to your project. We can now use it as an input to the v.distance tool.&#x20;

#### Execute v.distance tool

Open the Processing tools pane, and search for 'v.distance'. Fill in the fields as shown here:

<figure><img src="/files/YNOOTy4D4hvd0QYrOHeK" alt=""><figcaption></figcaption></figure>

Run the tool, and you will get a new line layer output to your project, which will connect each point to the closet point in on the sea ice edge. The layer is called `Distance`.

<figure><img src="/files/GmM4yuUiwguauFK78bcF" alt=""><figcaption></figcaption></figure>

### &#x20;**Step 3: calculate the length of the output lines**

We now have a set of connecting lines. If we calculate the length of these lines, we'll have a distance form each point to the closest point on the sea ice edge.&#x20;

For the sake of this exercise, we will calculate the distance on the ellipsoid. In QGIS, we can change how the software calculates distances in the Project Preferences.&#x20;

{% hint style="info" %}
There is more than one way to calculate distance in GIS. We can either calculate distance on the ellipsoid, or we can calculate it on a cartesian projection. For shorter distances, a cartesian based calculation will be fine, but we need to make sure in this case we are using an equal-distant projection. We can also calculate on the ellipsoid, which can be done for both shorter and longer distances, but should definitely be considered if we are calculating longer distances.&#x20;
{% endhint %}

#### Set QGIS to calculate distances on the ellipsoid

In the **Project** menu, select **Properties**. In this dialogue window that appears, choose the **General** tab. Choose the `WGS84` ellipsoid in the Ellipsoid drop-down menu under **Measurements.**&#x20;

![](/files/yryPhrIwS3kDvJm7B5pB)

Now we are ready to calculate the lengths of the lines.

**Use Field Calculator to extract the lengths of the lines**

In QGIS, we can make use of the Field Calculator, which allows us to make calculations based on features, their attribute&#x73;**,** and their geometries.&#x20;

{% hint style="info" %}
In GIS, vector data will always have an associated Attribute Table, which contains extra fields of information (columns) associated with each feature (rows).&#x20;
{% endhint %}

To access the attribute table of our lines feature, right click on the layer in the layer menu and select **Open Attribute Table.**&#x20;

The attribute table window will open. Locate and click the **Field Calculator** icon. This will open another window, allowing you to add a field to the table a populate it with the length of the lines. Fill in the Field Calculator as shown in the screenshot below and click **OK**:

<figure><img src="/files/VRf8la472ZqTnWvizxEZ" alt=""><figcaption></figcaption></figure>

Finally, click the Save Edits button in the Attribute Table Window, and Toggle off edit mode (the Pencil icon button).&#x20;

We now have a set of lines with length calculated in metres on the ellipsoid saved in the attribute table of the data.&#x20;

## Summary

This tutorial has described how to access sea ice edge datasets, how to load these into QGIS, how to load csv data of points and how to calculate distances. It's also highlighted some projection considerations.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guides.geospatial.bas.ac.uk/geospatial-tutorials/calculating-distance-to-the-sea-ice-edge-in-qgis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
