相交但不包含DotSpatial中另一个功能的功能

时间:2015-03-02 05:56:47

标签: contains intersection dotspatial

我需要DotSpatial中未完全包含的相交功能。如果我使用feature.Intersects(),它会为我提供相交和包含的功能,当我使用feature.Contains()时,它会为我提供刚才包含的功能。

我是这样手动完成的。

feature1.Intersects(feature2) && !feature1.Contains(feature2)

DotSpatial有任何方法可以直接执行此操作吗?

1 个答案:

答案 0 :(得分:2)

所以为了做到这一点,不必同时执行Intersects和" Not Contains"测试,你可以使用Touches。从您可以在此处找到的入门指南:Getting Started Guide触摸应该具有您想要的定义。请注意,在底部的示例中,即使考虑了所有的县,Placer县本身也不会出现在结果集中,但是它周围的每个县都会出现。

enter image description here

    IFeatureSet counties;
    IFeature placer;

    private void Form1_Load(object sender, EventArgs e)
    {
        // Open a FeatureSet from a shapefile containing Counties
        counties = Shapefile.Open("D:\\Data\\Counties\\CntyBnds_ESRI.shp");

        // Loop through the features to find the Feature with the Name equal to "Placer"
        foreach (IFeature f in counties.Features)
        {
            if (f.DataRow["NAME"].ToString() == "Placer")
            {
                placer = f;
                break;
            }
        }

        // Add the counties layer to the map to show all the counties
        this.map1.Layers.Add(counties);
    }

    private void button1_Click(object sender, EventArgs e)
    {

        FeatureSet result = new FeatureSet();

        // Cycle thorugh the shapes using the Touches operation
        foreach (IFeature county in counties.Features)
        {
            if (county.Touches(placer))
            {
                // Add only the features that touch to the result dataset.
                result.AddFeature(county);
            }
        }

        // Add the result to the map.
        this.map1.Layers.Add(result);
    }

enter image description here