I want to use GDAL/OGR to extract pixel values from a raster file. The extraction should be based on polygons, stored in a shapefile. My thought was to iterate over the features in the shapefile, extract the pixel values of those pixels that have there center point within the polygon and calculate a percentile from those values. When this is done I want to write the calculated percentile back to the polygon and go on with the next polygon.
Iterating over the polygons is easy, but what I do not get is how to extract the pixel values from the pixels, covered by the polygon.
I'm using Python.
Could somebody help me at this point?