Using the python gdal module to open images in the same projection but different sizes
I'm not sure this is the correct site 开发者_如何学编程for this but,
I'm using the gdal.Open() module on python 2.7 to open Landsat GeoTIFF images. They have the same UTM map projection, but different image sizes.
How do I fix the image sizes to be the same? I'd like to make direct pixel-by-pixel comparisons.
gdal_translate can be used simply to change the size of an image using the -outsize parameter, which takes two integer values as the xsize and ysize respectively, or two percentage values to scale the image. see here
gdal_translate -outsize newxsize newysize imageFile outputFile
You need to reproject all rasters to the same raster shape/size. You can do this with gdalwarp to each raster file, e.g.:
gdalwarp -te xmin ymin xmax ymax -tr xres yres -r resampling_method srcfile dstfile
You can optionally replace -tr
(target resolution) with -ts width height
to specify the number of rows/columns.
The -te
(target extents) and -tr
/-ts
(target resolution/size) options forces each of your source raster to have the same raster shape overlay, so you can correctly do a pixel-by-pixel comparison. You also need to choose a suitable -r
resampling method, depending on what your analysis is trying to achieve.
精彩评论