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
- Transform coordinates between WGS84, SWEREF99, and RT90 coordinate reference systems
-
Support for 20 different CRS projections:
- WGS84 (global GPS coordinates)
- SWEREF99 TM (national Swedish grid)
- 12 local SWEREF99 projection zones
- 6 local RT90 projection zones
- High precision transformations using Gauss-Kreuger projection formulas
- Comprehensive test suite with coordinate accuracy validation
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"}
]
endUsage
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
:wgs84- WGS84 (EPSG:4326):sweref_99_tm- SWEREF99 TM (EPSG:3006):sweref_99_12_00through:sweref_99_23_15- SWEREF99 local zones:rt90_7_5_gon_vthrough:rt90_5_0_gon_o- RT90 local zones
Get all available projections:
SwedenCrsTransformations.CrsProjection.get_all()
# => [:wgs84, :sweref_99_tm, :sweref_99_12_00, ...]Running Tests
mix testAll tests pass with coordinate accuracy within:
- 0.000007 degrees for WGS84 transformations
- 0.5 meters for SWEREF99 and RT90 transformations
License
MIT License - see LICENSE file for details.
This library is based on:
- sweden_crs_transformations_4typescript by Tomas Johansson (MIT)
- MightyLittleGeodesy by Björn Sållarp (MIT)
Credits
- Original C# implementation: Björn Sållarp
- TypeScript port: Tomas Johansson
- Elixir port: Based on the TypeScript version