daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Oct 13th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##Input_raster1=raster
  2. ##Band_raster1=output raster
  3. from qgis.core import *
  4. from qgis.gui import *
  5. from qgis.utils import iface
  6. from PyQt4.QtCore import *
  7. from PyQt4.QtGui import *
  8. import os
  9. from osgeo.gdalconst import *
  10. import numpy
  11. import sys
  12. import osr
  13. driver = gdal.GetDriverByName("GTiff")
  14. ds = gdal.Open(Input_raster1, GA_ReadOnly)
  15. dst_ds_red = driver.Create(Band_raster1, ds.RasterXSize, ds.RasterYSize, 1, GDT_Float32)
  16. dst_ds_red.SetProjection( ds.GetProjection())
  17. geotransform = ds.GetGeoTransform()
  18. if not geotransform is None:
  19.   st_ds_red.SetGeoTransform( geotransform )
  20.  
  21. bandList = []
  22. band = ds.GetRasterBand(2)
  23. data = band.ReadAsArray()
  24. bandList.append(data)
  25.  
  26. rasterlayer_red = numpy.zeros((ds.RasterYSize, ds.RasterXSize), dtype=numpy.float32)
  27. for i in range (0, ds.RasterXSize):
  28.   for j in range (0, ds.RasterYSize):
  29.  
  30.     RED = (float(bandList[0][j][i]))
  31.     rasterlayer_red[j][i] = RED
  32. dst_ds_red.GetRasterBand(1).WriteArray(rasterlayer_red)
  33.    
  34. ##Input_raster1=raster
  35. ##Band_raster1=folder
  36. from qgis.core import *
  37. from qgis.gui import *
  38. from qgis.utils import iface
  39. from PyQt4.QtCore import *
  40. from PyQt4.QtGui import *
  41. import os
  42. from osgeo.gdalconst import *
  43. import numpy
  44. import sys
  45. import osr
  46. driver = gdal.GetDriverByName("GTiff")
  47. ds = gdal.Open(Input_raster1, GA_ReadOnly)
  48. # Get filename of input raster
  49. result = os.path.splitext(os.path.basename(Input_raster1))[0] + "_new.tif"
  50. dst_ds_red = driver.Create(Band_raster1 + "/" + result, ds.RasterXSize, ds.RasterYSize, 1, GDT_Float32)
  51. dst_ds_red.SetProjection( ds.GetProjection())
  52. geotransform = ds.GetGeoTransform()
  53. if not geotransform is None:
  54.   st_ds_red.SetGeoTransform( geotransform )
  55. ...
  56.    
  57. import os
  58. in_rast = r"in_raster.tif" # input path
  59.  
  60. # Next you can split the file extension from the file name
  61. in_parts = os.path.splitext(in_rast)
  62.    
  63. # continuing from above
  64.  
  65. new_name = in_parts[0] + '_new' # in_raster_new
  66. new_path = new_name + in_parts[1] # in_raster_new.tif
  67.    
  68. new_ext = '.png' # note the period is included
  69. new_name = in_parts[0] + '_new' # in_raster_new
  70. new_path = new_name + new_ext # in_raster_new.png
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top