EcoMetriQReference Book

8. Spatial analyses (Spatial Analysis)

Tab: 🗺️ Spatial Analysis · Code: ui/main_dialog.py:1769-2209 (interface), modules/spatial_analysis.py (CoordProjector, EqualAreaProjector, KernelDensityEstimator, HotspotAnalysis, IUCNRangeIndices, AlphaShape), modules/qgis_layer_output.py (layers)

8.1 What this tab does

This tab analyzes where the records are. There are four tools:

Tool Question Output layer
Kernel density (KDE) Where do the records concentrate? density raster (GeoTIFF) + point layer
Getis-Ord Gi* Do units with high values cluster significantly next to one another? hotspot/coldspot layer
EOO / AOO Over how large an area does the species (or set of records) extend? convex hull + 2 km cell layer
Alpha shape What is the concave boundary of the range (excluding gaps)? area layer

All tools use the records loaded in Data Input. With Species Selection, either all records (All Species (combined)) or the records of a single species are analyzed.

8.2 Coordinates and projections

Records are read as WGS84 latitude-longitude (§3.4). Because distances and areas cannot be computed in degrees, in every computation EcoMetriQ converts the coordinates to a metric projection centered on the center of the data (the mean latitude and longitude of all points). A sphere of radius R = 6{,}371{,}008.8 m (the IUGG mean radius) is used.

Projection Where Property Code
Azimuthal equidistant (AEQD) KDE, Gi* Preserves distances from the center exactly; local distance distortion is less than 0.1% within 200 km of the center modules/spatial_analysis.py:73-135
Lambert azimuthal equal-area (LAEA) EOO, AOO, alpha shape Preserves areas exactly modules/spatial_analysis.py:139-190

The projection formulas are from Snyder (1987, pp. 182-202). With the mean point (\lambda_0, \varphi_0), a point (\lambda, \varphi) and \cos c = \sin\varphi_0 \sin\varphi + \cos\varphi_0 \cos\varphi \cos(\lambda - \lambda_0):

\text{AEQD:}\quad k = \frac{c}{\sin c} \qquad \text{LAEA:}\quad k = \sqrt{\frac{2}{1 + \cos c}}
x = R\,k \cos\varphi \sin(\lambda - \lambda_0) \qquad y = R\,k \left[ \cos\varphi_0 \sin\varphi - \sin\varphi_0 \cos\varphi \cos(\lambda - \lambda_0) \right]

Each output text gives the PROJ string of the projection used; for EOO in the sample data:

+proj=laea +lat_0=37.41116036156765 +lon_0=30.89557611538504 +x_0=0 +y_0=0 +R=6371008.8 +units=m +no_defs

A single projection center is suitable for regional studies (a few hundred km). For continental-scale data, distance distortion increases.

8.3 Screen

Figure 8.1. The whole Spatial Analysis tab, empty: species selection, the KDE, Gi*, EOO/AOO and alpha shape groups, and the shared result box.
Figure 8.1. The whole Spatial Analysis tab, empty: species selection, the KDE, Gi*, EOO/AOO and alpha shape groups, and the shared result box.
Name in the interface What it does Default Code
Species: + ↻ Refresh Records to analyze: all or a single species. The species list is filled with Refresh. All Species (combined) ui/main_dialog.py:1778-1786, 1750-1772

The results of the four tools are written to the same Spatial Analysis Results box; each run deletes the text of the previous one. Layers, however, accumulate.

Refresh the species list

After loading a CSV, the Species list contains only All Species (combined). To analyze a single species, first press the ↻ Refresh button.

8.4 Kernel density estimation (KDE)

8.4.1 Parameters

Name in the interface What it does Default Range Code
Bandwidth in metres (0 = auto): Kernel bandwidth h 0 (automatic) 0 - 50,000 m ui/main_dialog.py:1790-1799
Grid Size (pixels): Number of cells along the raster edge 100 20 - 500 ui/main_dialog.py:1794
Output File: GeoTIFF path; if empty, the raster is not saved empty .tif ui/main_dialog.py:1795-1798
▶ Run KDE Runs - - ui/main_dialog.py:1919-1973

