Skip to content

Commit

Permalink
Fix errors in code
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Sep 25, 2024
1 parent 3b45111 commit eee67bc
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions chapters/02-attribute-operations.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This chapter requires the following packages to be installed and attached:
using DataFrames
# Vector data access and manipulation
using GeoDataFrames
import GeoInterface as GI
# Raster data access and manipulation
using Rasters
# "Categorical" / "factor" vectors in Julia
Expand Down Expand Up @@ -225,7 +226,7 @@ There are ways to achieve this result using all of the DataFrame manipulation pa
DataFrames.jl also defines a `subset` function, which is another way to achieve this result:

```{julia}
subset(world_with_pop, :pop => x -> !ismissing(x) && 30_000_000 < x < 1_000_000_000)
subset(world_with_pop, :pop => ByRow(x -> !ismissing(x) && 30_000_000 < x < 1_000_000_000))
```

## DataFramesMeta.jl
Expand Down Expand Up @@ -334,15 +335,11 @@ grain_order = ["clay", "silt", "sand"]
grain_char = rand(grain_order, 6, 6)
grain_fact = CategoricalArray(grain_char, levels = grain_order)
using Rasters
# Then, wrap the categorical array in a Raster object
grain = Raster(grain_fact, (X(LinRange(-1.5, 1.5, 6)), Y(LinRange(-1.5, 1.5, 6))))
```

```{julia}
elev = Raster("data/elev.tif")
grain = Raster("data/grain.tif")
```

This `CategoricalArray` is stored in two parts: a matrix of integer codes, and a dictionary of levels, that maps the integer codes to the string values.
We can retrieve the levels of a `CategoricalArray` using the `levels` function, and modify them using the `recode` function.

Expand Down Expand Up @@ -382,4 +379,12 @@ Rasters.jl does not currently support color tables in rasters. This should come
### Raster subsetting

Raster subsetting is done with the Julia `getindex` syntax (square brackets), in the same way as we used it to subset DataFrames.
Raster selection is, however, far more powerful:
Raster selection is, however, far more powerful, since you can use [selectors](https://rafaqz.github.io/DimensionalData.jl/stable/) to select various spatial subsets of the raster, like `At`, `Near`, and `Between`.

```{julia}
elev[X(At(1)), Y(At(1))]
elev[X(Near(0)), Y(Near(0))]
elev[X(-1..0), Y(0..1)]
```

Of course, you can

0 comments on commit eee67bc

Please sign in to comment.