Learn R Programming

gdalraster (version 1.11.1)

g_transform: Apply a coordinate transformation to a WKT geometry

Description

g_transform() will transform the coordinates of a geometry from their current spatial reference system to a new target spatial reference system. Normally this means reprojecting the vectors, but it could include datum shifts, and changes of units.

Usage

g_transform(
  wkt,
  srs_from,
  srs_to,
  wrap_date_line = FALSE,
  date_line_offset = 10L
)

Value

Character string for a transformed OGC WKT geometry.

Arguments

wkt

Character. OGC WKT string for a simple feature geometry.

srs_from

Character string in OGC WKT format specifying the spatial reference system for the geometry given by wkt.

srs_to

Character string in OGC WKT format specifying the target spatial reference system.

wrap_date_line

Logical scalar. TRUE to correct geometries that incorrectly go from a longitude on a side of the antimeridian to the other side. Defaults to FALSE.

date_line_offset

Integer scalar. Longitude gap in degree. Defaults to 10.

See Also

bbox_transform()

Examples

Run this code
elev_file <- system.file("extdata/storml_elev.tif", package="gdalraster")
ds <- new(GDALRaster, elev_file)

# the convenience function bbox_transform() does this:
bbox_to_wkt(ds$bbox()) |>
  g_transform(ds$getProjection(), epsg_to_wkt(4326)) |>
  bbox_from_wkt()

ds$close()

# correct geometries that incorrectly go from a longitude on a side of the
# antimeridian to the other side
geom <- "LINESTRING (-179 0,179 0)"
srs <- epsg_to_wkt(4326)
g_transform(geom, srs, srs, wrap_date_line = TRUE)

Run the code above in your browser using DataLab