This project is read-only.

How do I calculate the intersection of a non rectangle polygon with a shapefile?

Jul 14, 2014 at 3:58 AM
I have a polygon shape (eg. a circle) and I want to generate a list of all the Features from a shapefile that this polygon will be overlapping with. How do I achieve that?

Looking at the the Select function on the FeatureSet, it seems I can only pass in an Extent which extends an IRectangle interface.
Jul 14, 2014 at 10:16 PM
Just circle over all the features in your shapefile and check which intersect with your circleShape like this:
 Shape circleShape;
 IGeometry poly = circleShape.ToGeometry();
 List<IFeature> result = new List<IFeature>();
 FeatureSet FS;
 for (int i = 0; i < FS.Features.Count; i++)
        if (FS.Features[i].Intersects(poly))
Jul 16, 2014 at 12:19 AM
I tried that approach.
var cords = new List<DotSpatial.Topology.Coordinate>() { .. .. };
var circle = new Feature(DotSpatial.Topology.FeatureType.Polygon, coords);
var circleShape = new DotSpatial.Data.Shape(feature: circle);
The issue is that constuctor of the Feature class that takes in coordinates, sets the datarow field of the feature to be null
and the constructor of shape class that takes in a Feature tries to access the ItemArray property of the datarow thus throwing a NullReferenceException
      public Shape(IFeature feature)
            : this((IBasicGeometry)feature)
            if (Equals(feature, null))
                throw new ArgumentNullException("feature");
            if (feature.NumPoints == 0)
                throw new ArgumentOutOfRangeException("feature", "The IFeature.NumPoints of the parameter feature must be greater than 0.");
            _attributes = feature.DataRow.ItemArray;
Jul 16, 2014 at 8:14 AM
If you do not need the circleFeature for anything else just do it like this:
var cords = new List<DotSpatial.Topology.Coordinate>() { .. .. };
IGeometry geo = new Polygon(cords);
If you need the Feature, create it with the help of the FeatureLayer it belongs to:
IFeaturelayer pFLayer;
IFeature circle = pFLayer.DataSet.AddFeature(new Polygon(cords));