2

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):

enter image description here

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

enter image description here

I get the real min and max.

What could be the issue here?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Nov 18, 2022 at 16:14

1 Answer 1

4

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.

enter image description here

You will get some pixel values if you use an index range as follows:

evapotr_trans_csv[2500:2505]
answered Mar 4, 2023 at 16:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.