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

Using polygonize function on a raster doesn't keep the original raster coordinates #199

Open
BG-AIMS opened this issue Aug 27, 2024 · 4 comments

Comments

@BG-AIMS
Copy link

BG-AIMS commented Aug 27, 2024

When I use GeometryOps.polygonize() on a raster the resulting polygons do not have the same coordinates as the input raster although the same CRS is attached to the resulting polygon. This is an example with lon/lat to show effect.

using GLMakie, ArchGDAL
using Rasters, GeometryOps, GeoFormatTypes, GeoInterface

lon, lat = X(120:1:150), Y(-40:-1:-60) # Example used for clear difference from polygonize() output
ras = Raster(rand(lon, lat); crs=GeoFormatTypes.EPSG(4326))
plot(ras)

plot(ras .< 0.3)
polygons = GeometryOps.polygonize(x-> x.<0.3, ras[:, end:-1:1]) # Flip reverseordered Y 
poly(polygons)
GeoInterface.coordinates(polygons)

plot(ras .< 0.3) output:
image

poly(polygons) output:
image

@asinghvi17
Copy link
Member

asinghvi17 commented Aug 27, 2024

I can confirm locally...guess our tests for DimensionalData and Rasters were a bit lacking. #200 should fix this but it might take a few days.

Thanks for the bug report!

@asinghvi17
Copy link
Member

Specifically this is because (evil is a Raster here)

julia> axes(evil)[1]
DimensionalData.Dimensions.DimUnitRange(Base.OneTo(100), X{Projected{Int64, UnitRange{Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Int64}, DimensionalData.Dimensions.Lookups.Points, DimensionalData.Dimensions.Lookups.NoMetadata, EPSG{1}, Nothing, X{Colon}}}([-100, -99, -98, -97, -96, -95, -94, -93, -92, -91    -10, -9, -8, -7, -6, -5, -4, -3, -2, -1]))

julia> axes(evil)[1] |> collect
100-element Vector{Int64}:
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
   
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100

(cc @rafaqz - what's the best way to get the actual lookup values generically? Do we need an extension?)

@rafaqz
Copy link
Member

rafaqz commented Aug 27, 2024

I'll have to look at the code... But if you call similar on those axes you get a Raster.

(But there is no generic Base way to get axis lookup values)

@rafaqz
Copy link
Member

rafaqz commented Aug 27, 2024

Also note this is covered in #178 I just need to find time to finish it. (and to even remember that I'm half way through working on that 😅 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants