2015-03-02 96 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