<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Automatically determine downstream grid cell ID in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/automatically-determine-downstream-grid-cell-id/m-p/1310780#M26932</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'll start by explaining a little about the project I'm working on.&amp;nbsp; I'm trying to analyze a watershed (~60 sq. km) using a lumped rainfall-runoff model.&amp;nbsp; To improve the resolution of the watershed, I've created a grid of polygons with a cell size of 100mX100m (each with an elevation assigned to it).&amp;nbsp; The grid cells act as subcatchments in the model and each subcatchment needs to have an outlet assigned to it.&amp;nbsp; With the size of my watershed and number of grid cells, I need the outlet IDs to be automatically determined as opposed to doing it all myself.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure there's a way for ArcGIS Pro to automatically tell me the name/ID of the neighboring cell that receives runoff.&amp;nbsp; The Flow Direction tool doesn't quite tell me what I need, since it just determines which direction each cell drains.&amp;nbsp; Does anyone know of a way to do this?&amp;nbsp; Ideally, the final result would be a column in the Attribute Table for my polygon grid called "Outlet", which would have the name of the neighboring cell that that cell drains to.&lt;/P&gt;&lt;P&gt;Hopefully that all makes sense.&amp;nbsp; I can't seem to find a solution to this in the rainfall-runoff model I'm using, so I'm hoping to process it in ArcGIS first and then import into my model.&amp;nbsp; That way, the outlet will already be defined for each cell to use in the model.&amp;nbsp; For reference, I'm using ArcGIS Pro 3.0.2.&lt;/P&gt;&lt;P&gt;I appreciate any help.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Taylor&lt;/P&gt;</description>
    <pubDate>Sat, 22 Jul 2023 19:29:01 GMT</pubDate>
    <dc:creator>TaylorJordan</dc:creator>
    <dc:date>2023-07-22T19:29:01Z</dc:date>
    <item>
      <title>Automatically determine downstream grid cell ID</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/automatically-determine-downstream-grid-cell-id/m-p/1310780#M26932</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'll start by explaining a little about the project I'm working on.&amp;nbsp; I'm trying to analyze a watershed (~60 sq. km) using a lumped rainfall-runoff model.&amp;nbsp; To improve the resolution of the watershed, I've created a grid of polygons with a cell size of 100mX100m (each with an elevation assigned to it).&amp;nbsp; The grid cells act as subcatchments in the model and each subcatchment needs to have an outlet assigned to it.&amp;nbsp; With the size of my watershed and number of grid cells, I need the outlet IDs to be automatically determined as opposed to doing it all myself.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure there's a way for ArcGIS Pro to automatically tell me the name/ID of the neighboring cell that receives runoff.&amp;nbsp; The Flow Direction tool doesn't quite tell me what I need, since it just determines which direction each cell drains.&amp;nbsp; Does anyone know of a way to do this?&amp;nbsp; Ideally, the final result would be a column in the Attribute Table for my polygon grid called "Outlet", which would have the name of the neighboring cell that that cell drains to.&lt;/P&gt;&lt;P&gt;Hopefully that all makes sense.&amp;nbsp; I can't seem to find a solution to this in the rainfall-runoff model I'm using, so I'm hoping to process it in ArcGIS first and then import into my model.&amp;nbsp; That way, the outlet will already be defined for each cell to use in the model.&amp;nbsp; For reference, I'm using ArcGIS Pro 3.0.2.&lt;/P&gt;&lt;P&gt;I appreciate any help.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Taylor&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2023 19:29:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/automatically-determine-downstream-grid-cell-id/m-p/1310780#M26932</guid>
      <dc:creator>TaylorJordan</dc:creator>
      <dc:date>2023-07-22T19:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically determine downstream grid cell ID</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/automatically-determine-downstream-grid-cell-id/m-p/1311108#M26933</link>
      <description>&lt;P&gt;Hmmm, this works, but I really hope I missed an easier solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# extract your watershed from the larger digital elevation model
ws_dem = arcpy.sa.ExtractByMask("DEM", "Cutter")

# resample to 100x100
ws_dem_resampled = arcpy.management.Resample(ws_dem, "ws_dem_resampled", "100 100")

# fill and flow dir
ws_dem_filled = arcpy.sa.Fill(ws_dem_resampled)
flow_dir = arcpy.sa.FlowDirection(ws_dem_filled)

# create an id raster (numbered sequentially)
cell_points = arcpy.conversion.RasterToPoint(ws_dem_filled, "cell_points", "Value")
id_raster = arcpy.Raster(arcpy.conversion.PointToRaster(cell_points, "pointid", "id_raster", cellsize=flow_dir))

# calculate downstream id
directions = {
    1: (1, 0),
    2: (1, 1),
    4: (0, 1),
    8: (-1, 1),
    16: (-1, 0),
    32: (-1, -1),
    64: (0, -1),
    128: (1, -1)
}
ds_id_raster = arcpy.Raster(id_raster.getRasterInfo())
for x, y in ds_id_raster:
    d = flow_dir[x, y]
    i = id_raster[x,y ]
    try:
        dy, dx = directions[d]
        i_ = id_raster[x+dx, y+dy]
    except:
        continue
    ds_id_raster[x, y] = i_
ds_id_raster.save("ds_id_raster")

# convert raster to polygons
cells = arcpy.conversion.RasterToPolygon(id_raster, "Cells", "NO_SIMPLIFY")
# extract values into the points and join
arcpy.sa.ExtractMultiValuesToPoints(cell_points, [(id_raster, "Cell"), (ds_id_raster, "CellDS"), (flow_dir, "FlowDir"), (ws_dem_filled, "Elevation")])
arcpy.management.JoinField(cells, "gridcode", cell_points, "pointid", ["Cell", "CellDS", "FlowDir", "Elevation"])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This script will:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;resample your dem&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1690219954987.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76126i5EA00DFF984FC5EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1690219954987.png" alt="JohannesLindner_0-1690219954987.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1690219966161.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76127i0701229B97713942/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1690219966161.png" alt="JohannesLindner_1-1690219966161.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;calculate flow direction&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_2-1690220026698.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76128i7297D670EDD6034C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_2-1690220026698.png" alt="JohannesLindner_2-1690220026698.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;Give a unique id to each raster cell&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_3-1690220137889.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76129i2F8DE0A92C5149CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_3-1690220137889.png" alt="JohannesLindner_3-1690220137889.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Use the flow direction to get the downstream cell id&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_4-1690220232474.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76130i98DE27430525C76F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_4-1690220232474.png" alt="JohannesLindner_4-1690220232474.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Extract all this information into a polygon grid&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_5-1690220337986.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/76132i781B22AEA2443738/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_5-1690220337986.png" alt="JohannesLindner_5-1690220337986.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 17:40:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/automatically-determine-downstream-grid-cell-id/m-p/1311108#M26933</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-07-24T17:40:00Z</dc:date>
    </item>
  </channel>
</rss>

