示例#1
0
文件: OsmFile.cs 项目: Levrum/Levrum
        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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
文件: OsmFile.cs 项目: Levrum/Levrum
        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);
                    }
                }
            }
        }