SwedenCrsTransformations

Elixir library for transformation of geographic coordinates between WGS84 and the Swedish coordinate reference systems SWEREF99 and RT90.

This library is a port of the TypeScript library sweden_crs_transformations_4typescript, which is based on the C#.NET library MightyLittleGeodesy. All libraries are released with the MIT license.

Features

Installation

If available in Hex, the package can be installed by adding sweden_crs_transformations to your list of dependencies in mix.exs:

def deps do
  [
    {:sweden_crs_transformations, "~> 0.1.0"}
  ]
end

Usage

Basic coordinate transformation

# Create a WGS84 coordinate (Stockholm Central Station)
coord = SwedenCrsTransformations.CrsCoordinate.new(:wgs84, 59.330231, 18.059196)

# Transform to SWEREF99 TM
sweref_coord = SwedenCrsTransformations.CrsCoordinate.transform(coord, :sweref_99_tm)
# => %SwedenCrsTransformations.CrsCoordinate{
#      crs_projection: :sweref_99_tm,
#      y_latitude: 6580822.0,
#      x_longitude: 674032.0
#    }

# Transform to RT90
rt90_coord = SwedenCrsTransformations.CrsCoordinate.transform(coord, :rt90_2_5_gon_v)

Using EPSG numbers

# Create coordinate by EPSG number (3006 = SWEREF99 TM)
{:ok, coord} = SwedenCrsTransformations.CrsCoordinate.new_by_epsg_number(3006, 6580822, 674032)

# Transform by EPSG number (4326 = WGS84)
wgs84_coord = SwedenCrsTransformations.CrsCoordinate.transform_by_epsg_number!(coord, 4326)

Convenient module-level functions

# You can also use the main module for convenience
coord = SwedenCrsTransformations.new(:wgs84, 59.330231, 18.059196)
transformed = SwedenCrsTransformations.transform(coord, :sweref_99_tm)

Available CRS projections

Get all available projections:

SwedenCrsTransformations.CrsProjection.get_all()
# => [:wgs84, :sweref_99_tm, :sweref_99_12_00, ...]

Running Tests

mix test

All tests pass with coordinate accuracy within:

License

MIT License - see LICENSE file for details.

This library is based on:

Credits