Content deleted Content added
more intelligent data handling |
add precision argument |
||
Line 628:
* OSBG36 Easting and Northing
]]
local function LatLon2OSGB36( latlon, prec )
local tm = LatLonOrigin2TM(latlon.lat, latlon.lon)
if not tm then return '' end
if not tonumber(prec) then prec = 5 end
prec = floor(prec+0.5)
if prec > 5 then prec = 5 end
if prec < 1 then prec = 1 end
-- fix by Roger W Haworth
Line 645 ⟶ 649:
local c2 = mw.ustring.sub(letters,indx2,indx2)
local
local
local grid = pow(10.0,5.0-prec)
easting = floor(easting/grid+0.5*grid)
northing = floor(northing/grid+0.5*grid)
local fmt = '%0'..prec..'d'
local e = mw.ustring.format(fmt, easting)
local n = mw.ustring.format(fmt, northing)
return c1..c2..e..n
Line 652 ⟶ 662:
end
function oscoord._WGS2OSGB(lat,lon,prec)
return LatLon2OSGB36(HelmertDatumShift(lat,lon),prec)
end
function oscoord.WGS2OSGB(frame)
local args = getArgs(frame)
return args[1] and args[2] and oscoord._WGS2OSGB(args[1],args[2],args[3]) or ''
end
Line 664 ⟶ 674:
local args = getArgs(frame)
if not args[1] or not args[2] then return '' end
local gridRef = oscoord._WGS2OSGB(args[1],args[2],args.prec)
if not gridRef or #gridRef == 0 then return '' end
if args[3] then
|