hypertidy / lazyraster

raster data via GDAL on-demand
https://hypertidy.github.io/lazyraster/
27 stars 1 forks source link

WMS example to write up #11

Open mdsumner opened 5 years ago

mdsumner commented 5 years ago
library(lazyraster)
#> 
#> Attaching package: 'lazyraster'
#> The following object is masked from 'package:graphics':
#> 
#>     plot
library(raster)
#> Loading required package: sp
e <- extent(153.00795, 153.04041, -27.49034, -27.45917)
qldimg_wms <- 'https://spatial-img.information.qld.gov.au/arcgis/services/Basemaps/LatestSatelliteWOS_AllUsers/ImageServer/WMSServer?'

u <-   paste0(qldimg_wms, 'service=WMS', '&version=1.3.0', '&request=GetMap',
              '&layers=LatestSatelliteWOS_AllUsers', '&styles=', '&crs=CRS%3A84')

lr <- lazyraster(u)
lr2 <- lazyraster(u, band = 2)
lr3 <- lazyraster(u, band = 3)
b <- brick(as_raster(crop(lr, e)), as_raster(crop(lr2, e)), as_raster(crop(lr3, e)))
plotRGB(b)
#> Warning in .couldBeLonLat(x, warnings = warnings): CRS is NA. Assuming it
#> is longitude/latitude

Created on 2019-10-14 by the reprex package (v0.3.0)

Taken from https://gist.github.com/obrl-soil/73916c6fe223d510293cb1a2bbf2879a

Compare raster and stars and discuss what lazyraster is doing here.

mdsumner commented 5 years ago

@obrl-soil this is as far as I got, I've tried few things to wrap this up but it's not clear if I want a in-memory brick, or a multi-layer lazy-raster ...

The key in lazyraster is that you can combine a crop and specified dimension for the output, without having data read when you crop.

Happy to follow this up if it's useful, it's something I want to write up in more detail eventually. I've only tried this on Ubuntu, but I think it should work (these days) also with the Windows and MacOS CRAN binaries.

obrl-soil commented 5 years ago

Ooooh this is super good! And works fine on windows too 👍 I still like a lot of control over resampling behaviour and the ability to get data at its source resolution and alignment but that's not really necessary for imagery