SharpMap is a great Open Source library, and NTS is proud to have a connector, allowing you to accomplish specialized topologic tasks, which are not yet implemented in SharpMap (although many seem to be in the works!). Here's an example of how one could get all features that TRULY intersect each other.


// this will return an ArrayList of object IDs for geometries
// that intersect the passed geometry. (C#)
public ArrayList TrueGeomsIntersect(SharpMap.Data.Providers.ShapeFile sf,
SharpMap.Geometries.Geometry isect)
{
ArrayList retval = new ArrayList();

// convert the test geometry to NTS.
GisSharpBlog.NetTopologySuite.Geometries.Geometry isectPt =
SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(isect,
new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory());
    
//this will filter out all the unreasonable geometries
//before we do more complex intersection testing.
System.Collections.Generic.List ids =
sf.GetObjectIDsInView(isect.GetBoundingBox());

// loop through all the candidate geometries (a reduced set,
// from the "filter" we just ran.),test intersection
bool doesIntersect = false;
foreach (uint id in ids)
{
//convert the candidate geometry to NTS
GisSharpBlog.NetTopologySuite.Geometries.Geometry geom =
SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(sf.GetGeometryByID(id),
new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory());
doesIntersect = geom.Contains(isectPt);
if (doesIntersect == true)
{
retval.Add(id);
}
}
return retval;
}