I had a number of TIFF files with a country's map. They had different rows, columns or different projections etc. I needed to make them with same projection, spatial resolution and same number of rows and columns. So I used
QGIS Raster->Projections-> Warp(Reproject) method and a vector boundary shapefile to get
TIFF files with the intended parameters.
After doing this each file contained two bands. One band with the original data values and another band with values from 0 to 255. (I think it is for visualization, is it?)
In some of these files I had specified no data values and in others, I didn't. But when I'm reading these files in
numpy arrays in Python using
gdal, I'm only getting an array of intended size
(53,54) but with no data values! I used the following code:
from osgeo import gdal from gdalconst import * from scipy import stats import numpy as np import os, glob import statsmodels.api as sm import matplotlib.pyplot as plt os.getcwd() os.chdir(r"H:\...\Processed") #load tiff files in numpy arrays ds1 = gdal.Open("cases2001.tiff") can01 = np.array(ds1.GetRasterBand(1).ReadAsArray()) #data type is float64 print can01.shape ds2 = gdal.Open("cases2002.tiff") can02 = np.array(ds2.GetRasterBand(1).ReadAsArray()) #data type is float 64 print can02.shape #Load the RASTER CLIPPED REPROJECTED IMAGE AM I DOING SOME MISTAKE HERE? ds3 = gdal.Open(r"H:\...\Annual 53-54\AOD2001.tiff") AOD01 = np.array(ds3.GetRasterBand(1).ReadAsArray()) AOD01 =AOD01.astype('float64') #Convertinf to float data type print AOD01.shape print AOD01
Why am I not getting the required values? And instead ending up with the "no data values"? For the files
cases2002, which are the original files according to which I re-projected my other files are having the perfect, intended values. But for the third file here i.e.
AOD2001 I'm getting an array of zeroes (I didn't change the default no data value). I've tried for both bands. But in
QGIS "Identify Features" I'm getting the correct values for the 1st band. But not while reading ion Python. I've already tried masking and a few other suggestions for similar problems (such as
GetStatistics not refreshing etc) but I haven't found exact problem anywhere yet.
On a side note I need to plot these 2-D arrays against each other and perform regression. Which I'm obviously getting incorrect same values for each row as the
AOD2001 file contains only zeroes. Another question, Can we compare (In my case perform regression on) two tiff files with same dimension, same spatial resolution and same end coordinates but different origins?
It's the first time I'm asking a question here, so I may have made mistakes in formatting etc., please point it out, I'd edit and take care in future. Also, please tell me if I should provide some other information or data.