Point on a line layer

299
3
09-18-2020 01:40 PM
BillChappell
Occasional Contributor II

I'm working for a GAS utility, I have Pipe Exposures (Points) and they are snapped to either a Main(line) or a Service (Line). 

Using ArcPy I've tried to do a intersect with a try/except block, if try the service and if not try the main. Along the way set a variable to let me know which layer it's on. It's part of editing, as each gets different values. My code snippet below:

try:
    arcpy.Intersect_analysis('Pipexposure #;Service #', PipeExposure_Intersect, "ONLY_FID", "", "INPUT")
    theLayer = "the Service"

except:
    arcpy.Intersect_analysis('PipeExposure #;DistributionMain #', PipeExposure_Intersect, "ONLY_FID", "", "INPUT")
     theLayer = "the Main"

arcpy.AddMessage('The Pipe Exposure is on '+ theLayer)

No matter what I put a point on, it returns on the Main. I'm stumped and wondering if there is a better way to determine what layer is intersected. I do have an "Exists/than Delete" for my in_memory/PipeExposure_Intersect FeatureClass. that runs before I check.

Tags (1)
0 Kudos
3 Replies
RandyBurton
MVP Regular Contributor

I'm not sure that your try/except is doing what is expected.  The way the code is set up, it appears to be generating an error on the first Intersect_analysis, possibly an error the second, and then setting the variable to "the Main".

If you don't need to create a "PipeExposure_Intersect" layer, you might try something like:

# select main intersects
arcpy.SelectLayerByLocation_management("pipeExposure", "INTERSECT", "Main")
main_item = [r[0] for r in arcpy.da.SearchCursor('pipeExposure',['OID@'])]

# select service intersects
arcpy.SelectLayerByLocation_management("pipeExposure", "INTERSECT", "Service")
service_item = [r[0] for r in arcpy.da.SearchCursor('pipeExposure',['OID@'])]

# clear any selections in pipeExposure layer
arcpy.SelectLayerByAttribute_management("pipeExposure", "CLEAR_SELECTION")

# results - can use an update cursor if updating attributes
with arcpy.da.SearchCursor("pipeExposure",["OID@"]) as cursor:
    for row in cursor:
        if row[0] in main_item:
            print("{} MAIN".format(row[0]))
        elif row[0] in service_item:
            print("{} SERVICE".format(row[0]))
        else:
            print("{} N/A".format(row[0]))
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You will have 2 lists of main/service lines by line 12 and may not need the additional code.

0 Kudos
BillChappell
Occasional Contributor II

More info may help. The techs are placing a pipe exposure on either a main or a service. As part of their workflow, they then copy/paste info to various fields. While the placing of the pipe exposure is a one at a time process, if I could take advantage of the process and populate some attributes, it would help.avoid data entry errors.

When they place the point it's still selected, so I wanted to make a button that would do a quick intersect, and if it was a service do this, if a main do that. It checks if it's a service first, and if it isn't the select by location fails, so I was using a try/except and if it failed, then try the main. Problem is if it's a service it still says it's a main.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Might be a case for attribute rules in Arcade.

That should just about do it....
0 Kudos