8.4.2 Formula

For each grid cell center \mathbf{x}, the density is the sum of the isotropic Gaussian kernels of the n points:

\hat f(\mathbf{x}) = \sum_{j=1}^{n} w_j \, \frac{1}{2\pi h^2} \exp\!\left( -\frac{\lVert \mathbf{x} - \mathbf{x}_j \rVert^2}{2 h^2} \right)

w_j is the weight of the point: the count of that row if there is a count column, otherwise 1. Contributions at distances greater than 5h are dropped (the truncated mass is less than 4 \times 10^{-6}; modules/spatial_analysis.py:44). The integral of the surface equals the sum of the weights; its unit is individuals (records) per square meter (modules/spatial_analysis.py:647-770).

8.4.3 Automatic bandwidth

If the bandwidth is left at 0, the bivariate normal-reference rule is used (Wand and Jones 1995; Worton 1989):

h_{\text{ref}} = \sigma \, n^{-1/6} \qquad \sigma = \sqrt{\frac{\sigma_x^2 + \sigma_y^2}{2}} \qquad \sigma_x = \min\!\left( s_x,\; \frac{\mathrm{IQR}_x}{1.349} \right)

s_x is the standard deviation and \mathrm{IQR}_x the interquartile range (a scale robust to outlying points; Silverman 1986). If h is smaller than 0.5% of the data extent, it is raised to this lower limit (modules/spatial_analysis.py:466-503). In the sample data, h_{\text{ref}} = 10{,}894 m. h_{\text{ref}} is derived for unimodal data; for records concentrated in several clusters it oversmooths the surface.

There is no cross-validation option in the window. Least-squares cross-validation (LSCV; Bowman 1984) is available in the KDE algorithm in Processing (at most 400 points; Section 10.3).

8.4.4 Grid

The grid is square: its side is found by adding a margin of \max(0.2 \times \text{extent},\; 3h) on each side to the longer side of the metric extent of the points, and it is divided into Grid Size cells. Cell size = side / grid size. In the sample data, a 200 × 200 grid and 1,415.7 m cells.

8.4.5 Output

  KDE RESULTS
  n_points                       1818
  bandwidth_m                    10894.03 m
  bandwidth_method               normal-reference h_ref = sigma * n^(-1/6)
  cell_size_m                    1415.73 m
  grid_size                      200
  max_density                    3.765e-07
  extent (WGS84)                 (29.4249, 36.2769, 32.6420, 38.8197)
  ✓ Raster saved: ...\kde_antalya.tif

max_density is a value per m²: 3.765 \times 10^{-7} records/m² = 0.38 records/km². The raster is written in the AEQD projection in which it was computed; QGIS reprojects it on the fly to the map projection. The window also adds the KDE Density raster layer and the Points — <species> point layer to the project (points are colored by species).

Figure 8.2. KDE in the sample data (h = 10.9 km, 200 × 200 grid) and the records; in the background, the boundaries of the five sub-watersheds. The raster was colored with a turquoise color ramp for this book; the plugin adds the layer in the default gray tones.
Figure 8.2. KDE in the sample data (h = 10.9 km, 200 × 200 grid) and the records; in the background, the boundaries of the five sub-watersheds. The raster was colored with a turquoise color ramp for this book; the plugin adds the layer in the default gray tones.

Interpretation. The density shows where the records are concentrated; it is the density of records, not of species. In the sample data, the densest area is the middle part of the Aksu. This does not mean that it is the richest area; it may also show that most of the fieldwork was done there. The bandwidth is the setting that determines the result: a small h gives a detailed but noisy surface, a large h a smooth but featureless one. In publications, state the value of h and how it was chosen.

8.5 Getis-Ord Gi* hotspot analysis

8.5.1 Parameters

