Skip to content

Instantly share code, notes, and snippets.

@severak
Created February 10, 2016 11:19
Show Gist options
  • Save severak/831d2624a96e4f4a0d20 to your computer and use it in GitHub Desktop.
Save severak/831d2624a96e4f4a0d20 to your computer and use it in GitHub Desktop.
computes km grid to gpx
-- kmgrid
local push = table.insert
-- délka rovnoběžky
function latLen(lat)
local d = 40074
return d * math.cos(math.rad(lat))
end
-- jedna horizontalni linka bodu
function horizontal(out, amount, lat, lon)
local horiKmLen = 360/latLen(lat)
for y=-amount,amount do
push(out, lat ..','.. (lon + (y*horiKmLen)) )
print(' <wpt lat="'..lat..'" lon="'..(lon + (y*horiKmLen))..'"/>')
end
return out
end
local coords = {}
local vertKmLen = 360/latLen(0)
local amount = 5
lat=0
lon=0
print('<gpx version="1.1" creator="kmgrid">')
for i=-amount,amount do
horizontal(coords, amount, lat + (i*vertKmLen), lon)
end
print('</gpx>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment