elev_file <- system.file("extdata/storml_elev.tif", package="gdalraster")
ds <- new(GDALRaster, elev_file)
invgt <- ds$getGeoTransform() |> inv_geotransform()
ds$close()
ptX = 324181.7
ptY = 5103901.4
## for a point x, y in the spatial reference system of elev_file
## raster pixel (column number):
pixel <- floor(invgt[1] +
invgt[2] * ptX +
invgt[3] * ptY)
## raster line (row number):
line <- floor(invgt[4] +
invgt[5] * ptX +
invgt[6] * ptY)
## get_pixel_line() applies this conversion
Run the code above in your browser using DataLab