Name in the interface What it does Default Range Code
Neighbourhood Radius in metres (0 = auto): Neighborhood distance band d 0 (= 2 h_{\text{ref}}) 0 - 50,000 m ui/main_dialog.py:1810-1813
Analysis Value: Analysis value of each point Presence/Absence (1 per point) — recommended 3 options (below) ui/main_dialog.py:1815-1820
Apply Benjamini-Hochberg FDR correction Multiple-testing correction on on / off ui/main_dialog.py:1822-1826
Two-tailed p threshold: Significance level for classification 0.050 0.001 - 0.10 ui/main_dialog.py:1828-1830
▶ Run Hotspot Runs - - ui/main_dialog.py:1975-2092

Analysis Value options (ui/main_dialog.py:1985-2023):

  1. Presence/Absence (1 per point): each point is 1. Because all values are equal, Gi* is undefined on the points; the program aggregates to a grid (§8.5.3).
  2. Species count per neighbourhood cell: the number of different species around each point (radius = distance band; 150 m if the band is 0). Because all pairs of points are compared, it slows down with the square of the number of points.
  3. Raw count column from CSV: the count value of the row (1 if there is no count column; that is, the same as option 1).

8.5.2 Formula

With x_j the analysis values, \bar x their mean, s their (population) standard deviation, w_{ij} = 1 if d_{ij} \le d (including i itself) or 0 otherwise, and W_i = \sum_j w_{ij}:

G_i^* = \frac{\sum_j w_{ij} x_j - \bar x\, W_i}{s \sqrt{\dfrac{n W_i - W_i^2}{n - 1}}} \qquad s = \sqrt{\frac{1}{n}\sum_j (x_j - \bar x)^2}

Source: Getis and Ord (1992); Ord and Getis (1995). G_i^* is a z value with a standard normal distribution. Two-tailed p = 2[1 - \Phi(|z|)]. If FDR is on, the p values are adjusted with the Benjamini and Hochberg (1995) step-up method (modules/spatial_analysis.py:795-1058):

p_{(k)}^{\text{BH}} = \min_{l \ge k} \left( \frac{n}{l}\, p_{(l)} \right)

Classification: if the adjusted p is below the threshold and z > 0, Hotspot; if z < 0, Coldspot; otherwise Neutral. For a location with no neighbor other than itself within the band, Gi* is only its own standardized value; such locations are labeled Isolated, are not classified, and are reported in a warning. The confidence field labels the 99%, 95% and 90% levels, so the threshold can be at most 0.10. If n < 30, a warning is produced that the normal approximation is unreliable.

8.5.3 Presence-only data: aggregation to a grid

If all values are equal (s = 0), the program aggregates the points to a grid with side d/3, takes the number of records in each occupied cell as its value and reruns Gi* on the cell centers (modules/spatial_analysis.py:845-891). The unit of analysis is now the cell, not the point. The result is hotspots of record density, and it is sensitive to the cell size and the grid origin (the modifiable areal unit problem; Openshaw 1984).

In this case the program produces the warning "ANALYSIS UNIT CHANGED … density hotspot analysis over grid cells … modifiable areal unit problem". The window writes this warning to the WARNINGS section at the end of the result box, and the Processing algorithm writes it to the log (ui/main_dialog.py:2057-2082). The result box gives the number of input records (Input records) and the number of analysis units (Analysis units) on separate lines: in the sample data, 1,818 records and 677 occupied cells.

In addition, only occupied cells enter the analysis. Because empty cells are not evaluated, areas with few records do not come out as coldspots; the analysis finds only "places where records are concentrated".

8.5.4 Running and output

In the sample data, the analysis was run with a distance band of 10,000 m (cell size 3,333 m). If the band had been left at 0, 2 \times 10{,}894 = 21{,}788 m would have been used.

  HOTSPOT ANALYSIS (Getis-Ord Gi*)
  Input records     : 1818
  Analysis units    : 677 occupied grid cells
  Analysis Value    : Presence/Absence (1 per point)
  p-threshold       : 0.05 (FDR-corrected, two-tailed)
  Distance band     : 10000 m
  Projection        : WGS84 → metres (isotropic)
  Hotspots          : 42
  Coldspots         : 0
  Neutral           : 631
  Isolated          : 4

  Top 10 Hotspot Points:
    (30.87663, 37.69594)  Gi*=7.521  99% (BH-FDR)
    (30.83868, 37.78586)  Gi*=7.283  99% (BH-FDR)
    ...

  WARNINGS:
    ANALYSIS UNIT CHANGED: all input values are identical (s = 0), so
    Gi* cannot be computed on the points themselves. Points were
    aggregated onto a 3333 m grid and the analysis was run on CELL
    COUNTS. ...
    4 location(s) have no neighbour other than themselves within the
    distance band; their Gi* reduces to the standardised value of the
    location itself, so they are labelled 'Isolated' and not classified
    as hot or cold spots. Consider a wider band.

