gdal-helper 0.0.1.3 → 0.0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
|
File without changes
|
data/examples/foo.tif
ADDED
Binary file
|
data/lib/gdal_helper.rb
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# Author:: Jay Cable <jay@spruceboy.net>
|
3
|
+
# Copyright:: Copyright (c) 2010 Jay Cable
|
4
|
+
# License:: Distributes under the same terms as Ruby.
|
5
|
+
##
|
6
|
+
# = \Gdal Helper - A simple wrapper class for gdal
|
2
7
|
# A simple wrapper class for gdal - the goal is to provide a very simple and easy interface to gdal in ruby.
|
3
8
|
# Ruby's gdal bindings, and ruby's ogr bindings are required.
|
4
9
|
# blame for this work goes to jay@spruceboy.net
|
5
|
-
#
|
6
|
-
#
|
10
|
+
# == Roadmap
|
11
|
+
# * Feel free to fork/revamp/whatever - credit would be nice, but not required.
|
12
|
+
# * I am hoping some more qualified folks will take this on and make it gleam with super goodness - Have at it folks!
|
13
|
+
# == Summary
|
14
|
+
# Once installed, you can read a file like this:
|
15
|
+
# require "gdal_helper"
|
16
|
+
# infile = GdalFile.new(filename)
|
17
|
+
# infile.each_line do |data|
|
18
|
+
# ..do something with data..
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# And write some gdal file like this:
|
22
|
+
# require "gdal_helper"
|
23
|
+
# outfile = GdalFile.new(file_name, "w", 30,30,3,"GTiff", String, ["COMPRESS=DEFLATE", "TILED=YES"])
|
24
|
+
# #write some data..
|
25
|
+
# outfile.write_bands(0,1,30,1,data)
|
26
|
+
#
|
27
|
+
# For more examples see the "examples" directory.
|
28
|
+
# Have fun!
|
7
29
|
|
8
30
|
##
|
9
31
|
# I am confused about how gdal shows up on varous distros - here are two tries..
|
@@ -109,7 +131,8 @@ class GdalBand < GdalStuff
|
|
109
131
|
end
|
110
132
|
|
111
133
|
private
|
112
|
-
|
134
|
+
#--
|
135
|
+
# This is just for reference - don't rdoc this stuff..
|
113
136
|
# string.pack notes - for refrence for the function below.
|
114
137
|
# Format | Returns | Function
|
115
138
|
#-------+---------+-----------------------------------------
|
@@ -218,6 +241,7 @@ class GdalBand < GdalStuff
|
|
218
241
|
# @ | --- | skip to the offset given by the
|
219
242
|
# | | length argument
|
220
243
|
#-------+---------+-----------------------------------------
|
244
|
+
#++
|
221
245
|
#unpacks the data
|
222
246
|
def unpack ( items, data)
|
223
247
|
pack_template = case (@band.DataType)
|
@@ -238,6 +262,9 @@ class GdalBand < GdalStuff
|
|
238
262
|
return data.unpack(pack_template*data.length)
|
239
263
|
end
|
240
264
|
|
265
|
+
|
266
|
+
#--
|
267
|
+
# dont rdoc this stuff.. just notes from pack for my own quick reference..
|
241
268
|
#Notes for pack..
|
242
269
|
# #Directives for pack.
|
243
270
|
#
|
@@ -279,6 +306,7 @@ class GdalBand < GdalStuff
|
|
279
306
|
# X | Back up a byte
|
280
307
|
# x | Null byte
|
281
308
|
# Z | Same as ``a'', except that null is added with *
|
309
|
+
#++
|
282
310
|
# packs data in prep to write to gdal..
|
283
311
|
def pack(data)
|
284
312
|
pack_template = case(@band.DataType)
|
@@ -414,6 +442,7 @@ class GdalFile < GdalStuff
|
|
414
442
|
end
|
415
443
|
|
416
444
|
#gets the geo transform (wld file traditionally)
|
445
|
+
# Returns an array with this information: [Origin (top left corner), X pixel size, Rotation (0 if north is up),Y Origin (top left corner), Rotation (0 if north is up), Y pixel size *-1 (its negitive)]
|
417
446
|
def get_geo_transform()
|
418
447
|
@gdalfile.get_geo_transform
|
419
448
|
end
|
@@ -428,4 +457,17 @@ class GdalFile < GdalStuff
|
|
428
457
|
0.upto(ysize-1){|y| yield(y,read_bands(0,y,xsize,1))}
|
429
458
|
end
|
430
459
|
|
460
|
+
# returns the extents as a {"xmin" => min, "ymin" => ymin, "xmax" => xmax, "ymax" => ymax} sort of construct..
|
461
|
+
def get_extents
|
462
|
+
transform = @gdalfile.get_geo_transform
|
463
|
+
#[274785.0, 30.0, 0.0, 4906905.0, 0.0, -30.0]
|
464
|
+
#[(0)Origin (top left corner), (1) X pixel size, (2) Rotation (0 if north is up),(3)Y Origin (top left corner), (4) Rotation (0 if north is up), (5) Y pixel size]
|
465
|
+
{
|
466
|
+
"xmin" => transform[0].to_f,
|
467
|
+
"ymin"=> transform[3].to_f + ysize().to_f * transform[5].to_f,
|
468
|
+
"ymax" => transform[3].to_f,
|
469
|
+
"xmax" => transform[0].to_f + xsize().to_f * transform[1].to_f
|
470
|
+
}
|
471
|
+
end
|
472
|
+
|
431
473
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- JC
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-06-30 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- examples/basic_example.rb
|
36
36
|
- examples/print_info_example.rb
|
37
37
|
- examples/ndvi_color.rb
|
38
|
+
- examples/foo.tif
|
38
39
|
- examples/basic_example_using_each_line.rb
|
39
40
|
- examples/gdal_helper_test.rb
|
40
41
|
has_rdoc: true
|