Last active
August 27, 2019 08:55
-
-
Save hhrhhr/c234a495a438522df3f9e8bb1ba7a9a7 to your computer and use it in GitHub Desktop.
converter for gcp list from M2_LRPT_Decoder for use with GDAL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------+---------+---------+---------+---------+---------+---------+---------+ | |
--[[ arg[1] - input.gcp | |
-- arg[2] arg[3] - sparse coff [50 [200]] | |
--]] | |
local gpcs = "-gcp %d %d %f %f" | |
local xcoff = arg[2] and tonumber(arg[2]) or 50 | |
local ycoff = arg[3] and tonumber(arg[3]) or 200 | |
local gcp, grid = {}, {} | |
local xmax, ymax | |
for line in io.lines(arg[1]) do | |
if "" == line then goto skip end | |
for x, y, lat, lon in string.gmatch(line, "(.+) (.+) (.+) (.+)") do | |
x = tonumber(x) | |
y = tonumber(y) | |
lat = lat:gsub(",", ".") | |
lat = tonumber(lat) | |
lon = lon:gsub(",", ".") | |
lon = tonumber(lon) | |
table.insert(gcp, {x, y, lon, lat}) | |
table.insert(grid, {lon, lat, x, -y}) | |
xmax = x | |
ymax = y | |
end | |
::skip:: | |
end | |
local wg = io.open(arg[1] .. ".gcps", "w+b") -- for gdal_translate | |
local wp = io.open(arg[1] .. ".points", "w+b") -- for QGis georef plugin | |
for i = 1, #gcp do | |
local g = gcp[i] | |
if (g[1] % xcoff == 0 or g[1] == xmax) and (g[2] % ycoff == 0 or g[2] == ymax) then | |
wg:write(" -gcp ", table.concat(g, " ")) | |
g = grid[i] | |
wp:write(table.concat(g, ",")) | |
wp:write(",1,0,0,0\n") | |
end | |
end | |
wg:close() | |
wp:close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment