「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年1月19日 (木) 18:55(UTC)より
template>K-iczn (en:Module:Wd 2017年1月12日 (木) 22:42(UTC)より) |
template>K-iczn (en:Module:Wd 2017年1月19日 (木) 18:55(UTC)より) |
||
635行目: | 635行目: | ||
return value | return value | ||
elseif snak.datavalue.type == 'globecoordinate' then | elseif snak.datavalue.type == 'globecoordinate' then | ||
-- logic from https://github.com/DataValues/Geo | |||
local precision, numDigits, strFormat, value, globe | local precision, numDigits, strFormat, value, globe | ||
local latValue, latitude, latDegrees, latMinutes, latSeconds | local latValue, latitude, latDegrees, latMinutes, latSeconds | ||
local latDirection = " | local latDirection = "北緯" | ||
local lonValue, longitude, lonDegrees, lonMinutes, lonSeconds | local lonValue, longitude, lonDegrees, lonMinutes, lonSeconds | ||
local lonDirection = " | local lonDirection = "東経" | ||
local degSymbol = " | local degSymbol = "度" | ||
local minSymbol = " | local minSymbol = "分" | ||
local secSymbol = ' | local secSymbol = '秒' | ||
local partsGlue = ", " | local partsGlue = ", " | ||
657行目: | 659行目: | ||
if latitude < 0 then | if latitude < 0 then | ||
latDirection = " | latDirection = "南緯" | ||
latitude = math.abs(latitude) | latitude = math.abs(latitude) | ||
end | end | ||
if longitude < 0 then | if longitude < 0 then | ||
lonDirection = " | lonDirection = "西経" | ||
longitude = math.abs(longitude) | longitude = math.abs(longitude) | ||
end | end | ||
670行目: | 672行目: | ||
longitude = math.floor(longitude / precision + 0.5) * precision | longitude = math.floor(longitude / precision + 0.5) * precision | ||
numDigits = math.ceil(-math.log10(3600 * precision)) | |||
if numDigits < 0 or numDigits == -0 then | |||
numDigits = 0 | |||
end | |||
strFormat = "%." .. numDigits .. "f" | |||
-- use string.format() to strip decimal point followed by a zero (.0) for whole numbers | |||
latSeconds = tonumber(string.format(strFormat, math.floor(latitude * 3600 * 10^numDigits + 0.5) / 10^numDigits)) | |||
lonSeconds = tonumber(string.format(strFormat, math.floor(longitude * 3600 * 10^numDigits + 0.5) / 10^numDigits)) | |||
latMinutes = math.floor(latSeconds / 60) | |||
lonMinutes = math.floor(lonSeconds / 60) | |||
latSeconds = latSeconds - (latMinutes * 60) | |||
lonSeconds = lonSeconds - (lonMinutes * 60) | |||
latDegrees = math.floor(latMinutes / 60) | |||
lonDegrees = math.floor(lonMinutes / 60) | |||
latMinutes = latMinutes - (latDegrees * 60) | |||
lonMinutes = lonMinutes - (lonDegrees * 60) | |||
latValue = latDegrees .. degSymbol | latValue = latDegrees .. degSymbol | ||
688行目: | 705行目: | ||
if precision < (1 / 60) then | if precision < (1 / 60) then | ||
latSeconds = string.format(strFormat, latSeconds) | latSeconds = string.format(strFormat, latSeconds) | ||
lonSeconds = string.format(strFormat, lonSeconds) | lonSeconds = string.format(strFormat, lonSeconds) |