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 would expect ISpatialFilter.SpatialRelDescription to behave consistently with IRelationalOperator.Relation. However, when I run the code below, I get:

    Total features : 44368
    Count1: 9 T********
    Count2: 9 T********
    Count1: 21 F********
    Count2: 44359 F********
    Count1: 1 ******F**
    Count2: 1 ******F**

Is this a bug in the F******** relation ?

private void TestSpatialFilter()
{
    IMxDocument mxdoc = ((IApplication)m_application).Document as IMxDocument;
    IFeatureLayer fLayer = mxdoc.FocusMap.get_Layer(0) as IFeatureLayer;
    IEnvelope env = ((IActiveView)mxdoc.FocusMap).Extent;
    env.Expand(0.5, 0.5, true);
    env.Project(((IGeoDataset)fLayer.FeatureClass).SpatialReference);
    Debug.Print("Total features : {0}", fLayer.FeatureClass.FeatureCount(null));
    IFeatureClass fc = fLayer.FeatureClass;
    string[] rels = { "T********", "F********", "******F**" };
    foreach (string rel in rels)
    {
        Debug.Print("Count1: {0} {1}", Count1(fc, env, rel), rel);
        Debug.Print("Count2: {0} {1}", Count2(fc, env, rel), rel);
    }
}

public static int Count1(IFeatureClass fc, IGeometry geom,  string relDescription)
{
    ISpatialFilter sf = new SpatialFilterClass();
    sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation;
    sf.SpatialRelDescription = relDescription;
    sf.Geometry = geom;
    int i = fc.FeatureCount(sf);
    Marshal.FinalReleaseComObject(sf);
    return i;
}
public static int Count2(IFeatureClass fc, IGeometry geom, string relDescription)
{
    int i = 0;
    string relation = String.Format("RELATE(G1,G2,'{0}')", relDescription);
    IRelationalOperator relOp = geom as IRelationalOperator;

    IFeatureCursor fCur = fc.Search(null, false);
    IFeature feat;
    while ((feat = fCur.NextFeature()) != null)
    {
        if(relOp.Relation(feat.Shape,relation))
            i++;
    }
    Marshal.FinalReleaseComObject(fCur);
    return i;
}
share|improve this question
1  
sorry, no answer but +1 for the geospatial humor –  bFlood Aug 12 '10 at 14:14

1 Answer 1

up vote 2 down vote accepted

That does seem a bit odd. Perhaps it was only tested with few specific operations, Ex: Intersects, Disjoint, etc? What does FF*FF**** (inverse of T********) do for you? I seem to remember Within not working a few versions back so it does not surprise me.

share|improve this answer
1  
That seems to work. If spatial is so special, it sure seems like it should receive better QA. –  Kirk Kuykendall Aug 31 '10 at 17:48

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.