Module:Ordnance Survey coordinates/sandbox: Difference between revisions

Content deleted Content added
drop unused
factor out data
 
(11 intermediate revisions by the same user not shown)
Line 71:
-- Datum parameters
 
local data = mw.loadData('Module:Ordnance Survey coordinates/data')
local OSGBglobe = {
semimajor = 6377563.396,
semiminor = 6356256.910,
ecc = 0.006670539761597529073698869358812557054558,
n1 = 0.00167322025032508731869331280635710896296,
scale = 0.9996012717,
e0 = 400000.0,
n0 = -100000.0,
lat0 = 49.0,
lon0 = -2.0
}
 
local IEglobeOSGBglobe = {data.OSGBglobe
local IEglobe = data.IEglobe
semimajor = 6377340.189,
local WGSglobe = data.WGSglobe
semiminor = 6356034.447,
local WGS2OSGBparam = data.WGS2OSGBparam
ecc = 0.006670540293336110419293763349975612794125,
local OSGB2WGSparam = data.OSGB2WGSparam
n1 = 0.001673220384152058651484728058385228837777,
local IE2WGSparam = data.IE2WGSparam
scale = 1.000035,
e0 = 200000.0,
n0 = 250000.0,
lat0 = 53.5,
lon0 = -8.0
}
 
local WGSglobe = {
semimajor = 6378137.0,
semiminor = 6356752.3141,
ecc = 0.00669438003551279089034150031998869922791
}
 
local WGS2OSGBparam = {
-- Table 4, Section 6.6, Ordnance Survey document
semimajor_src = WGSglobe.semimajor,
semiminor_src = WGSglobe.semiminor,
ecc_src = WGSglobe.ecc,
semimajor_dst = OSGBglobe.semimajor,
semiminor_dst = OSGBglobe.semiminor,
ecc_dst = OSGBglobe.ecc,
tx = -446.448,
ty = 125.157,
tz = -542.060,
s0 = 0.0000204894,
rx = deg2rad ( -.1502/3600. ),
ry = deg2rad ( -.2470/3600. ),
rz = deg2rad ( -.8421/3600. )
}
 
local OSGB2WGSparam = {
semimajor_src = OSGBglobe.semimajor,
semiminor_src = OSGBglobe.semiminor,
ecc_src = OSGBglobe.ecc,
semimajor_dst = WGSglobe.semimajor,
semiminor_dst = WGSglobe.semiminor,
ecc_dst = WGSglobe.ecc,
tx = -WGS2OSGBparam.tx,
ty = -WGS2OSGBparam.ty,
tz = -WGS2OSGBparam.tz,
s0 = -WGS2OSGBparam.s0,
rx = -WGS2OSGBparam.rx,
ry = -WGS2OSGBparam.ry,
rz = -WGS2OSGBparam.rz,
}
 
local IE2WGSparam = {
semimajor_src = IEglobe.semimajor,
semiminor_src = IEglobe.semiminor,
ecc_src = IEglobe.ecc,
semimajor_dst = WGSglobe.semimajor,
semiminor_dst = WGSglobe.semiminor,
ecc_dst = WGSglobe.ecc,
tx = 482.53,
ty = -130.596,
tz = 564.557,
s0 = 8.15/1000000.0,
rx = deg2rad( -1.042/3600.0 ),
ry = deg2rad( -0.214/3600.0 ),
rz = deg2rad( -0.631/3600.0 )
}
 
local function HelmertDatumShift ( latitude , longitude, param )
Line 407 ⟶ 337:
url = url..'pagename='..pagename..'&'
end
LL.lat = LL.lat or 0
LL.long = LL.long or 0
LL.lat = ceil(LL.lat*1000000)/1000000
LL.long = ceil(LL.long*1000000)/1000000
url = url..'params='..mw.ustring.format('%.6f',LL.lat)..'_N_'
if LL.long < 0 then
Line 431 ⟶ 357:
url = url .. "&title=" .. mw.uri.encode(namearg)
end
return url
end
 
-- function to generate direct link to OS map
local function directLink(main_args, other_args, LL)
-- create link to Bing server for OS maps. Example:
-- https://www.bing.com/maps/?mkt=en-gb&v=2&cp=56.796026%7E-5.01307&lvl=16.0&sp=Point.56.796029_-5.004711_Ben+Nevis&sty=s&style=s
local current_page = mw.title.getCurrentTitle()
local namearg = mw.uri.encode( main_args["name"] or current_page.prefixedText, 'QUERY' )
local args = {}
for _, a in ipairs(other_args) do
local splitOut = mw.text.split(a, ':', true)
args[splitOut[1]] = splitOut[2]
end
if not args.scale and not args.type and not args.dim then
args.dim = LL.prec and tostring(floor(50*LL.prec+0.5))..'m'
end
args.viewport_cm = 10
local zoom = require('Module:Infobox dim')._zoom
local lvl = zoom(args) or 12
local url = mw.ustring.format('https://www.bing.com/maps/?mkt=en-gb&v=2&cp=%.6f~%.6f&lvl=%d&sp=Point.%.6f_%.6f',LL.lat,LL.long,lvl,LL.lat,LL.long)
if not empty(namearg) then
url = url..'_'..namearg
end
url = url..'&sty=s&style=s'
return url
end
Line 441 ⟶ 392:
local linktitle = main_args[2]
local rawurl = yesno(main_args["rawurl"])
local direct = yesno(main_args["direct"])
local args = split(input,'_')
local LL
Line 472 ⟶ 424:
return linktitle ..warning(LL.err)
end
LL.lat = LL.lat or 0
LL.long = LL.long or 0
LL.lat = ceil(LL.lat*1000000)/1000000
LL.long = ceil(LL.long*1000000)/1000000
local other_args = {}
for i = restargs, #args do
table.insert(other_args, args[i])
end
local url
local url = geohack(main_args, other_args, LL, restargs)
if not direct then
url = geohack(main_args, other_args, LL)
else
url = directLink(main_args, other_args, LL)
end
if not rawurl then
url = '['..url..' '..linktitle..']'