The layer is added under the name Hotspot — <species>: hotspots as red, coldspots as blue and neutral cells as gray circles. Attributes: gi_star, z_score, p_2tailed, p_adjusted, p_method, confidence, type, value (number of records in the cell), n_neigh (number of neighbors within the band), band_m (modules/qgis_layer_output.py:134-200).

Figure 8.3. Gi* result layer (10 km band, 3.33 km cells, BH-FDR). Red: 42 hot cells, all in the middle part of the Aksu; gray: non-significant cells.
Figure 8.3. Gi* result layer (10 km band, 3.33 km cells, BH-FDR). Red: 42 hot cells, all in the middle part of the Aksu; gray: non-significant cells.

If the band is left at 0, the Distance band line writes the value used together with its rule: auto: 2 x normal-reference h = 21,788 m (§8.4.3; ui/main_dialog.py:2052-2056).

Interpretation. Of the 677 occupied cells, 42 are significant hotspots after the FDR correction, coinciding with the KDE density peak. With the 10 km band, 4 cells have no neighbor other than themselves; they are labeled Isolated and are not classified. Because only occupied cells are analyzed, the null hypothesis is that cell counts are randomly arranged among occupied cells, not that records are randomly distributed in space. The result says that cells with many records sit next to other cells with many records; it does not test departure from complete spatial randomness. The count is setting-dependent: in the sample data it ranges from 42 to 50 when the grid origin is shifted and is 31 and 28 with 5 km and 20 km bands. Because the cell side is one third of the band, axis neighbors lie exactly at the band distance. Report the number of hotspots as a range over bands and grid origins, not as a single value. For skewed count data, permutation-based p-values (e.g. spdep::localG_perm) are more reliable. Because record counts, not species richness, are analyzed, a hotspot should not be interpreted as a "biodiversity hotspot".

8.6 EOO and AOO (IUCN criterion B)

8.6.1 Parameters

Name in the interface What it does Default Range Code
AOO cell size (IUCN standard: 2 km): AOO cell side 2.000 km 0.05 - 50 km ui/main_dialog.py:1846-1854
▶ Compute EOO / AOO Runs - - ui/main_dialog.py:2095-2147

8.6.2 Formulas

Extent of occurrence (EOO): the area of the smallest convex polygon (convex hull) containing all points. The hull is found with the Graham scan, and the area is computed in the LAEA plane with the shoelace formula (modules/spatial_analysis.py:1097-1137, 1045-1080):

A = \frac{1}{2} \left| \sum_{k} (x_k\, y_{k+1} - x_{k+1}\, y_k) \right|

Area of occupancy (AOO): the number of cells containing at least one record in a square grid with side c, × c^2. The cell index is (\lfloor x/c \rfloor, \lfloor y/c \rfloor); the grid origin is the projection center (modules/spatial_analysis.py:1139-1214).

AOO depends on where the grid starts (IUCN Standards and Petitions Committee 2024; Moat et al. 2018). The program shifts the grid in steps of c/4 along both axes, tries 16 origins, and also gives the minimum and maximum numbers of occupied cells. The reported AOO_km2 belongs to the origin at the projection center, not to the minimum; the minimum is given on the AOO_km2_min line (885 cells, 3,540 km² in the sample data). For species near a threshold, report the range and the minimum as well.

8.6.3 Threshold comparison

Criterion Critically Endangered (CR) Endangered (EN) Vulnerable (VU)
B1: EOO < 100 km² < 5,000 km² < 20,000 km²
B2: AOO < 10 km² < 500 km² < 2,000 km²

