Search code examples
rrasterspatialnetcdfterra

How to convert a coarse raster to a smooth polygon


Say you have a raster, could be e.g. Sea Surface Temperature from NOAA with a grid: 0.25 degree latitude x 0.25 degree longitude global grid (1440x720).

Is it possible to convert a raster like this with R, so the output is smooth polygons? This would be an example from NYTimes where similar coarse raster files where somehow converted to 3 classes of smooth polygons.

Is there a clever way? I tried a lot with disaggregate, focal, reclassify, terra: aspolygons, smoothr:smooth

Nothing is really close to a smooth polygon. Any clues?

Here is a screenshot from the NYTimes NYTimes polygons for smoke plume


Solution

  • Here is a possible work-flow. First go to a high spatial resolution with resample; make polygons; simplify.

    library(terra)
    x <- rast("filename")
    x <- disagg(x, 10, method="bilinear")
    # reclassify to get NA and one other value, e.g.
    x <- ifel(x < 1, NA, 1) 
    p <- as.polygons(x)
    s <- simplifyGeoms(p)