-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
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.
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)
fOriginally posted by @asinghvi17 in #1033 (comment)
rafaqz
Metadata
Metadata
Assignees
Labels
No labels