% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/conversion.R
\name{latlon_to_xy}
\alias{latlon_to_xy}
\title{Convert Latitude-Longitude to Projected Coordinates}
\usage{
latlon_to_xy(
  dataInfo,
  longitude,
  latitude,
  xName = "rows",
  yName = "cols",
  crs = NULL
)
}
\arguments{
\item{dataInfo}{Metadata object containing CRS information, typically obtained
from a \code{rerddap::info()} call on a dataset. It should include global attributes
that contain CRS information.}

\item{longitude}{Numeric vector of longitudes to be converted.}

\item{latitude}{Numeric vector of latitudes to be converted.}

\item{xName}{Name of the longitude coordinate in the output projection. Defaults
to 'longitude'.}

\item{yName}{Name of the latitude coordinate in the output projection. Defaults
to 'latitude'.}

\item{crs}{Optional. A character string specifying the CRS to use for the
projection. This can be an EPSG code (e.g., 'EPSG:4326' for WGS84) or a PROJ
string. If NULL, the function attempts to detect the CRS from \code{dataInfo}.}
}
\value{
A matrix with columns corresponding to the projected x and y coordinates
(in the order specified by \code{xName} and \code{yName}). Each row in the matrix
corresponds to a pair of input latitude and longitude values.
}
\description{
This function converts geographic coordinates (latitude and longitude) into
projected coordinates based on a specified Coordinate Reference System (CRS).
The function can automatically detect the CRS from provided metadata (\code{dataInfo})
or use a specified CRS code. It is designed to work with datasets obtained
from \code{rerddap::griddap()} but can be used with any geographic data that requires
coordinate transformation.
}
\examples{
# myURL <- 'https://coastwatch.noaa.gov/erddap/'
# iceInfo <- rerddap::info('noaacwVIIRSn20icethickNP06Daily', url = myURL)
data(iceInfo)
latitude <- c( 80., 85.)
longitude <- c(-170., -165)
coords <- latlon_to_xy(iceInfo,  longitude, latitude)

}
