@@ -36,7 +36,7 @@ georef(table, geoms::AbstractVector{<:Geometry}) = georef(table, GeometrySet(geo
36
36
Georeference `table` using coordinates `coords` of points.
37
37
38
38
Optionally, specify the coordinate reference system `crs`, which is
39
- set by default based on heuristics, and the `lenunit` (default to meters)
39
+ set by default based on heuristics, and the `lenunit` (default to meters for unitless values )
40
40
that will be used in CRS types that allow this flexibility. Any `CRS` or `EPSG`/`ESRI`
41
41
code from [CoordRefSystems.jl](https://github.com/JuliaEarth/CoordRefSystems.jl)
42
42
is supported.
@@ -50,7 +50,7 @@ julia> georef((a=[1, 2, 3], b=[4, 5, 6], [(0, 0), (1, 1), (2, 2)], crs=EPSG{4326
50
50
julia> georef((a=[1, 2, 3], b=[4, 5, 6], [(0, 0), (1, 1), (2, 2)], lenunit=u"cm")
51
51
```
52
52
"""
53
- function georef (table, coords:: AbstractVector ; crs= nothing , lenunit= u " m " )
53
+ function georef (table, coords:: AbstractVector ; crs= nothing , lenunit= nothing )
54
54
clen = length (first (coords))
55
55
ccrs = isnothing (crs) ? Cartesian{NoDatum,clen} : validcrs (crs)
56
56
point = pointbuilder (ccrs, lenunit)
64
64
Georeference `table` using coordinates of points stored in column `names`.
65
65
66
66
Optionally, specify the coordinate reference system `crs`, which is
67
- set by default based on heuristics, and the `lenunit` (default to meter )
67
+ set by default based on heuristics, and the `lenunit` (default to meters for unitless values )
68
68
that will be used in CRS types that allow this flexibility. Any `CRS` or `EPSG`/`ESRI`
69
69
code from [CoordRefSystems.jl](https://github.com/JuliaEarth/CoordRefSystems.jl)
70
70
is supported.
@@ -78,7 +78,7 @@ georef((a=rand(10), x=rand(10), y=rand(10)), ("x", "y"), crs=EPSG{4326})
78
78
georef((a=rand(10), x=rand(10), y=rand(10)), ("x", "y"), lenunit=u"cm")
79
79
```
80
80
"""
81
- function georef (table, names:: AbstractVector{Symbol} ; crs= nothing , lenunit= u " m " )
81
+ function georef (table, names:: AbstractVector{Symbol} ; crs= nothing , lenunit= nothing )
82
82
cols = Tables. columns (table)
83
83
tnames = Tables. columnnames (cols)
84
84
if names ⊈ tnames
@@ -158,19 +158,27 @@ end
158
158
159
159
# point builder for given crs and lenunit
160
160
function pointbuilder (crs, u)
161
- if crs <: Cartesian
162
- (xyz... ) -> Point (crs ((xyz .* u). .. ))
163
- elseif crs <: Polar
164
- (ρ, ϕ) -> Point (crs (ρ * u, ϕ * u " rad" ))
165
- elseif crs <: Cylindrical
166
- (ρ, ϕ, z) -> Point (crs (ρ * u, ϕ * u " rad" , z * u))
167
- elseif crs <: Spherical
168
- (r, θ, ϕ) -> Point (crs (r * u, θ * u " rad" , ϕ * u " rad" ))
161
+ if ! isnothing (u)
162
+ if crs <: Cartesian
163
+ (xyz... ) -> Point (crs (withunit .(xyz, u)... ))
164
+ elseif crs <: Polar
165
+ (ρ, ϕ) -> Point (crs (withunit (ρ, u), withunit (ϕ, u " rad" )))
166
+ elseif crs <: Cylindrical
167
+ (ρ, ϕ, z) -> Point (crs (withunit (ρ, u), withunit (ϕ, u " rad" ), withunit (z, u)))
168
+ elseif crs <: Spherical
169
+ (r, θ, ϕ) -> Point (crs (withunit (r, u), withunit (θ, u " rad" ), withunit (ϕ, u " rad" )))
170
+ else
171
+ (coords... ) -> Point (crs (coords... ))
172
+ end
169
173
else
170
174
(coords... ) -> Point (crs (coords... ))
171
175
end
172
176
end
173
177
178
+ # add unit or convert to chosen unit
179
+ withunit (x:: Number , u) = x * u
180
+ withunit (x:: Quantity , u) = uconvert (u, x)
181
+
174
182
# variants of given names with uppercase, etc.
175
183
variants (names) = [names; uppercase .(names); uppercasefirst .(names)]
176
184
0 commit comments