Tiling and Image

B Tuttle funkbucket at GMAIL.COM
Fri Aug 18 16:43:57 PDT 2006


I don't know if this will help you are not, but I had to do the same
thing (tile a large global data set) I used ruby and gdal and I added
overviews to each tile. In case it is of use I've included the script
below. It was something I wrote in a hurry so no error checking and it
is specific to my image dimensions and it oculd probably be prettied
up a bit, but could easily be edited to work on a different size
image.
===========================================
#!/usr/bin/ruby

if ARGV.length != 1
  puts "Usage: tiles <file_name>";
else
  input_file = ARGV[0];
end

#These sizes will create 10x10 degree tiles for a 43200x15601 image
#spanning -180 to 180 and -65 to 65 with 30 arcsec pixels
tile_x_size = 1200
tile_x_count = 36
tile_y_size = 1200
tile_y_count = 13

input_dir = "/tiles/"
output_dir = "/tiles/"

subset = "/usr/bin/gdal_translate"
pyramid = "/usr/bin/gdaladdo"

y_count = 0
x_count = 0

while y_count < (tile_y_count - 1)
  while x_count < tile_x_count
    xoff = tile_x_size * x_count
    yoff = tile_y_size * y_count
    puts "x #{x_count} y #{y_count}"
    tile_name = "#{input_file.chomp(".tif")}_x#{x_count + 1}y#{y_count + 1}.tif"
    #puts "#{subset} -of GTiff -srcwin #{xoff} #{yoff} #{tile_x_size} #{tile_y_s
ize} #{input_dir}#{input_file} #{output_dir}#{tile_name}"
    system("#{subset} -of GTiff -srcwin #{xoff} #{yoff} #{tile_x_size} #{tile_y_
size} #{input_dir}#{input_file} #{output_dir}#{tile_name}")
    system("#{pyramid} -r nearest #{output_dir}#{tile_name} 2 4 8 16")
    x_count = x_count.succ
  end
  x_count = 0
  y_count = y_count.succ
end

while x_count < tile_x_count
  xoff = tile_x_size * x_count
  yoff = tile_y_size * y_count
  puts "x #{x_count} y #{y_count}"
  tile_name = "#{input_file.chomp(".tif")}_x#{x_count + 1}y#{y_count + 1}.tif"
  #puts "#{subset} -of GTiff -srcwin #{xoff} #{yoff} #{tile_x_size} #{tile_y_siz
e + 1} #{input_dir}#{input_file} #{output_dir}#{tile_name}"
  system("#{subset} -of GTiff -srcwin #{xoff} #{yoff} #{tile_x_size} #{tile_y_si
ze + 1} #{input_dir}#{input_file} #{output_dir}#{tile_name}")
  system("#{pyramid} -r nearest #{output_dir}#{tile_name} 2 4 8 16")
  x_count = x_count.succ
end



More information about the MapServer-users mailing list