「モジュール: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 = "N"
local latDirection = "北緯"
local lonValue, longitude, lonDegrees, lonMinutes, lonSeconds
local lonValue, longitude, lonDegrees, lonMinutes, lonSeconds
local lonDirection = "E"
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 = "S"
latDirection = "南緯"
latitude = math.abs(latitude)
latitude = math.abs(latitude)
end
end
if longitude < 0 then
if longitude < 0 then
lonDirection = "W"
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
latDegrees = math.floor(latitude)
numDigits = math.ceil(-math.log10(3600 * precision))
lonDegrees = math.floor(longitude)
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)
latMinutes = math.floor((latitude - latDegrees) * 60)
latDegrees = math.floor(latMinutes / 60)
lonMinutes = math.floor((longitude - lonDegrees) * 60)
lonDegrees = math.floor(lonMinutes / 60)
latSeconds = (latitude - (latDegrees + latMinutes / 60)) * 3600
latMinutes = latMinutes - (latDegrees * 60)
lonSeconds = (longitude - (lonDegrees + lonMinutes / 60)) * 3600
lonMinutes = lonMinutes - (lonDegrees * 60)
latValue = latDegrees .. degSymbol
latValue = latDegrees .. degSymbol
688行目: 705行目:
if precision < (1 / 60) then
if precision < (1 / 60) then
numDigits = math.ceil(-math.log10(3600 * precision))
if numDigits < 0 or numDigits == -0 then
numDigits = 0
end
strFormat = "%." .. numDigits .. "f"
latSeconds = string.format(strFormat, latSeconds)
latSeconds = string.format(strFormat, latSeconds)
lonSeconds = string.format(strFormat, lonSeconds)
lonSeconds = string.format(strFormat, lonSeconds)
匿名利用者