I am interested to know why ‘Flow Direction Raster’, derived from ‘Filled DEM’, generates values ranges from 1-128, with pixel depth of 8 bit unsigned integer which is readily capable to store values 0-255, As such, in the Tool’s Help, it is clearly stated that “the output of the Flow Direction tool is an integer raster whose values range from 1 to 255”. My ‘filled DEM’ carries 16bit signed integer pixel depth already, which has capacity to store values range from -32768 to 32767!
[GIS] Flow Direction Raster Value Range
arcgis-desktopflow-direction
Related Solutions
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.
Values other than the D8 values indicate that you have sinks in your DEM. Try the work flow shown here..
Best Answer
There are eight valid output directions relating to the eight adjacent cells into which flow could travel. This approach is commonly referred to as an eight-direction (D8) flow model, the direction coding is shown:
If the water will flow to the cell immediately to the right, it will be assigned a code of 1, if it flows to the top right cell then the code assigned is 128 as so on.