I have a GDAL python script that is wrong but it work perfectly on my python interpretor. Is this a virus? The code is:
from math import floor
from osgeo import gdal,ogr
import pandas as pd
src_filename='C:/Users/admin/Desktop/RF/vrt_vrancea.tif'
shp_filename = 'C:/Users/admin/Desktop/RF/labels_shp/labels.shp'
src_ds=gdal.Open(src_filename)
gt_forward=src_ds.GetGeoTransform()
gt_reverse=gdal.InvGeoTransform(gt_forward)
df=pd.DataFrame(columns['label_id',1,2,3,4,5,6,7])
ds=ogr.Open(shp_filename)
lyr=ds.GetLayer()
for feat in lyr:
pixel_value = []
pixel_value.append(feat.GetField('label'))
for band in range(1,8):
rb=src_ds.GetRasterBand(band)
geom=feat.GetGeometryRef()
mx,my=geom.GetX(), geom.GetY() #coord in map units
#Convert from map to pixel coordinates.
px,py=gdal.ApplyGeoTransform(gt_reverse, mx, my)
px = floor(px) #x pixel
py = floor(py) #y pixel
intval=rb.ReadAsArray(px,py,1,1)
pixel_value.append(intval[0][0])
print(intval[0][0]) ## WRONG. Should be intval[0]
df_temp=pd.DataFrame([pixel_value],columns=['label_id',1,2,3,4,5,6,7])
df = pd.concat([df,df_temp])
df.to_csv('C:/Users/admin/Desktop/df.csv')
My problem is with this line: print(intval[0][0])
There is not a nested list in ReadAsArray function