using CoordRefSystems, Unitful
rand(Cartesian2D{NoDatum, typeof(1.0u"m")})
does not work.
using CoordRefSystems, Unitful
rand(Cartesian2D{NoDatum, typeof(1.0u"m")})
does not work.
What is your ultimate goal? The rand
api in CoordRefSystems.jl is pretty low-level and mostly internal at this point.
I want to create synthetic scenes to test geometric inference algorithms. For that, I need to generate random data. I canโt generate random data without default units, which seems limiting.
The Unitful types are not easy to parse (or understand). Unfortunately, I could not add a rand function that will allow me to specify units.
using Meshes
using CoordRefSystems
using Unitful
rand(Point, crs=Cartesian2D, 100) |> LengthUnit(u"ft")
100-element Vector{Point{๐ผ{2}, Cartesian2D{NoDatum, Quantity{Float64, ๐, Unitful.FreeUnits{(ft,), ๐, nothing}}}}}:
Point(x: 1.22995723127453 ft, y: 1.2578581984621078 ft)
Point(x: 3.2635361225527983 ft, y: 0.971571140767104 ft)
Point(x: 1.1144842750799535 ft, y: 0.2029331909786202 ft)
Point(x: 2.6062199812344695 ft, y: 1.858510920611926 ft)
Point(x: 2.0589584140282247 ft, y: 0.41389288343385094 ft)
Point(x: 3.216505822297655 ft, y: 2.2673788472511975 ft)
Point(x: 2.41786630208288 ft, y: 0.9093777827293031 ft)
โฎ
Point(x: 2.926702134428096 ft, y: 0.6350027654665833 ft)
Point(x: 0.5839771521068765 ft, y: 2.6268370350416834 ft)
Point(x: 0.9673777618597657 ft, y: 0.028165002572651938 ft)
Point(x: 0.7529699261753467 ft, y: 0.7977590577763877 ft)
Point(x: 2.4358324180744475 ft, y: 1.354883318069243 ft)
Point(x: 2.4433776979835145 ft, y: 2.717828820597342 ft)
No I want random points with units that I specify, not default u"m"
I shared an example above where the LengthUnit
transform is used to change the units after creation of the random Point
from Meshes.jl
Okay, yes, that works, but youโre changing the default units from u"m" to u"ft." It seems you should be able to specify units as a type parameter to Cartesian2D, so this can be passed around as one type. I would like to specify the Cartesian coordinate system (with units) and then have the synthetic scene generated according to type, instead of carrying around separate type info for the units.
This would apply to Meshes as well, where random geometries are constructed.
Cartesian2D
is an alias to Cartesian
:
const Cartesian2D{Datum} = Cartesian{Datum,2}
The full type is
Cartesian{Datum,N,L<:Len} <: Basic{Datum}
where Len
is another alias:
const Len{T} = Quantity{T,u"๐"}
You can read the source code here:
I understand, but the original code doesnโt work when I specify L <: Len. I donโt know why when the type is fully defined.
e.g. this doesnt work either:
rand(Cartesian{NoDatum,2,Quantity{Float64,u"๐"}})
which I would expect should.
The type that is generated by default is:
Cartesian{NoDatum,2,CoordRefSystems.Met{Float64}}
where Met
is also an alias:
const Met{T} = Quantity{T,u"๐",typeof(m)}
You can create an alias for the unit you have in mind, and define the type likewise:
const Ft{T} = Quantity{T,u"๐",typeof(ft)}
Cartesian{NoDatum,2,Ft{Float64}}
The rand
methods are only defined for default units with default machine precision (Float64).
Thanks for the responses.