2

I need just intersected features not fully contained in DotSpatial. If I use feature.Intersects(), it gives me intersected and contained features and when I use feature.Contains(), it gives me just contained features.

I have done it manually like this.

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

Does DotSpatial have any method to do that directly?

Moshi
  • 1,385
  • 2
  • 17
  • 36

1 Answers1

2

So in order to do this without having to perform both an Intersects and a "Not Contains" test, you can use Touches. From the Getting Started Guide that you can find here: Getting Started Guide Touches should have the definition you want. Notice in the example at the bottom that even though all the counties are considered, Placer county itself does not appear in the result set, but every county around it does.

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

Ted
  • 3,212
  • 25
  • 20