Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::open($save_path, $session_name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/PHPSessionHandler.php on line 205
Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/PHPSessionHandler.php on line 220
Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::read($id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/PHPSessionHandler.php on line 234
Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::write($id, $dataStr) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/PHPSessionHandler.php on line 262
Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::destroy($id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/PHPSessionHandler.php on line 368
Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/PHPSessionHandler.php on line 389
Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 70
Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 80
Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 75
Deprecated: Return type of Wikimedia\Rdbms\ResultWrapper::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php on line 117
Deprecated: Return type of Wikimedia\Rdbms\ResultWrapper::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php on line 90
Deprecated: Return type of MediaWiki\Session\Session::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 625
Deprecated: Return type of MediaWiki\Session\Session::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 631
Deprecated: Return type of MediaWiki\Session\Session::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 643
Deprecated: Return type of MediaWiki\Session\Session::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 637
Deprecated: Return type of MediaWiki\Session\Session::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 655
Deprecated: Return type of MediaWiki\Session\Session::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 649
Deprecated: Return type of MediaWiki\Session\Session::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 665
Deprecated: Return type of & MediaWiki\Session\Session::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 678
Deprecated: Return type of MediaWiki\Session\Session::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 688
Deprecated: Return type of MediaWiki\Session\Session::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/lfg/itchan.official.jp/public_html/wiki/includes/session/Session.php on line 693
Deprecated: Message implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /home/lfg/itchan.official.jp/public_html/wiki/includes/Message.php on line 159
Deprecated: RawMessage implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /home/lfg/itchan.official.jp/public_html/wiki/includes/RawMessage.php on line 34
Deprecated: Creation of dynamic property RequestContext::$recursion is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/includes/context/RequestContext.php on line 326
Deprecated: Creation of dynamic property Parser::$mPreprocessorClass is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/includes/parser/Parser.php on line 279
Deprecated: Creation of dynamic property Parser::$extCite is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/extensions/Cite/includes/Cite.php on line 1296
Deprecated: Creation of dynamic property Parser::$scribunto_engine is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/extensions/Scribunto/includes/common/Hooks.php on line 81
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/includes/parser/Preprocessor_DOM.php on line 845
Warning: Cannot modify header information - headers already sent by (output started at /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php:24) in /home/lfg/itchan.official.jp/public_html/wiki/includes/Feed.php on line 294
Warning: Cannot modify header information - headers already sent by (output started at /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php:24) in /home/lfg/itchan.official.jp/public_html/wiki/includes/Feed.php on line 300
Warning: Cannot modify header information - headers already sent by (output started at /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php:24) in /home/lfg/itchan.official.jp/public_html/wiki/includes/WebResponse.php on line 46
Warning: Cannot modify header information - headers already sent by (output started at /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php:24) in /home/lfg/itchan.official.jp/public_html/wiki/includes/WebResponse.php on line 46
Warning: Cannot modify header information - headers already sent by (output started at /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php:24) in /home/lfg/itchan.official.jp/public_html/wiki/includes/WebResponse.php on line 46
Warning: Cannot modify header information - headers already sent by (output started at /home/lfg/itchan.official.jp/public_html/wiki/includes/libs/rdbms/database/resultwrapper/ResultWrapper.php:24) in /home/lfg/itchan.official.jp/public_html/wiki/includes/WebResponse.php on line 46 http://itchan.official.jp/wiki/index.php?action=history&feed=atom&title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%3ACoordinatesモジュール:Coordinates - 版の履歴2026-03-25T12:26:22Zこのウィキのこのページに関する変更履歴MediaWiki 1.31.1 Deprecated: Creation of dynamic property PoolCounterWorkViaCallback::$poolCounter is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/includes/poolcounter/PoolCounterWork.php on line 39
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/includes/parser/Preprocessor_DOM.php on line 845
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /home/lfg/itchan.official.jp/public_html/wiki/includes/parser/Preprocessor_DOM.php on line 845 http://itchan.official.jp/wiki/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:Coordinates&diff=1069&oldid=prevいんふぉ™: 1版2014-03-20T16:07:16Z<p>1版</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr class="diff-title" lang="ja">
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">← 古い版</td>
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">2014年3月20日 (木) 16:07時点における版</td>
</tr><tr><td colspan="2" class="diff-notice" lang="ja"><div class="mw-diff-empty">(相違点なし)</div>
</td></tr></table>いんふぉ™http://itchan.official.jp/wiki/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:Coordinates&diff=1068&oldid=prevFryed-peach: :en:Module:Coordinates oldid=562174757 より2013-07-01T00:17:25Z<p><a href="/wiki/index.php?title=En:Module:Coordinates&action=edit&redlink=1" class="new" title="En:Module:Coordinates (存在しないページ)">en:Module:Coordinates</a> oldid=562174757 より</p>
<p><b>新規ページ</b></p><div>--[[<br />
This module is intended to replace the functionality of {{Coord}} and related<br />
templates. It provides several methods, including<br />
<br />
{{#Invoke:Coordinates | coord }} : General function formatting and displaying<br />
coordinate values.<br />
<br />
{{#Invoke:Coordinates | dec2dms }} : Simple function for converting decimal<br />
degree values to DMS format.<br />
<br />
{{#Invoke:Coordinates | dms2dec }} : Simple function for converting DMS format<br />
to decimal degree format.<br />
<br />
]]<br />
<br />
math_mod = require( "Module:Math" );<br />
globalFrame = nil<br />
<br />
coordinates = {};<br />
<br />
--[[ Helper function, replacement for {{coord/display/title}} ]]<br />
function displaytitle (s, notes)<br />
local l = "[[地理座標系|座標]]: " .. s<br />
local co = '<span id="coordinates">' .. l .. notes .. '</span>';<br />
return '<span style="font-size: small;">' .. co .. '</span>';<br />
end<br />
<br />
--[[ Helper function, Replacement for {{coord/display/inline}} ]]<br />
function displayinline (s, notes)<br />
return s .. notes <br />
end<br />
<br />
--[[ Helper function, used in detecting DMS formatting ]]<br />
local dmsTest = function(first, second)<br />
local concatenated = first:upper() .. second:upper();<br />
<br />
if concatenated == "NE" or concatenated == "NW" or concatenated == "SE" or concatenated == "SW" or<br />
concatenated == "EN" or concatenated == "WN" or concatenated == "ES" or concatenated == "WS" then<br />
return true;<br />
end<br />
return false;<br />
end<br />
<br />
--[[<br />
parseDec<br />
<br />
Transforms decimal format latitude and longitude into the a<br />
structure to be used in displaying coordinates<br />
]]<br />
function parseDec( lat, long, format )<br />
local coordinateSpec = {}<br />
local errors = {}<br />
<br />
if long == "" or long == nil then<br />
return nil, {{"parseDec", "経度が指定されていません"}}<br />
end<br />
<br />
errors = validate( lat, nil, nil, long, nil, nil, 'parseDec', false ); <br />
coordinateSpec["dec-lat"] = lat;<br />
coordinateSpec["dec-long"] = long;<br />
<br />
local mode = coordinates.determineMode( lat, long );<br />
coordinateSpec["dms-lat"] = convert_dec2dms( lat, "北緯", "南緯", mode) -- {{coord/dec2dms|{{{1}}}|N|S|{{coord/prec dec|{{{1}}}|{{{2}}}}}}}<br />
coordinateSpec["dms-long"] = convert_dec2dms( long, "東経", "西経", mode) -- {{coord/dec2dms|{{{2}}}|E|W|{{coord/prec dec|{{{1}}}|{{{2}}}}}}} <br />
<br />
if format ~= "" then<br />
coordinateSpec.default = format<br />
else<br />
coordinateSpec.default = "dec"<br />
end<br />
<br />
return coordinateSpec, errors<br />
end<br />
<br />
--[[ Helper function, handle optional args. ]]<br />
function optionalArg(arg, suplement)<br />
if arg ~= nil and arg ~= "" then<br />
return arg .. suplement<br />
end<br />
return ""<br />
end<br />
<br />
--[[<br />
parseDMS<br />
<br />
Transforms degrees, minutes, seconds format latitude and longitude <br />
into the a structure to be used in displaying coordinates<br />
]]<br />
function parseDMS( lat_d, lat_m, lat_s, lat_f, long_d, long_m, long_s, long_f, format )<br />
local coordinateSpec = {}<br />
local errors = {}<br />
local format_en2ja = {<br />
N = "北緯",<br />
S = "南緯",<br />
E = "東経",<br />
W = "西経"<br />
}<br />
<br />
lat_f = lat_f:upper();<br />
long_f = long_f:upper();<br />
<br />
-- Check if specified backward<br />
if lat_f == 'E' or lat_f == 'W' then<br />
local t_d, t_m, t_s, t_f;<br />
t_d = lat_d;<br />
t_m = lat_m;<br />
t_s = lat_s;<br />
t_f = lat_f;<br />
lat_d = long_d;<br />
lat_m = long_m;<br />
lat_s = long_s;<br />
lat_f = long_f;<br />
long_d = t_d;<br />
long_m = t_m;<br />
long_s = t_s;<br />
long_f = t_f;<br />
end <br />
<br />
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS', true );<br />
if long_d == nil or long_d == "" then<br />
table.insert(errors, {"parseDMS", "経度が指定されていません" })<br />
end<br />
<br />
if lat_m == nil and lat_s == nil and long_m == nil and long_s == nil and #errors == 0 then <br />
if math_mod._precision( lat_d ) > 0 or math_mod._precision( long_d ) > 0 then<br />
if lat_f:upper() == 'S' then <br />
lat_d = '-' .. lat_d;<br />
end<br />
if long_f:upper() == 'W' then <br />
long_d = '-' .. long_d;<br />
end <br />
<br />
return parseDec( lat_d, long_d, format );<br />
end <br />
end <br />
<br />
coordinateSpec["dms-lat"] = format_en2ja[lat_f] .. lat_d.."度"..optionalArg(lat_m,"分") .. optionalArg(lat_s,"秒")<br />
coordinateSpec["dms-long"] = format_en2ja[long_f] .. long_d.."度"..optionalArg(long_m,"分") .. optionalArg(long_s,"秒")<br />
coordinateSpec["dec-lat"] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) -- {{coord/dms2dec|{{{4}}}|{{{1}}}|0{{{2}}}|0{{{3}}}}}<br />
coordinateSpec["dec-long"] = convert_dms2dec(long_f, long_d, long_m, long_s) -- {{coord/dms2dec|{{{8}}}|{{{5}}}|0{{{6}}}|0{{{7}}}}}<br />
<br />
if format ~= "" then<br />
coordinateSpec.default = format<br />
else<br />
coordinateSpec.default = "dms"<br />
end <br />
<br />
return coordinateSpec, errors<br />
end<br />
<br />
--[[<br />
specPrinter<br />
<br />
Output formatter. Takes the structure generated by either parseDec<br />
or parseDMS and formats it for inclusion on Wikipedia.<br />
]]<br />
function specPrinter(args, coordinateSpec)<br />
local uriComponents = coordinateSpec["param"]<br />
if uriComponents == "" then<br />
-- RETURN error, should never be empty or nil<br />
return "エラー: param が空です"<br />
end<br />
if args["name"] ~= "" and args["name"] ~= nil then<br />
uriComponents = uriComponents .. "&title=" .. mw.uri.encode(coordinateSpec["name"])<br />
end<br />
<br />
local geodmshtml = '<span class="geo-dms" title="この位置の地図や航空写真などにリンクするページを表示します">'<br />
.. '<span class="latitude">' .. coordinateSpec["dms-lat"] .. '</span> '<br />
.. '<span class="longitude">' ..coordinateSpec["dms-long"] .. '</span>'<br />
.. '</span>'<br />
<br />
local lat = tonumber( coordinateSpec["dec-lat"] ) or 0<br />
if lat < 0 then<br />
-- FIXME this breaks the pre-existing precision<br />
geodeclat = "南緯" .. coordinateSpec["dec-lat"]:sub(2) .. "度"<br />
else<br />
geodeclat = "北緯" .. (coordinateSpec["dec-lat"] or 0) .. "度"<br />
end<br />
<br />
local long = tonumber( coordinateSpec["dec-long"] ) or 0<br />
if long < 0 then<br />
-- FIXME does not handle unicode minus<br />
geodeclong = "西経" .. coordinateSpec["dec-long"]:sub(2) .. "度"<br />
else<br />
geodeclong = "東経" .. (coordinateSpec["dec-long"] or 0) .. "度"<br />
end<br />
<br />
local geodechtml = '<span class="geo-dec" title="この位置の地図や航空写真などにリンクするページを表示します">'<br />
.. '<span class="nowrap">' .. geodeclat .. '</span> '<br />
.. '<span class="nowrap">' .. geodeclong .. '</span>'<br />
.. '</span>'<br />
<br />
local geonumhtml = '<span class="geo">'<br />
.. coordinateSpec["dec-lat"] .. '; '<br />
.. coordinateSpec["dec-long"]<br />
.. '</span>'<br />
<br />
local inner;<br />
inner = '<span class="' .. displayDefault(coordinateSpec["default"], "dms" ) .. '">' .. geodmshtml .. '</span>'<br />
.. '<span class="geo-multi-punct">&#xfeff; / &#xfeff;</span>'<br />
.. '<span class="' .. displayDefault(coordinateSpec["default"], "dec" ) .. '">';<br />
<br />
if args["name"] == "" or args["name"] == nil then<br />
inner = inner .. geodechtml <br />
.. '<span style="display:none">&#xfeff; / ' .. geonumhtml .. '</span></span>'<br />
else<br />
inner = inner .. '<span class="vcard">' .. geodechtml <br />
.. '<span style="display:none">&#xfeff; / ' .. geonumhtml .. '</span>'<br />
.. '<span style="display:none">&#xfeff; (<span class="fn org">'<br />
.. args["name"] .. '</span>)</span></span></span>'<br />
end<br />
<br />
return '<span class="plainlinks nourlexpansion">' .. globalFrame:preprocess(<br />
'[//tools.wmflabs.org/geohack/geohack.php?language=ja&pagename={{FULLPAGENAMEE}}&params=' ..<br />
uriComponents .. ' ' .. inner .. ']') .. '</span>'<br />
end<br />
<br />
--[[<br />
Formats any error messages generated for display<br />
]]<br />
function errorPrinter(errors)<br />
local result = ""<br />
for i,v in ipairs(errors) do<br />
local errorHTML = '<strong class="error">座標: ' .. v[2] .. '</strong>'<br />
result = result .. errorHTML .. "<br />"<br />
end<br />
return result<br />
end<br />
<br />
--[[<br />
Determine the required CSS class to display coordinates<br />
<br />
Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himself<br />
default is the mode as specificied by the user when calling the {{coord}} template<br />
mode is the display mode (dec or dms) that we will need to determine the css class for <br />
]]<br />
function displayDefault(default, mode)<br />
if default == "" then<br />
default = "dec"<br />
end<br />
<br />
if default == mode then<br />
return "geo-default"<br />
else<br />
return "geo-nondefault"<br />
end<br />
end<br />
<br />
--[[ <br />
Check the input arguments for coord to determine the kind of data being provided<br />
and then make the necessary processing.<br />
]]<br />
function formatTest(args)<br />
local result, errors;<br />
local primary = false;<br />
<br />
if args[1] == "" then<br />
-- no lat logic<br />
return errorPrinter( {{"formatTest", "緯度が指定されていません"}} )<br />
elseif args[4] == "" and args[5] == "" and args[6] == "" then<br />
-- dec logic<br />
result, errors = parseDec( args[1], args[2], args['format'] )<br />
if result == nil then<br />
return errorPrinter( errors );<br />
end <br />
result.param = table.concat( {args[1], "_N_", args[2], "_E_", args[3] } );<br />
elseif dmsTest(args[4], args[8]) then<br />
-- dms logic<br />
result, errors = parseDMS( args[1], args[2], args[3], args[4], <br />
args[5], args[6], args[7], args[8], args['format'] )<br />
result.param = table.concat( { args[1], args[2], args[3], args[4], args[5],<br />
args[6], args[7], args[8], args[9] } , '_' );<br />
if args[10] ~= '' then<br />
table.insert( errors, { 'formatTest', '座標オプションが認識できません' } );<br />
end <br />
elseif dmsTest(args[3], args[6]) then<br />
-- dm logic<br />
result, errors = parseDMS( args[1], args[2], nil, args[3], <br />
args[4], args[5], nil, args[6], args['format'] )<br />
result.param = table.concat( { args[1], args[2], args[3], args[4], args[5],<br />
args[6], args[7] } , '_' );<br />
if args[8] ~= '' then<br />
table.insert( errors, { 'formatTest', '座標オプションが認識できません' } );<br />
end <br />
elseif dmsTest(args[2], args[4]) then<br />
-- d logic<br />
result, errors = parseDMS( args[1], nil, nil, args[2], <br />
args[3], nil, nil, args[4], args['format'] )<br />
result.param = table.concat( { args[1], args[2], args[3], args[4], args[5] } , '_' );<br />
if args[6] ~= '' then<br />
table.insert( errors, { 'formatTest', '座標オプションが認識できません' } );<br />
end <br />
else<br />
-- Error<br />
return errorPrinter( {{"formatTest", "引数の形式が認識できません"}} )<br />
end<br />
result.name = args["name"]<br />
<br />
local extra_param = {'dim', 'globe', 'scale', 'region', 'source', 'type'}<br />
for _, v in ipairs( extra_param ) do<br />
if (args[v] or '') ~= '' then <br />
table.insert( errors, {'formatTest', '引数: "' .. v .. '=" は "' .. v .. ':" という形式でなければいけません' } );<br />
end<br />
end<br />
<br />
if #errors == 0 then<br />
return specPrinter( args, result ) <br />
else<br />
return specPrinter( args, result ) .. " " .. errorPrinter(errors) .. '[[Category:座標タグに誤りがあるページ]]'; <br />
end <br />
end<br />
<br />
--[[ <br />
Helper function, convert decimal latitude or longitude to <br />
degrees, minutes, and seconds format based on the specified precision. <br />
]]<br />
function convert_dec2dms(coordinate, firstPrefix, secondPrefix, precision)<br />
local coord = tonumber(coordinate) or 0<br />
local prefix<br />
if coord >= 0 then<br />
prefix = firstPrefix<br />
else<br />
prefix = secondPrefix<br />
end<br />
<br />
precision = precision:lower();<br />
if precision == "dms" then<br />
return prefix .. convert_dec2dms_dms( math.abs( coord ) );<br />
elseif precision == "dm" then<br />
return prefix .. convert_dec2dms_dm( math.abs( coord ) );<br />
elseif precision == "d" then<br />
return prefix .. convert_dec2dms_d( math.abs( coord ) );<br />
end<br />
end<br />
<br />
--[[ Helper function, convert decimal to degrees ]]<br />
function convert_dec2dms_d(coordinate)<br />
local d = math_mod._round( coordinate, 0 ) .. "度"<br />
return d .. ""<br />
end<br />
<br />
--[[ Helper function, convert decimal to degrees and minutes ]]<br />
function convert_dec2dms_dm(coordinate) <br />
coordinate = math_mod._round( coordinate * 60, 0 );<br />
local m = coordinate % 60;<br />
coordinate = math.floor( (coordinate - m) / 60 );<br />
local d = coordinate % 360 .."度"<br />
<br />
return d .. string.format( "%02d分", m )<br />
end<br />
<br />
--[[ Helper function, convert decimal to degrees, minutes, and seconds ]]<br />
function convert_dec2dms_dms(coordinate)<br />
coordinate = math_mod._round( coordinate * 60 * 60, 0 );<br />
local s = coordinate % 60<br />
coordinate = math.floor( (coordinate - s) / 60 );<br />
local m = coordinate % 60<br />
coordinate = math.floor( (coordinate - m) / 60 );<br />
local d = coordinate % 360 .."度"<br />
<br />
return d .. string.format( "%02d分", m ) .. string.format( "%02d秒", s )<br />
end<br />
<br />
--[[<br />
Convert DMS format into a N or E decimal coordinate<br />
]]<br />
function convert_dms2dec(direction, degrees_str, minutes_str, seconds_str)<br />
local degrees = tonumber(degrees_str) or 0<br />
local minutes = tonumber(minutes_str) or 0<br />
local seconds = tonumber(seconds_str) or 0<br />
<br />
local factor<br />
direction = mw.ustring.gsub(direction, '^[ ]*(.-)[ ]*$', '%1');<br />
if direction == "N" or direction == "E" then<br />
factor = 1<br />
else<br />
factor = -1<br />
end<br />
<br />
local precision = 0<br />
if seconds_str ~= nil and seconds_str ~= '' then<br />
precision = 5 + math.max( math_mod._precision(seconds_str), 0 );<br />
elseif minutes_str ~= nil and minutes_str ~= '' then<br />
precision = 3 + math.max( math_mod._precision(minutes_str), 0 );<br />
else<br />
precision = math.max( math_mod._precision(degrees_str), 0 );<br />
end<br />
<br />
local decimal = factor * (degrees+(minutes+seconds/60)/60) <br />
return string.format( "%." .. precision .. "f", decimal ) -- not tonumber since this whole thing is string based.<br />
end<br />
<br />
--[[ <br />
Checks input values to for out of range errors.<br />
]]<br />
function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source, strong )<br />
local errors = {};<br />
lat_d = tonumber( lat_d ) or 0;<br />
lat_m = tonumber( lat_m ) or 0;<br />
lat_s = tonumber( lat_s ) or 0;<br />
long_d = tonumber( long_d ) or 0;<br />
long_m = tonumber( long_m ) or 0;<br />
long_s = tonumber( long_s ) or 0;<br />
<br />
if strong then<br />
if lat_d < 0 then<br />
table.insert(errors, {source, "緯度が0度を下回っていますが南北が指定されています"})<br />
end<br />
if long_d < 0 then<br />
table.insert(errors, {source, "経度が0度を下回っていますが東西が指定されています"})<br />
end<br />
--[[ <br />
#coordinates is inconsistent about whether this is an error. If globe: is<br />
specified, it won't error on this condition, but otherwise it will.<br />
<br />
For not simply disable this check.<br />
<br />
if long_d > 180 then<br />
table.insert(errors, {source, "経度が180度を上回っていますが東西が指定されています"})<br />
end<br />
]]<br />
end <br />
<br />
if lat_d > 90 then<br />
table.insert(errors, {source, "緯度の度が90を上回っています"})<br />
end<br />
if lat_d < -90 then<br />
table.insert(errors, {source, "緯度の度が-90を下回っています"})<br />
end<br />
if lat_m >= 60 then<br />
table.insert(errors, {source, "緯度の分が60以上です"})<br />
end<br />
if lat_m < 0 then<br />
table.insert(errors, {source, "緯度の分が0を下回っています"})<br />
end<br />
if lat_s >= 60 then<br />
table.insert(errors, {source, "緯度の秒が60以上です"})<br />
end<br />
if lat_s < 0 then<br />
table.insert(errors, {source, "緯度の秒が0を下回っています"})<br />
end<br />
if long_d >= 360 then<br />
table.insert(errors, {source, "経度の度が360以上です"})<br />
end<br />
if long_d <= -360 then<br />
table.insert(errors, {source, "経度の度が-360以下です"})<br />
end<br />
if long_m >= 60 then<br />
table.insert(errors, {source, "経度の分が60以上です"})<br />
end<br />
if long_m < 0 then<br />
table.insert(errors, {source, "経度の分が0を下回っています"})<br />
end<br />
if long_s >= 60 then<br />
table.insert(errors, {source, "経度の秒が60以上です"})<br />
end<br />
if long_s < 0 then<br />
table.insert(errors, {source, "経度の秒が0を下回っています"})<br />
end<br />
<br />
return errors;<br />
end<br />
<br />
--[[<br />
dec2dms<br />
<br />
Wrapper to allow templates to call dec2dms directly.<br />
<br />
Usage:<br />
{{ Invoke:Coordinates | dec2dms | decimal_coordinate | positive_suffix | <br />
negative_suffix | precision }}<br />
<br />
decimal_coordinate is converted to DMS format. If positive, the positive_suffix<br />
is appended (typical N or E), if negative, the negative suffix is appended. The<br />
specified precision is one of 'D', 'DM', or 'DMS' to specify the level of detail<br />
to use.<br />
]]<br />
function coordinates.dec2dms(frame)<br />
globalFrame = frame<br />
local coordinate = frame.args[1]<br />
local firstPostfix = frame.args[2]<br />
local secondPostfix = frame.args[3]<br />
local precision = frame.args[4]<br />
<br />
return convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision)<br />
end<br />
<br />
--[[<br />
Helper function to determine whether to use D, DM, or DMS<br />
format depending on the precision of the decimal input.<br />
]]<br />
function coordinates.determineMode( value1, value2 )<br />
local precision = math.max( math_mod._precision( value1 ), math_mod._precision( value2 ) );<br />
if precision <= 0 then<br />
return 'd'<br />
elseif precision <= 2 then<br />
return 'dm';<br />
else<br />
return 'dms';<br />
end<br />
end <br />
<br />
--[[<br />
dms2dec<br />
<br />
Wrapper to allow templates to call dms2dec directly.<br />
<br />
Usage:<br />
{{ Invoke:Coordinates | dms2dec | direction_flag | degrees | <br />
minutes | seconds }}<br />
<br />
Converts DMS values specified as degrees, minutes, seconds too decimal format.<br />
direction_flag is one of N, S, E, W, and determines whether the output is <br />
positive (i.e. N and E) or negative (i.e. S and W).<br />
]]<br />
function coordinates.dms2dec(frame)<br />
globalFrame = frame<br />
local direction = frame.args[1]<br />
local degrees = frame.args[2]<br />
local minutes = frame.args[3]<br />
local seconds = frame.args[4]<br />
<br />
return convert_dms2dec(direction, degrees, minutes, seconds)<br />
end<br />
<br />
--[[<br />
coord<br />
<br />
Main entry point for Lua function to replace {{coord}}<br />
<br />
Usage:<br />
{{ Invoke:Coordinates | coord }}<br />
{{ Invoke:Coordinates | coord | lat | long }}<br />
{{ Invoke:Coordinates | coord | lat | lat_flag | long | long_flag }}<br />
...<br />
<br />
Refer to {{coord}} documentation page for many additional parameters and <br />
configuration options.<br />
<br />
Note: This function provides the visual display elements of {{coord}}. In<br />
order to load coordinates into the database, the {{#coordinates:}} parser <br />
function must also be called, this is done automatically in the Lua<br />
version of {{coord}}.<br />
]]<br />
function coordinates.coord(frame)<br />
globalFrame = frame<br />
local args = frame.args<br />
if args[1] == nil then<br />
local pFrame = frame:getParent();<br />
args = pFrame.args;<br />
for k,v in pairs( frame.args ) do<br />
args[k] = v;<br />
end<br />
end<br />
<br />
for i=1,10 do <br />
if args[i] == nil then <br />
args[i] = ""<br />
else<br />
args[i] = args[i]:match( '^%s*(.-)%s*$' ); --remove whitespace<br />
end <br />
end<br />
args['format'] = args['format'] or '';<br />
<br />
local contents = formatTest(args)<br />
local Notes = args.notes or ""<br />
local Display = string.lower(args.display or "inline")<br />
if Display == '' then<br />
Display = 'inline';<br />
end<br />
<br />
local text = ''<br />
if string.find( Display, 'inline' ) ~= nil or Display == 'i' or <br />
Display == 'it' or Display == 'ti' then<br />
text = displayinline(contents, Notes)<br />
end<br />
if string.find( Display, 'title' ) ~= nil or Display == 't' or <br />
Display == 'it' or Display == 'ti' then<br />
text = text .. displaytitle(contents, Notes)<br />
end<br />
return text<br />
end<br />
<br />
return coordinates</div>Fryed-peach