I'm dealing with vector data in which the square outline of a house has been cut out of the polygon. Is there a specific way to select the polygons that have or do not have this cutout?
I'm not sure if there's a way to do it with standard tools, but I know of a way using Python given that in a polygon with holes, null point values (None in Python) separate the outer ring from inner rings:
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">findHoles</SPAN><SPAN class="punctuation token">(</SPAN>polygonLayerName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Get the layer from the current map document.</SPAN> mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN> lyrList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> polygonLayerName<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>lyrList<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Layer not found"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> layer <SPAN class="operator token">=</SPAN> lyrList<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># Iterate through the layer's features.</SPAN> oidList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</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>layer<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"OID@"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@"</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> polygon <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> partIdx <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> polygon<SPAN class="punctuation token">.</SPAN>partCount<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> None <SPAN class="keyword token">in</SPAN> list<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">.</SPAN>getPart<SPAN class="punctuation token">(</SPAN>partIdx<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> oidList<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>row<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">break</SPAN> <SPAN class="comment token"># Select the features and refresh the view.</SPAN> layer<SPAN class="punctuation token">.</SPAN>setSelectionSet<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"NEW"</SPAN><SPAN class="punctuation token">,</SPAN> oidList<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<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>
I would put the houses back in as a polygon layer and the do a select by location to find the polygons that don't have a house.
This is yet another example where file geodatabases fall down (I am getting more and more down on file geodatabases, Esri really needs to update them). Enterprise geodatabases provide more options here. For example with SQL Server, the following in the WHERE clause of the Select By Attributes dialog would work (assuming the shape file is "shape":
SHAPE<SPAN class="punctuation token">.</SPAN>STNumInteriorRing<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.