Polygon Class Statistics Producing Unexpected Statistics Given Input Raster


Hi, I’m using QGIS to click points on a raster image, and subsequently I use ogr from osgeo to expand the region by creating a new polygon feature with a given x and y expansion distance around the clicked points. I’m trying to use PolygonClassStatistics (followed by SampleSelection and SampleExtraction) to extract all the points inside this expansion. PolygonClassStatistics states that for polygon geometries it will “select pixels whose center is inside the polygon.” When I look visually at the polygon added (a square with the expanded x and y dimensions), I see that it encompasses several pixels. However PolygonClassStatistics only counts 2. I’m unsure how to debug this issue, as clearly several pixels aren’t being accounted for. How might I be able to recapture these pixels?

Configuration setup

My system: macOS
Version of the OTB: 7.2
I installed the OTB with: the binaries
QGIS version: 3.10.10
Python version: 3.7.7

Dear @chriswill21,

Did you check that the polygons you provide to PolygonClassStatistics contain a field specific to the class associated to the polygon? And did you specify the name of this field with the field argument?

If so, could you share with us any log message provided by QGIS?

Julien :slight_smile:

Hi @julienosman,

Thank you for your response! I apologize for the delay; I thought I’d sent the message. Upon digging into my code to find the answer to your question, I actually discovered the issue I was having. It turns out that in preprocessing, I was manipulating the input image and decreasing the resolution. I was however, looking at the original, unmodified image while annotating on QGIS. However, it was this modified image that PolygonClassStatistics was reading from. Since it had lower resolution, the pixels were larger. Thus when I saw the expanded square polygon that PolygonClassStatistics was processing on the original image, I saw it encompassing several pixels, however on the low res image, it in face only encompassed 2.

Thank you again for your response!

1 Like