First let's open up ArcMap I have loaded dm data which is a raster file. dm is a short for digital elevation model. Basically this is a terrain terrain data. In this class we will use Spatial Analyst tool hydrology tools to generate drainage a path from this terrain data. In a traditional method, we just use the tools. The typical steps is first we use a few to put in the DM I'm gonna create a new folder called class to I will put a few few to dm dm And then we create a flow direction from the FDM.
I will just put it in the same directory and then kind of FTR the following step is called flow accumulation. The input is the output of last step out of phase DC. Each cell means how many upstream cells are doing To this. So, from there I want to define the stream I use condition tools value is greater than 2000 I would just say if the value is greater than 2000 otherwise it has zero values which are greater than 2000, which is the threshold it used to define my stream lines. So, there I got my streams and those four steps that can be conducted Using each different Spatial Analyst or tours, but what if I wanted to just use Python script to to contain all the process to process a beam like one click. We can do that use model viewer.
First I use certain tools from here. I go to toolboxes system to boxes. I'll just say special analyst hydrology. In the input file is this one I would just make a new folder so it doesn't mess up. And then AI users flow direction and I know my flow to dm it's gonna be the input of the power flow direction scientist Connect directory No accumulation the input of accumulation is the output or flow direction correct to the output directory name and the last condition do need to put the expression value greater than 2000? Well, this 2000 is a threshold value basically, you can define this value yourself if you want to train it, it has to be finer to be more dense.
This number shouldn't be smaller. If you want your training to pass to be like only the major river, this number should be bigger. You have to with a two one because we say zero output is stream test. Okay, it worked. We can export this into a script. Now let's find the code we just exported.
Well here we can see that here's our input file. Here is the FTM location. Here's after dir FA CC, conditional tour variables and then this cream probably needed to change that this is going out here. So str is our, our variable name already pre defined in Python. So we, we will change it to maybe stream. Okay?
If we want to make this code to be more robotic like we can use it in any condition, we need to do a little bit of modification here. Like this one, let's just say it's input the From our Python input import environment over right out people, too with with that was that same text there, we don't need to worry about whether or not the files already this thing because data won't be overwrite if it's existing. If we don't put this thing text here in a worse throw off the air when the house Ready to define the environmental workplace works let's put the directory here as well. Since we already predefined the workspace is here so um we don't really need all that Let's keep it that way. Yeah, let's run. Okay, it'll work exactly where we want to apply the same method into a different region to a different terrain data.
The only thing we need to modify from this code is this, this line, input a DM, name and in directory. We don't need to open the arc map to do all the model building or to open each tool to click it. We simply needed to open this PI file, and then we change this line and then it will give us the result. And then we can just grab the result from there without even In opening ArcMap right so years over less than two