identify the nearest gages downstream from dams

4841
18
06-15-2016 07:55 AM
XianyingFan
New Contributor II

Help please:

Task: identify the nearest gages downstream from dams

Data: Stream Flowline (line feature class), streamgage point feature class, dam point feature class (both point feature classes contain thousands of points)

What I did: Using geometric network analysis tools to first create a geometric network, then set flow direction and finally trace geometric network, I got the output of a group layer.

My questions: I am hoping to add a new field which contains the ID of the nearest gage point for each dam point in my dam point attribute table, is that possible to realize this using the output of tracing geometric network? How can I realize it?

Thank you so much!

Maggie

0 Kudos
18 Replies
BillDaigle
Occasional Contributor III

Hi Maggie,

Sorry for the lapse in response.  I've been out for a few days. If you are still struggling, could you zip up a portion of you're network dataset and share it?  It has been a while since I've worked with one and I don't seem to have any good examples for you.

0 Kudos
XianyingFan
New Contributor II

Hi Bill,

Excited to see you're back! How can I share the zip file? I saw insert image, insert video, insert link, but no insert files. Can I send directly to your email? Many thanks!

0 Kudos
BillDaigle
Occasional Contributor III

Use the "Advanced Editor" option, then you will see an "Attach" link in the lower right hand corner. 

0 Kudos
XianyingFan
New Contributor II

Thank you very much Bill! Here is the data.

For the two options that you mention:

Option1: I am able to trace downstream of one dam point using the Geometric Network Analysis Toolset and then join the selective line features with gage points to get the closest gage point info. My difficulty is to write the python code of the tracing process and automate to other points;

Option 2: I accept the logic of treating the flowline as one way street and use the Network Analysis Toolset (specifically: find closest facilities tool) to find the closest points for all dam point at one time, however I failed to get the result because I can't find a way to set the direction so that it will find the closest facilities downstream along the flowline.

0 Kudos
BillDaigle
Occasional Contributor III

Let’s focus on option 1 first. Can you send me a python snippet from the geoprocessing result? If you run the tool, then find the geoprocessing task in the Results window, you can get a python snippet by right clicking on the result object. I think I can get you started on a python script without actually setting up the network on my end.

0 Kudos
XianyingFan
New Contributor II

Hi  Bill, with the help of an incredibly nice friend's help, we have a draft python code to work with.

The attached includes a test geodatabase & a test script (traceGeometric.py). Unfortunately, the script works, so far, on the first feature (dam) only. It does assign a closest gage ID. By the way, there are two fields with reachcode  info. of gage points because I snapped it to flowline feature class and I think using REACHCODE is the right field as gages ID instead of REACHCODE2.

Here is what she wrote about the current issue of the code:

---------------------------

After the first dam, "TraceGeometricNetwork" tool fails. The problem is, I think, the output Network/layer group. In m script, the output has to be the same as the input network, Hydro_Net. I've seen other examples and they seem to be able to create a new output. I think it would let the script to run against the rest of the dams if I can use a different output (but not so sure). The tool seems to be very picky, unfortunately. Anyway, I will share what I have so far and let you play with the script.

PS: my script runs directly from Python shell (2 not version 3, because ArcGIS doesn't use 3..), without opening ArcGIS (but you have to have ArcGIS on your local machine) and it's on Windows - below is the screenshot of the output.

-----------------------------

Can you please take a look at our data and python code how can we address the issue? Many thanks!

0 Kudos
BillDaigle
Occasional Contributor III

Can you add the python script? It didn’t get included with the toolbox.

0 Kudos
BillDaigle
Occasional Contributor III

I think this is probably what you need. You can run it independent of ArcMap.  It should scale up pretty easily.

import arcpy, os

pathToGdb =  r'C:\temp\HydroNet\TraceGeometric\test.gdb'
geoNetwork = os.path.join(pathToGdb,'Hydro','Hydro_Net')
damsFC = os.path.join(pathToGdb,'Hydro','DamPoints')
gagesFC = os.path.join(pathToGdb,'Hydro','GagePoints')

temporaryOutputGroupLayerLoc = r'in_memory\outGroup'

#loop through each dam
with arcpy.da.SearchCursor(damsFC,['SHAPE@','OBJECTID']) as cursor_Dam:
    for row_Dam in cursor_Dam:
        print 'Current Dam ObjectID:',row_Dam[1]
        startGeom = row_Dam[0]

        #run the trace on a single dam
        arcpy.TraceGeometricNetwork_management(
            geoNetwork,
            temporaryOutputGroupLayerLoc,                                # using an in_memory workspace lets you access it via python
            startGeom,
            "TRACE_DOWNSTREAM",
            gagesFC,
            "#","#","#","#",
            "TRACE_ENDS")

        #loop through the output group layer to find the gages layer
        for layer in arcpy.mapping.Layer(temporaryOutputGroupLayerLoc): #referencing Group Layer in_memory
            if layer.name == 'GagePoints':
                #loop through the selected gages
                with arcpy.da.SearchCursor(layer, 'OBJECTID') as cursor_selectedGages:
                    for row_gage in cursor_selectedGages:
                        print '  Downstream Gage ObjectID',row_gage[0]

        #delete the layer temporary group layer before starting the next dam
        arcpy.Delete_management(temporaryOutputGroupLayerLoc)
0 Kudos
XianyingFan
New Contributor II

Thank you so much Bill! We will try in our computer and get back to you if there is any further question!

0 Kudos