Because the coordinates are transformed to WGS84 on loading (§3.4), there is no separate "degrees or meters" option; the points are always projected to an LAEA projection centered on the data, and the projection used is written on the Projection line of the output. The program performs only a threshold comparison and does not assign a Red List category (modules/spatial_analysis.py:1216-1270). In addition to the area threshold, criterion B requires at least two of the conditions (a) severe fragmentation or a small number of locations, (b) continuing decline, (c) extreme fluctuations; these cannot be derived from coordinates (IUCN 2012).

8.6.4 Output

For all records:

  EOO_km2                      23340.26
  EOO_B1_threshold_status      above all B1 thresholds (>= 20 000 km2)
  AOO_km2                      3580.0
  AOO_B2_threshold_status      above all B2 thresholds (>= 2 000 km2)
  Category_assigned            NONE — this tool does not assign Red List categories.
  ...

  AOO cells occupied : 895  (range over grid origins: 885–903)
  Occurrences        : 1818
  Projection         : +proj=laea +lat_0=37.41116036156765 +lon_0=30.89557611538504 ...

For a single species (Cistus creticus, 22 records):

  EOO_km2                      1138.98
  EOO_B1_threshold_status      below the EN B1 threshold (< 5 000 km2)
  AOO_km2                      60.0
  AOO_B2_threshold_status      below the EN B2 threshold (< 500 km2)
  AOO cells occupied : 15  (range over grid origins: 14–16)

The output does not include a number of locations: in IUCN terms, a location is a geographically distinct area in which a single threatening event can rapidly affect all individuals, and it cannot be derived from the number of records (ui/main_dialog.py:2107-2109). For subcriterion B1(a)/B2(a), determine the number of locations separately from information on threats.

Layers added: EOO — <species> (the polygon of the reported area) and AOO Grid (2 km) — <species> (exactly the cells counted; n_records in each cell). Both layers are saved with EPSG:4326 (ui/main_dialog.py:2112).

Figure 8.4. EOO hull of all records (red polygon) and the 2 km AOO cells.
Figure 8.4. EOO hull of all records (red polygon) and the 2 km AOO cells.

Interpretation. In the Cistus creticus example, EOO and AOO are below the EN thresholds. This does not mean that the species is "Endangered": it is a value based only on the 22 records of a widespread maquis species in this dataset. EOO and AOO are sensitive to sampling effort, coordinate errors and outlying records; check the records before using them in an assessment. For all records, EOO and AOO describe "the area covered by the regional flora"; they are not an assessment in the IUCN sense.

8.7 Alpha shape

8.7.1 Parameter

Name in the interface What it does Default Code
Radius threshold 1/alpha (0 = heuristic default): Circumcircle radius threshold r = 1/\alpha (meters); if 0, the heuristic default 0 m ui/main_dialog.py:1866-1873
▶ Build Alpha Hull Runs - ui/main_dialog.py:2149-2209

The parameter is given as the radius, the inverse of \alpha, instead of \alpha itself, because typical \alpha values (of the order of 10^{-4} m^{-1}) are too small to be entered in a number box. The box is set between 0 and 1,000,000 m in steps of 500 m. For example, entering 3,275 m corresponds to 2 times the default \alpha.

