rafaqz / Rasters.jl

Raster manipulation for the Julia language
MIT License
197 stars 34 forks source link

rebuilding Projected dimension loose projection info #689

Open felixcremer opened 6 days ago

felixcremer commented 6 days ago

When I rebuild a Projected dimension with new values. I get a Sampled dimension back. I would have expected to keep the Projection information intact. I am using the rebuild in PyramidScheme to construct the dimensions of the aggregated layers.

using Rasters
using RasterDataSources
julia> ras = Raster(WorldClim{Elevation},:elev, res="30s", lazy=true)

julia> dix = dims(ras, X)
X Projected{Float64} ForwardOrdered Regular DimensionalData.Dimensions.Lookups.Intervals{DimensionalData.Dimensions.Lookups.Start}
wrapping: 43200-element LinRange{Float64, Int64}:
 -180.0, -179.992, -179.983, -179.975, -179.967, …, 179.95, 179.958, 179.967, 179.975, 179.983, 179.992

julia> dixr = rebuild(dix, LinRange(first(dix), last(dix), cld(length(dix), 4)))
X LinRange{Float64}(-180.0, 179.99166666666667, 10800)

julia> typeof(dix)
X{Projected{Float64, LinRange{Float64, Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Float64}, DimensionalData.Dimensions.Lookups.Intervals{DimensionalData.Dimensions.Lookups.Start}, DimensionalData.Dimensions.Lookups.NoMetadata, WellKnownText{GeoFormatTypes.CRS}, Nothing, X{Colon}}}

julia> typeof(dixr)
X{LinRange{Float64, Int64}}
rafaqz commented 6 days ago

You have to do a nested rebuild because rebuild is very low level. set will do what you want like set(dix, somerange). It handles the nesting for you.

felixcremer commented 5 days ago

Thanks, yes that works. Should we mention the low levelness somewhere in the docs and hint from the rebuild docs to set?