2

I am extracting the pixel values from a raster using two different methods: one is extracting the values to points (centroids of polygon grids)

folder = (...)
S2_green = "band_green.tif"
OS_green = os.path.join(folder, S2_green)

Open the raster and store metadata

src = rasterio.open(OS_green)

centroids['lon'] = centroids['geometry'].x centroids['lat'] = centroids['geometry'].y

coords = [(x,y) for x, y in zip(centroids.lon, centroids.lat)]

Sample the raster at every point location and store values in DataFrame

centroids['Raster Value'] = [x for x in src.sample(coords)] centroids['Raster Value'] = centroids.apply(lambda x: x['Raster Value'][0], axis=1)

(seen in Python - Extract raster values at point locations)

The other method is using the zonal_stats() function in rasterstats python library (as I have only one value, the "mean" should be the same value as the pixel)

Then, what I see is a small variation of value (see image took in QGIS pixel info). Should I consider this as normal?

Important: all layers are in the same projection.

enter image description here

Shawn
  • 1,817
  • 9
  • 21

0 Answers0