2

I'm trying to write a script that looks into a dataset and list all the elements in the dataset. The dataset comprises of Feature classes and FGDB Toppology. When I uses ListFeatureClasses, it outputs all the feature classes in the dataset,so I know the code works, but I want to list also the topology file. ListFiles does not work. Which of the List functions should I use to list topology? This is the code I have so far:

import arcpy
import os
PATH1 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFM.gdb"
PATH2 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\Complete Final Capstone Map\Z2 Map File Geodatabase.gdb"
arcpy.env.workspace = PATH2
arcpy.env.overwriteOutput=True
for data in arcpy.ListDatasets():
    if data == "AllZones":
        print data + "1"
        path = os.path.join(PATH2,data)
        print path
        arcpy.env.workspace = path
        for file in arcpy.ListFiles():
            print file 

If I change arcpy.ListFiles() to arcpy.ListFeatureClasses(), the code works as I stated above.

4

Listing topology name is not possible using arcpy directly as listing feature classes. You have to get to the feature dataset first and then iterate through objects within the feature dataset. ListFeatureClasses() will not return topologies.

import arcpy
import os
path = r"C:\ArcGIS\Default.gdb"

arcpy.env.workspace = path
gdb_objects = arcpy.ListDatasets(wild_card=None, feature_type='Feature')
print "Feature datasets are: " + str(gdb_objects) #only feature datasets are here
for obj in gdb_objects:
    fd_path = os.path.join(path,obj)
    arcpy.env.workspace = fd_path #get a new workspace pointed to the fd
    fd_objects = arcpy.ListDatasets(wild_card=None, feature_type='')

    for dataset in fd_objects: #iterate feature dataset objects
        desc_dataset = arcpy.Describe(dataset)
        if desc_dataset.datasetType == 'Topology': #finding out whether is topology
            print dataset

However, once you get the topology name, you can use the Topology properties to learn more about it.

0

once you set the workspace to the feature dataset, you should be able to call the ListDatasets again with the 'Topology' feature type:

so glomming onto the above code...

for obj in gdb_objects:
    fd_path = os.path.join(path,obj)
    arcpy.env.workspace = fd_path #get a new workspace pointed to the fd
    fd_objects = arcpy.ListDatasets(wild_card=None, feature_type='Topology')

this returns a list of the topologies that are defined in that feature dataset.

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.