Module:Coordinates: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(per edit request on talk page) |
(add new functions per request of User:Jc86035) |
||
Line 3: | Line 3: | ||
templates. It provides several methods, including |
templates. It provides several methods, including |
||
{{# |
{{#invoke:Coordinates | coord }} : General function formatting and displaying |
||
coordinate values. |
coordinate values. |
||
{{# |
{{#invoke:Coordinates | dec2dms }} : Simple function for converting decimal |
||
degree values to DMS format. |
degree values to DMS format. |
||
{{# |
{{#invoke:Coordinates | dms2dec }} : Simple function for converting DMS format |
||
to decimal degree format. |
to decimal degree format. |
||
{{# |
{{#invoke:Coordinates | link }} : Export the link used to reach the tools |
||
]] |
]] |
||
Line 520: | Line 520: | ||
Usage: |
Usage: |
||
{{ |
{{#invoke:Coordinates | link }} |
||
]] |
]] |
||
Line 533: | Line 533: | ||
Usage: |
Usage: |
||
{{ |
{{#invoke:Coordinates | dec2dms | decimal_coordinate | positive_suffix | |
||
negative_suffix | precision }} |
negative_suffix | precision }} |
||
Line 572: | Line 572: | ||
Usage: |
Usage: |
||
{{ |
{{#invoke:Coordinates | dms2dec | direction_flag | degrees | |
||
minutes | seconds }} |
minutes | seconds }} |
||
Line 595: | Line 595: | ||
Usage: |
Usage: |
||
{{ |
{{#invoke:Coordinates | coord }} |
||
{{ |
{{#invoke:Coordinates | coord | lat | long }} |
||
{{ |
{{#invoke:Coordinates | coord | lat | lat_flag | long | long_flag }} |
||
... |
... |
||
Line 651: | Line 651: | ||
end |
end |
||
return text |
return text |
||
end |
|||
--[[ |
|||
coord2text |
|||
Extracts a single value from a transclusion of {{Coord}}. |
|||
IF THE GEOHACK LINK SYNTAX CHANGES THIS FUNCTION MUST BE MODIFIED. |
|||
Usage: |
|||
{{#invoke:Coordinates | coord2text | {{Coord}} | parameter }} |
|||
Valid values for the second parameter are: lat (signed integer), long (signed integer), type, scale, dim, region, globe, source |
|||
]] |
|||
function coordinates.coord2text(frame) |
|||
if frame.args[1] == '' or frame.args[2] == '' or not frame.args[2] then return nil end |
|||
frame.args[2] = mw.text.trim(frame.args[2]) |
|||
if frame.args[2] == 'lat' or frame.args[2] == 'long' then |
|||
local result, negative = mw.text.split((mw.ustring.match(frame.args[1],'%d+.?%d*°[NS] %d+.?%d*°[EW]') or ''), ' ') |
|||
if frame.args[2] == 'lat' then |
|||
result, negative = result[1], 'S' |
|||
else |
|||
result, negative = result[2], 'W' |
|||
end |
|||
result = mw.text.split(result, '°') |
|||
if result[2] == negative then result[1] = '-'..result[1] end |
|||
return result[1] |
|||
else |
|||
return mw.ustring.match(frame.args[1], 'params=.-_'..frame.args[2]..':(.-)[ _]') |
|||
end |
|||
end |
|||
--[[ |
|||
coordinsert |
|||
Injects some text into the Geohack link of a transclusion of {{Coord}} (if that text isn't already in the transclusion). Outputs the modified transclusion of {{Coord}}. |
|||
IF THE GEOHACK LINK SYNTAX CHANGES THIS FUNCTION MUST BE MODIFIED. |
|||
Usage: |
|||
{{#invoke:Coordinates | coordinsert | {{Coord}} | parameter:value | parameter:value | … }} |
|||
Do not make Geohack unhappy by inserting something which isn't mentioned in the {{Coord}} documentation. |
|||
]] |
|||
function coordinates.coordinsert(frame) |
|||
for i, v in ipairs(frame.args) do |
|||
if i ~= 1 then |
|||
if not mw.ustring.find(frame.args[1], (mw.ustring.match(frame.args[i], '^(.-:)') or '')) then frame.args[1] = mw.ustring.gsub(frame.args[1], '(params=.-)_? ', '%1_'..frame.args[i]..' ', 1) end |
|||
end |
|||
end |
|||
return frame.args[1] |
|||
end |
end |
||