3

Let's say I have an excel file that has a large number of lat/lon points that can be brought into QGIs such as:

image1

I then also have a raster layer that looks like the following:

image2

Each color in the above image represents a numerical value. For example, any color that is blue < 1, and green is < 2, yellow is < 3, etc. In QGIS, I go to 'Raster Calculator', and create a masked layer of instances where my raster values are less than 2:

image3

Now, I would like to intersect the lat/lon points that I have (first image) to where the mask = 1 (i.e., where the raster is < 2). I know there is a 'clip' / 'intersect' option for a vector field (instead of raster), but I cannot convert this raster to a vector field.

The final product would be a list / field of the lat/lon points (image 1) that intersect the Boolean mask (image 3) which is based off of values where the raster is less than 2.

Update:

Based on the answer by Babel, I right-clicked on the lat/lon points layer, and opened up the field calculator. From here, I entered the information provided:

field calculator

I then run the program, and the field calculator seems to have updated with everything in red, and there doesn't seem to be the correct points filtered. Perhaps I am overlooking something?

The sample lat/lonfile is below. Note, that the lat/lon coordinates are 'slat' and 'slon', respectively: https://drive.google.com/file/d/1yxXKm0FBGQyYgBpiJ8CvBSOEs4iVo6Ep/view?usp=drive_link

The sample raster file is below: https://drive.google.com/file/d/1TML5182ZaeNoto7Y9XJS16OGo-yzbqGj/view?usp=drive_link

3
  • Did you want use code or Raster / Vector processing tools?
    – Cary H
    Jan 10 at 20:34
  • The question specifically says I cannot convert to vector. But raster processing tools would be plenty fine. Jan 12 at 0:50
  • The linked sample files can't be downloaded without an account. Can you share on a platform where download is possible without login?
    – Babel
    Jan 12 at 14:38

2 Answers 2

1

You can do this directly, without creating any "boolean" raster using raster calculator. Get the raster value for each point and select those with a value < 2.

Use Select by Expression on the point layer with this expression (see help for function raster_value()):

raster_value ('raster',1,$geometry) < 2

Replace raster with the name of your raster layer. Use this to create a new attribute for the selected features or to delete the unselected features if you don't need them any more.

Be sure to use the name of the raster layer as first argument as you can see here; yellow points are selected (<2), red points are not selecte (>=2): enter image description here

By the way: you provided your point layer as CSV file. Be aware that CSV files cannot be edited in QGIS. So if you use field calculator with the expression to create a new field, this will not work properly. Instead, export the file to a Geopackage.

9
  • I updated my post based on your response - this seems to have good promise. Jan 12 at 1:10
  • In which band are the raster values? If unsure, select the raster layer , use the identify tool, click on the raster and post the screenshot
    – Babel
    Jan 12 at 6:25
  • The values are within band 1 Jan 12 at 14:03
  • I have added the raster and lat/lon file to the question. Jan 12 at 14:36
  • 1
    Perfect - thank you very much for the help. Jan 12 at 17:43
0

After Raster Calculator, you could run Polygonize (Raster to Vector) on each new masked layer. Menu => Raster => Conversion => Polygonize (Raster to Vector). Open the new polygon layer attributes and add a Poly_ID or some other field that gives a Unique Identifier. Then you could find the points inside each polygon using Menu => Geoprocessing Tools => Intersection.

This will generate a new set of points that will have a field of which polygon they are inside.

Then you can seperate the points by that field and export them. enter image description here

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.