6

I have a raster layer with a Shapefile grid with cells measuring 3 x 3 m overlaid on top. All I want to do is find the pixel with the maximum value within each cell, and place a Shapefile point over that pixel such that each cell has a point. See figure below (excuse the poor job).

Figure: Imagine that there is a white dot in each of the cells. The point is that they are over the maximal pixel, not the centroid of the cell

I've found Q&As that show how to identify the maximum values, but none that transform the query to a point explicitly. The point is that the points sit above the maximal pixel, not the cell centroid.

1
  • 1
    Why are the white polygons different sizes? Are they meant to be identical single-raster-pixel-sized rectangle polygons but you couldn't draw them right? What happens if you have more than one pixel with the max value within a rectangle? – Spacedman Jan 15 at 17:22
8

First, sample your raster values via "Raster pixels to points" from Processing Toolbox. It will create a point on each pixel of your raster, containing the rastervalue.

enter image description here

Now join your points to the grid. Your grid must have a unique "ID", add it now if needed. Then you can run "Join attributes by location", choose your Sampled Points as "Base" and your Grid as "Join Layer". Select 'within' as geometric predicate.

enter image description here

Now run "Extract by expression" from Processing Toolbox. Use your just Joined-Layer as Input and this expression: "value" = maximum("value","gridID") where "value" refers to the fieldname of your sampled rastervalue and "gridID" refers to the unique ID of your grid.

enter image description here

Done. You will now have at least one point per grid cell, representing the maximum rastervalue. Note: if several points within one grid cell have the same maximum value, you will get these several points returned.

2
  • Thanks so much! This workflow makes sense, but I'm being estimated some 11 hours to process the expression. There's about 1.5 million points and 41,000 grid cells. Does that seem excessive? – Jesse Jan 18 at 10:12
  • @Jesse seems doable. Might take some time depending on your hardware though, but 11 hours sounds a little long to me... – MrXsquared Jan 18 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.