Hi,
Are there any hooks to get the count of errors in a topology via Arcpy? Using Describe only returns information about the Topology settings, not the number of errors, types, etc.
TIA,
Greg
I figured this out: I converted all of the topologies to feature classes using ExportTopologyErrors_management() and then counted the resulting feature class features. Code is below. The topologies were generated by a script across File GDBS, so I'm relying on the naming convention to process them all.
import arcpy, os from arcpy import env outws = r'D:\temp\topocount.gdb' env.workspace = r'D:\data' fgdbs = arcpy.ListWorkspaces('*','FileGDB') for fgdb in fgdbs: env.workspace = fgdb dataset = arcpy.ListDatasets('*','Feature')[0] topology = os.path.join(dataset, dataset + '_topology') topology = os.path.join(fgdb, topology) print 'Converting %s' %topology arcpy.ExportTopologyErrors_management(topology,outws,dataset + '_') print 'Counting topology errors.' # count 'em up with open(r'D:\temp\topology_error_count.txt', 'w+') as f: env.workspace = outws fcs = arcpy.ListFeatureClasses() for fc in fcs: count = arcpy.GetCount_management(fc) print count outStr = fc + ',' + str(count) + '\n' f.writelines(outStr)
Thanks for sharing that Greg. I had a slightly different need but this got me going in the right direction. I was needing to get a count to help verify the error count of a child replica (personal SDE) matched that of the parent (enterprise SDE), before marking them all as exceptions. I didn't need to write to a file, just print in the python window (for now), and in my case the _topology layer. I thought I'd share in case anyone else stumbles across this thread.
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="comment token"># sets temp output to scratchGDB</SPAN> outGDB <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchGDB arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> topoBaseName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"jnu2w"</SPAN> <SPAN class="comment token"># basename for temp topo files.. </SPAN> topoFC <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'jnu2way.DBO.DWCMasters_topology'</SPAN> <SPAN class="comment token"># _topology feature class from ArcMap TOC</SPAN> <SPAN class="comment token">#topoFC = r"sde_wcgis_master.DBO.DWCMasters_topology"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ExportTopologyErrors_management<SPAN class="punctuation token">(</SPAN>topoFC<SPAN class="punctuation token">,</SPAN> outGDB<SPAN class="punctuation token">,</SPAN> topoBaseName<SPAN class="punctuation token">)</SPAN> errorCnt <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">for</SPAN> fType <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"_line"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"_point"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"_poly"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token">#print("fType {0}".format(fType))</SPAN> lyr <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{0}{1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>topoBaseName<SPAN class="punctuation token">,</SPAN> fType<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#print("layer name {0}".format(lyr))</SPAN> fType <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">" ->Layer {0} Errors: {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">,</SPAN> fType<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> errorCnt <SPAN class="operator token">=</SPAN> errorCnt <SPAN class="operator token">+</SPAN> fType <SPAN class="comment token"># cleanup - removes temp FC from scratch</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Total topology errors for {0}: {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>topoFC<SPAN class="punctuation token">,</SPAN> errorCnt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n NOTICE: if {0} same as exceptions in parent, edit and mark all as exceptions"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>errorCnt<SPAN class="punctuation token">,</SPAN> errorCnt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
nothing fancy, but works for a quick count on a single _topology layer..
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.