Skip to content

boolmask should error if the lookup is Points but boundary != :center #1034

@asinghvi17

Description

@asinghvi17

Rasters.create defaults to a point lookup instead of an interval lookup which is causing this confusion.

I think we should either error or convert to an interval lookup, if you have points X, Y dims but you try to rasterize / mask as anything but boundary = :center - it will do the same thing so your option won't be respected.

download
using Rasters
import GeoInterface as GI
using StatsBase

width, height = 10, 10

polygons = [
    GI.Polygon([[(0., 0.), (1., 0.), (1., 1.), (0., 1.), (0., 0.)]]),
    GI.Polygon([[(0.5, 0.), (1.5, 0.), (1.5, 1.), (0.5, 1.), (0.5, 0.)]]),
]

result = Rasters.rasterize(
    polygons;
    to = Rasters.Extents.grow(GI.extent(GI.GeometryCollection(polygons)), .25),
    fill = [[i] for i in 1:length(polygons)],
    missingval = Int[],
    init = Int[],
    op = vcat,
    eltype = Vector{Int},
    progress = true,
    boundary = :touches,
    size = (width, height),
)

result_bang = Rasters.create(
    Vector{Int},
    Rasters.Extents.grow(GI.extent(GI.GeometryCollection(polygons)), .25);
    size = (width, height),
    fill = Int[],
    missingval = Int[],
)

result_bang = rasterize!(
    result_bang,
    polygons;
    fill = [[i] for i in 1:length(polygons)],
    missingval = Int[],
    init = Int[],
    op = vcat,
    boundary = :touches,
    eltype = Vector{Int},
    progress = true,
)

StatsBase.countmap(result)
StatsBase.countmap(result_bang)

using CairoMakie
f, a, p = heatmap(length.(result); colorbar = false, axis = (; title = "rasterize", aspect = DataAspect()))
a2, p2 = heatmap(f[1, 2], length.(result_bang); colorbar = false, axis = (; title = "rasterize!", aspect = DataAspect()))
cb = Colorbar(f[2, 1:2], p; vertical = false, label = "length.(raster)", flipaxis = false)
f

Originally posted by @asinghvi17 in #1033 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions