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

08-01-2017 11:46 AM
New Contributor III

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 import *
from arcpy import env

  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)
0 Kudos
3 Replies
Frequent Contributor

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


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):



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?

New Contributor III

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