8.7.2 Method

  1. The points are converted to LAEA and duplicate points are removed.
  2. A Delaunay triangulation is built (with SciPy if available, otherwise with the plugin's own algorithm; with more than 5,000 points, grid subsampling is applied on the pure Python path).
  3. Triangles with a circumcircle radius smaller than 1/\alpha are kept (Edelsbrunner et al. 1983).
  4. The edges of the kept triangles that are used only once are the boundary edges; these are chained into closed rings.
  5. The area is the sum of the areas of the kept triangles (modules/spatial_analysis.py:1330-1589).

The default \alpha, with the mean length \bar e of the Delaunay edges:

\alpha = \frac{1}{2 \bar e} \qquad r_{\max} = \frac{1}{\alpha} = 2 \bar e

This is a heuristic rule with no theoretical basis. The α-hull of Burgman and Fox (2003) uses a different criterion (it deletes Delaunay edges longer than α times the mean edge length), so the two areas are not the same. The area is very sensitive to \alpha.

8.7.3 Output

  ALPHA HULL RESULTS
  Method                         alpha_shape_scipy
  Area                           12177.045572 km²
  Mean edge length               3275.02 m
  Alpha parameter                0.000152671  (1/m)
  Radius threshold 1/alpha       6,550 m
  Total triangles                3443
  Kept triangles                 3277
  Boundary vertices              167

  ALPHA SENSITIVITY (default alpha = heuristic, report this profile)
   x default   radius (m)     area (km²)
         0.5       13,100       15,413.5
           1        6,550       12,177.0
           2        3,275        5,029.3
           4        1,638          567.7
           8          819           28.7

The result box also writes the sensitivity profile on every run (ui/main_dialog.py:2159, 2074-2082): when \alpha is set to 0.5, 1, 2, 4 and 8 times the default, the area decreases from 15,413 km² to 29 km². The profile is always computed relative to the default \alpha; when you enter the radius by hand, the first lines show your value, while the profile shows the neighborhood of the default.

Figure 8.5. The Alpha shape — All Species (combined) layer added by the plugin with the default alpha (the plugin's default style: red outline, light fill) and the records; sub-watershed boundaries in the background. Interior gaps are kept as holes.
Figure 8.5. The Alpha shape — All Species (combined) layer added by the plugin with the default alpha (the plugin's default style: red outline, light fill) and the records; sub-watershed boundaries in the background. Interior gaps are kept as holes.

When the layer is created, each ring is first repaired with makeValid(); the rings are sorted by area from largest to smallest, and a ring that lies inside the shape is subtracted as a hole, while one that lies outside is added (modules/qgis_layer_output.py:256-291). In the sample data, the layer's area_km2_g field agrees with the area in the result box to within 0.05% (the difference arises because the layer is saved in WGS84 and measured again). If the layer still cannot be built, the result box writes "WARNING: the polygon layer could not be built from the rings; the reported area is still correct."

Interpretation. The alpha shape excludes large gaps inside the convex hull (e.g. areas without records between sub-watersheds); in the sample data, 12,177 km² against an EOO of 23,340 km². An area reported with a single \alpha is misleading: the profile above shows that the area can vary between 29 and 15,413 km². When reporting the area, give \alpha and the sensitivity together. Only the convex-hull EOO may be compared with the IUCN B1 thresholds; the alpha-shape area must not be used in place of EOO (IUCN Standards and Petitions Committee 2024).

8.8 Common mistakes

8.9 Expert questions

Q1. Is the KDE result the same as QGIS's own Heatmap (Kernel Density Estimation) tool? No. The QGIS tool works in layer units, its default kernel is quartic, and the radius is given by the user. EcoMetriQ uses a Gaussian kernel, a metric projection and a normal-reference bandwidth; the unit is records per square meter.

Q2. Are the Gi* results the same as spdep::localG in R? Yes. With the same cell centers, the same distance band and binary weights built with include.self(), spdep::localG gives the same z values. In the cleaned Antalya data, the classification was the same in all 675 cells and the largest z difference was 5 \times 10^{-5} (the cleaned file is not distributed with this book).

Q3. Why are there no coldspots? Because only occupied cells are analyzed, areas without records do not enter the comparison (§8.5.3). Occupied cells with few records stay close to the mean and therefore do not get a significant negative z.

Q4. What projection does the IUCN recommend for EOO? The IUCN requires areas to be computed in an equal-area projection; EcoMetriQ uses LAEA centered on the center of the data. GeoCAT (Bachman et al. 2011) and ConR (Dauby et al. 2017) also use equal-area projections; small differences arise from the choice of sphere/ellipsoid and grid origin.

Q5. When is a cell size other than 2 km used for AOO? The IUCN requires 2 km for comparison with the thresholds; other sizes are only for sensitivity analysis (IUCN Standards and Petitions Committee 2024).