Skip to content

Conversation

@felixcremer
Copy link
Contributor

Add a TiledDiskArray type which handles a collection of tiles that lay in the same grid with a predictable pattern .

@rafaqz
Copy link
Collaborator

rafaqz commented Oct 24, 2025

Could we use this to lazily wrap a tile server?

@felixcremer
Copy link
Contributor Author

Main problem might be, that a Tile Server has color values and not actual array values. But this might work for wrapping a tile server and giving the RGB values from the pngs.

This would currently expect a function that would from a given tile position return a matrix of the data in this position. So we could have a function that reads the data from the tile server.

The interface we are aiming for currently is this:

using ArchGDAL

function geturl(east, north) 
    baseurl = "https://download.geoservice.dlr.de/FNF50/files"
    xsym, xval = if east < 180
        'W',180-east
    else
        'E', east-180
    end
    ysym, yval = if north < 90
        'S', 90-north
    else
        'N', north-90
    end
    xpadround = xsym * lpad(Int(round(xval, RoundDown, digits=-1)), 3, "0")
    ypadround = ysym * lpad(Int(round(yval, RoundDown, digits=-1)), 2, "0")
    xpad = xsym * lpad(xval, 3, "0")
    ypad = ysym * lpad(yval, 2,"0")
    tdm = "TDM_FNF_20_" * ypad * xpad
    join([baseurl, ypad, xpadround, tdm, tdm * "_cog.tif"], "/")
end

function gettile(east, north)
    response = HTTP.head(geturl(1,1), status_exception=false)
    if response.status == 200
        ArchGDAL.readraster("/vsicurl/"*geturl(east, north))[:,:]::Matrix{UInt8}
    else
        fill(UInt8(3), (2001,2001))
    end
end

A = DiskArrays.TiledDiskArray{UInt8,2}(gettile, (360,180), (2001,2001))

chunk_indices = findchunk.(chunks.chunks, I)
data_offset = OffsetArray(data, map(i -> first(i) - 1, I)...)
foreach(CartesianIndices(chunk_indices)) do ci
@show ci
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

foreach(CartesianIndices(chunk_indices)) do ci
@show ci
chunkindex = ChunkIndex(ci; offset=true)
@show chunkindex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment on lines +37 to +39
tilefunction
tilenum
tilesizes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use this definition instead:

struct TiledDiskArray{T,N,F} <: AbstractChunkTiledDiskArray{T,N}
    tilefunction::F
    tilenum::NTuple{N,Int}
    tilesizes::NTuple{N,Int}
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth having the tile definition be GridChunks instead - for example the Copernicus DEM has irregular sizes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a link to that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct TiledDiskArray{T,N} <: AbstractChunkTiledDiskArray{T,N}
tilefunction
tilenum
tilesizes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tilesizes just tilesize? What does the pluralisation mean?

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

Successfully merging this pull request may close these issues.

4 participants