private ILinearRing Translate(ILinearRing input) { return(new LinearRing( input.Coordinates .Select(c => MyNetTopologySuiteUtils.ToVector2(c)) .Select(c => _translator.TranslateToUnity(c)) .Select(c => MyNetTopologySuiteUtils.ToCoordinate(c)) .ToArray() )); }
//19.64311408996582 49.603153228759766 // 1914206496 // 180998242 //19.71388099829122, 49.648193645648 // 19.628429388931949, 49.617853376339596 private ILinearRing ToLinearRing(List <Vector2> nodes) { var nodesAsCoordinates = nodes.Select(c => MyNetTopologySuiteUtils.ToCoordinate(c)).ToList(); if (!nodesAsCoordinates.First().Equals(nodesAsCoordinates.Last())) { var repairedRing = nodesAsCoordinates.ToList(); repairedRing.Add(nodesAsCoordinates.First()); var ring = new LinearRing(repairedRing.ToArray()); if (!ring.IsValid) { //simple connection failed. Propably should do crectangle merging var ringRect = ring.EnvelopeInternal; Debug.Log("Pushing your luck. Lets hope that it is his only, 2415555 relation!"); //todo make better invalid circular way repairing algorithm. Like find which two sides // of enveloping rectangle would be shorted in repairing road var newRingPoint = ringRect.ToMyRectangle().TopRightPoint; repairedRing[repairedRing.Count - 1] = new Coordinate(newRingPoint.x, newRingPoint.y); repairedRing.Add(nodesAsCoordinates.First()); ring = new LinearRing(repairedRing.ToArray()); if (!ring.IsValid) { var validOp = new IsValidOp(ring); Debug.Log("Validation error is: " + validOp.ValidationError); Debug.Log("R1 Ring is " + ring.ToString()); return(null); //var text = ring.ToText(); //File.WriteAllText(@"C:\inz\wrongRing.wkt", text); } Preconditions.Assert(ring.IsValid, "Ring still invalid. What to do?"); } return(ring); } else { return(new LinearRing(nodesAsCoordinates.ToArray())); } }