I have 38 line Feature Classes located on my Enterprise Server. Without merging the files into one Feature Class, is there a way to discover the grand total of all line lengths in all 38 Feature Classes.
Honestly, it is difficult to provide specific suggestions without more information about the structure of tables within the DB and the schema of the tables. The specifics of how the data is stored and structured can make a big difference on which approach makes sense, or doesn't make sense. I am not sure how comfortable you are with sharing more information, or are even allowed to, but sharing more might help myself or others provide specific suggestions.
Hi Joshua, Thank You for your help on this issue, but this project has evolved into something much bigger. We are a water utility Company with hundreds of miles of pipeline, valves and various equipment. For water quality purposes, I have been asked to provide a total inventory of everything and that includes pipeline sizes & lengths and the various types of valves and equipment. Unfortunately not all our GIS fields are numeric but are text. As a solution, I could merge similar feature classes into one big feature class but this could be labor intensive. Your thoughts Please.
Larry
Instead of copying data sets into temporary workspaces, you should be able to use the fact that cursors can do projection on the fly. The following code uses the ArcPy Walk function to find all polyline feature classes in a geodatabase and sum the length of all features in all of those feature classes:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os gdb <SPAN class="operator token">=</SPAN> <SPAN class="comment token"># path to GDB or GDB connection file</SPAN> SR <SPAN class="operator token">=</SPAN> <SPAN class="comment token"># common spatial reference for calculating lengths</SPAN> walk <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Walk<SPAN class="punctuation token">(</SPAN>gdb<SPAN class="punctuation token">,</SPAN> datatype<SPAN class="operator token">=</SPAN><SPAN class="string token">"FEATURECLASS"</SPAN><SPAN class="punctuation token">,</SPAN> type<SPAN class="operator token">=</SPAN><SPAN class="string token">"POLYLINE"</SPAN><SPAN class="punctuation token">)</SPAN> sum_length <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">for</SPAN> root<SPAN class="punctuation token">,</SPAN> dirnames<SPAN class="punctuation token">,</SPAN> filenames <SPAN class="keyword token">in</SPAN> walk<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> name <SPAN class="keyword token">in</SPAN> filenames<SPAN class="punctuation token">:</SPAN> sum_length <SPAN class="operator token">+=</SPAN> sum<SPAN class="punctuation token">(</SPAN> length <SPAN class="keyword token">for</SPAN> length<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>root<SPAN class="punctuation token">,</SPAN>name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@LENGTH"</SPAN><SPAN class="punctuation token">,</SPAN> spatial_reference<SPAN class="operator token">=</SPAN>SR<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> sum_length<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>
If you don't wall all polyline feature classes, you could add some additional logic to exclude or include feature classes of interest.
Thanks You, I getting a lot of very good Ideas how to make this happen,
Larry Adgate
What about using Summarize Statistics?
The first example appears to summarize the SHAPE_LENGTH field into an output table.
Thank You, I will give this a try
Hi Larry,
I should think so. How about something like this:
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="comment token"># point the workspace to your enterprise geodatabase</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"[path to enterprise GDB]"</SPAN> <SPAN class="comment token"># set the environment to overwrite output</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> <SPAN class="comment token"># list the line feature classes (might have to modify </SPAN> <SPAN class="comment token"># this depending on how many FCs are in your workspace</SPAN> linear_fcs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Arc"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create a float variable to store the total length</SPAN> total_length <SPAN class="operator token">=</SPAN> <SPAN class="number token">0.0</SPAN> <SPAN class="comment token"># copy each FC into the in memory workspace, add a </SPAN> <SPAN class="comment token"># length attribute, and add the length of each to the total</SPAN> <SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> linear_fcs<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># copy</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">"in_memory\temp"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># add length attribute</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddGeometryAttributes_management<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"in_memory\temp"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LENGTH"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FEET_US"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># add the length of each feature to the total</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"in_memory\temp"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"LENGTH"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> total_length <SPAN class="operator token">+=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># print the result</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"The total length is {} feet."</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>total_length<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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hope this helps.
Micah
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.