I have a feature class that contains one polygon feature, and I need to check if said feature lies completely within another polygon feature.
Used selectLayerByLocation and then retrieved the count (arcpy.GetCount_management) for some other intersection based checks that need to be done; in this case however there is only ever one feature in the feature class and retrieving the count will only return one (regardless of if the polygon is fully contained or not).
Any ideas?
2 Answers 2
The Select Layer By Location (Data Management) tool has various overlap_type values that you can use so I think you should try:
COMPLETELY_CONTAINS —The features in the input layer will be selected if they completely contain a selecting feature. The input features must be polygons.
An "amusing" way to solve the issue of there being only one feature in your input feature class would be to make a feature layer to select every feature (in this case, 1) and then run select layer by location with the parameter selection_type="REMOVE_FROM_SELECTION"
. Then, GetCount() will return a 0 if the feature is indeed within the polygon (selected and therefore removed) and a 1 if it is not.
A bit backwards, so just cast to int and not
the result if you want your 0 to be a 1.