Search code examples
nettopologysuite

Computing an event offset using NetTopologySuite?


Does NetTopologySuite have the tools necessary to compute a point a given distance along and away from a polyline offset in a perpendicular direction?

This would be for placing signs on a map that are described as 3.1 miles along route 242, 50 feet from the centerline. I've discovered NetTopologySuite.Geometries.Triangle.PerpendicularBisector, but it's not making much sense to me (seems to return a formula for the perpendicular line).


Solution

  • To get a single point offset off a lineal geometry you should use LocationIndexedLine:

    var gf = new NetTopologySuite.Geometries.GeometryFactory();
    var l = gf.CreateLineString(new GeoAPI.Geometries.Coordinate[]
    {
        new GeoAPI.Geometries.Coordinate(10, 10),
        new GeoAPI.Geometries.Coordinate(1000, 10),
    });
    
    var lid = new NetTopologySuite.LinearReferencing.LocationIndexedLine(l);
    var p = lid.ExtractPoint(500, 10);
    

    p is at (510, 20)