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.

  • Yeah that's the type I used, my issue is that there is only one feature in the dataset and getCount_management returns one either way (if there is no selection it returns the number of features). Any idea on an alternative?
    – Whytefish
    Jul 8, 2014 at 12:24
  • @user33279 It was not clear from your question what parameters you had used so I had to take a guess that you had overlooked this.
    – PolyGeo
    Jul 8, 2014 at 22:21

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.

  • Sometimes backwards is beautiful. I can see that working, will implement tomorrow. Cheers Paul.
    – Whytefish
    Jul 8, 2014 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.