Select to view content in your preferred language

ISpatialFilter SpatialRelDescription find points not in polygon

1159
6
01-19-2012 04:57 AM
AlexanderGray
Honored Contributor
Hi there,
I have a point featureclass (not M or Z aware) and a polygon.  I want to use a spatial query to find all the points not in the polygon.  As far as I can tell only the spatialRelDescription will do this.  The problem is I get inconsistent results.  Some points are found as expected other are not.

I used the following string:
"F********"
"******T**"

It finds some of the points but never all of the points.  I am somewhat perplexed.

The alternative is to loop through all the point and use a relational operator but that seems like it would be slower.  The SpatialRelDescription should work.
0 Kudos
6 Replies
NeilClemmons
Honored Contributor
Do the search geometry and the featureclass have the same spatial reference?  If not, you'll need to project the search geometry into the same spatial reference as the featureclass you're searching.  Alternately, you can set the OutputSpatialReference property on the spatial filter object.  Trying to set the description string can be confusing and there have been bugs found in the past, so you may ultimately have to log an incident with ESRI to get to the bottom of it.
0 Kudos
AlexanderGray
Honored Contributor
Thanks Neil,

The polygon and featureclass both have the same spatial reference which is a custom polar stereographic.  I have had a bad experience going to esri support about the spatialreldescription in the past.  I was told that their topologist had just left and they were waiting to get a new one to fix the problem, later the issue was closed because they refused to acknowledge that the behaviour of the method was incorrect.  To be honest I think the help on the subject is really poor, so I often have a hard time figuring out if my strings are correct in the first place.

Cheers
0 Kudos
NeilClemmons
Honored Contributor
Thanks Neil,

To be honest I think the help on the subject is really poor, so I often have a hard time figuring out if my strings are correct in the first place.

Cheers


That's the problem I've had when trying to use it.  One thing you might try is to use IFeatureSelection to select the points you want.  Call SelectFeatures once to select all features then call it again to subtract the points inside the polygon.  It will be slower than using a single query but it should work.
0 Kudos
AlexanderGray
Honored Contributor
Thanks again Neil,
I am doing it on the featureclass level to delete unwanted points in the featureclass and I have some attribute criteria along with the spatial constraints.  The code is called inside of arcmap but also in an exe.  Reversing the selection would mean also reversing my attribute query.  There shouldn't be more than a few hundred points meeting the attribute constraint, so I think I will just use the Irelationaloperator.disjoint on each point.  Not the most efficient but probably easier to support in the long term. 
I just find it annoying that the spatialfilter spatial relationship enum is very limited and the shape comparison language is poorly implemented.
0 Kudos
LanceShipman
Esri Regular Contributor
What version of ArcGIS are you using? There is a bug in spatialRelDescription at 10.0 that is fixed in 10.0 sp4.
0 Kudos
AlexanderGray
Honored Contributor
I am using SP2.  I am probably going to be stuck at SP2 for a long time because NIM074169 has been declined, the solution being: "Use SP2".  I hope this is not the solution for 10.1 or we will be permanently stuck and 10.0 SP2.

http://support.esri.com/en/bugs/nimbus/TklNMDc0MTY5
0 Kudos