ianmackenzie / elm-units

Simple, safe and convenient unit types and conversions for Elm
https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/
BSD 3-Clause "New" or "Revised" License
85 stars 14 forks source link

LatLon/Utm-WGS84 units and conversion #16

Closed hakonrossebo closed 6 years ago

hakonrossebo commented 6 years ago

Would it be interesting to have these units/conversion in this package? Some examples and info here

https://github.com/TimothyGu/utm https://github.com/jjimenezshaw/Leaflet.UTM

ianmackenzie commented 6 years ago

My initial reaction is that I think these would fit better in a separate elm-geography or elm-wgs-84 or similar package...one of my goals for elm-units is for it to have a very simple, stable API that other packages can safely depend on without risking dependency version conflicts. As a result, every module other than Quantity is basically just a collection of conversion factors (with the exception of Temperature, which is a bit of a special case but is so common I felt it really had to be included).

It seems to me that latitude/longitude to UTM conversion involves some not-totally-trivial design choices (e.g. should UTM coordinates be represented by a record or a custom type?), so would ideally be in a separate package that can evolve independently.

That said, I think it would make a lot of sense to build such a package on top of elm-units, and I'd be happy to add necessary functionality to elm-units to make that as easy as possible! Off the top of my head, it would probably make sense to add Angle construction/conversion functions for minutes and seconds so that Angle values would be nice to use as the representation for latitude/longitude. And if there are length units that are commonly used when working with UTM coordinates that aren't included in the Length module, then I'd be open to adding them.

Thoughts? Does that make sense?

hakonrossebo commented 6 years ago

Thanks - Seems very reasonable. I'll see if I have time to create a package for this and ping you back if I'm missing some functions in elm-units.

gampleman commented 6 years ago

One thing comes up in geospatial computing which is that you can treat Angle as Length...

I have something like this defined in my code:


earthRadius : Float
earthRadius =
    6371.0088

lengthToAngle : Length -> Angle
lengthToAngle l =
    Angle.radians <| Length.inKilometers l / earthRadius
ianmackenzie commented 6 years ago

@gampleman I think something like that would also make sense in an elm-geography (or maybe elm-geospatial?) package, perhaps as a set of extensions to Length:

module Geospatial.Length exposing (toAngle, fromAngle)

import Length exposing (Length)
import Angle exposing (Angle)

lengthPerAngle : Quantity Float (Rate Length Angle)
lengthPerAngle =
    Length.kilometers 6371.0088 |> Quantity.per (Angle.radians 1)

toAngle : Length -> Angle
toAngle length =
    length |> Quantity.at_ lengthPerAngle

fromAngle : Angle -> Length
fromAngle angle =
    angle |> Quantity.at lengthPerAngle
gampleman commented 6 years ago

I'm working on it...

ianmackenzie commented 6 years ago

Awesome! Let me know if there's some way I can help =) I think I will at least add minutes/seconds support to Angle (just logged as #21), but happy to consider other additions where that makes sense.