gdal-helper 0.0.1 → 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ require "gdal_helper"
6
6
  #basic plan - open a 256 by 256 image, write some data, set the projection and geo_trans, then quit, job done.
7
7
  image_size = 256
8
8
  # Open a tiff to write to, with default create options (TILED=YES, COMPRESS=LZW) to write to..
9
- outfile = Gdal_File.new(ARGV[0], "w", image_size ,image_size,3,"GTiff", String, ["COMPRESS=DEFLATE", "TILED=YES"])
9
+ outfile = GdalFile.new(ARGV[0], "w", image_size ,image_size,3,"GTiff", String, ["COMPRESS=DEFLATE", "TILED=YES"])
10
10
  0.upto(image_size-1) do |y|
11
11
  #Read a single line, line y
12
12
  bands = outfile.read_bands(0,y,image_size,1)
@@ -3,12 +3,12 @@ require "rubygems"
3
3
  require "gdal_helper"
4
4
 
5
5
  ## Open input file
6
- infile = Gdal_File.new(ARGV[0])
6
+ infile = GdalFile.new(ARGV[0])
7
7
  puts ("#{ARGV[0]} -> #{infile}")
8
8
  # Read the upper left hand quarter
9
9
  bands = infile.read_bands(0,0,infile.xsize/4,infile.ysize/4)
10
10
  # Open a file to write to..
11
- outfile = Gdal_File.new(ARGV[1], "w", infile.xsize/4 , infile.ysize/4,infile.number_of_bands,"GTiff", infile.data_type )
11
+ outfile = GdalFile.new(ARGV[1], "w", infile.xsize/4 , infile.ysize/4,infile.number_of_bands,"GTiff", infile.data_type )
12
12
  # write the upper left hand quarter..
13
13
  outfile.write_bands(0,0,infile.xsize/4,infile.ysize/4,bands)
14
14
  # Set the projection
@@ -4,7 +4,7 @@ require "rubygems"
4
4
  require "gdal_helper"
5
5
 
6
6
  ARGV.each do |item|
7
- gdal_file = Gdal_File.new(item) #open the file..
7
+ gdal_file = GdalFile.new(item) #open the file..
8
8
  size = gdal_file.size() #get the size hash..
9
9
  puts("#{item}: #{size["x"]}x#{size["y"]}")
10
10
  puts("#{item}: #{size["bands"]} bands of type #{size["data_type"]}")
data/lib/gdal_helper.rb CHANGED
@@ -13,7 +13,7 @@ require 'gdal/osr'
13
13
  # Helper class for gdal.
14
14
 
15
15
  # class with constants and bits that will be used by all gdal-helper classes
16
- class Gdal_Stuff
16
+ class GdalStuff
17
17
  # Does type mappings from gdal to ruby - pretty basic, and needs to be expanded so other types can be done, like for example
18
18
  # 32 bit integer types, 16 bit types, double floating bit types, unsigned int types, etc..
19
19
  def data_type_from_gdal(data_type)
@@ -30,6 +30,7 @@ class Gdal_Stuff
30
30
  when Gdal::Gdalconst::GDT_CINT32; return Float
31
31
  when Gdal::Gdalconst::GDT_CFLOAT32; return Float
32
32
  when Gdal::Gdalconst::GDT_CFLOAT64; return Float
33
+ else raise ArgumentError("Unknown data type.. not sure what to do here folks", caller)
33
34
  end
34
35
  end
35
36
 
@@ -53,7 +54,7 @@ end
53
54
 
54
55
  ##
55
56
  # Class wrapping up a gdal band.
56
- class Gdal_Band < Gdal_Stuff
57
+ class GdalBand < GdalStuff
57
58
 
58
59
  def initialize( band)
59
60
  @band = band
@@ -87,7 +88,8 @@ class Gdal_Band < Gdal_Stuff
87
88
  when Gdal::Gdalconst::GDT_CINT16; 'GDT_CINT16'
88
89
  when Gdal::Gdalconst::GDT_CINT32; 'GDT_CINT32'
89
90
  when Gdal::Gdalconst::GDT_CFLOAT32; 'GDT_CFLOAT32'
90
- when Gdal::Gdalconst::GDT_CFLOAT64; 'GDT_CFLOAT64'
91
+ when Gdal::Gdalconst::GDT_CFLOAT64; 'GDT_CFLOAT64'
92
+ else raise ArgumentError("Unknown data type.. not sure what to do here folks", caller)
91
93
  end
92
94
  type_string
93
95
  end
@@ -222,6 +224,7 @@ class Gdal_Band < Gdal_Stuff
222
224
  when Gdal::Gdalconst::GDT_CINT32; '' #What are these?
223
225
  when Gdal::Gdalconst::GDT_CFLOAT32; '' #What are these?
224
226
  when Gdal::Gdalconst::GDT_CFLOAT64; '' #What are these?
227
+ else raise ArgumentError("Unknown data type.. not sure what to do here folks", caller)
225
228
  end
226
229
  return data.unpack(pack_template*data.length)
227
230
  end
@@ -282,6 +285,7 @@ class Gdal_Band < Gdal_Stuff
282
285
  when Gdal::Gdalconst::GDT_CINT32; '' #What are these?
283
286
  when Gdal::Gdalconst::GDT_CFLOAT32; '' #What are these?
284
287
  when Gdal::Gdalconst::GDT_CFLOAT64; '' #What are these?
288
+ else raise ArgumentError, "Unknown datatype.. not sure what to do here folks", caller
285
289
  end
286
290
  raise(ArgumentError, "Complex type requested, but no complex type handling.. not sure what to do here folks", caller) if ( pack_template == '')
287
291
  return data.pack(pack_template*data.length)
