I have a few questions about the suggested Python scripting for the Analyze Datasets tool. The suggested Python (from Analyze Datasets—Help | ArcGIS Desktop is:
<SPAN class="comment token"># Import system modules</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="comment token"># set workspace</SPAN>
<SPAN class="comment token"># the user in this workspace must be the owner of the data to analyze.</SPAN>
workspace <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># set the workspace environment</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> workspace
<SPAN class="comment token"># NOTE: Analyze Datasets can accept a Python list of datasets.</SPAN>
<SPAN class="comment token"># Get a list of all the datasets the user has access to.</SPAN>
<SPAN class="comment token"># First, get all the stand alone tables, feature classes and rasters.</SPAN>
dataList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListTables<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Next, for feature datasets get all of the datasets and featureclasses</SPAN>
<SPAN class="comment token"># from the list and add them to the master list.</SPAN>
<SPAN class="keyword token">for</SPAN> dataset <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Feature"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN>dataset<SPAN class="punctuation token">)</SPAN>
dataList <SPAN class="operator token">+=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># reset the workspace</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> workspace
<SPAN class="comment token"># Get the user name for the workspace</SPAN>
userName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>connectionProperties<SPAN class="punctuation token">.</SPAN>user<SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># remove any datasets that are not owned by the connected user.</SPAN>
userDataList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>ds <SPAN class="keyword token">for</SPAN> ds <SPAN class="keyword token">in</SPAN> dataList <SPAN class="keyword token">if</SPAN> ds<SPAN class="punctuation token">.</SPAN>lower<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>find<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".%s."</SPAN> <SPAN class="operator token">%</SPAN> userName<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Execute analyze datasets</SPAN>
<SPAN class="comment token"># Note: to use the "SYSTEM" option the workspace user must be an administrator.</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AnalyzeDatasets_management<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NO_SYSTEM"</SPAN><SPAN class="punctuation token">,</SPAN> dataList<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ANALYZE_BASE"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"ANALYZE_DELTA"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"ANALYZE_ARCHIVE"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Analyze Complete"</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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Questions:
- Something I am unclear on and doesn't seem to be addressed in the documentation, should the Analyze Datasets tool should be run for BOTH the feature dataset AND feature classes and other datasets contained within a feature dataset, i.e. should line 16 in the script above be edited to include a list of feature datasets, such as in line 8 in the script below?
- On line 20 above an iteration through all the feature datasets begins. The workspace is set to the current feature dataset. A list of feature classes and datasets is then generated and added to the list. When the Analyze Datasets tool is run, my understanding is that 'Dataset names use paths relative to the input workspace; full paths are not accepted as input.' If that is the case, shouldn't the feature classes and datasets that reside within a feature dataset added have a relative path that includes the name of the feature dataset when added to the data list? If so, would the code need to be altered as below on lines 14-21?
<SPAN class="comment token"># set the workspace environment </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="operator token">=</SPAN>workspace
<SPAN class="comment token"># NOTE: Analyze Datasets can accept a Python list of datasets. </SPAN>
<SPAN class="comment token"># Get a list of all the datasets the user has access to. </SPAN>
<SPAN class="comment token"># First, get all the stand alone tables, feature classes and rasters. </SPAN>
dataList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListTables<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Feature'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Next, for feature datasets get all of the datasets and featureclasses </SPAN>
<SPAN class="comment token"># from the list and add them as a relative path to the master list </SPAN>
<SPAN class="keyword token">for</SPAN> dataset <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Feature'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN>dataset<SPAN class="punctuation token">)</SPAN>
fc_list <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> fc_list<SPAN class="punctuation token">:</SPAN>
fc_add <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>dataset<SPAN class="punctuation token">,</SPAN> fc<SPAN class="punctuation token">)</SPAN>
dataList<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>fc_add<SPAN class="punctuation token">)</SPAN>
ds_list <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListDatasets<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> ds <SPAN class="keyword token">in</SPAN> ds_list<SPAN class="punctuation token">:</SPAN>
ds_add <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>dataset<SPAN class="punctuation token">,</SPAN> ds<SPAN class="punctuation token">)</SPAN>
dataList<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>ds_add<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># reset workspace...</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> Thank you in advance for any clarification or suggestions!