Module:Coordinates: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(more formatting / comments) |
(more formatting) |
||
Line 299: | Line 299: | ||
end |
end |
||
--[[ Helper function, convert decimal to degrees ]] |
|||
function convert_dec2dms_d(coordinate) |
function convert_dec2dms_d(coordinate) |
||
local d = math_mod._round( coordinate, 0 ) .. "°" |
local d = math_mod._round( coordinate, 0 ) .. "°" |
||
Line 304: | Line 305: | ||
end |
end |
||
--[[ Helper function, convert decimal to degrees and minutes ]] |
|||
function convert_dec2dms_dm(coordinate) |
function convert_dec2dms_dm(coordinate) |
||
coordinate = math_mod._round( coordinate * 60, 0 ); |
coordinate = math_mod._round( coordinate * 60, 0 ); |
||
Line 313: | Line 315: | ||
end |
end |
||
--[[ Helper function, convert decimal to degrees, minutes, and seconds ]] |
|||
function convert_dec2dms_dms(coordinate) |
function convert_dec2dms_dms(coordinate) |
||
coordinate = math_mod._round( coordinate * 60 * 60, 0 ); |
coordinate = math_mod._round( coordinate * 60 * 60, 0 ); |
||
Line 324: | Line 327: | ||
end |
end |
||
--[[ |
|||
--- Convert a latitude or longitude to the DMS format |
|||
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) |
function convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision) |
||
-- {{Coord/dec2dms/{{{4}}}|{{#ifexpr:{{{1}}} >= 0||-}}{{{1}}}}}{{#ifexpr:{{{1}}} >= 0|{{{2}}}|{{{3}}}}} |
-- {{Coord/dec2dms/{{{4}}}|{{#ifexpr:{{{1}}} >= 0||-}}{{{1}}}}}{{#ifexpr:{{{1}}} >= 0|{{{2}}}|{{{3}}}}} |
||
Line 356: | Line 362: | ||
local minutes = tonumber(minutes_str) or 0 |
local minutes = tonumber(minutes_str) or 0 |
||
local seconds = tonumber(seconds_str) or 0 |
local seconds = tonumber(seconds_str) or 0 |
||
-- {{#expr:{{#switch:{{{1}}}|N|E=1|S|W=-1}}*({{{2|0}}}+({{{3|0}}}+{{{4|0}}}/60)/60) round {{{precdec|{{#if:{{{4|}}}|5|{{#if:{{{3|}}}|3|0}}}}+{{precision1|{{{4|{{{3|{{{2}}}}}}}}}}}}}}}} |
|||
local factor |
local factor |
||
Line 381: | Line 386: | ||
end |
end |
||
-- Check the input for out of range errors. |
|||
function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source, strong ) |
function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source, strong ) |
||
local errors = {}; |
local errors = {}; |