Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. ```{r}
  2.  
  3. # read in geotif as raster
  4. relief <- raster("/Users/zehran/Downloads/srgyhii200l_nt00248/srgyhii200l.tif") %>%
  5. # convert to data frame
  6. as("SpatialPixelsDataFrame") %>%
  7. as.data.frame() %>%
  8. rename(value = `srgyhii200l`) %>%
  9. # filter out blues in geotif
  10. # this reduces the number of rows from 16m to 420k
  11. filter(value != 255)
  12.  
  13. ggplot(
  14. data = relief,
  15. aes(
  16. x = x,
  17. y = y,
  18. alpha = value
  19. )
  20. ) +
  21. geom_raster() +
  22. # the important part I guess is inverting the alpha range here
  23. # it goes now from high to low
  24. scale_alpha(range = c(0.4, 0.01), guide = FALSE) +
  25. theme_void()
  26.  
  27. # just a quick helper to produce images with the right aspect ratio (square px)
  28. aspect_ratio <- (max(relief$y) - min(relief$y)) / (max(relief$x) - min(relief$x))
  29.  
  30. # save as png
  31. ggsave(
  32. "/Users/zehran/Downloads/srgyhii200l_nt00248/new_zealand.png",
  33. width = 100,
  34. height = 100 * aspect_ratio,
  35. units = "mm"
  36. )
  37.  
  38. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement