From 1dd9a425e9fdf69e308f2dd9f92609012c805265 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:06:49 +0100 Subject: [PATCH 1/2] CompatHelper: bump compat for ColorTypes to 0.12, (keep existing compat) (#808) Co-authored-by: CompatHelper Julia Co-authored-by: Rafael Schouten --- Project.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ea8db0693..8ef210f98 100644 --- a/Project.toml +++ b/Project.toml @@ -54,7 +54,7 @@ Adapt = "2, 3.0, 4" Aqua = "0.8" ArchGDAL = "0.9, 0.10" CFTime = "0.1" -ColorTypes = "0.10, 0.11" +ColorTypes = "0.10, 0.11, 0.12" CommonDataModel = "0.2.3, 0.3" ConstructionBase = "1" CoordinateTransformations = "0.6.2" @@ -106,6 +106,7 @@ RasterDataSources = "3cb90ccd-e1b6-4867-9617-4276c8b2ca36" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From b89b0b6314657e124d9771eab12c82f93fc6fbfe Mon Sep 17 00:00:00 2001 From: Tiem van der Deure Date: Thu, 26 Dec 2024 23:08:21 +0100 Subject: [PATCH 2/2] Improve performance for extract on point tables (#838) * _get_geometries should not touch geometries * move _get_geometries to top --- src/methods/extract.jl | 9 ++++----- src/utils.jl | 11 +++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/methods/extract.jl b/src/methods/extract.jl index ef41b04e7..feb0b6001 100644 --- a/src/methods/extract.jl +++ b/src/methods/extract.jl @@ -58,7 +58,8 @@ function extract end names=_names(x), name=names, skipmissing=false, geometry=true, index=false, geometrycolumn=nothing, kw... ) n = DD._astuple(name) - _extract(x, data; + geoms = _get_geometries(data, geometrycolumn) + _extract(x, geoms; dims=DD.dims(x, DEFAULT_POINT_ORDER), names=NamedTuple{n}(n), # These keywords are converted to _True/_False for type stability later on @@ -66,7 +67,6 @@ function extract end geometry=_booltype(geometry), index=_booltype(index), skipmissing=_booltype(skipmissing), - geometrycolumn, kw... ) end @@ -78,10 +78,9 @@ end function _extract(A::RasterStackOrArray, geom; names, kw...) _extract(A, GI.geomtrait(geom), geom; names, kw...) end -function _extract(A::RasterStackOrArray, ::Nothing, data; - names, skipmissing, geometrycolumn, kw... +function _extract(A::RasterStackOrArray, ::Nothing, geoms; + names, skipmissing, kw... ) - geoms = _get_geometries(data, geometrycolumn) T = _rowtype(A, eltype(geoms); names, skipmissing, kw...) # Handle empty / all missing cases (length(geoms) > 0 && any(!ismissing, geoms)) || return T[] diff --git a/src/utils.jl b/src/utils.jl index 18aead165..3de723b03 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -211,10 +211,12 @@ function _get_geometries(data, ::Nothing) data else trait = GI.trait(data) - if GI.trait(data) isa GI.FeatureCollectionTrait + if trait isa GI.FeatureCollectionTrait [GI.geometry(f) for f in GI.getfeature(data)] - else + elseif isnothing(trait) collect(data) + else + data end end # check if data iterates valid geometries before returning @@ -240,9 +242,10 @@ function _get_geometries(data, geometrycolumn::NTuple{<:Any, <:Symbol}) return points end function _check_geometries(geoms) + !isnothing(GI.trait(geoms)) && return for g in geoms - ismissing(g) || GI.geomtrait(g) !== nothing || - throw(ArgumentError("$g is not a valid GeoInterface.jl geometry")) + ismissing(g) || !isnothing(GI.geomtrait(g)) || + throw(ArgumentError("$g is not a valid GeoInterface.jl geometry")) end return end