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=prev Fryed-peach: :en:Module:Coordinates oldid=562174757 より 2013-07-01T00:17:25Z <p><a href="/wiki/index.php?title=En:Module:Coordinates&amp;action=edit&amp;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( &quot;Module:Math&quot; );<br /> globalFrame = nil<br /> <br /> coordinates = {};<br /> <br /> --[[ Helper function, replacement for {{coord/display/title}} ]]<br /> function displaytitle (s, notes)<br /> local l = &quot;[[地理座標系|座標]]: &quot; .. s<br /> local co = &#039;&lt;span id=&quot;coordinates&quot;&gt;&#039; .. l .. notes .. &#039;&lt;/span&gt;&#039;;<br /> return &#039;&lt;span style=&quot;font-size: small;&quot;&gt;&#039; .. co .. &#039;&lt;/span&gt;&#039;;<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 == &quot;NE&quot; or concatenated == &quot;NW&quot; or concatenated == &quot;SE&quot; or concatenated == &quot;SW&quot; or<br /> concatenated == &quot;EN&quot; or concatenated == &quot;WN&quot; or concatenated == &quot;ES&quot; or concatenated == &quot;WS&quot; 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 == &quot;&quot; or long == nil then<br /> return nil, {{&quot;parseDec&quot;, &quot;経度が指定されていません&quot;}}<br /> end<br /> <br /> errors = validate( lat, nil, nil, long, nil, nil, &#039;parseDec&#039;, false ); <br /> coordinateSpec[&quot;dec-lat&quot;] = lat;<br /> coordinateSpec[&quot;dec-long&quot;] = long;<br /> <br /> local mode = coordinates.determineMode( lat, long );<br /> coordinateSpec[&quot;dms-lat&quot;] = convert_dec2dms( lat, &quot;北緯&quot;, &quot;南緯&quot;, mode) -- {{coord/dec2dms|{{{1}}}|N|S|{{coord/prec dec|{{{1}}}|{{{2}}}}}}}<br /> coordinateSpec[&quot;dms-long&quot;] = convert_dec2dms( long, &quot;東経&quot;, &quot;西経&quot;, mode) -- {{coord/dec2dms|{{{2}}}|E|W|{{coord/prec dec|{{{1}}}|{{{2}}}}}}} <br /> <br /> if format ~= &quot;&quot; then<br /> coordinateSpec.default = format<br /> else<br /> coordinateSpec.default = &quot;dec&quot;<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 ~= &quot;&quot; then<br /> return arg .. suplement<br /> end<br /> return &quot;&quot;<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 = &quot;北緯&quot;,<br /> S = &quot;南緯&quot;,<br /> E = &quot;東経&quot;,<br /> W = &quot;西経&quot;<br /> }<br /> <br /> lat_f = lat_f:upper();<br /> long_f = long_f:upper();<br /> <br /> -- Check if specified backward<br /> if lat_f == &#039;E&#039; or lat_f == &#039;W&#039; 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, &#039;parseDMS&#039;, true );<br /> if long_d == nil or long_d == &quot;&quot; then<br /> table.insert(errors, {&quot;parseDMS&quot;, &quot;経度が指定されていません&quot; })<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 ) &gt; 0 or math_mod._precision( long_d ) &gt; 0 then<br /> if lat_f:upper() == &#039;S&#039; then <br /> lat_d = &#039;-&#039; .. lat_d;<br /> end<br /> if long_f:upper() == &#039;W&#039; then <br /> long_d = &#039;-&#039; .. long_d;<br /> end <br /> <br /> return parseDec( lat_d, long_d, format );<br /> end <br /> end <br /> <br /> coordinateSpec[&quot;dms-lat&quot;] = format_en2ja[lat_f] .. lat_d..&quot;度&quot;..optionalArg(lat_m,&quot;分&quot;) .. optionalArg(lat_s,&quot;秒&quot;)<br /> coordinateSpec[&quot;dms-long&quot;] = format_en2ja[long_f] .. long_d..&quot;度&quot;..optionalArg(long_m,&quot;分&quot;) .. optionalArg(long_s,&quot;秒&quot;)<br /> coordinateSpec[&quot;dec-lat&quot;] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) -- {{coord/dms2dec|{{{4}}}|{{{1}}}|0{{{2}}}|0{{{3}}}}}<br /> coordinateSpec[&quot;dec-long&quot;] = convert_dms2dec(long_f, long_d, long_m, long_s) -- {{coord/dms2dec|{{{8}}}|{{{5}}}|0{{{6}}}|0{{{7}}}}}<br /> <br /> if format ~= &quot;&quot; then<br /> coordinateSpec.default = format<br /> else<br /> coordinateSpec.default = &quot;dms&quot;<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[&quot;param&quot;]<br /> if uriComponents == &quot;&quot; then<br /> -- RETURN error, should never be empty or nil<br /> return &quot;エラー: param が空です&quot;<br /> end<br /> if args[&quot;name&quot;] ~= &quot;&quot; and args[&quot;name&quot;] ~= nil then<br /> uriComponents = uriComponents .. &quot;&amp;title=&quot; .. mw.uri.encode(coordinateSpec[&quot;name&quot;])<br /> end<br /> <br /> local geodmshtml = &#039;&lt;span class=&quot;geo-dms&quot; title=&quot;この位置の地図や航空写真などにリンクするページを表示します&quot;&gt;&#039;<br /> .. &#039;&lt;span class=&quot;latitude&quot;&gt;&#039; .. coordinateSpec[&quot;dms-lat&quot;] .. &#039;&lt;/span&gt; &#039;<br /> .. &#039;&lt;span class=&quot;longitude&quot;&gt;&#039; ..coordinateSpec[&quot;dms-long&quot;] .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;/span&gt;&#039;<br /> <br /> local lat = tonumber( coordinateSpec[&quot;dec-lat&quot;] ) or 0<br /> if lat &lt; 0 then<br /> -- FIXME this breaks the pre-existing precision<br /> geodeclat = &quot;南緯&quot; .. coordinateSpec[&quot;dec-lat&quot;]:sub(2) .. &quot;度&quot;<br /> else<br /> geodeclat = &quot;北緯&quot; .. (coordinateSpec[&quot;dec-lat&quot;] or 0) .. &quot;度&quot;<br /> end<br /> <br /> local long = tonumber( coordinateSpec[&quot;dec-long&quot;] ) or 0<br /> if long &lt; 0 then<br /> -- FIXME does not handle unicode minus<br /> geodeclong = &quot;西経&quot; .. coordinateSpec[&quot;dec-long&quot;]:sub(2) .. &quot;度&quot;<br /> else<br /> geodeclong = &quot;東経&quot; .. (coordinateSpec[&quot;dec-long&quot;] or 0) .. &quot;度&quot;<br /> end<br /> <br /> local geodechtml = &#039;&lt;span class=&quot;geo-dec&quot; title=&quot;この位置の地図や航空写真などにリンクするページを表示します&quot;&gt;&#039;<br /> .. &#039;&lt;span class=&quot;nowrap&quot;&gt;&#039; .. geodeclat .. &#039;&lt;/span&gt; &#039;<br /> .. &#039;&lt;span class=&quot;nowrap&quot;&gt;&#039; .. geodeclong .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;/span&gt;&#039;<br /> <br /> local geonumhtml = &#039;&lt;span class=&quot;geo&quot;&gt;&#039;<br /> .. coordinateSpec[&quot;dec-lat&quot;] .. &#039;; &#039;<br /> .. coordinateSpec[&quot;dec-long&quot;]<br /> .. &#039;&lt;/span&gt;&#039;<br /> <br /> local inner;<br /> inner = &#039;&lt;span class=&quot;&#039; .. displayDefault(coordinateSpec[&quot;default&quot;], &quot;dms&quot; ) .. &#039;&quot;&gt;&#039; .. geodmshtml .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;span class=&quot;geo-multi-punct&quot;&gt;&amp;#xfeff; / &amp;#xfeff;&lt;/span&gt;&#039;<br /> .. &#039;&lt;span class=&quot;&#039; .. displayDefault(coordinateSpec[&quot;default&quot;], &quot;dec&quot; ) .. &#039;&quot;&gt;&#039;;<br /> <br /> if args[&quot;name&quot;] == &quot;&quot; or args[&quot;name&quot;] == nil then<br /> inner = inner .. geodechtml <br /> .. &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; / &#039; .. geonumhtml .. &#039;&lt;/span&gt;&lt;/span&gt;&#039;<br /> else<br /> inner = inner .. &#039;&lt;span class=&quot;vcard&quot;&gt;&#039; .. geodechtml <br /> .. &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; / &#039; .. geonumhtml .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; (&lt;span class=&quot;fn org&quot;&gt;&#039;<br /> .. args[&quot;name&quot;] .. &#039;&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&#039;<br /> end<br /> <br /> return &#039;&lt;span class=&quot;plainlinks nourlexpansion&quot;&gt;&#039; .. globalFrame:preprocess(<br /> &#039;[//tools.wmflabs.org/geohack/geohack.php?language=ja&amp;pagename={{FULLPAGENAMEE}}&amp;params=&#039; ..<br /> uriComponents .. &#039; &#039; .. inner .. &#039;]&#039;) .. &#039;&lt;/span&gt;&#039;<br /> end<br /> <br /> --[[<br /> Formats any error messages generated for display<br /> ]]<br /> function errorPrinter(errors)<br /> local result = &quot;&quot;<br /> for i,v in ipairs(errors) do<br /> local errorHTML = &#039;&lt;strong class=&quot;error&quot;&gt;座標: &#039; .. v[2] .. &#039;&lt;/strong&gt;&#039;<br /> result = result .. errorHTML .. &quot;&lt;br /&gt;&quot;<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 == &quot;&quot; then<br /> default = &quot;dec&quot;<br /> end<br /> <br /> if default == mode then<br /> return &quot;geo-default&quot;<br /> else<br /> return &quot;geo-nondefault&quot;<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] == &quot;&quot; then<br /> -- no lat logic<br /> return errorPrinter( {{&quot;formatTest&quot;, &quot;緯度が指定されていません&quot;}} )<br /> elseif args[4] == &quot;&quot; and args[5] == &quot;&quot; and args[6] == &quot;&quot; then<br /> -- dec logic<br /> result, errors = parseDec( args[1], args[2], args[&#039;format&#039;] )<br /> if result == nil then<br /> return errorPrinter( errors );<br /> end <br /> result.param = table.concat( {args[1], &quot;_N_&quot;, args[2], &quot;_E_&quot;, 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[&#039;format&#039;] )<br /> result.param = table.concat( { args[1], args[2], args[3], args[4], args[5],<br /> args[6], args[7], args[8], args[9] } , &#039;_&#039; );<br /> if args[10] ~= &#039;&#039; then<br /> table.insert( errors, { &#039;formatTest&#039;, &#039;座標オプションが認識できません&#039; } );<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[&#039;format&#039;] )<br /> result.param = table.concat( { args[1], args[2], args[3], args[4], args[5],<br /> args[6], args[7] } , &#039;_&#039; );<br /> if args[8] ~= &#039;&#039; then<br /> table.insert( errors, { &#039;formatTest&#039;, &#039;座標オプションが認識できません&#039; } );<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[&#039;format&#039;] )<br /> result.param = table.concat( { args[1], args[2], args[3], args[4], args[5] } , &#039;_&#039; );<br /> if args[6] ~= &#039;&#039; then<br /> table.insert( errors, { &#039;formatTest&#039;, &#039;座標オプションが認識できません&#039; } );<br /> end <br /> else<br /> -- Error<br /> return errorPrinter( {{&quot;formatTest&quot;, &quot;引数の形式が認識できません&quot;}} )<br /> end<br /> result.name = args[&quot;name&quot;]<br /> <br /> local extra_param = {&#039;dim&#039;, &#039;globe&#039;, &#039;scale&#039;, &#039;region&#039;, &#039;source&#039;, &#039;type&#039;}<br /> for _, v in ipairs( extra_param ) do<br /> if (args[v] or &#039;&#039;) ~= &#039;&#039; then <br /> table.insert( errors, {&#039;formatTest&#039;, &#039;引数: &quot;&#039; .. v .. &#039;=&quot; は &quot;&#039; .. v .. &#039;:&quot; という形式でなければいけません&#039; } );<br /> end<br /> end<br /> <br /> if #errors == 0 then<br /> return specPrinter( args, result ) <br /> else<br /> return specPrinter( args, result ) .. &quot; &quot; .. errorPrinter(errors) .. &#039;[[Category:座標タグに誤りがあるページ]]&#039;; <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 &gt;= 0 then<br /> prefix = firstPrefix<br /> else<br /> prefix = secondPrefix<br /> end<br /> <br /> precision = precision:lower();<br /> if precision == &quot;dms&quot; then<br /> return prefix .. convert_dec2dms_dms( math.abs( coord ) );<br /> elseif precision == &quot;dm&quot; then<br /> return prefix .. convert_dec2dms_dm( math.abs( coord ) );<br /> elseif precision == &quot;d&quot; 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 ) .. &quot;度&quot;<br /> return d .. &quot;&quot;<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 ..&quot;度&quot;<br /> <br /> return d .. string.format( &quot;%02d分&quot;, 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 ..&quot;度&quot;<br /> <br /> return d .. string.format( &quot;%02d分&quot;, m ) .. string.format( &quot;%02d秒&quot;, 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, &#039;^[ ]*(.-)[ ]*$&#039;, &#039;%1&#039;);<br /> if direction == &quot;N&quot; or direction == &quot;E&quot; then<br /> factor = 1<br /> else<br /> factor = -1<br /> end<br /> <br /> local precision = 0<br /> if seconds_str ~= nil and seconds_str ~= &#039;&#039; then<br /> precision = 5 + math.max( math_mod._precision(seconds_str), 0 );<br /> elseif minutes_str ~= nil and minutes_str ~= &#039;&#039; 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( &quot;%.&quot; .. precision .. &quot;f&quot;, 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 &lt; 0 then<br /> table.insert(errors, {source, &quot;緯度が0度を下回っていますが南北が指定されています&quot;})<br /> end<br /> if long_d &lt; 0 then<br /> table.insert(errors, {source, &quot;経度が0度を下回っていますが東西が指定されています&quot;})<br /> end<br /> --[[ <br /> #coordinates is inconsistent about whether this is an error. If globe: is<br /> specified, it won&#039;t error on this condition, but otherwise it will.<br /> <br /> For not simply disable this check.<br /> <br /> if long_d &gt; 180 then<br /> table.insert(errors, {source, &quot;経度が180度を上回っていますが東西が指定されています&quot;})<br /> end<br /> ]]<br /> end <br /> <br /> if lat_d &gt; 90 then<br /> table.insert(errors, {source, &quot;緯度の度が90を上回っています&quot;})<br /> end<br /> if lat_d &lt; -90 then<br /> table.insert(errors, {source, &quot;緯度の度が-90を下回っています&quot;})<br /> end<br /> if lat_m &gt;= 60 then<br /> table.insert(errors, {source, &quot;緯度の分が60以上です&quot;})<br /> end<br /> if lat_m &lt; 0 then<br /> table.insert(errors, {source, &quot;緯度の分が0を下回っています&quot;})<br /> end<br /> if lat_s &gt;= 60 then<br /> table.insert(errors, {source, &quot;緯度の秒が60以上です&quot;})<br /> end<br /> if lat_s &lt; 0 then<br /> table.insert(errors, {source, &quot;緯度の秒が0を下回っています&quot;})<br /> end<br /> if long_d &gt;= 360 then<br /> table.insert(errors, {source, &quot;経度の度が360以上です&quot;})<br /> end<br /> if long_d &lt;= -360 then<br /> table.insert(errors, {source, &quot;経度の度が-360以下です&quot;})<br /> end<br /> if long_m &gt;= 60 then<br /> table.insert(errors, {source, &quot;経度の分が60以上です&quot;})<br /> end<br /> if long_m &lt; 0 then<br /> table.insert(errors, {source, &quot;経度の分が0を下回っています&quot;})<br /> end<br /> if long_s &gt;= 60 then<br /> table.insert(errors, {source, &quot;経度の秒が60以上です&quot;})<br /> end<br /> if long_s &lt; 0 then<br /> table.insert(errors, {source, &quot;経度の秒が0を下回っています&quot;})<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 &#039;D&#039;, &#039;DM&#039;, or &#039;DMS&#039; 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 &lt;= 0 then<br /> return &#039;d&#039;<br /> elseif precision &lt;= 2 then<br /> return &#039;dm&#039;;<br /> else<br /> return &#039;dms&#039;;<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] = &quot;&quot;<br /> else<br /> args[i] = args[i]:match( &#039;^%s*(.-)%s*$&#039; ); --remove whitespace<br /> end <br /> end<br /> args[&#039;format&#039;] = args[&#039;format&#039;] or &#039;&#039;;<br /> <br /> local contents = formatTest(args)<br /> local Notes = args.notes or &quot;&quot;<br /> local Display = string.lower(args.display or &quot;inline&quot;)<br /> if Display == &#039;&#039; then<br /> Display = &#039;inline&#039;;<br /> end<br /> <br /> local text = &#039;&#039;<br /> if string.find( Display, &#039;inline&#039; ) ~= nil or Display == &#039;i&#039; or <br /> Display == &#039;it&#039; or Display == &#039;ti&#039; then<br /> text = displayinline(contents, Notes)<br /> end<br /> if string.find( Display, &#039;title&#039; ) ~= nil or Display == &#039;t&#039; or <br /> Display == &#039;it&#039; or Display == &#039;ti&#039; then<br /> text = text .. displaytitle(contents, Notes)<br /> end<br /> return text<br /> end<br /> <br /> return coordinates</div> Fryed-peach