# Minimum Convex Polygon

### Overview

Create Minimum Convex Polygon (MCP) of the movement data using Minimum Bounding Geometry tool and R. These are the simplest defined areas; polygons defined by the outside extent of the data points. The MCP is probably the most widely used estimation method. This method consists in the calculation of the smallest convex polygon enclosing all the relocations of the animal. Convex polygons do tend to overestimate home ranges and may include a lot of area not utilized or occupied

### Minimum Bounding Geometry

1. In the processing tool box, search for `Minimum Bounding Geometry`
2. Select your input layer, and Convex Hull as the geometry type. Alternatively you could select concave, however this will encompass fewer regions of space not used by the animal when compared to convex geometry. \*Extreme outlier points will impact the shape, area, perimeter or centroid of this output.

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

3. Your map should look something like this:

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

### DB Manager

Alternatively, we can use a SQL statement to create a convex hull.&#x20;

1. Navigate to `Database` > `DB manager`
2. Select `Virtual Layers` > `points`
3. Select `SQL Window` and enter the following Query:

`SELECT row_number() OVER () As tag_ident, ST_ConvexHull(ST_Collect(geometry)) FROM points;`

4. Toggle on `Load as Layer`
5. Select `Load`

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

Looks like there's a lot of unused space. Is the area calculated normally used by these individuals? We can see how MCP home range size changes by excluding a certain percentage of points using the MCP function in the R Provider.&#x20;

{% hint style="warning" %}
In this next part we will run an R script to specify the percentage of coordinates to be included. You need R and the adehabitatHR package installed to run the script in QGIS.
{% endhint %}

### MCP adehabitatHR package (<mark style="color:red;">Advanced</mark>)

The package adehabitatHR contains functions dealing with home-range analysis. See [this ](https://mran.microsoft.com/snapshot/2016-08-05/web/packages/adehabitatHR/vignettes/adehabitatHR.pdf)link for more information.

Being able to interface from R to QGIS has multiple benefits to the R user community. It is a special feature of QGIS that it acts as an umbrella integrating various other GIS power houses under its hood.&#x20;

When you downloaded GIS resources there are already some shared R scripts that can be used without having to write any code. Navigate to your processing tool > R > Home Range Analysis

<figure><img src="/files/9mx7PXYi251ozvkBGQ7U" alt=""><figcaption></figcaption></figure>

Right click on this script and select Edit. You can now see exactly what the tool will be doing using R.

```
##Home Range Analysis=group
##load_vector_using_rgdal
##Layer=vector
##Percentage=number 50

##Home_ranges=Output vector
library(adehabitatHR)
Home_ranges<-mcp(Layer,percent=Percentage)

```

If you want to group it by a field copy and paste this code in your script editor

```
##Home Range Analysis=group
##load_vector_using_rgdal
##Layer=vector
##Percentage=number 50
##Field=Field Layer
##Home_ranges=Output vector
library(adehabitatHR)
Home_ranges<-mcp(Layer[,Field],percent=Percentage)
```

Every R Script in QGIS **must** specify some parameters **before** the script body:

1. The name of the group in which you want to put your script (if the group does not exist, it will be created):

   ```
   ##Home Range Analysis=group
   ```
2. You have to tell Processing that you want to display a vector

   ```
   ##load_vector_using_rgdal
   ```
3. You also need to tell Processing about your input data. In this example we want to create a MCP from a field of a vector layer:

   ```
   ##Layer=vector
   ```

   Processing now knows that the input is a vector. The name *Layer* is not important, what matters is the **vector** parameter.
4. You also  have to specify the input field of the vector layer (using the name you have provided above - *Layer*):

   ```
   ##Field=Field Layer
   ```

   Processing now knows that you need a field of *Layer*, and that you will call it **X**.
5. Finally you have to specify output type

   ```
   ##Home_ranges=Output vector
   ```

To run the R script, double click it from the processing tool box and a GUI will appear. Fill in the parameters and click `Run.`

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

One problem with Convex Hulls is they don't account for different densities of points in different areas of the home range. Kernel density estimates the probability of finding a point within every area of the study region and maps those probabilities as a continuous surface. Let's run a KDE next!


---

# 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://uttws.gitbook.io/gis-workshop/exercise/visualization-methods/minimum-convex-polygon.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.
