Help with Snap_edit error in stand alone script

569
4
Jump to solution
04-28-2017 08:59 AM
deleted-user-25j2k-XonNEg
New Contributor III

Hello, all.

I am writing a script that will selectively snap address points to a road centerline.  This will ultimately be used to determine and report the closest hydrant to an address.

I am able to search through and select the addresses and the appropriate road segment, however I get an error (Error 000800: Not a member of END | VERTEX | EDGE) when I include the Snap_edit function.  It works from within ArcMap using a mdx, but not in a stand-alone script.  Any help is greatly appreciated.

Thanks in advance,

Charlie

import arcpy
from arcpy import da

def even_addr(arow, crow):
    if int(arow[0]) in range(int(crow[2]), int(crow[3])):
        snapexpr = """{0} = {1}""".format(arcpy.AddFieldDelimiters('ADDR_Layer','OBJECTID'), arow[2])
        print('Even', snapexpr)  ## Flow trace
        arcpy.SelectLayerByAttribute_management(snap, 'NEW_SELECTION', snapexpr)
        arcpy.Snap_edit(snap, snapenv)

def odd_addr(arow, crow):
    if int(arow[0]) in range(int(crow[0]), int(crow[1])):
        snapexpr = """{0} = {1}""".format(arcpy.AddFieldDelimiters('ADDR_Layer','OBJECTID'),arow[2])
        print('Odd', snapexpr)  ## Flow trace
        arcpy.SelectLayerByAttribute_management(snap, 'NEW_SELECTION', snapexpr)
        arcpy.Snap_edit(snap, snapenv )

addr = r'Z:\Data\Projects\FIRE\Preplan\Closest_Hydrant.gdb\ADDRPTS_812'
aflds = ['COMPLETE_ADDRESS_NUMBER', 'COMPLETE_STREET_NAME', 'OBJECTID'] 
aexpr = 'COMPLETE_STREET_NAME IS NOT NULL'

cline = r'Z:\Data\Projects\FIRE\Preplan\Closest_Hydrant.gdb\WORK_RDCENTERLINES'
cflds = ['LLEFT', 'HLEFT', 'LRGT', 'HRGT','FULLNAME']
cexpr = 'FULLNAME > \' \''

snap = r'\ADDR_Layer'
snapenv = [cline, 'EDGE', '500 Feet']

arcpy.MakeFeatureLayer_management(addr, snap, workspace = None)
print('Feature Layer created')  ## Flow trace

with da.SearchCursor(addr, aflds, where_clause = aexpr, sql_clause = (None,'ORDER BY COMPLETE_STREET_NAME, COMPLETE_ADDRESS_NUMBER')) as acursor:
    for arow in acursor:

        with da.SearchCursor(cline, cflds, where_clause = cexpr ,sql_clause = (None,'ORDER BY FULLNAME, LLEFT')) as ccursor:
            for crow in ccursor:

                if '/' in arow[0]:
                    print('Fractional address: {0}'.format(arow[0]))  ## Flow trace
                    break
                if (arow[1]) == crow[4]:

                    if int(arow[0]) % 2 > 0:
                        odd_addr(arow, crow)
                    else:
                        if int(arow[0]) % 2 == 0:
                            even_addr(arow, crow)
                        else:
                            print('Error?  {0} : {1}'.format(arow, crow))  ## Flow trace

    print("Processed address")  ## Flow trace

print('Completed')  ## Flow trace


#  arow[0] - Address Number
#  arow[1] - Street Name
#  arow[2] - ObjectID

#  crow[0] - Lower Left Address Number
#  crow[1] - Higher Left Address Number
#  crow[2] - Lower Right Address Number
#  crow[3] - Higher Right Address Number
#  crow[4] - Street Name
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

from the help topic... the snap environment seems to be a list of lists even if there is only one... check to make sure

View solution in original post

4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

from the help topic... the snap environment seems to be a list of lists even if there is only one... check to make sure

curtvprice
MVP Esteemed Contributor

I recommend avoiding use of global variables. There is a reason this is best practice.

All variables used in your function (ie snap, snapenv) should be passed as function parameters. 

0 Kudos
deleted-user-25j2k-XonNEg
New Contributor III

I get the same result when I pass the variables to the function, but I'll try both ways with added brackets.

deleted-user-25j2k-XonNEg
New Contributor III

Well, the double brackets did the trick; thank you.  Snapping or the copy features opened up another issue that I'll work around.

0 Kudos