0

I have a surface model raster layer. Is there any way to select only the light colored cells? Or just the cells with a certain color characteristic such as color value? This is a DSM of crop plots and soil. I am using QGIS.

enter image description here

This is what I am trying to achieve by the use of zonal statistics, field calculator, and so on. enter image description here

5
  • 1
    Can you clarify your problem? Do you have a series of polygons (black lines on your graphic) that you want to populate with the values from the surface or do you want to isolate some portion of the surface that is lighter in color? Depending on the problem your solution might be the one provided by Val P, or you might want to look at tools titled raster reclassification, supervised or unsupervised image classification, or focal statistics
    – GBG
    Feb 25 '20 at 23:46
  • 2
    As well as clarifying for @GBG, what software/API do you have available to do this. You could perform conditional raster analysis on the raster but first you have to decide what is dark and what is light - the method for performing con on your raster is software dependent. Probably the best way to grid is to resample the raster to your grid cell size, using a resampling method that works for you (probably not nearest, bilinear or mean perhaps), again software dependent. Feb 26 '20 at 0:02
  • The image is of crop plots. I am trying to find a way to isolate the soil level from the crops automatically. I lay a 1 X 1 foot grid over the DSM and am trying to find a way to select only the cells with crops in them. A person could manually select them but this is time consuming. I do not know if a DSM contains color values, but if they could be selected with the field calculator based upon color I think this would work. The challenge is getting the algorithm to work across different locations. The field calculator has a function: color_grayscale_average(color), but would not work.
    – Dan Olson
    Feb 26 '20 at 14:24
  • 1
    You mention drone imagery - do you have a color mosaic aerial image of this crop? Differentiating plant from soil is a perfect application for a supervised image classification. I have only done this in ArcGIS myself but here is a link to a tutorial for QGIS. igismap.com/…
    – GBG
    Feb 26 '20 at 15:48
  • I have actually done that exact operation in the past. I am now trying to build a method within the Process Modeler that would not require the numerous steps at the beginning. I would like to get to the point where a single raster can be loaded into the algorithm and then the person can just press "Go" and have the desired data output. I am exploring the attributes that can be exploited such as _range, or _stdev of each grid cell from zonal statistics as a way of differentiating crop and soil. Thanks.
    – Dan Olson
    Feb 26 '20 at 15:55
2

To solve your problem, you can use an expression to create a new field in the grid layer and then select them for a range of colour. Open the Field Calculator, select Create a new field (I suggest Decimal number (real))) and copy this:

raster_value('RASTER_LAYER_TO_USE', 1, centroid($geometry))

With the new field in the vector layer, you can use the tool Select by expression and

use the expression

"NAME_OF_YOUR_NEW_FIELD"< YOUR_RANGE

To create grid use the tool Create Grid from the Processing Toolbox panel, and in Grid extent select "Use layer extent" with your raster: in this way you will create a grid that overlaps your raster.

3
  • This works for the elevation of the DSM. The challenge I am having is that I want to apply this to the QGIS Process Modeler and I need it to work at a number of different farm locations, crops, and crop heights. If certain colors could be selected maybe that would work? I also tried selecting upon _variance, _range, and _stdev from zonal statistics but the algorithms I made were not transferable among locations. The algorithms was only situational for the one location. Thanks.
    – Dan Olson
    Feb 26 '20 at 14:31
  • 1
    Your request is doable. I am trying to create a model for you. One question: do you now the RGB of the colours that you want to extract or it is different case by case?
    – Val P
    Feb 26 '20 at 18:00
  • I was just trying this approach with RGB images and found that it would not work due to crop and non crop plants sharing the same color. There is no absolute attribute that could be exploited among locations and time periods. The DSM would give an absolute in the plants vertical height. Anything that is above the soil should be able to exploited in some way with GIS tools. For example soil has less statistical range than crops. I might also try to combine this with some infrared data. I have red, green, blue, red edge, and near infrared. Thanks.
    – Dan Olson
    Feb 26 '20 at 18:22

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.