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( -889533.8, -469356.9)
cols <- c(622858.3, 270983.4)
myURL <- 'https://polarwatch.noaa.gov/erddap/'
myInfo <- rerddap::info('noaacwVIIRSn20icethickNP06Daily', url = myURL)
proj_extract <- rerddap::griddap(myInfo,
                                 time = c('2023-01-01T00:00:00Z', '2023-01-01T00:00:00Z'),
                                 rows = rows,
                                 cols = cols,
                                 altitude = c(0., 0.),
                                 fields = 'IceThickness',
                                 url = myURL
 )
#> info() output passed to x; setting base url to: https://polarwatch.noaa.gov/erddap
test <- xy_to_latlon(proj_extract)