This function converts the projected coordinates from a 'rerddap::griddap()' response into geographical coordinates (latitude and longitude). It supports responses from griddap, rxtracto, and rxtracto3D by detecting the response type and applying the appropriate Coordinate Reference System (CRS) transformation.

xy_to_latlon(resp, yName = "cols", xName = "rows", crs = NULL)

Arguments

resp

A response object from a call to rerddap::griddap(). It is expected to be of type griddap_nc, rxtracto3D, or rxtractoTrack, which contains the projected coordinate data along with metadata including the dataset's CRS.

yName

The name of the variable in resp that represents the Y coordinate (typically latitude or northing). Defaults to 'cols'.

xName

The name of the variable in resp that represents the X coordinate (typically longitude or easting). Defaults to 'rows'.

crs

An optional CRS code to be used for the transformation. If a CRS is found in the resp metadata this is ignored. CRS code should be a valid EPSG code (e.g., 4326 for WGS84) or a PROJ string.

Value

A matrix with two columns (longitude, latitude) containing the geographic coordinates corresponding to the projected coordinates in the input resp. Each row in the matrix corresponds to a point in resp.

Examples

rows <- c(300112.5, 250027.5)
cols <- c(-400282.5, -350197.5)
# myURL <- 'https://coastwatch.noaa.gov/erddap/'
# iceInfo <- rerddap::info('noaacwVIIRSn20icethickNP06Daily', url devtoo= myURL)
# proj_extract <- rerddap::griddap(iceInfo,
#                           time = c('2026-05-18T12:28:57Z', '2026-05-18T12:28:57Z'),
#                            rows = rows,
#                             cols = cols,
#                             altitude = c(0., 0.),
#                             fields = 'IceThickness',
#                            url = myURL
#
data(proj_extract)
test <- xy_to_latlon(proj_extract)