Skip to content
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

Rasterize with ext and res uses wrong corners of the Extent #851

Closed
felixcremer opened this issue Jan 7, 2025 · 5 comments
Closed

Rasterize with ext and res uses wrong corners of the Extent #851

felixcremer opened this issue Jan 7, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@felixcremer
Copy link
Contributor

When I am running rasterize with a extent as to and a resolution I would have expected that the X axis spans the range of the X extent and the Y axis range of extent.Y. It seems that the X-axis is constructed from the first of the entries in extent and Y from the last entries.
In the example below I would have expected that X has values -1:0.01:1 and Y 0.33:0.01:2

julia> extr =Extent(X=(-1,1.1), Y=(0.33,2));

julia> rasr = rasterize(prand, to=extr, res=0.1, fill=1, reducer=sum)
┌ 14×10 Raster{Union{Missing, Int64}, 2} nothing ┐
├────────────────────────────────────────────────┴─────────────────────────────────────────── dims ┐
   X Projected{Float64} -1.0:0.1:0.3 ForwardOrdered Regular Intervals{Start},
   Y Projected{Float64} 1.1:0.1:2.0 ForwardOrdered Regular Intervals{Start}
├──────────────────────────────────────────────────────────────────────────────────────── metadata ┤
  Metadata of Dict{Any, Any}()
├────────────────────────────────────────────────────────────────────────────────────────── raster ┤
  extent: Extent(X = (-1.0, 0.4), Y = (1.1, 2.1))
  missingval: missing
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
         
@felixcremer felixcremer added the bug Something isn't working label Jan 7, 2025
@asinghvi17
Copy link
Collaborator

That is indeed awkward...probably a typo?

@tiemvanderdeure
Copy link
Collaborator

It hits this path

extr =Extent(X=(-1,1.1), Y=(0.33,2));
Rasters._extent(extr; geometrycolumn = nothing)

Which returns Extent(X = (-1.0, 0.33), Y = (1.1, 2.0)) because it treats the extent as 2 x-y points!

@tiemvanderdeure
Copy link
Collaborator

While #852 mostly fixes this, maybe there is still room for improvement on how edges are handled.

point = (0.5,0.5)
extr =Extent(X=(-1,1.1), Y=(0.0,2.0));
rasr = rasterize(point, to=extr, res=0.1, fill=1, reducer=sum)
extent(rasr)

Gives Extent(X = (-1.0, 1.2000000000000002), Y = (0.0, 2.1)). So it's like 1 row and 1 column more than I would expect.

This happens in _extent2dims

@rafaqz
Copy link
Owner

rafaqz commented Jan 7, 2025

We need extents.jl to have closed or open intervals.

We currently have to hack a tiny pad in so closed intervals of e.g. a Multipoint is not cut off in the open high edge of a raster. R does this too

@tiemvanderdeure
Copy link
Collaborator

Fixed now!

julia> using Rasters, Extents

julia> extr =Extent(X=(-1,1.1), Y=(0.33,2));

julia> rasr = rasterize((1,1), to=extr, res=0.1, fill=1, reducer=sum)
┌ 22×17 Raster{Union{Missing, Int64}, 2} nothing ┐
├────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────── dims ┐       
  ↓ X Projected{Float64} -1.0:0.1:1.1 ForwardOrdered Regular Intervals{Start},
  → Y Projected{Float64} 0.33:0.1:1.93 ForwardOrdered Regular Intervals{Start}
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── metadata ┤       
  Metadata of Dict{Any, Any}()
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── raster ┤       
  extent: Extent(X = (-1.0, 1.2000000000000002), Y = (0.33, 2.03))
  missingval: missing
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘       
 ↓ →  0.33      0.43      0.53      0.63      0.73      0.83      0.93      1.03      …  1.23      1.33      1.43      1.53      1.63      1.73      1.83      1.93
 ⋮                                            ⋮                                       ⋱  ⋮                                                 ⋮
 1.1   missing   missing   missing   missing   missing   missing   missing   missing      missing   missing   missing   missing   missing   missing   missing   missing    

The open-closed interval thing is a separate issue, I think we can close this one

@rafaqz rafaqz closed this as completed Jan 17, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in JuliaEO 2025 Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants