private static void DouglasPeukerReductionIterator(int firstPnt, int lastPnt, double tolerance, Line myLine) { double maxDistance = 0; int farthestIndex = 0; double distance; for (int i = firstPnt; (i < (lastPnt - 1)); i++) { distance = Point.PerpendicularDistance(myLine.getPoint(firstPnt), myLine.getPoint(lastPnt), myLine.getPoint(i)); if ((distance > maxDistance)) { maxDistance = distance; farthestIndex = i; } } if (((maxDistance > tolerance) & (farthestIndex != 0))) { reducedLineIndices.Add(farthestIndex); LineThinner.DouglasPeukerReductionIterator(firstPnt, farthestIndex, tolerance, myLine); LineThinner.DouglasPeukerReductionIterator(farthestIndex, lastPnt, tolerance, myLine); } }
static void Main(string[] args) { Console.WriteLine("Begin"); Properties props = new Properties(); string currentDirectory = Directory.GetCurrentDirectory(); string propertiesFileName = currentDirectory + "\\properties.txt"; string USGSSiteInformationDownloadURL = "https://waterservices.usgs.gov/nwis/site/?format=rdb&sites=01646500&siteStatus=all"; props.read(propertiesFileName); bool dataExists; foreach (Gage gage in props.MyGages) { gage.DownloadRatingCurve(gage.USGSRatingCurveURL, currentDirectory + "\\" + gage.gageNumber.ToString() + ".txt"); dataExists = gage.ParseRatingCurveTextfile(currentDirectory + "\\" + gage.gageNumber.ToString() + ".txt"); if (dataExists) { gage.ratingCurveRaw = LineThinner.DouglasPeukerReduction(gage.ratingCurveRaw, .01); gage.ConvertToNAVD88(); gage.WriteToCSV(currentDirectory + "\\" + gage.gageNumber.ToString() + ".csv"); } else { //do nothing } } Console.WriteLine("Done"); }
// methods public static Line DouglasPeukerReduction(Line myLine, double tolerance) { reducedLineIndices = new List <int>(); int firstPnt = 0; int lastPnt = (myLine.getVerticesCount() - 1); Line newLine = new Line(); reducedLineIndices.Add(firstPnt); reducedLineIndices.Add(lastPnt); LineThinner.DouglasPeukerReductionIterator(firstPnt, lastPnt, tolerance, myLine); reducedLineIndices.Sort(); foreach (int index in reducedLineIndices) { Point pointToAdd = myLine.getPoint(index); newLine.AddPoint(pointToAdd); } return(newLine); }
public void thinRatingCurve() { ratingCurve = LineThinner.DouglasPeukerReduction(ratingCurve, .1); }