-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One can not rasterize non-numeric attributes into an array #752
Comments
Can you do that in other languages? But I think there will be a way around it. I just assumed numbers. |
I highly doubt this can be done in any other language... but it would certainly be a nice to have |
I think you could hack around this using categorical arrays for now, you'd basically rasterize the category in as an integer, then rebuild the raster with |
Actually it works if you define some methods. But there are quite a few method ambiguities. Maybe we should have a default fallback, just to make things work? julia> Rasters._reduce_init(f::Function, ::Type{String}, missingval) = ""
julia> Rasters._reduce_init(f, ::Type{String}, missingval) = ""
julia> Rasters._reduce_init(f::Nothing, ::Type{String}, missingval) = ""
julia> ras = rasterize(first, countries; res=1.0, fill=:NAME, missingval="test", crs=EPSG(4326))
Burning each geometry to a BitArray slice... 100%|██████████████████████████████████████████████████| Time: 0:00:01
╭───────────────────────────────╮
│ 361×174 Raster{String,2} NAME │
├───────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── dims ┐
↓ X Projected{Float64} -180.0:1.0:180.0 ForwardOrdered Regular Intervals{Start},
→ Y Projected{Float64} -90.0:1.0:83.0 ForwardOrdered Regular Intervals{Start}
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── metadata ┤
Metadata of Dict{Any, Any}()
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── raster ┤
extent: Extent(X = (-180.0, 181.0), Y = (-90.0, 84.0))
missingval: "test"
crs: EPSG:4326
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
↓ → -90.0 -89.0 -88.0 -87.0 -86.0 -85.0 … 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0
-180.0 "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test"
-179.0 "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test"
-178.0 "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test"
⋮ ⋮ ⋱ ⋮ ⋮
177.0 "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test"
178.0 "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test"
179.0 "Antarctica" "Antarctica" "Antarctica" "Antarctica" "Antarctica" "test" … "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test"
180.0 "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" "test" I would propose something on the lines of: _reduce_init(f, x, missingval) = _placeholder_value(x)
_placeholder_value(x) = zero(x)
_placeholder_value(x::String) = ""
# ... then users can define If, without defining those methods, you define |
Rasterizing the continent names 😂 Maybe we can call it But we'll have to remember what it's zeroness is actually used for to get the name right, I don't! Something somewhere in how the reductions work. But I also think in many cases it's not even used |
I think this could just be the |
Yeah need to look at the alg some time. Sometimes there is a reason it's different and after three rewrites there isn't anymore but the code is still there |
The text was updated successfully, but these errors were encountered: