Hi,
So I am trying to figure out how to get the date for a selected feature using the spatial location using arcpy. I keep running into an issue where the MakeFeatureLayer keeps returning an error and I am not sure as to why. I followed several examples and yet I still keep getting an error. I would greatly appreciate any help with this.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'Database Connections\Some Connection.sde'</SPAN>
fcs <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</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>workspace<SPAN class="punctuation token">,</SPAN> datatype<SPAN class="operator token">=</SPAN><SPAN class="string token">"FeatureClass"</SPAN><SPAN class="punctuation token">)</SPAN>
Dist_LL <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Database Connections\Some.sde\FeatureClass"</SPAN>
<SPAN class="keyword token">for</SPAN> dirpath<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> filename <SPAN class="keyword token">in</SPAN> filenames<SPAN class="punctuation token">:</SPAN>
fcs<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>dirpath<SPAN class="punctuation token">,</SPAN> filename<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> fcs<SPAN class="punctuation token">:</SPAN>
geometryType <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>shapeType
<SPAN class="keyword token">print</SPAN> geometryType
<SPAN class="keyword token">if</SPAN> geometryType <SPAN class="operator token">==</SPAN> <SPAN class="string token">'Point'</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#Get feature class name</SPAN>
fcsname <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN>
name <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>fcsname<SPAN class="punctuation token">)</SPAN>
y <SPAN class="operator token">=</SPAN> name<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>lstrip<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'.'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> y
<SPAN class="comment token">#For fields in some feature classes</SPAN>
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"OID@"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LANDDISTRICT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LANDLOT"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Make feature layers</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'fc'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer<SPAN class="punctuation token">(</SPAN>Dist_LL<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Dist_LL'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> fields<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">is</SPAN> None<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByLocation_management <SPAN class="punctuation token">(</SPAN>fc_layer<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'INTERSECT'</SPAN><SPAN class="punctuation token">,</SPAN> Dist_LL_lyr<SPAN class="punctuation token">)</SPAN>
select_records <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>Dist_LL_lyr<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> select_records
<SPAN class="keyword token">print</SPAN> row
<SPAN class="keyword token">elif</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">is</SPAN> None<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> row
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">continue</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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Robert