I have a raster tiff file containing vegetation index & also a shapefile of fields. I want to extract the field wise values from that raster file using GDAL. How can I do this?
I can read the shapefile in python using gdal, but don't know how to extract its coordinates and how to extract that polygon from the raster tiff file.
import optparse from osgeo import gdal, ogr, osr import numpy as np g_nd = gdal.Open('ndvi.tif') nd_array = g_nd.ReadAsArray() nd_array = np.array(nd_array, dtype=float) osgeo.ogr.UseExceptions() myShapefile = r"/home/cr.shp" driver = ogr.GetDriverByName('ESRI Shapefile') dataSource = driver.Open(Shapefile, 0) dataSource = ogr.Open(Shapefile)