Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```{r}
- # read in geotif as raster
- relief <- raster("/Users/zehran/Downloads/srgyhii200l_nt00248/srgyhii200l.tif") %>%
- # convert to data frame
- as("SpatialPixelsDataFrame") %>%
- as.data.frame() %>%
- rename(value = `srgyhii200l`) %>%
- # filter out blues in geotif
- # this reduces the number of rows from 16m to 420k
- filter(value != 255)
- ggplot(
- data = relief,
- aes(
- x = x,
- y = y,
- alpha = value
- )
- ) +
- geom_raster() +
- # the important part I guess is inverting the alpha range here
- # it goes now from high to low
- scale_alpha(range = c(0.4, 0.01), guide = FALSE) +
- theme_void()
- # just a quick helper to produce images with the right aspect ratio (square px)
- aspect_ratio <- (max(relief$y) - min(relief$y)) / (max(relief$x) - min(relief$x))
- # save as png
- ggsave(
- "/Users/zehran/Downloads/srgyhii200l_nt00248/new_zealand.png",
- width = 100,
- height = 100 * aspect_ratio,
- units = "mm"
- )
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement