Open mdsumner opened 1 year ago
that code does this
n <- 1000
pts0 <- cbind(runif(n, -180, 180), runif(n, -80, 80))
in_crs <- "OGC:CRS84"
out_crs <- "EPSG:3857"
pts <- reproj::reproj_xy(pts0, out_crs, source = in_crs)
## grid specification (bounds, shape)
## we could be tidier about the extent, but I'm not sure how the py was intended to user-input this
ex <- c(range(pts[,1]), range(pts[,2]))
dm <- c(200, 200) ## again, could be aspect ratioed of the data but just go for it
## the rasterio transform point to grid part
cell <- vaster::cell_from_xy(dm, ex, pts)
## we're not sparse now
cnt <- matrix(tabulate(cell, nbins = prod(dm)), dm[2L], byrow = TRUE)
## now we need something to write a tif
vapour::vapour_create("file.tif", extent = ex, dimension = dm, projection = out_crs, n_bands = 1, overwrite = TRUE)
## I think the current orientation is the write fun might be a mistake ... or at least needs doc
vapour::vapour_write_raster_block("file.tif", t(cnt), offset = c(0, 0), dimension = dm, band = 1, overwrite = TRUE)
## now, get the info and plot
info <- vapour::vapour_raster_info("file.tif")
dat <- whatarelief::elevation(source = "file.tif", extent = info$extent, dimension = info$dimension, projection = info$projection)
ximage::ximage(dat, extent = info$extent, asp = 1)
points(pts)
https://gist.github.com/vincentsarago/b00f50f8b66ab5ccbd4449f6a1bd8b71#file-rasterize_point-py-L79
from this tweet (they missed the IDW part, but still very useful code for me) https://twitter.com/_VincentS_/status/1597971755939016710?s=20&t=ZpcAHSd0zMVO8K0iAZjq0Q