Anonymous user
Module:Coordinates: Difference between revisions
more formatting / comments
(more formatting) |
(more formatting / comments) |
||
Line 1:
--[[
This module is intended to replace the functionality of {{Coord}} and related
{{#Invoke:Coordinates | coord }} : General function formatting and displaying
coordinate values.
{{#Invoke:Coordinates | dec2dms }} : Simple function for converting decimal
degree values to DMS format.
{{#Invoke:Coordinates | dms2dec }} : Simple function for converting DMS format
to decimal degree format.
]]
Line 134 ⟶ 138:
else
coordinateSpec.default = "dms"
end
return coordinateSpec, errors
Line 238 ⟶ 241:
end
--[[
Check the input arguments for coord to determine the kind of data being provided
and then make the necessary processing.
]]
function formatTest(args)
local result, errors;
Line 297 ⟶ 303:
return specPrinter( args, result ) .. " " .. errorPrinter(errors) .. '[[Category:Pages with malformed coordinate tags]]';
end
end
--[[
Helper function, convert decimal latitude or longitude to
degrees, minutes, and seconds format based on the specified precision.
]]
function convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision)
local coord = tonumber(coordinate) or 0
local postfix
if coord >= 0 then
postfix = firstPostfix
else
postfix = secondPostfix
end
precision = precision:lower();
if precision == "dms" then
return convert_dec2dms_dms( math.abs( coord ) ) .. postfix;
elseif precision == "dm" then
return convert_dec2dms_dm( math.abs( coord ) ) .. postfix;
elseif precision == "d" then
return convert_dec2dms_d( math.abs( coord ) ) .. postfix;
end
end
Line 327 ⟶ 356:
end
--[[
Convert DMS format into a N or E decimal coordinate
]]
function convert_dms2dec(direction, degrees_str, minutes_str, seconds_str)
local degrees = tonumber(degrees_str) or 0
Line 379 ⟶ 380:
end
local decimal = factor * (degrees+(minutes+seconds/60)/60)
return string.format( "%." .. precision .. "f", decimal ) -- not tonumber since this whole thing is string based.
end
--[[
Checks input values to for out of range errors.
]]
function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source, strong )
local errors = {};
Line 455:
end
--[[
dec2dms
Wrapper to allow templates to call dec2dms directly.
Usage:
{{ Invoke:Coordinates | dec2dms | decimal_coordinate | positive_suffix |
negative_suffix | precision }}
decimal_coordinate is converted to DMS format. If positive, the positive_suffix
is appended (typical N or E), if negative, the negative suffix is appended. The
specified precision is one of 'D', 'DM', or 'DMS' to specify the level of detail
to use.
]]
function coordinates.dec2dms(frame)
globalFrame = frame
Line 473 ⟶ 479:
end
--[[
Helper function to determine whether to use D, DM, or DMS
format depending on the precision of the decimal input.
]]
function coordinates.determineMode( value1, value2 )
local precision = math.max( math_mod._precision( value1 ), math_mod._precision( value2 ) );
Line 484 ⟶ 494:
end
--[[
dms2dec
Wrapper to allow templates to call dms2dec directly.
Usage:
{{ Invoke:Coordinates | dms2dec | direction_flag | degrees |
minutes | seconds }}
Converts DMS values specified as degrees, minutes, seconds too decimal format.
direction_flag is one of N, S, E, W, and determines whether the output is
positive (i.e. N and E) or negative (i.e. S and W).
]]
function coordinates.dms2dec(frame)
globalFrame = frame
Line 495 ⟶ 517:
end
--[[
coord
Main entry point for Lua function to replace {{coord}}
Usage:
{{ Invoke:Coordinates | coord }}
{{ Invoke:Coordinates | coord | lat | long }}
{{ Invoke:Coordinates | coord | lat | lat_flag | long | long_flag }}
...
Refer to {{coord}} documentation page for many additional parameters and
configuration options.
Note: This function provides the visual display elements of {{coord}}. In
order to load coordinates into the database, the {{#coordinates:}} parser
function must also be called, this is done automatically in the Lua
version of {{coord}}.
]]
function coordinates.coord(frame)
globalFrame = frame
|