-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_geo_info.rb
executable file
·84 lines (71 loc) · 1.9 KB
/
copy_geo_info.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby
require "rubygems"
require "yaml"
require 'getoptlong'
require "pp"
def runner ( s )
puts("Runner running \"#{s}\"")
start_time = Time.now.to_f
system(s)
end_time = Time.now.to_f
run_time = (end_time-start_time)
if ( run_time > 60)
printf("This run took %d m\n", (end_time-start_time)/60)
else
printf("This run took %d s\n", (end_time-start_time))
end
end
def get_geo_info (path)
return YAML.load(`gdal_list_corners #{path}`)
end
def write_wld(path,cfg)
s = path.split(".")
s.pop
s = s.join(".")
s += ".wld"
#affine"=>[560290.5932, 0.6, 0.0, 7126029.9645, 0.0, -0.6]
#Example
#25.40000078[1]
#0.00000000 [2]
#0.00000000 [4]
#-25.40000078 [5]
#493568.398193100002 [0]
#7440989.090747700073[3]
File.open(s, "w") do |fd|
fd.puts(cfg["affine"][1])
fd.puts(cfg["affine"][2])
fd.puts(cfg["affine"][4])
fd.puts(cfg["affine"][5])
fd.puts(cfg["affine"][0])
fd.puts(cfg["affine"][3])
end
end
##
# Options..
opts = GetoptLong.new(
[ "--geo_source", "-g", GetoptLong::REQUIRED_ARGUMENT ],
[ "--infile", "-i", GetoptLong::REQUIRED_ARGUMENT ],
[ "--outfile", "-o", GetoptLong::REQUIRED_ARGUMENT ],
[ "--gdal_args", "-c", GetoptLong::REQUIRED_ARGUMENT ],
[ "--help", "-h", GetoptLong::NO_ARGUMENT ]
)
begin
opts.each do |opt, arg|
case opt
when "--geo_source"
puts("Reading geo information from #{arg}")
@geo_info = get_geo_info(arg)
when "--infile"
@infile = arg
when "--outfile"
@outfile = arg
when "--gdal_args"
@gdalargs = arg
end
end
rescue
puts("Hmmm, errored out while arg processing.. not sure what the deal is..")
end
#pp @geo_info
write_wld(@infile, @geo_info)
runner("gdal_translate #{@gdalargs if (@gdalargs) } -a_srs \"#{@geo_info["s_srs"]}\" #{@infile} #{@outfile}")