Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

New Post: Find all Polygons a Linestring intersects

$
0
0
You should go with NetTopologySuite's PreparedGeometry functionality. There is a conversion project between DotSpatial geometries/shapes and GeoAPI/NTS geometries if you rely on other DotSpatial functionality.

the code would then look somewhat like this:
//get line strings from somewhere
var dsLineStrings = new List<DotSpatial.Topology.ILineString>();
// get polygons from somewhere else
var dsPolygons = new Dictionary<DotSpatial.Topology.IPolygon, int>();

// build a quadtree index on the polygons
var dsQuadTree = new DotSpatial.Topology.Index.Quadtree.Quadtree();
var i = 0;
foreach (var dsPolygon in dsPolygons.Keys)
{
    dsQuadTree.Insert(dsPolygon.EnvelopeInternal, i++);
}

// iterate over all line strings
foreach (var dsLineString in dsLineStrings)
{
    // convert to GeoAPI linestring
        var lineString = dsLineString.ToGeoAPI();
        // build a prepared geometry, which is optimized for a one against many comparison
    var prepLineString = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(lineString);
        // search quad tree for polygon candidates
    foreach (var kvp in dsQuadTree.Query(dsLineString.EnvelopeInternal))
    {
                // Do intersection test and increment counter
        if (prepLineString.Intersects(kvp.Key))
        {
                        // Does this really work, I have not tried.
            dsPolygons[kvp.Key]++;
        }
    }
}

Viewing all articles
Browse latest Browse all 3973

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>