Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created September 5, 2022 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/d73748c44aef4a0923760401d3dc605d to your computer and use it in GitHub Desktop.
Save mdsumner/d73748c44aef4a0923760401d3dc605d to your computer and use it in GitHub Desktop.

First, a simple pass with R helpers.

  ## packages from github.com/hypertidy dep on CRAN {vapour}
library(whatarelief)
library(ximage)
f <- normalizePath("~/20220902T00Z_MSC_HRDPS_HGT_SFC_RLatLon0.0225_P001.grib2")

ex <- c(-180, 180, -90, 90)
dat <- elevation(source = f, extent = ex)
ximage::ximage(dat, extent = ex)
## CRAN {maps}
maps::map(add = T)

Created on 2022-09-05 by the reprex package (v2.0.1)

Now, just let gdalwarp do its magic. You should do your own work to figure out an appropriate target grid with combination of tr/ts/te/t_srs args.

gdalwarp  ~/20220902T00Z_MSC_HRDPS_HGT_SFC_RLatLon0.0225_P001.grib2 out.tif -t_srs "OGC:CRS84"
gdalinfo --version
#GDAL 3.4.3, released 2022/04/22

Have a look at it in R

library(terra)
plot(rast("out.tif"))
maps::map(add = TRUE)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment