Skip to content

Commit 9ce2d5e

Browse files
Masking layer with polygon hotfix (#595)
* fix(sdt): masking layers with polygons bugfix and simplification * fix(sdt): simplify fix for tests * fix(sdt): polygon simplification test has fcs
1 parent c336c08 commit 9ce2d5e

4 files changed

Lines changed: 8 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## `v1.9.2`
9+
10+
- **fixed** a bug for masking layers with polygons with holes
11+
812
## `v1.9.1` - 2026-04-09
913

1014
- **added** a `getindex` method for a vector of layers and a vector of occurrences

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SpeciesDistributionToolkit"
22
uuid = "72b53823-5c0b-4575-ad0e-8e97227ad13b"
3-
version = "1.9.1"
3+
version = "1.9.2"
44
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
55

66
[deps]

src/boundingbox.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const _SDMPOLY_TYPES = Union{
110110
}
111111

112112
function boundingbox(fc::T; kwargs...) where {T <: _SDMPOLY_TYPES}
113-
return SimpleSDMPolygons.boundingbox(fc.geometry; kwargs...)
113+
return SimpleSDMPolygons.boundingbox(fc; kwargs...)
114114
end
115115

116116
function boundingbox(fc::SimpleSDMPolygons.FeatureCollection; kwargs...)

src/polygons/polygons.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,13 @@ function change_inclusion!(inclusion, layer, polygon::P) where {P}
8585
chunk_size = max(1, length(grid) ÷ (10 * Threads.nthreads()))
8686
data_chunks = Base.Iterators.partition(grid, chunk_size)
8787

88-
coords = SimpleSDMPolygons.GI.coordinates(transformed_polygon.geometry)
8988

9089
tasks = map(data_chunks) do chunk
9190
Threads.@spawn begin
9291
for position in chunk
9392
coord = (E[position[2]], N[position[1]])
94-
val = false
95-
if polygon isa MultiPolygon
96-
inpoly = [
97-
[PolygonOps.inpolygon(coord, ci) for ci in c] for
98-
c in coords
99-
]
100-
else
101-
inpoly = [PolygonOps.inpolygon(coord, c) for c in coords]
102-
end
103-
val = if eltype(inpoly) <: Vector
104-
any(isone, vcat(inpoly...))
105-
else
106-
any(isone, inpoly)
107-
end
108-
inclusion[position] = val
93+
inpoly = SimpleSDMPolygons.AG.contains(transformed_polygon.geometry, SimpleSDMPolygons.AG.createpoint(coord))
94+
inclusion[position] = inpoly
10995
end
11096
end
11197
end

0 commit comments

Comments
 (0)