2

I have a script that identifies certain layers from a folder containing several geodatabases. Part of the scripts purposes, or intended purpose is to have it add a topology dataset to the dataframe. I have tried both of these methods below with no success. It's as if the topology cannot be treated as a layer and therefore cannot be added. Is there a workaround to allow for topology data to be added to the map? If anyone has a solution for this I would be very grateful.

 elif name == "Topo_" + str(fileNameFull) + "_Topology":
        tempTopoPath = os.path.join(tempData,str(fileNameFull) + "_topoTemp")
        topologyPath = os.path.join(r'N:\29000s\29910\GIS\GI02\QC_Processing',fileNameFull,"FW_" + str(fileNameFull) + "_" + str(gdbDate) + ".gdb","Layers",str(name))
        topoLayer = arcpy.MakeFeatureLayer_management(topologyPath, tempTopoPath)
        topologyLayer = arcpy.mapping.Layer(tempTopoPath)
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, topologyLayer, "TOP")
        arcpy.RefreshActiveView()

Here is another method I tried.

elif name == "Topo_" + str(fileNameFull) + "_Topology":
        topologyPath = os.path.join(r'N:\29000s\29910\GIS\GI02\QC_Processing',fileNameFull,"FW_" + str(fileNameFull) + "_" + str(gdbDate) + ".gdb","Layers",str(name))
        topologyLayer = arcpy.mapping.Layer(topologyPath)
        arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, topologyLayer, "TOP")
        arcpy.RefreshActiveView()
1

The only types of layers you can add to an mxd with arcpy.mapping are map layers (layers in an mxd), and layer files (.lyr). A feature layer (in-memory layer) you create using the Make Feature Layer tool is not valid.

In addition, Make Feature Layer doesn't accept topologies as input (a topology is a dataset, not a feature class).

You can export a topology to a .lyr file by right-clicking it in the Catalog window, but not using the Save To Layer File tool, so you won't be able to automate this with arcpy.

So if a .lyr file of the topology doesn't already exist and if your topology isn't already present as a layer in another mxd, you will need ArcObjects to add it to your mxd.

  • This cleared up my confusion, thanks. In addition to what @GISGe said above, I was able to use the "Export Topology Errors" tool to create a representation of the topology data in a script that automates the whole process. – GeoJohn Oct 20 '14 at 18:30

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.