If I understand you correctly I think you can solve it like this (their are comments in the code that explain what is going on):
import numpy, arcpy, random
#Establish the extent which your random samples can be within
rangeX = (100, 2500000) # Enter the actual range in x values of your rasters * 100 in order to get coordinates with decimals
rangeY = (100, 2500000) # Enter the actual range in y values of your rasters * 100 in order to get coordinates with decimals
qty = 1000 # Enter in the number greater than random points you need
#Generate random x,y coordinates
randPoints = []
while len(randPoints) < qty:
x = random.randrange(*rangeX)/100.0 # divide by 100.0 to be able to get coordinates with decimal values
y = random.randrange(*rangeY)/100.0 # divide by 100.0 to be able to get coordinates with decimal values
randPoints.append((x,y))
#Create dictionary of key and lists, list will house tuples of (x,y,z)
#Enter in actual classified values for dictionary keys
valueDict = {'Class1' : [],
'Class2' : [],
'Class3' : [],
'Class4' : []}
######Get Rasters bands as well as cell height, width, origin info to be able to get
######index of x,y location in the numpy array
arcpy.env.workspace = inPath + '\\aster.img'
bands = arcpy.ListRasters()
Ras = arcpy.Raster(inPath + '\\aster.img')
originX = Ras.extent.upperLeft.X
originY = Ras.extent.upperLeft.Y
pixelWidth = Ras.meanCellWidth
pixelHeight = Ras.meanCellHeight
#Create a list that houses each raster array
bandsList = []
for i in bands:
bandsList.append(arcpy.RasterToNumPyArray(i).astype(numpy.float32))
#loop over all of the random point locations and collect raster values at their
#locations if the dictionary entry for that value is not full populate it
#with a tuple of (x,y,z), keep going until each class is full
for i in randPoints:
X = i[0]
Y = i[1]
xOffset = int((X-originX)/pixelWidth)
yOffset = int(abs(Y-originY)/pixelHeight)
for j in range(0,len(bands)):
sampleValue = bandsList[j][yOffset, xOffset]
for key in valueDict.keys():
if sampleValue == key:
if len(valueDict[key]) < 10:
valueDict[key].append((X, Y, sampleValue))
break
else:
continue
This is a variation of a script that I have used to extract raster values at random x,y locations, so it may need some tweaking but I think the major elements are their to get the job done for you.
Best Answer
QGIS 2.18
If you are using QGIS 2.18, you can use Reclassify values under SAGA in Processing toolbox
Processing toolbox → SAGA → Raster tools → Reclassify values
…
a new window will openIn the example, the raster data were classified into six classes, so you need to change the values based desired range and output
Reclassified grid: write a name for the new classified raster data.
Please make sure that you have selected the correct projection when you created the slope percent to give you the desired output from reclassify tool.
QGIS 3.4
In QGIS 3.4.1, there is a Reclassify by table tool which is located under Processing toolbox -> Raster analysis -> Reclassify by table.
Using the tool is almost same as the one explained for SAGA Reclassify tool.
After reclassify the data, you can use Vectorize tool to convert the raster into vector data. The Vectorize tool exists in both QGIS 2.18 and 3.4.