Learn R Programming

gdalraster (version 1.11.1)

apply_geotransform: Apply geotransform (raster column/row to geospatial x/y)

Description

apply_geotransform() applies geotransform coefficients to raster coordinates in pixel/line space (column/row), converting into georeferenced (x/y) coordinates. Wrapper of GDALApplyGeoTransform() in the GDAL API, operating on matrix input.

Usage

apply_geotransform(col_row, gt)

Value

Numeric matrix of geospatial x/y coordinates.

Arguments

col_row

Numeric matrix of raster column/row (pixel/line) coordinates (or two-column data frame that will be coerced to numeric matrix).

gt

Either a numeric vector of length six containing the affine geotransform for the raster, or an object of class GDALRaster from which the geotransform will be obtained.

See Also

GDALRaster$getGeoTransform(), get_pixel_line()

Examples

Run this code
raster_file <- system.file("extdata/storm_lake.lcp", package="gdalraster")
ds <- new(GDALRaster, raster_file)

# compute some raster coordinates in column/row space
set.seed(42)
col_coords <- runif(10, min = 0, max = ds$getRasterXSize() - 0.00001)
row_coords <- runif(10, min = 0, max = ds$getRasterYSize() - 0.00001)
col_row <- cbind(col_coords, row_coords)

# convert to geospatial x/y coordinates
gt <- ds$getGeoTransform()
apply_geotransform(col_row, gt)

# or, using the class method
ds$apply_geotransform(col_row)

# bounds checking
col_row <- rbind(col_row, c(ds$getRasterXSize(), ds$getRasterYSize()))
ds$apply_geotransform(col_row)

ds$close()

Run the code above in your browser using DataLab