/edl-scripts/tif2bil-native.py

http://alageospatialportal.googlecode.com/ · Python · 25 lines · 19 code · 5 blank · 1 comment · 7 complexity · cc4657a86e513b4c80c267ecba76e213 MD5 · raw file

  1. #!/usr/bin/python
  2. import os
  3. import shutil
  4. import edlconfig
  5. for root, dirs, files in os.walk(edlconfig.dataset):
  6. for name in files:
  7. if name.endswith(".geotiff"):
  8. layername = name.replace(".geotiff","")
  9. print(layername)
  10. p = os.popen(edlconfig.gdalapps+"/gdalinfo -mm " + os.path.join(root,name),"r")
  11. while 1:
  12. line = p.readline()
  13. if not line: break
  14. if "Type" in line:
  15. dataType = line.split("Type=")[1].split(",")[0]
  16. if dataType == "Int32": #Diva can't handle Int32
  17. dataType = "Float32"
  18. command = edlconfig.gdalapps+"/gdalwarp -ot " + dataType + " -s_srs '" + edlconfig.s_srs + "' -t_srs '" + edlconfig.t_srs + "' -of EHdr -srcnodata -9999 -dstnodata -9999 " + os.path.join(root,layername) + ".geotiff " + os.path.join("/data/ala/data/source/native-bil",layername) + ".bil"
  19. print(command)
  20. os.system(command)