Modul:Coordinate
Utseende
Moduldokumentasjon
[opprett]
--local math = require('Module:Math');
-------------------------------------------------------------------------------
-- Coordinate class
-------------------------------------------------------------------------------
local Coordinate = {}
-------------------------------------------------------------------------------
-- Creates a new coordinate object.
-- @param o
--
function Coordinate:new(frame)
local o = {} -- create object
meta = {__index = self} --
setmetatable(o, meta) --
o:init(frame) -- do some initialization
--[[
o.fromWikidata = function(latitude, longitude, precision)
return self:fromWikidata(latitude, longitude, precision)
end
o.formatForTitle = function(frame)
return self:formatForTitle()
end
o.formatForInline = function(frame)
return self:formatForInline()
end
]]
return o
end
-------------------------------------------------------------------------------
-- Initialize the coordinate object
--
function Coordinate:init( frame )
-- store the frame
self.frame = frame
-- We use DMS for internal storage
self.lat = { deg = nil, min = nil, sec = nil, sign = nil }
self.long = { deg = nil, min = nil, sec = nil, sign = nil }
end
function Coordinate:parseDecimal( value, uncertainty )
local o = {}
o.sign = (value < 0 and -1 or 1)
value = math.abs(value)
value = math.floor(value/uncertainty + 1/2) * uncertainty
o.deg = math.floor(value) -- degrees
value = (value - o.deg) * 60
o.min = math.floor(value) -- arcminutes
o.sec = (value - o.min) * 60 -- arcseconds
-- Unless uncertainty is higher than to an arcsecond, we round off
if (uncertainty >= 1/3600.001) then o.sec = math.floor(o.sec + 1/2) end
if (o.sec >= 60) then
o.sec = o.sec - 60
o.min = o.min + 1
end
if (o.min == 60) then
o.min = 0
o.deg = o.deg + 1
end
-- om precision är 1/3600 (eller mindre) blir format = dms
-- om precision är mellan 1/3600 och 1/60 blir format = dm
-- om precision är större än 1/60 blir format = d
-- If uncertainty > 1/3600
if (uncertainty > 1/3599.99) then
o.sec = nil
end
-- If uncertainty > 1/60
if (uncertainty > 1/59.99) then
o.min = nil
end
return o
end
function Coordinate:fromDecimal( latitude, longitude, precision )
if (precision == nil) then
precision = 1/3600 -- set default precision to one arcsecond (1/3600 degree)
end
self.lat = Coordinate.parseDecimal(latitude, precision)
self.long = Coordinate.parseDecimal(longitude, precision)
--[[
local antal_decimaler = 3
if (prec >= 1e-8) then antal_decimaler = math.max(0,math.floor(-math.log(prec*3600)/math.log(10)+0.5)) end
local format = coordinates.wdprec2dms(frame)
if (format == 'd') then frame.args = {latd .. "", latNS, longd .. "", longEW, display=disp, 'region:'..reg..'_type:'..type..'_source:Wikidata'} end
if (format == 'dm') then frame.args = {latd .. "", latm .. "", latNS, longd .. "", longm .. "", longEW, display=disp, 'region:'..reg..'_type:'..type..'_source:Wikidata'} end
if (format == 'dms') then frame.args = {latd .. "", latm .. "", string.format('%2.'..antal_decimaler..'f',lats) .. "",latNS, longd .. "", longm .. "",string.format('%2.'..antal_decimaler..'f',longs) .. "",longEW, display=disp, 'region:'..reg..'_type:'..type..'_source:Wikidata'} end
return coordinates.local_coord(frame)
]]
end
-------------------------------------------------------------------------------
-- Returns the coordinate formatted for title
--
function Coordinate:formatForTitle()
return nil
end
return Coordinate