I am often creating terrain / surface models from LiDAR data which I want to save as GeoTIFF. Recently, I had a discussion where I was made aware that for GeoTIFF files it can be specified if the raster pixel values should correspond to area (below the pixel) or point (at the pixel centre). For DTMs it would be best to configure PixelIsPoint. So I thought no problem I'll just export it differently and read into the GeoTIFF file format descriptions. As I'm using terra
to do all my raster stuff, I figured I just need to provide the gdal
argument when exporting the file using writeRaster()
. I tried many different things but I can not figure out which exact option I need to provide to do that. Currently, my code runs without any error when doing the following:
library(terra)
r <- system.file("ex/elev.tif", package="terra")
raster_data <- rast(r)
writeRaster(raster_data, filename = ".../test.tif", gdal = c("COMPRESS=NONE", "AREA_OR_POINT=POINT", "TILED=YES"), overwrite = T)
However, when I check the data using QGIS, looking into the Layer Properties under Information and still see AREA_OR_POINT=Area. Therefore, I assume that AREA_OR_POINT=POINT
is incorrect. What can I do to export my GeoTIFF file with PixelIsPoint?
I expanded the terra::metags
method such that you can set a domain (for this metadata item you need the default domain). Now you can do
library(terra)
# terra 1.8.31
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
metags(r) <- cbind("AREA_OR_POINT", "Point", "")
x <- writeRaster(r, "test.tif", overwrite=TRUE)
metags(x)
# name value domain
#1 AREA_OR_POINT Point
describe("test.tif")[36]
#[1] " AREA_OR_POINT=Point"
Version 1.8-31 is currently the development version of terra. You can install it with
install.packages('terra', repos='https://rspatial.r-universe.dev')