Radial Distance Simplifier

23 views
Skip to first unread message

Harel Mazor

unread,
Dec 13, 2016, 7:15:37 AM12/13/16
to NetTopologySuite
Hi,
I have written a short class for radial distance simplifier that is somewhat similar to the interface the D-P simplifier is exposing.
The code is very simple and can be written better, but the idea is what's important here.
Feel free to use this code any way you want.

public class RadialDistanceSimplifier
   {
       private readonly IGeometry _geometry;
       public double DistanceTolerance { get; set; }

        public RadialDistanceSimplifier(IGeometry geometry)
       {
           _geometry = geometry;
       }

        public ILineString GetResultGeometry()
       {
           var coordinates = _geometry.Coordinates;
           if (coordinates.Length == 0)
           {
               // throw?
               return null;
           }
           var simplified = new List<Coordinate> {coordinates.First()};
           foreach (var coordinate in coordinates.Skip(1))
           {
               if (coordinate.Distance(simplified.Last()) > DistanceTolerance)
               {
                 simplified.Add(coordinate);
                }
                   
           
}
            return simplified.Count <= 1 ? null : new LineString(simplified.ToArray());
       }
    }
Reply all
Reply to author
Forward
0 new messages