1

I was working on this a bit ago and had something which I thought worked however, it does not seem to be working at the moment. What I'm trying to do is match feature classes having similar files. One will be a buffered version of the original and have 'Buffer_' in the name the other will simply be the original feature class. I'd like to then bring the buffered version and original feature class into a .mxd, symbolize both, create a legend, save the .mxd and export the map to a pdf. Everything is working as it should with the exception of getting the buffered feature class to match it's original.

I am able to bring the buffered feature class into the .mxd, rename the .mxd to the name of the buffered feature class. I am also able to bring in an original feature class to the map document however, it is not the original feature class which corresponds to the buffered feature class.

The portion of my code which attempts to match the 2 feature classes looks like:

buffered = arcpy.ListFeatureClasses('Buffer_*')


original = [buffer.split("Buffer_")[-1] for buffer in buffered]


fccount = -1   
buffered.sort()
for fc in buffered:
    fccount += 1
    print fc + " " + str(fccount)
    #REPLACE sandbox WITH tip_2014
    fcclean = fc.replace('tBuffer_','')
    print "fcclean = " + fcclean

    copymxd = templatemxd.saveACopy(r"map output directory\\" + fcclean + ".mxd")
    print "Saved Copy"
    mxd = arcpy.mapping.MapDocument(r"map output directory\\" + fcclean + ".mxd")
    print "MXD set"
    df = arcpy.mapping.ListDataFrames(mxd,"*")[0]




    buffLayer = arcpy.mapping.Layer(buffered[fccount]) 
    orgLayer = arcpy.mapping.Layer(original[fccount])

I have a feeling I am missing something with the count but am puzzled as to what. Thanks for any help you can provide with this issue.

1

You should be able to use the same index for both buffLayer and orgLayer -- the problem was that you sorted buffered after creating original, and so the lists would no longer correctly match up.

buffered = arcpy.ListFeatureClasses("Buffer_*")
buffered.sort()
original = [buffer.split("Buffer_")[-1] for buffer in buffered]

Separate from your actual problem, you might consider using Python's slice function instead of split to drop the prefix:

original = [buffer[7:] for buffer in buffered]
  • thanks @Erica, that works as well and is less convoluted then what I have. – standard Aug 5 '14 at 21:56
0

I got this to work using a second count for the original feature classes. Here's what my final code ended up looking like(naturally you''l have to set your work space and layer symbology variables, etc.:

original = [buffer.split("Buffer_")[-1] for buffer in buffered]


fccount = -1
ofccount = -1   
buffered.sort()
original.sort()
for fc in buffered:
    fccount += 1
    print fc + " " + str(fccount)
    fcclean = fc.replace('tBuffer_','')
    print "fcclean = " + fcclean

    copymxd = templatemxd.saveACopy(r"map output directory\\" + fcclean + ".mxd")
    print "Saved Copy"
    mxd = arcpy.mapping.MapDocument(r"map output directory\\" + fcclean + ".mxd")
    print "MXD set"
    df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
    ofccount +=1




buffLayer = arcpy.mapping.Layer(buffered[fccount]) 
orgLayer = arcpy.mapping.Layer(original[ofccount])

The remainder of the code which I have not included sets symbology and exports to PDF.

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.