Learn R Programming

M3 (version 0.3)

project.lonlat.to.M3: Project coordinates from longitude/latitude to model units.

Description

Project coordinates from longitude/latitude to model units as specified according to the projection given by a user-designated Models3-formatted file.

Usage

project.lonlat.to.M3(longitude, latitude, file, units, ...)

Arguments

longitude
Vector of longitudes for the points to be projected.
latitude
Vector of latitudes for the points to be projected.
file
File name of Models3-formatted file which contains information about the projection to which you want x and y to be projected.
units
Units in which to return x and y. Options are "km" or "m", with "km" as the default.
...
Other arguments to pass to get.proj.info.M3 function. In this case, the only relevant argument would be the earth radius to use for the projection in file.

Value

coords and units. The element coords contains a matrix of coordinates using the projection in file. The element units contains the units of the coordinates, as specifed by units or "km" by default.

Details

This function uses the function project from the package rgdal to project from longitude/latitude to the projection defined by the Models3-formatted file. Package rgdal provides the R interface to GDAL (Geospatial Data Abstraction Library, http://www.gdal.org).

References

http://www.gdal.org

See Also

project.M3.to.lonlat, project.M3.1.to.M3.2, get.proj.info.M3

Examples

Run this code
## List of state capital longitudes/latitudes
## (from http://www.xfront.com/us_states).
capitals <- data.frame(x=c(-84.39,-86.28,-81.04,-86.78,-78.64,-84.86),
                       y=c(33.76,32.36,34.00,36.17,35.77,38.20),
                       name=c("Atlanta", "Montgomery", "Columbia",
                                 "Nashville", "Raleigh", "Frankfort")
                        )
## Plot these on a map, with state lines.
plot(capitals$x, capitals$y)
map("state", add=TRUE)

## Now, put these on the same Lambert conic conformal projection used
## in the demo file below.
lcc.file <- system.file("extdata/ozone_lcc.ncf", package="M3")
lcc.capitals <- project.lonlat.to.M3(capitals$x, capitals$y, lcc.file)

## Put these on a new plot.
dev.new()
plot(lcc.capitals$coords)
## Project state lines to this projection.
lcc.map <- get.map.lines.M3.proj(lcc.file)
lines(lcc.map$coords)

Run the code above in your browser using DataLab