I would like to get a CSV file with x,y coordinates and the correspondent single raster band value: (x, y, value)
This is my code:
from osgeo import gdal
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
evapotr = gdal.Open('example.tif')
evapotr_trans = gdal.Translate('example.xyz', evapotr)
evapotr_trans_csv = pd.read_csv('example.xyz', sep= " ", header = None)
evapotr_trans_csv.columns = ["x", "y", "ET0"]
evapotr_trans_csv.to_csv('example.csv', index = False)
the result is (only no-values):
I get also to many rows, vectorizing the raster in Qgis I have an attribute table made of: 8061 rows
While, if I check for the min and max raster value:
srcband = evapotranspiration.GetRasterBand(1)
# Get raster statistics
stats = srcband.GetStatistics(True, True)
stats
I get the real min and max.
What could be the issue here?
1 Answer 1
You encounter a common issue when working on a georeferenced raster using pandas and numpy. Printing the table displays only the head and tail pixels which are usually in the nodata area shown in green rectangles.
You will get some pixel values if you use an index range as follows:
evapotr_trans_csv[2500:2505]