in my project, there are some Line shapefiles (transport related) and I want to create topology for those shapefiles. I can create topology
by converting shapefiles into Geodatabase
adding feature classes and rules to topology
Running and validating topology errors
Exporting topology errors into shapefile
I found some separate ArcPy codes for each task(as shown in below) for above mentioned but I am looking for single arcpy code by including all above tasks
Finally, what I want to say is, I have some shape files in one folder and I need topology errors directly by running ArcPy.
My English is not good enough to explain more about this but can you help me with my ArcPy code?
import arcpy from arcpy import env # Set workspace env.workspace = r"C:\SOFTWARE\Shapefiles\topo" # Set local variables out_dataset_path =r"C:\SOFTWARE\Shapefiles\topo\out\topo.gdb" out_name = "topo1" # Creating a spatial reference object sr = arcpy.SpatialReference(r"C:\SOFTWARE\Shapefiles\topo\line.prj") # Create a FileGDB for the fds arcpy.CreateFileGDB_management(r"C:\SOFTWARE\Shapefiles\topo\out", "topo.gdb") # Execute CreateFeaturedataset arcpy.CreateFeatureDataset_management(out_dataset_path, out_name, sr) print "GDB created" # Set local variables in_features = ['line.shp', 'parcel_1.shp'] out_location = r"C:\SOFTWARE\Shapefiles\topo\out\topo.gdb\topo1" # Execute FeatureClassToGeodatabase arcpy.FeatureClassToGeodatabase_conversion(in_features, out_location) print "shape exported to GDB" input_dataset = r"C:\SOFTWARE\Shapefiles\topo\out\topo.gdb\topo1" topo_name = "Topology" cluster_tol = 0.001 input_fc = r"C:\SOFTWARE\Shapefiles\topo\out\topo.gdb\topo1\line 1 1;C:\SOFTWARE\Shapefiles\topo\out\topo.gdb\topo1\parcel_1 1 1" rules = r"'Must Not Have Dangles (Line)' C:\SOFTWARE\Shapefiles\topo\out\topo.gdb\topo1\line #;'Must Not Intersect (Line)' C:\SOFTWARE\Shapefiles\topo\out\topo.gdb\topo1\line1 #" validate = "true" # Create the topology out_topo = arcpy.CreateTopology_management(input_dataset, topo_name, cluster_tol) print("Created topology.") # Loop through the list of feature classes and add them to the topology input_fcL = input_fc.split(";") for fc in input_fcL: param = fc.rsplit(" ", 2) in_fc = param arcpy.AddFeatureClassToTopology_management(out_topo, in_fc) print(arcpy.GetMessages()) # Loop through the list of rules and add rules to the topology rulesL = rules.split(";") for rule in rulesL: r = rule.rsplit(" ", 4) rule_type = r.replace("'","") in_fc1 = r subtype1 = r in_fc2 = r subtype2 = r arcpy.AddRuleToTopology_management(out_topo, rule_type, in_fc1, subtype1, in_fc2, subtype2) print(arcpy.GetMessages()) # Validate the topology if validate == "true": try: arcpy.ValidateTopology_management(out_topo) except: print(arcpy.GetMessages()) print("Finished.")