I'm trying to create .mxd and PDF outputs for a series of feature classes in an SDE. I'll need to match 2 feature classes (one original, one buffered) in the SDE based on similar file names. The buffered FC will simply be prefaced with 'Buffer_' prior to sharing the original file path name. I'm trying to bring both feature classes into a new mxd, zoom to the extent of the buffered feature class as it will naturally occupy more area, symbolize the 2 layers and create a saved mxd and pdf based on the features and repeat this process for subsequent buffered feature classes and original feature classes.

I'm stuck trying to get the buffered and original feature classes to match and as a result be added to the map as a layer. So far I am able to create the new mxd and set the zoom extent. The code I'm stuck on is as follows:

arcpy.env.workspace = "SDE"
fcList = sorted(arcpy.ListFeatureClasses('Buffer_*'))

matchFClist = arcpy.ListFeatureClasses()

for fc in fcList:
    print fc

    fcclean = fc.replace('Buffer_','')
    copymxd = templatemxd.saveACopy(r"Folder\\" + fcclean + ".mxd")
    mxd = arcpy.mapping.MapDocument(r"Q:\outputFolder\TMaps\\" + fcclean + ".mxd")
    df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
    for fcclean in matchFClist:
        if fnmatch.fnmatch(fcclean, matchFClist):
            newlayer = arcpy.mapping.Layer(fcclean)
            newMatchlayer = arcpy.mapping.Layer(matchFClist)

I know this is probably way off however, but I'm not sure how to get the match to work. I could always try using an array as well however, I'm pretty confused at this point.

  • I would first try adding print statements for fcclean and for certain steps afterwards to help you see what's going on, or where the code is failing. Also is this code meant to be standalone or run within each mxd? – GISKid Jul 31 '14 at 15:50
  • The code should be run with each mxd. – standard Jul 31 '14 at 15:56

Could try something like this instead:

arcpy.env.workspace = r"SDE"

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

for x in xrange(len(buffered)):
  • original = [buffer_feature.split("_")[-1] for buffer_feature in buffer_features] <- This assumes there are no other underscores in the name of the feature class. You should probably concatenate everything from [1:]. – papadoo Jul 31 '14 at 16:16
  • 1
    Very true, could use buffer.split("ffer_")[-1] instead. – ianbroad Jul 31 '14 at 16:19
  • 1
    thanks @ian, I think this gets me looking in a better direction than with the fnmatch or array method, I do have multiple underscores in the file names and as you mentioned, .split("ffer_") resolved it. I'll keep plugging away at this, if I manage to get something that works I'll post it as I'd imagine this will be useful to others. – standard Jul 31 '14 at 16:33
  • Hey no problem, good luck! – ianbroad Jul 31 '14 at 16:56

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.