Class: Kamelopard::Functions::LatLonInterp
- Inherits:
-
FunctionMultiDim
- Object
- Function
- FunctionMultiDim
- Kamelopard::Functions::LatLonInterp
- Defined in:
- lib/kamelopard/function.rb
Overview
Interpolates between two points, choosing the shortest great-circle distance between the points.
Instance Attribute Summary collapse
-
#latfunc ⇒ Object
readonly
a and b are points.
-
#lonfunc ⇒ Object
readonly
a and b are points.
Attributes inherited from FunctionMultiDim
Attributes inherited from Function
#append, #compose, #end, #max, #min, #start, #verbose
Instance Method Summary collapse
-
#initialize(a, b) ⇒ LatLonInterp
constructor
A new instance of LatLonInterp.
- #run_function(x) ⇒ Object
Methods inherited from FunctionMultiDim
Methods inherited from Function
Constructor Details
#initialize(a, b) ⇒ LatLonInterp
Returns a new instance of LatLonInterp.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/kamelopard/function.rb', line 185 def initialize(a, b) super() (lat1, lon1) = [a.latitude, a.longitude] (lat2, lon2) = [b.latitude, b.longitude] # if (lat2 - lat1).abs > 90 # if lat2 > 0 # lat2 = lat2 - 180 # else # lat2 = lat2 + 180 # end # end @latfunc = yield lat1, lat2, :latitude if (lon2 - lon1).abs > 180 if lon2 > 0 lon2 = lon2 - 360 else lon2 = lon2 + 360 end end @lonfunc = yield lon1, lon2, :longitude end |
Instance Attribute Details
#latfunc ⇒ Object (readonly)
a and b are points. This function will yield three variables, twice, expecting the block to return a one-dimensional function interpolating between the first two variables it was sent. The third variable yielded is a symbol, either :latitude or :longitude, to indicate which set of coordinates is being processed.
183 184 185 |
# File 'lib/kamelopard/function.rb', line 183 def latfunc @latfunc end |
#lonfunc ⇒ Object (readonly)
a and b are points. This function will yield three variables, twice, expecting the block to return a one-dimensional function interpolating between the first two variables it was sent. The third variable yielded is a symbol, either :latitude or :longitude, to indicate which set of coordinates is being processed.
183 184 185 |
# File 'lib/kamelopard/function.rb', line 183 def lonfunc @lonfunc end |
Instance Method Details
#run_function(x) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/kamelopard/function.rb', line 211 def run_function(x) (lat, lon) = [@latfunc.run_function(x), @lonfunc.run_function(x)] lat = lat - 180 if lat > 90 lat = lat + 180 if lat < -90 lon = lon - 360 if lon > 180 lon = lon + 360 if lon < -180 return [lat, lon] end |