public List <OSMWay> GetWaysIntersectingLine(LatitudeLongitude point1, LatitudeLongitude point2) { List <OSMWay> output = new List <OSMWay>(); try { foreach (OSMWay way in Ways) { if (way.BoundingBox.IntersectsLine(point1, point2)) { for (int i = 0; i < way.NodeReferences.Count - 1; i++) { OSMNode thisNode, thatNode; if (!NodesById.TryGetValue(way.NodeReferences[i], out thisNode) || !NodesById.TryGetValue(way.NodeReferences[i + 1], out thatNode)) { continue; } Point2 intersectionPoint = LineSegment2.Intersection(point1, point2, thisNode.Location, thatNode.Location); if (intersectionPoint != null) { output.Add(way); } } } } return(output); } catch (Exception ex) { LogHelper.LogException(ex, "Error getting intersecting ways", true); } return(output); }
public bool IntersectsLine(LatitudeLongitude point1, LatitudeLongitude point2) { try { Point2 westIntersection = LineSegment2.Intersection(point1.Longitude, point1.Latitude, point2.Longitude, point2.Latitude, MinLon, MaxLat, MinLon, MinLat); Point2 southIntersection = LineSegment2.Intersection(point1.Longitude, point1.Latitude, point2.Longitude, point2.Latitude, MinLon, MinLat, MaxLon, MinLat); Point2 eastIntersection = LineSegment2.Intersection(point1.Longitude, point1.Latitude, point2.Longitude, point2.Latitude, MaxLon, MaxLat, MaxLon, MinLat); Point2 northIntersection = LineSegment2.Intersection(point1.Longitude, point1.Latitude, point2.Longitude, point2.Latitude, MinLon, MaxLat, MaxLon, MaxLat); return(westIntersection != null || southIntersection != null || eastIntersection != null || northIntersection != null); } catch (Exception ex) { LogHelper.LogException(ex, "Error testing line intersection", false); return(false); } }
private void searchWayForIntersectionAndSplit(OSMWay way, LatitudeLongitude point1, LatitudeLongitude point2) { if (way.BoundingBox.IntersectsLine(point1, point2)) { for (int i = 0; i < way.NodeReferences.Count - 1; i++) { OSMNode thisNode, thatNode; if (!NodesById.TryGetValue(way.NodeReferences[i], out thisNode) || !NodesById.TryGetValue(way.NodeReferences[i + 1], out thatNode)) { continue; } Point2 intersectionPoint = LineSegment2.Intersection(point1, point2, thisNode.Location, thatNode.Location); if (intersectionPoint != null) { splitWayByLine(way, point1, point2, thisNode.Location, thatNode.Location, i, intersectionPoint); } } } }