@@ -292,22 +296,22 @@ end
292
296
  ##
293
297
  # Class for a file - this is what most folks want
294
298
  # Use like:
295
- #infile = Gdal_File.new("foo.tif")
299
+ #infile = GdalFile.new("foo.tif")
296
300
  #bands = infile.read_bands(0,0,infile.xsize/4,infile.ysize/4)
297
301
  #..do something..
298
- class Gdal_File < Gdal_Stuff
302
+ class GdalFile < GdalStuff
299
303
  def initialize ( name, mode="r", xsize=nil, ysize=nil,bands=3, driver="GTiff", data_type=String, options=['TILED=YES','COMPRESS=DEFLATE'] )
300
304
  if ( mode == "r" )
301
- @gdal_file = Gdal::Gdal.open(name)
305
+ @Gdalfile = Gdal::Gdal.open(name)
302
306
  else
303
307
  if ( mode == "w")
304
308
  if (File.exists?(name))
305
- @gdal_file = Gdal::Gdal.open(name,Gdal::Gdalconst::GA_UPDATE )
309
+ @Gdalfile = Gdal::Gdal.open(name,Gdal::Gdalconst::GA_UPDATE )
306
310
  else
307
311
  driver = Gdal::Gdal.get_driver_by_name(driver)
308
- puts(driver.class)
309
- puts("Creating create(#{name}, #{xsize}, #{ysize}, #{bands}, #{data_type_to_gdal(data_type).to_s})")
310
- @gdal_file = driver.create(name, xsize, ysize, bands, data_type_to_gdal(data_type), options)
312
+ #puts(driver.class)
313
+ #puts("Creating create(#{name}, #{xsize}, #{ysize}, #{bands}, #{data_type_to_gdal(data_type).to_s})")
314
+ @Gdalfile = driver.create(name, xsize, ysize, bands, data_type_to_gdal(data_type), options)
311
315
  end
312
316
  else
313
317
  raise ArgumentError, "mode of \"#{mode}\" is not useful (not r|w) not sure what to do here folks", caller
@@ -316,7 +320,7 @@ class Gdal_File < Gdal_Stuff
316
320
 
317
321
  @bands=[]
318
322
  #1 is not a mistake - the raster bands start at 1 no 0. just a fyi.
319
- 1.upto(@gdal_file.RasterCount).each {|x| @bands << Gdal_Band.new(@gdal_file.get_raster_band(x))}
323
+ 1.upto(@Gdalfile.RasterCount).each {|x| @bands << GdalBand.new(@Gdalfile.get_raster_band(x))}
320
324
  end
321
325
 
322
326
  ###
@@ -347,20 +351,20 @@ class Gdal_File < Gdal_Stuff
347
351
 
348
352
  #returns basic size info as a hash
349
353
  def size()
350
- { "x"=> @gdal_file.RasterXSize,
351
- "y" => @gdal_file.RasterYSize,
354
+ { "x"=> @Gdalfile.RasterXSize,
355
+ "y" => @Gdalfile.RasterYSize,
352
356
  "bands" => @bands.length,
353
357
  "data_type" => @bands[0].data_type()}
354
358
  end
355
359
 
356
360
  #x dimention size
357
361
  def xsize()
358
- @gdal_file.RasterXSize
362
+ @Gdalfile.RasterXSize
359
363
  end
360
364
 
361
365
  #y dim size
362
366
  def ysize()
363
- @gdal_file.RasterYSize
367
+ @Gdalfile.RasterYSize
364
368
  end
365
369
 
366
370
  #number of bands
@@ -380,29 +384,29 @@ class Gdal_File < Gdal_Stuff
380
384
 
381
385
  # gets the projection
382
386
  def get_projection
383
- @gdal_file.get_projection
387
+ @Gdalfile.get_projection
384
388
  end
385
389
 
386
390
  #sets the projection
387
391
  def set_projection(proj_str)
388
- @gdal_file.set_projection(proj_str)
392
+ @Gdalfile.set_projection(proj_str)
389
393
  end
390
394
 
391
395
  #looks up the projection in the epsg database, give it a number like 102006.
392
396
  def set_projection_epsg(epsg)
393
397
  srs = Gdal::Osr::SpatialReference.new()
394
398
  srs.import_from_epsg(epsg)
395
- @gdal_file.set_projection(srs.export_to_wkt)
399
+ @Gdalfile.set_projection(srs.export_to_wkt)
396
400
  end
397
401
 
398
402
  #sets the geo_transform, the wld file generally.
399
403
  def set_geo_transform(srs)
400
- @gdal_file.set_geo_transform(srs)
404
+ @Gdalfile.set_geo_transform(srs)
401
405
  end
402
406
 
403
407
  #gets the geo transform (wld file traditionally)
404
408
  def get_geo_transform()
405
- @gdal_file.get_geo_transform
409
+ @Gdalfile.get_geo_transform
406
410
  end
407
411
 
408
412
  end
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Gdal_Helper
2
- Version = "0.0.1"
2
+ Version = "0.0.1.1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gdal-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.0.1.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - JC
@@ -41,18 +47,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
47
  requirements:
42
48
  - - ">="
43
49
  - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
44
52
  version: "0"
45
- version:
46
53
  required_rubygems_version: !ruby/object:Gem::Requirement
47
54
  requirements:
48
55
  - - ">="
49
56
  - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
50
59
  version: "0"
51
- version:
52
60
  requirements:
53
61
  - PostgreSQL >= 7.4
54
62
  rubyforge_project:
55
- rubygems_version: 1.3.4
63
+ rubygems_version: 1.3.6
56
64
  signing_key:
57
65
  specification_version: 3
58
66
  summary: A helper library for the ruby bindings to gdal (http://gdal.org)