I am trying to move 1700 points (of an existing shapefile) to a new pixel of a raster layer. If the dot is already in the highest pixel of the NDVI raster layer then no need to change.

The criteria can be summarized like so:

  1. New points need to be on the pixel with the highest NDVI raster value (within 5m buffer)

  2. New points should have the same information in the attribute table than the old ones

  3. If two points share same pixel because the highest pixel is within their buffer then one of the points should be given the the pixel with the second highest value. Never should two points share the same pixel.

  4. Each point should be represented (regardless of being shifted or not) in the new vector layer

I tried a given Code, but not every point was represented in the new layer. It also didn't meet the criteria of being within the 5m buffer (last picture with the orange points).

enter image description here enter image description here enter image description here

  • Welcome to GIS SE. As a new user, please take the Tour. Since it doesn't seem likely that this is a task which is common enough to own a tool, what have you tried? Any attempts to locate local maximal? Any conversion of local maximal to points? What about an attempt to walk the points and click on a new location? Or to convert all the highest cells to points and use simple selection? There are so many alternatives. What have you tried?
    – Vince
    Nov 19, 2023 at 18:18
  • Thanks for the answer. I already calculated the local maxima for the NDVI within each buffer. Unfortunately it didn't really work to allocate these maxima in the attribute table to the pixels in the raster layer since there isn't any tool for it. For now i just got stuck trying to adjust some python code which was posted for a similar question on this website. I guess its not very efficient to walk 1700 points and put them on the new location.
    – Tom Runge
    Nov 19, 2023 at 19:15

2 Answers 2


Here's an approach that will work, but whether it works for you is going to come down to the size of your raster dataset, which you haven't included in the question.

First convert your raster data to vector using say "Raster pixels to polygons". If you have a large dataset this might be problematic.

Then use "Geometry by expression" on your point layer, with the following expression:

        overlay_nearest('Vector Polygons',

This looks complex (and is a bit!). Essentially, it:

  1. Gets all the features from the Vector Polygons layer within 5m of each point feature
  2. Creates an array of arrays, with one element per feature. The the first element of each sub-array is the value from the raster, and the second element is the (x,y) values of the centroid of each raster point
  3. Sorts the array by the value (descending) - you could probably also use array_max instead
  4. Takes the first element (the largest value) and stores the (x,y) value in a variable (@xy)
  5. Makes a new point using the (x,y) value

You may need to change the layer name ('Vector Polygons') and field name ("VALUE") if your data is different.

  • Thanks for the answer and i apologize for the inaccurate question /description. I have a point layer which contains 1700 dots. Each dot represents a tree. Since the spatial resolution of the NDVI Raster Layer is 3m, the points aren't always on the correct pixel. Basically I want to put every point from the vector layer on the pixel with the highest NDVI Value within a 5m buffer. In some cases more than one point shares the same highest pixel within their buffer. That is because they are very close to each other. I tried your method. Some points aren't within the new vector layer.
    – Tom Runge
    Nov 20, 2023 at 9:52
  • I'm not sure what you mean when you say "Some points aren't within the new vector layer." Which points are you referring to? I assume when you say "the new vector layer" you are referring to the Vector Polygons layer. If so, I can't see how this would be the case since the Vector Polygons layer should have an identical extent to the original raster layer. Nov 20, 2023 at 10:43
  • 1
    Also, please remember to update the original question with any new information from the comments. Comments are transient. Also, consider posting a (possibly cut down) sample of points/raster - it's always easier for answerers to be using the same dataset. Nov 20, 2023 at 10:48

There is no straight tool for this, but you can do bit of spatial data processing here. Here are few steps you can try out.

1 - Get coordinates of new locations.

Reclassify raster for greater than 0.8 as 1 everything else as 0. Covert this to polygon (Name it raster_polygon.shp). Calculate geometry (lat long) of centroid in attribute table.

2- fill these latlong to your source point shp.

Create buffer for your points (Name it Point_Buffer.shp). Select Raster_Polygon.shp that intersect with Point_Buffer.shp. Export selected (Name as Raster_Polygon_in_Buffer.shp).

---This will reduce number of polygons created by raster.

Join Point_Buffer.shp and Raster_Polygon_in_Buffer.shp by location (Name it as Raster_Polygon_in_Buffer.shp1). Join this Raster_Polygon_in_Buffer.shp1 and Point.shp (Name this is Point_Moved.shp).

----Hence, you get lat long of new points at center of red pixel (that is where you want to move your points).

3 - Draw point shapefile with new lat long. This will draw points in center of red polygons.

  • Thank you for your support. I tried to make the mask for the highest pixel values (>0.8). I probably didn't explained the problem accurate enough (sorry for that). The criteria I have to meet is: 1) If the point is already on the highest pixel value of the raster layer (NDVI) no need to change that. 2) If it isn't it needs to be shifted to the pixel with the highest NDVI value. 3) Many points are so close to each other that the pixel with the highest NDVI value is the same for both of points. In this case they should probably take the second highest value (NDVI layer) within their buffer
    – Tom Runge
    Nov 20, 2023 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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