2

I use gdal_rasterize to clip mask by shpaefile. however, the parameter "-te" does not work.

get subprocess to call GDAL util

import subprocess

# define paths to raster and vector
inraster = r'I:\HY_project\HY1B-JPG2\2011\deepwater\test\H1B_OPER_OCT_L1A_20110120T_011319707_geo.img'
inshape = r'I:\HY_project\HY1B-JPG2\2011\deepwater\test\H1B_OPER_OCT_L1A_20110120T_011319707_geo.shp'

# the extent of shapefile
driver = ogr.GetDriverByName("ESRI Shapefile")
dataSource = driver.Open(shp, 0)
layer = dataSource.GetLayer()
feature = layer[0]
geom = feature.GetGeometryRef()
extent = geom.GetEnvelope()
xmin = extent[0]
xmax = extent[1]
ymin = extent[2]
ymax = extent[3]

cmd = 'gdal_rasterize -burn -999 -te '+str(xmin)[0:7]+' '+str(ymin)[0:7]+' '+str(xmax)[0:7]+' '+\
     str(ymax)[0:7]+' '+inshape + ' ' + inraster

cmd = 'gdal_rasterize -burn -999 -i -te 130.827 24.8857 140.357 26.8057 '+ inshape + ' ' + inraster

# run command
subprocess.call(cmd, shell=True)

If the parameter "-te" is not set. this command line can work. such as:

cmd = 'gdal_rasterize -burn -999 -i '+ inshape + ' ' + inraster
  • what does gdalinfo say for the image? may be projection is different or lat/lon not lon/lat – Ian Turton Sep 17 at 15:03
  • 1
    Does image H1B_OPER_OCT_L1A_20110120T_011319707_geo.img already exist? What do you mean with "parameter -te does not work"? In which way it does not work? – user30184 Sep 17 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.