0

I get a series of NDVI rasters every 2 weeks and need to calculate changes. The rasters overlap, but are different in area. The resolution is also a little different in each raster,

raster 1: -0.34533, 0.34533
raster 2: -0.35001, 0.35001

This can change slightly with every raster.

I am trying to automate the process with python, GDAL. the rasters are between 1gb-20gb in size.

I think i am almost there, but when i try to change the pixel size of the rasters to match, there seems to be a shift, which messes up the calcs.

If i can get the pixel sizes to match, i should then be able to calc the differences.

here is the code for adjusting the pixel size:

WorkingFolder = 'C:/Users/me/Desktop/NDVI/Testing/'

for f in os.listdir(WorkingFolder): 
    print (f)
    fName, fExt = os.path.splitext(f)
    if fExt.lower() == '.tif':

        ds = gdal.OpenShared(os.path.join(WorkingFolder,f),gdalconst.GA_Update)
        gt = ds.GetGeoTransform()

        gtLst = list(gt)

        gtLst[1] = 0.36
        gtLst[5] = -0.36

        # apply the changes
        ds.SetGeoTransform(gtLst)

Has anyone done anything similar? or know a better solution for matching big tiffs to subtract? I believe that i am able to match the extents and do all other calculations, but the pixels are driving me crazy

4
  • I don't know where the rasters came from, but it would probably be better to actually resample them instead of shifting them arbitrarily. This can be done with nearest-neighbor resampling using gdalwarp, which also has an entry point in the python bindings
    – mikewatt
    Commented Aug 27, 2019 at 18:58
  • yeah, i dont want the shift. i'm trying to match the rasters pixel size, array shape, etc to do a ndvi-ndvi on them. I'm really new with gdal so i'll have to look over gdalwarp and see if that would work
    – Messak
    Commented Aug 27, 2019 at 19:06
  • Do they have the same number of rows and columns? Also check this message from the gdal-dev mailing list Commented Aug 27, 2019 at 19:29
  • not initially, but i have the python that generates matching rows and columns
    – Messak
    Commented Aug 27, 2019 at 19:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.