Select to view content in your preferred language

How do you create point shapefiles on a raster to create watersheds?

633
3
08-01-2017 11:46 AM
AndrewMartin8
Deactivated User

Hey I am trying to automate the process to add watersheds at the most accumulated points at the bottom of the dem layer. I created a stream order to provide as a template to place the points and a flow direction to create the watershed. The stream order has 9111 columns and 6941 rows. I am creating a point  shapefile at every value (1,2,3) at the last row of the matrix. The main problem I have is saving multiple points and given them each a unique name and saving watersheds and giving them a unique name each time it goes through a loop. I am pretty novice at python. I need help with the last part of the code. I keep getting a syntax error on the last line.

 

import arcpy
from arcpy.sa import *
from arcpy import env
demorder="C:\Temp\ARCGIS_PROJECT\Tutorial\LAYERS\dem_order"
flowdirection="C:\Temp\ARCGIS_PROJECT\Tutorial\LAYERS\dem_fd"

try:
  for columns in range(0,9111):
    point=arcpy.Point(demorder.xmin + columns, dem_order.ymin+6941)
    pointval= arcpy.GetCellValue_management("dem_order","point", "2")
    if (pointval==1 or pointval==2 or pointval==3):
        pointgeom = arcpy.pointgeometry(point,"W:\ArcMap\Coordinate_Systems\NAD 1983 StatePlane Texas S Central FIPS 4204 (US Feet) SURFACE.prj")
        Pshape= arcpy.CopyFeatures_management(pointgeom,"C:\Temp\ARCGIS_PROJECT\Tutorial\points")
        watershed= arcpy.watershed(flowdirection,Pshape)
        arcpy.CopyRaster_management(watershed,"C:\Temp\ARCGIS_PROJECT\Tutorial\points")
0 Kudos
3 Replies
IanMurray
Honored Contributor

I'd make sure all your file paths are raw strings, the backslashes in the file paths are being treated as escape characters.

demorder=r"C:\Temp\ARCGIS_PROJECT\Tutorial\LAYERS\dem_order"

XanderBakker
Esri Esteemed Contributor

The other part to take into account is the fact that you look through the columns. And if your cell size is not 1 unit, it will not extract the values you are after, since your point coordinates and the lower left corner of the raster and you add the number of rows to it and the current column without taking into account the cell size.

point=arcpy.Point(demorder.xmin + columns, dem_order.ymin+6941)

And why is "dem_order.ymin+6941" fixed?

Since your question is about creating a unique name for each iteration (in your code the same output is used for each iteration), you could use something like (on lines 13 and 15):

"C:\Temp\ARCGIS_PROJECT\Tutorial\points_{0}.shp".format(columns)

"C:\Temp\ARCGIS_PROJECT\Tutorial\watershed_{0}.TIF".format(columns)

However,  I am not quite sure why you would want to create that many (>9000) featureclasses and rasters. What will you do with the result?

AndrewMartin8
Deactivated User

my goal is to add a point where the stream meets the bottom of the DEM and use those points to make watersheds. I used "dem_order.ymin+6941" because I havent made a variable yet that holds the number of rows and columns in that given raster. Adding +6941 will give me the last row in the raster where the stream touches the bottom of the page. In this example I would want two watersheds to be made. Am I using the right approach to do this?

 

0 Kudos