Content deleted Content added
try trunc again |
factor out data |
||
(21 intermediate revisions by the same user not shown) | |||
Line 45:
local abs = math.abs
local floor = math.floor
local ceil = math.ceil
local sin = math.sin
local cos = math.cos
Line 70 ⟶ 71:
-- Datum parameters
local data = mw.loadData('Module:Ordnance Survey coordinates/data')
local
local IEglobe = data.IEglobe
local WGSglobe = data.WGSglobe
local WGS2OSGBparam = data.WGS2OSGBparam
local OSGB2WGSparam = data.OSGB2WGSparam
local IE2WGSparam = data.IE2WGSparam
local function HelmertDatumShift ( latitude , longitude, param )
Line 349 ⟶ 280:
local function NGR2LL(ngr)
local result = {}
local _ = 0
ngr, _ = mw.ustring.gsub(mw.ustring.upper(ngr),"[%s%p]","")
local first, last, lett, num = mw.ustring.find(ngr,"^([A-Z]+)(%d+)$")
Line 371 ⟶ 303:
local function trim(s)
local _ = 0
s, _ = mw.ustring.gsub(s,"^%s+","")
s, _ = mw.ustring.gsub(s,"%s+$","")
Line 392 ⟶ 325:
end
-- generate URL of geohack map
local function geohack(main_args, other_args, LL)
-- create geohack link. Example:
-- https://geohack.toolforge.org/geohack.php?pagename=Mount_Whitney¶ms=36.578580925_N_118.29199495_W_type:mountain_region:US-CA_scale:100000_source:NGS
local url = 'https://geohack.toolforge.org/geohack.php?'
local input = main_args[1]
local namearg = main_args["name"]
local current_page = mw.title.getCurrentTitle()
local pagename = mw.uri.encode( current_page.prefixedText, 'WIKI' )
if not empty(pagename) then
url = url..'pagename='..pagename..'&'
end
url = url..'params='..mw.ustring.format('%.6f',LL.lat)..'_N_'
if LL.long < 0 then
url = url..mw.ustring.format('%.6f',-LL.long)..'_W'
else
url = url..mw.ustring.format('%.6f',LL.long)..'_E'
end
for _, a in ipairs(other_args) do
url = url..'_'..a
end
if not mw.ustring.find(input,"region") and LL.region then
url = url..'_region:'..LL.region
end
if not mw.ustring.find(input,"scale") and
not mw.ustring.find(input,"type") and
not mw.ustring.find(input,"dim") and LL.prec then
url = url..'_dim:'..floor(50*LL.prec+0.5)..'m'
end
if not empty(namearg) then
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
function oscoord._main(main_args)
local input = main_args[1]
if empty(input) then
return warning(nil)
end
local linktitle =
local
local
local args = split(input,'_')
local LL
local restargs = 1
if #args >= 2 and alldigits(args[2]) then
if mw.ustring.sub(args[1],1,1) == 'i' then
Line 432 ⟶ 423:
if not empty(LL.err) then
return linktitle ..warning(LL.err)
end
LL.lat = LL.lat or 0
LL.long = LL.long or 0
local other_args = {}
for i = restargs, #args do
table.insert(other_args, args[i])
end
local url
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..']'
end
return url
Line 525 ⟶ 499:
local function find_M ( lat_rad )
local e = OSGBglobe.ecc
local e2 = e*e
local e3 = e*e*e
return OSGBglobe.semimajor * ( ( 1 - e/4 - 3 *
- 5 *
) * lat_rad
- ( 3 * e/8 + 3 *
+ 45 *
) * sin(2 * lat_rad)
+ ( 15 *
45 *
) * sin(4 * lat_rad)
- ( 35 *
) * sin(6 * lat_rad) )
end
Line 558 ⟶ 534:
local v = OSGBglobe.semimajor / sqrt(1 - e * sin(lat_rad)*sin(lat_rad))
local
local T = tank*tank
local T2 = T*T
local C = e_prime_sq * pow( cos(lat_rad), 2)
local A = deg2rad( longitude2 -OSGBglobe.lon0 ) * cos(lat_rad)
local A2 = A*A
local A3 = A2*A
local A4 = A2*A2
local A5 = A3*A2
local A6 = A3*A3
local M = find_M( lat_rad )
local M0 = 0.0
Line 569 ⟶ 552:
local northing = OSGBglobe.n0 + OSGBglobe.scale *
( (M - M0) + v*tan(lat_rad) *
(
+ (5 - T + 9*C + 4*C*C) *
+ (61 - 58*T +
+ 600*C - 330*e_prime_sq) *
local easting = OSGBglobe.e0 + OSGBglobe.scale * v *
( A
+ (1-T+C)*
+ (5 - 18*T +
- 58 * e_prime_sq)*
return {northing=northing,easting=easting}
|