2015-03-02 54 views
2

我只需要相互交叉的功能未完全包含在DotSpatial中。如果我使用feature.Intersects(),它给了我相交和包含的功能,当我使用feature.Contains()时,它给了我只是包含的功能。相交但不包含DotSpatial中另一个功能的功能

我已经这样手动完成了。

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

DotSpatial是否有任何方法直接做到这一点?

回答

2

所以为了做到这一点而不必执行相交和“不包含”测试,您可以使用触摸。从您可以在这里找到的入门指南:Getting Started Guide触摸应该有你想要的定义。在底部的例子中注意到,尽管考虑了所有的县,普莱塞县本身并没有出现在结果集中,但是它周围的每个县都有。

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