0

Below is the code I'm using in an SDE GDB, on ArcMap 10.4.1:

import arcpy

# Variables
inputAsbuilt = arcpy.GetParameterAsText(0)
transmedia = inputAsbuilt + "\\Transmedia"
structure = inputAsbuilt + "\\Structure"
spliceClosure = inputAsbuilt + "\\SpliceClosure"
span = inputAsbuilt + "\\Span"
equipment = inputAsbuilt + "\\Equipment"
buildingfootPrint = inputAsbuilt + "\\BuildingFootPrint"
attachment = inputAsbuilt + "\\Attachment"

spliceClosure1 = '\\\\Bvweb104draco\\e\\03_MapServices\\SDE_CONNECTIONS\\bvtampadev.sde\\bvtampadev.sde.Telecom\\bvtampadev.sde.SPLICECLOSURE'
buildingfootPrint1 = '\\\\Bvweb104draco\\e\\03_MapServices\\SDE_CONNECTIONS\\bvtampadev.sde\\bvtampadev.sde.Telecom\\bvtampadev.sde.BUILDINGOUTLINE'

fcList = [transmedia, structure, spliceClosure, span, equipment, buildingfootPrint, attachment]
sdefcList = [spliceClosure1, buildingfootPrint1, fiberEquipment1, conduit1, structure1, fiberCable1]

# Print out FQNID's of feature classes inside As-Built GDB      
fqnList = []
for fc in fcList:
    with arcpy.da.SearchCursor(fc, "FQN_ID") as cursor:
        for row in cursor:
             fqnList.append(row)

for fqn in fqnList:
arcpy.AddMessage(fqn)

# Update "bv_asbuilt_gdb_uploaded" field in SDE feature classes
for fc in sdefcList:
    with arcpy.da.UpdateCursor(fc, ["bv_fqn_id", "bv_asbuilt_gdb_uploaded"])      as cursor:
    for row in cursor:
        if row[0] in fqnList:
            row[1] = "Y"
        else:
            row[1] = "N" 
            cursor.updateRow(row)`

What I want the code to do:

  1. Make a list of unique values from a field in the input feature class

  2. Take that list of unique values, check it against a field in another feature class to see if they're ==, if not write N in the "FQN_ID" field, if yes wrote Y in the "FQN_ID" field

The code is throwing no errors and appends a string "N" where I want it to, but it's not checking the row[0] against "fqnList" correctly, so it populates the entire field with "N" even if there the list matches a value in the feature class field and should populate as "Y"

3
  • 1
    Your paths are crazy, start using os.path.join
    – BERA
    Oct 10 '18 at 17:15
  • 1
    I'm extremely new to Python, Ill check that out, thanks.
    – GIS_GOD
    Oct 10 '18 at 17:17
  • 3
    The last line is indented so that updates are only stored when row[0] is not in your the fqnList. Dedent cursor.updateRow(row) one level so that it aligns with the if and else above it. the line that reads fqnList.append(row) is also not indented correctly and needs to be indented one level. Oct 10 '18 at 17:20
3

You are creating a list of tuples with fqnList.append(row), for example somelist = [(1,),(2,)], 1 is not in this list, (1,) is.

So when you then check for the id's in list there will never be a match. Change it to fqnList.append(row[0])

You also need to fix the indentation after for row in cursor:

fqnList = []
for fc in fcList:
    with arcpy.da.SearchCursor(fc, "FQN_ID") as cursor:
        for row in cursor:
            fqnList.append(row)

Can be shorter using list comprehension:

fqnList = [i[0] for i in arcpy.da.SearchCursor(fc,"FQN_ID")]
1
  • Trying to wrap my head around List Comprehension, I literally just got done wrapping my head around SearchCursors.
    – GIS_GOD
    Oct 10 '18 at 17:20
0

fcList = [transmedia, structure, spliceClosure, span, equipment, buildingfootPrint, attachment]

sdefcList = [spliceClosure1, buildingfootPrint1, fiberEquipment1, conduit1, structure1, fiberCable1]

I wasn't creating a full list of the features, such a simple error, but easy to overlook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.