in my project, there are some Line shapefiles (transport related) and I want to create topology for those shapefiles. I can create topology

  1. by converting shapefiles into Geodatabase

  2. creating topology

  3. adding feature classes and rules to topology

  4. Running and validating topology errors

  5. 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[0]   
    arcpy.AddFeatureClassToTopology_management(out_topo, in_fc)

# 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[0].replace("'","")
    in_fc1 = r[1]
    subtype1 = r[2]
    in_fc2 = r[3]
    subtype2 = r[4]

    arcpy.AddRuleToTopology_management(out_topo, rule_type, in_fc1, subtype1, in_fc2, subtype2)

# Validate the topology
if validate == "true":

  • You say you've found separate arcpy code for each task - can you please edit your question to include each of them? You are wanting one code to combine them all, is that correct?
    – Midavalo
    Apr 21, 2017 at 18:14
  • What happened when you ran the code that you have presented? That looks to be for your step 1 so once you have that working you will be able to start addressing step 2.
    – PolyGeo
    Apr 21, 2017 at 19:00
  • This is my full code
    – Arb
    Apr 22, 2017 at 15:14
  • @Midavalo, I updated my full code & I am getting an error at line 59. ExecuteError: Failed to execute. Parameters are not valid ERROR 000732: Input Feature class: Dataset Dangles does not exist or is not supported Failed to execute (AddRuleToTopology).
    – Arb
    Apr 22, 2017 at 15:18
  • @Arb Please edit your question to include your error message in full. Where is line 59 in your code above?
    – Midavalo
    Apr 22, 2017 at 18:29


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.