You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Computing the area of each cell in a raster is useful for a number of reasons - if you have a variable like
12
+
population per cell, or elevation ([spatially extensive variables](https://r-spatial.org/book/05-Attributes.html#sec-extensiveintensive)),
13
+
you'll want to account for the fact that different cells have different areas.
14
+
15
+
Let's construct a raster and see what this looks like! We'll keep it in memory.
16
+
17
+
The spherical method relies on the [Proj.jl](https://github.com/JuliaGeo/Proj.jl) package to perform coordinate transformation, so that has to be loaded explicitly.
18
+
19
+
````@example cellarea
20
+
using Rasters, Proj
21
+
````
22
+
23
+
To construct a raster, we'll need to specify the `x` and `y` dimensions. These are called `lookups` in `Rasters.jl.`
24
+
25
+
````@example cellarea
26
+
using Rasters.Lookups
27
+
````
28
+
29
+
We can now construct the x and y lookups. Here we'll use a start-at-one, step-by-five grid.
30
+
Note that we're specifying that the "sampling", i.e., what the coordinates actually mean,
31
+
is `Intervals(Start())`, meaning that the coordinates are the starting point of each interval.
32
+
33
+
This is in contrast to `Points()` sampling, where each index in the raster represents the value at a sampling point;
34
+
here, each index represents a grid cell, which is defined by the coordinate being at the start.
35
+
36
+
````@example cellarea
37
+
x = X(1:5:30; sampling = Intervals(Start()), crs = EPSG(4326))
38
+
y = Y(50:5:80; sampling = Intervals(Start()), crs = EPSG(4326));
39
+
nothing # hide
40
+
````
41
+
42
+
I have chosen the y-range here specifically so we can show the difference between spherical and planar `cellarea`.
43
+
44
+
````@ansi cellarea
45
+
ras = Raster(ones(x, y); crs = EPSG(4326))
46
+
````
47
+
48
+
We can just call `cellarea` on this raster, which returns cell areas in meters, on Earth, assuming it's a sphere:
49
+
50
+
````@ansi cellarea
51
+
cellarea(ras)
52
+
````
53
+
54
+
and if we plot it, you can see the difference in cell area as we go from the equator to the poles:
We can also try this using the planar method, which simply computes the area of the rectangle using `area = x_side_length * y_side_length`:
62
+
63
+
````@ansi cellarea
64
+
cellarea(Planar(), ras)
65
+
````
66
+
67
+
Note that this is of course wildly inaccurate for a geographic dataset - but if you're working in a projected coordinate system, like polar stereographic or Mercator, this can be very useful (and a _lot_ faster)!
Copy file name to clipboardExpand all lines: docs/src/tutorials/gbif_wflow.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This example shows a full Species distribution modelling workflow, from loading data, to cleaning it, to fitting an ensemble and generating predictions.
4
4
5
-
It uses GBIF and WorldClim data, which are common datasets in ecology.
5
+
It uses GBIF and WorldClim data, which are common datasets in ecology. We'll load occurrences for the Mountain Pygmy Possum species using [GBIF2.jl](https://github.com/rafaqz/GBIF2.jl), an interface to the [Global Biodiversity Information Facility](https://www.gbif.org/), and extract environmental variables using BioClim data from [RasterDataSources.jl](https://github.com/EcoJulia/RasterDataSources.jl).
6
6
7
7
## Load Rasters, ArchGDAL, RasterDataSources and GBIF
8
8
The GBIF2 library is used to download occurrence data, RasterDataSources to conveniently access Bioclim data. ArchGDAL is necessary to load in the Bioclim data.
0 commit comments