srs_convert: Convert spatial reference definitions to OGC Well Known Text

srs_convertR Documentation

Convert spatial reference definitions to OGC Well Known Text

Description

These functions convert various spatial reference formats to Well Known Text (WKT).

Usage

epsg_to_wkt(epsg, pretty = FALSE)

srs_to_wkt(srs, pretty = FALSE)

Arguments

epsg

Integer EPSG code.

pretty

Logical. TRUE to return a nicely formatted WKT string for display to a person. FALSE for a regular WKT string (the default).

srs

Character string containing an SRS definition in various formats (see Details).

Details

epsg_to_wkt() exports the spatial reference for an EPSG code to WKT format. Wrapper for OSRImportFromEPSG() in the GDAL Spatial Reference System API with output to WKT.

srs_to_wkt() converts a spatial reference system (SRS) definition in various text formats to WKT. The function will examine the input SRS, try to deduce the format, and then export it to WKT. Wrapper for OSRSetFromUserInput() in the GDAL Spatial Reference System API with output to WKT.

The input SRS may take the following forms:

  • WKT - to convert WKT versions (see below)

  • EPSG:n - EPSG code n

  • AUTO:proj_id,unit_id,lon0,lat0 - WMS auto projections

  • urn:ogc:def:crs:EPSG::n - OGC URNs

  • PROJ.4 definitions

  • filename - file to read for WKT, XML or PROJ.4 definition

  • well known name such as NAD27, NAD83, WGS84 or WGS72

  • IGNF:xxxx, ESRI:xxxx - definitions from the PROJ database

  • PROJJSON (PROJ >= 6.2)

srs_to_wkt() is intended to be flexible, but by its nature it is imprecise as it must guess information about the format intended. epsg_to_wkt() could be used instead for EPSG codes.

As of GDAL 3.0, the default format for WKT export is OGC WKT 1. The WKT version can be overridden by using the OSR_WKT_FORMAT configuration option (see set_config_option()). Valid values are one of: SFSQL, WKT1_SIMPLE, WKT1, WKT1_GDAL, WKT1_ESRI, WKT2_2015, WKT2_2018, WKT2, DEFAULT. If SFSQL, a WKT1 string without AXIS, TOWGS84, AUTHORITY or EXTENSION node is returned. If WKT1_SIMPLE, a WKT1 string without AXIS, AUTHORITY or EXTENSION node is returned. WKT1 is an alias of WKT1_GDAL. WKT2 will default to the latest revision implemented (currently WKT2_2018). WKT2_2019 can be used as an alias of WKT2_2018 since GDAL 3.2

Value

Character string containing OGC WKT.

See Also

srs_query

Examples

epsg_to_wkt(5070)
writeLines(epsg_to_wkt(5070, pretty=TRUE))

srs_to_wkt("NAD83")
writeLines(srs_to_wkt("NAD83", pretty=TRUE))
set_config_option("OSR_WKT_FORMAT", "WKT2")
writeLines(srs_to_wkt("NAD83", pretty=TRUE))
set_config_option("OSR_WKT_FORMAT", "")

gdalraster documentation built on June 8, 2025, 12:37 p.m.