Proj (proj v0.2.3)
Provides functions to transform coordinates between given coordinate systems.
iex> {:ok, bng} = Proj.from_epsg(27700) # British National Grid CRS is EPSG:27700
{:ok, #Proj<+init=epsg:27700 ...>}
iex> Proj.to_lat_lng!({529155, 179699}, bng)
{51.50147938477216, -0.1406319210455952}
Link to this section Summary
Functions
Returns a new Proj projection specification object for a given PROJ.4 parameter list.
Returns a Proj object for a given EPSG code from the EPSG Geodetic Parameter Dataset.
Returns a Proj object for a given known PROJ.4 init file definition.
Converts a given WGS84 {latitude, longitude}
pair in degrees to the
equivalent {easting, northing}
in the CRS proj
.
Returns the def
string given to create the given Proj object, expanded to
its fullest form if possible.
Turns a {longitude_radians, latitude_radians, z}
tuple into
{longitude_degrees, latitude_degrees, z}
.
Converts a given {easting, northing}
pair and its CRS proj
to a WGS84
{latitude, longitude}
pair, where latitude
and longitude
are in degrees.
Turns a {longitude_degrees, latitude_degrees, z}
tuple into
{longitude_radians, latitude_radians, z}
.
Transforms coordinates from one Proj CRS to another.
Returns a Proj object for the WGS84 geographic coordinate reference system.
Link to this section Functions
from_def(def)
Returns a new Proj projection specification object for a given PROJ.4 parameter list.
Returns {:ok, proj}
on success, or {:error, "reason"}
if the PROJ.4
parameter string is invalid.
Examples
Proj.from_def("+init=epsg:4326")
Proj.from_def("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
Proj.from_def("+init=world:bng")
Proj.from_def("+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
+y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs")
See https://trac.osgeo.org/proj/wiki/GenParms for documentation on how these parameter lists.
One way of finding the the PROJ.4 parameter list you require is to search http://spatialreference.org/ for your desired CRS and find the PROJ.4 parameter list under the "Proj4" link on a CRS's page.
from_epsg(name)
Returns a Proj object for a given EPSG code from the EPSG Geodetic Parameter Dataset.
Returns {:ok, proj}
on success, or {:error, "reason"}
if the EPSG
definition is not found.
Proj.from_epsg(4326) # WGS84
Proj.from_epsg(27700) # British National Grid
from_known_def(file, name)
Returns a Proj object for a given known PROJ.4 init file definition.
Returns {:ok, proj}
on success, or {:error, "reason"}
if the definition is
not found.
On Linux, by default, these definitions should be stored in /usr/share/proj/
with your PROJ.4 installation.
Proj.from_known_def("epsg", "4326") # WGS84
Proj.from_known_def("world", "bng") # British National Grid
from_lat_lng!(arg, proj)
Converts a given WGS84 {latitude, longitude}
pair in degrees to the
equivalent {easting, northing}
in the CRS proj
.
This function raises on error, unlike Proj.transform/3
.
This is a convenience function for a common use case of Proj.
iex> {:ok, bng} = Proj.from_epsg(27700)
{:ok, #Proj<+init=epsg:27700 ...>}
iex> Proj.from_lat_lng!({51.501479, -0.140631}, bng)
{529155.0658918166, 179698.9583449281}
get_def(proj)
Returns the def
string given to create the given Proj object, expanded to
its fullest form if possible.
iex> Proj.get_def(Proj.wgs84)
" +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
load()
to_deg(arg)
Turns a {longitude_radians, latitude_radians, z}
tuple into
{longitude_degrees, latitude_degrees, z}
.
to_lat_lng!(arg, proj)
Converts a given {easting, northing}
pair and its CRS proj
to a WGS84
{latitude, longitude}
pair, where latitude
and longitude
are in degrees.
This function raises on error, unlike Proj.transform/3
.
This is a convenience function for a common use case of Proj.
iex> {:ok, bng} = Proj.from_epsg(27700)
{:ok, #Proj<+init=epsg:27700 ...>}
iex> Proj.to_lat_lng!({529155, 179699}, bng)
{51.50147938477216, -0.1406319210455952}
to_rad(arg)
Turns a {longitude_degrees, latitude_degrees, z}
tuple into
{longitude_radians, latitude_radians, z}
.
transform(arg, from_proj, to_proj)
Transforms coordinates from one Proj CRS to another.
Coordinates are given in the order {x, y, z}
, or for geographic coordinates,
{longitude, latitude, z}
, where z
is the altitude above the geoid of the
CRS. longitude
and latitude
must be given in radians. Proj.to_rad/1
may be helpful if you have coordinates in degrees.
Returns {:ok, {x, y, z}}
on success, or {:error, "reason"}
if the PROJ.4
library was unable to perform a transformation. If geographic coordinates are
returned, they will be in the order {longitude, latitude, z}
, and will be in
radians.
wgs84()
Returns a Proj object for the WGS84 geographic coordinate reference system.
WGS84 is the standard coordinate system used for GPS and is most likely what
you need when working with {latitude, longitude}
coordinates.