% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/conversion.R
\name{xy_to_latlon}
\alias{xy_to_latlon}
\title{Convert Projected 'rerddap::griddap()' Coordinates to Latitude-Longitude}
\usage{
xy_to_latlon(resp, yName = "cols", xName = "rows", crs = NULL)
}
\arguments{
\item{resp}{A response object from a call to \code{rerddap::griddap()}.
It is expected to be of type \code{griddap_nc}, \code{rxtracto3D}, or \code{rxtractoTrack},
which contains the projected coordinate data along with metadata
including the dataset's CRS.}

\item{yName}{The name of the variable in \code{resp} that represents
the Y coordinate (typically latitude or northing). Defaults to 'cols'.}

\item{xName}{The name of the variable in \code{resp} that represents the X coordinate
(typically longitude or easting). Defaults to 'rows'.}

\item{crs}{An optional CRS code to be used for the transformation.
If a CRS is found in the  \code{resp} metadata this is ignored.
CRS code should be a valid EPSG code (e.g., \code{4326} for WGS84) or a PROJ string.}
}
\value{
A matrix with two columns (\code{longitude}, \code{latitude}) containing the geographic
coordinates corresponding to the projected coordinates in the input \code{resp}. Each row
in the matrix corresponds to a point in \code{resp}.
}
\description{
This function converts the projected coordinates from a 'rerddap::griddap()'
response into geographical coordinates (latitude and longitude).
It supports responses from \code{griddap}, \code{rxtracto}, and \code{rxtracto3D} by
detecting the response type and applying the appropriate
Coordinate Reference System (CRS) transformation.
}
\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)

}
