new_file <- file.path(tempdir(), "newdata.tif")
create(format="GTiff", dst_filename=new_file, xsize=143, ysize=107,
nbands=1, dataType="Int16")
ds <- new(GDALRaster, new_file, read_only=FALSE)
## EPSG:26912 - NAD83 / UTM zone 12N
ds$setProjection(epsg_to_wkt(26912))
gt <- c(323476.1, 30, 0, 5105082.0, 0, -30)
ds$setGeoTransform(gt)
ds$setNoDataValue(band = 1, -9999)
ds$fillRaster(band = 1, -9999, 0)
## ...
## close the dataset when done
ds$close()
deleteDataset(new_file)
Run the code above in your browser using DataLab