Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Sometimes backwards is beautiful. I can see that working, will implement tomorrow. Cheers Paul. –  Whytefish Jul 8 at 13:05

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.

share|improve this answer
    
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 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 at 22:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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