JuliaGeo / MapTiles.jl

Work with tiled web maps in Julia
MIT License
24 stars 7 forks source link

More convenient methods to get basemaps from MapTiles/Tyler (potentially write to an RGB raster, etc) #37

Closed asinghvi17 closed 3 months ago

asinghvi17 commented 5 months ago

This would probably be best put in the MapTiles.jl repo, but might also go into Tyler if we need Tyler's dependencies. I envision the method to be something like:


basemapraster(provider, extent, zoomlevel)
basemapraster(provider, extent, size::NTuple{2, Int} #=this converts to zoom level internally for convenience=#) 
felixcremer commented 5 months ago

What is the use case for this? Is it to be able to save the tiles in some local file so that it is possible to plot the basemap without internet connection? I am wondering whether it would make sense to fetch all zoomlevels below a given zoom level and to build a Pyramid out of them.

asinghvi17 commented 5 months ago

The idea would be to return a Matrix{RGB} or even a Raster, just to make it extremely easy to get a basemap layer to plot. Since Tyler doesn't work without display, this would be a path for people who want to do it manually.

That being said, we should definitely support downloading pyramids for local use. Does PyramidScheme support saving to file?

felixcremer commented 5 months ago

I am currently working on saving to zarr but that cant be read by Rasters yet. I might look into saving to geotiff.

rafaqz commented 5 months ago

Pretty easy to add Zarr support to Rasters now with https://github.com/JuliaGeo/ZarrDatasets.jl

rafaqz commented 5 months ago

@asinghvi17 we could add a RastersMapTilesExt extension for Rasters.jl like for RasterDataSources.jl

Then we can just use the normal constructor syntax but with a provider instead of a file name, and extra keywords:

Raster(provider; extent, [zoomlevel, size, res])

We should also be able to use any Raster/Extexts/GeoInterface object for the extent keyword. Having size and res keyword like in Rasters.resample would help pick the right zoom level rather than using trial and error. You would get the closest possible size/res to the keyword rather than the exact size/res.

asinghvi17 commented 5 months ago

That should work nicely! Does Rasters have any image loading dependencies?

rafaqz commented 5 months ago

No, but probly gdal can do it 😱

asinghvi17 commented 5 months ago

The horror :trollface:

felixcremer commented 5 months ago

I opened a PR for Rasters to add ZarrDatasetsExt.

felixcremer commented 5 months ago

Should this functionality live her or in TileProviders? I don't understand the boundaries of these packages but saw, that you opened a similar issue on TileProviders.

asinghvi17 commented 5 months ago

Huh, I completely forgot about that. I think that implementing it either in an extension on Rasters here or as an extension on MapTiles in Rasters would be the way to go.

The only thing is that we would need some form of image loading library, which might be a pain. ImageIO could probably handle it, and is a Makie dependency so would get automatically pulled in most of the time anyway.

asinghvi17 commented 3 months ago

I just wrote a basic script that does this at https://gist.github.com/asinghvi17/cfc8266bc084bc55678c87b5d14dcbc9. It needs HTTP.jl and ImageMagick.jl though, so it may be best to make this a separate package...I'm not sure how we would name it though.

Alternatively, the code could sit in Tyler, since it has all of those dependencies, and then Rasters could implement an extension on Tyler which just dimensionalizes the (x, y, z) output of the function.

asinghvi17 commented 3 months ago

Pushed a PR (https://github.com/MakieOrg/Tyler.jl/pull/89) to Tyler along with some conversion methods so you can plot image(provider, extent, size) - this should substantially improve the situation. Tyler can also now have a RecipesBase extension that adds (a) a recipe for Plots.image a la what I did in this PR for Makie and potentially something that can query axis size in Plots if that's possible and figure out size and extent automatically.