Skip to content

Instantly share code, notes, and snippets.

View mdsumner's full-sized avatar

Michael Sumner mdsumner

  • Integrated Digital East Antarctica, Australian Antarctic Division
  • Hobart, Australia
View GitHub Profile
    library(raadtools)
#> Loading required package: raster
#> Loading required package: sp
#> global option 'raadfiles.data.roots' set:
#> '
#> /rdsi/PRIVATE/raad/data               
#>  /rdsi/PRIVATE/raad/data_local         
#>  /rdsi/PRIVATE/raad/data_staging       
#>  /rdsi/PRIVATE/raad/data_deprecated    
spec_tile2 <- function(dimension, extent = NULL, blocksize, overlap = 0) {
  if (is.null(extent)) extent <- c(0, dimension[1L], 0, dimension[2L])
  ## note the strange reversal of blocksize x/y and how st_tile names its arguments
  ## see an easier to grok impl in hypertidy/grout
  tiles <- stars::st_tile(dimension[1], dimension[2], 
                          x_window = blocksize[2], 
                          y_window = blocksize[1], overlap = overlap)
  library(geos)
set.seed(1)
sd <- 0.01
coords <- rbind(
  matrix(c(-1, 1, -1, 1) + rnorm(4, 0, sd), 2, 2), 
  matrix(c(-1, 1, 1, -1) + rnorm(4, 0, sd), 2, 2)
)

ids <- c(1, 1, 2, 2)

This path syntax should also work in fiona, but need creds set with GDAL_HTTP_HEADER_FILE (or GDAL_HTTP_HEADERS)

ogrinfo /vsizip/vsicurl/https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_010_001_AF_20240125T004648_20240125T004658_PIC0_01.zip
INFO: Open of `/vsizip/vsicurl/https://archive.swot.podaac.earthdata.nasa.gov/podaac-swot-ops-cumulus-protected/SWOT_L2_HR_RiverSP_2.0/SWOT_L2_HR_RiverSP_Reach_010_001_AF_20240125T004648_20240125T004658_PIC0_01.zip'
 using driver `ESRI Shapefile' successful.
## imagery source
dsn <- "<GDAL_WMS><Service name=\"TMS\"><ServerUrl>http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/${z}/${y}/${x}</ServerUrl></Service><DataWindow><UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY><LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY><TileLevel>17</TileLevel><TileCountX>1</TileCountX><TileCountY>1</TileCountY><YOrigin>top</YOrigin></DataWindow><Projection>EPSG:900913</Projection><BlockSizeX>256</BlockSizeX><BlockSizeY>256</BlockSizeY><BandsCount>3</BandsCount><MaxConnections>10</MaxConnections><Cache /><ZeroBlockHttpCodes>204,404,403</ZeroBlockHttpCodes></GDAL_WMS>"

## return a function to transform coordinates to nara space (for a given extent)
nr_trans <- function(nara, extent = c(0, ncol(nara), 0, nrow(nara))) {
  function(xy) {
    cbind(scales::rescale(xy[,1], from = extent[1:2], to = c(0, ncol(nara))),
          scales::rescale(xy[,2], from = extent[3:4], to = c(nrow(nara), 0)))
    
library(terra)

## this is a reasonable coastline, but maybe doesn't have ice shelves??
poly <- vect("/vsizip//vsicurl/https://github.com/wmgeolab/geoBoundaries/raw/main/releaseData/CGAZ/geoBoundariesCGAZ_ADM0.zip", 
             query = "SELECT shapeGroup FROM geoBoundariesCGAZ_ADM0 WHERE shapeGroup IN ('ATA')")


pt &lt;- vect(cbind(81.7968, -62.3801), crs = "EPSG:4326")
https://www.oceancolour.org/thredds/fileServer/cci//v6.0-release/geographic/
terra::rast("/vsicurl/https://opentopography.s3.sdsc.edu/raster/COP30/COP30_hh.vrt")