You need to sample the raster layers along points within the polygons.
1. Generate points inside the polygons in the polygon layer
For this you can use three methods. I will explain the simpler one, using Vector Creation > Random points in polygons
(NOT Random points inside polygons
). Select your polygon layer as Input polygon layer
and enter the Number of points for each feature
- say 35 and set a Minimum distance between points
. This will create a new point layer with fixed number of random points inside each of the polygon feature. If you have rock types/lithology or any identifier as your polygon feature attribute, you can check the Include polygon attributes
. Checking this option will add the attribute information to the generated points.
Alternatively, you can create regularly spaced points using Generate points (pixel centroids) inside polygons
to generate points for each pixel of the raster layer inside the polygons or use Regular Points
and then use Join attributes by location
to join the polygon attributes with the point layer.
2. Sample raster values along the generated points
Now that you have your point layer with attributes, you can sample the raster layer with this point layer using Raster Analysis > Sample Raster Values
. Choose your newly created point layer as Input layer
and the imagery as Raster layer
. Add an output column prefix
if required. This will sample the raster layer along the points and generate a new point layer with the raster values as additional attributes. For each band in your raster layer, separate attribute fields will be created. In your case, there will be attribute fields corresponding to every index that you have stacked in the raster layer.
3. Export the layer with sampled values and plot ternary diagram in a third party application
Export the layer generated in step 2 to excel/csv for data plotting in third party applications. Use any application like Grapher/ Excel templates/ QGIS plugins like Dataplotly to plot the ternary diagram. Select the columns corresponding to the sampled band values as the axes and use the rock type attribute for color coding/ styling your points (optional).