コード例 #1
0
        public static IEnumerable <IPoint> Execute(IPolygon poly1, IPolygon poly2)
        {
            foreach (IPoint point in poly1.GetCoordinates().First())
            {
                if (PointInPolygon.Execute(point, poly2))
                {
                    yield return(point);
                }
            }
            foreach (IPoint point in poly2.GetCoordinates().First())
            {
                if (PointInPolygon.Execute(point, poly1))
                {
                    yield return(point);
                }
            }
            IEnumerable <IPoint> intersections = LineIntersect.Execute(PolygonToLine.Execute(poly1), PolygonToLine.Execute(poly2));

            if (intersections != null && intersections.Count() > 0)
            {
                foreach (IPoint point in intersections)
                {
                    yield return(point);
                }
            }
        }
コード例 #2
0
        public static bool ExecuteBoolean(IPolygon poly1, IPolygon poly2)
        {
            foreach (IPoint point in poly1.GetCoordinates().First())
            {
                if (PointInPolygon.Execute(point, poly2))
                {
                    return(true);
                }
            }
            foreach (IPoint point in poly2.GetCoordinates().First())
            {
                if (PointInPolygon.Execute(point, poly1))
                {
                    return(true);
                }
            }

            IEnumerable <IPoint> intersections = LineIntersect.Execute(PolygonToLine.Execute(poly1), PolygonToLine.Execute(poly2));

            if (intersections != null && intersections.Count() > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #3
0
        public static IEnumerable <IPoint> Execute(IEnumerable <IPoint> line, IPolygon poly)
        {
            IPoint    previous    = null;
            IGeometry polygonLine = PolygonToLine.Execute(poly);

            foreach (IPoint point in line)
            {
                if (PointInPolygon.Execute(point, poly))
                {
                    yield return(point);
                }
                if (previous != null)
                {
                    IEnumerable <IPoint> intersections = LineIntersect.Execute(LineString.Create(previous, point), polygonLine);
                    if (intersections != null)
                    {
                        foreach (IPoint intersection in intersections)
                        {
                            yield return(intersection);
                        }
                    }
                }

                previous = point;
            }
        }
コード例 #4
0
        public static bool ExecuteBoolean(IMultiLine line1, IMultiLine line2)
        {
            IEnumerable <IPoint> intersections = LineIntersect.Execute(line1, line2);

            if (intersections != null && intersections.Count() > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #5
0
        public static IEnumerable <IPoint> Execute(IMultiLine line1, IMultiLine line2)
        {
            IEnumerable <IPoint> intersections = LineIntersect.Execute(line1, line2);

            if (intersections != null && intersections.Count() > 0)
            {
                return(intersections);
            }
            return(null);
        }
コード例 #6
0
        public static bool ExecuteBoolean(IEnumerable <IPoint> line, IPolygon poly)
        {
            foreach (IPoint point in line)
            {
                if (PointInPolygon.Execute(point, poly))
                {
                    return(true);
                }
            }
            IEnumerable <IPoint> intersections = LineIntersect.Execute(LineString.Create(line.ToArray()), PolygonToLine.Execute(poly));

            if (intersections != null && intersections.Count() > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #7
0
        public static Result Execute(IPoint point = null, IGeometry lines = null)
        {
            if (point == null)
            {
                throw new Exception("point is a required parameter");
            }
            if (lines == null)
            {
                throw new Exception("lines is a required parameter");
            }

            IPoint closestPoint         = new Point(Double.PositiveInfinity, Double.PositiveInfinity);
            double closestPointDistance = Double.PositiveInfinity;
            double closestPointLocation = Double.PositiveInfinity;

            int closestPointIdx = -1;


            double length = 0.0;

            foreach (IEnumerable <IPoint> line in lines.GetCoordinates())
            {
                IPoint start = null, end = null;
                int    startIdx = -1, endIdx = -1;
                foreach (IPoint coord in line)
                {
                    start    = end;
                    startIdx = endIdx;
                    end      = coord;
                    endIdx++;
                    if (start == null)
                    {
                        continue;
                    }
                    double startDistance = point.DistanceTo(start);
                    double endDistance   = point.DistanceTo(end);
                    double sectionLength = start.DistanceTo(end);

                    double intersectDistance = double.PositiveInfinity;
                    double intersectlocation = double.PositiveInfinity;

                    double bearing     = start.BearingTo(end);
                    double maxDistance = Math.Max(startDistance, endDistance);

                    IPoint ppt1 = point.Destination(maxDistance, bearing + 90);
                    IPoint ppt2 = point.Destination(maxDistance, bearing - 90);

                    IEnumerable <IPoint> intersect = LineIntersect.Execute(
                        LineString.Create(ppt1, ppt2),
                        LineString.Create(start, end));

                    IPoint intersectPt = null;
                    if (intersect.Count() > 0)
                    {
                        intersectPt       = intersect.First();
                        intersectDistance = point.DistanceTo(intersectPt);
                        intersectlocation = length + start.DistanceTo(intersectPt);
                    }

                    if (startDistance < closestPointDistance)
                    {
                        closestPoint         = start;
                        closestPointIdx      = startIdx;
                        closestPointLocation = length;
                        closestPointDistance = startDistance;
                    }

                    if (endDistance < closestPointDistance)
                    {
                        closestPoint         = end;
                        closestPointIdx      = endIdx;
                        closestPointLocation = length + sectionLength;
                        closestPointDistance = endDistance;
                    }

                    if (intersectPt != null && intersectDistance < closestPointDistance)
                    {
                        closestPoint         = intersectPt;
                        closestPointIdx      = startIdx;
                        closestPointDistance = intersectDistance;
                        closestPointLocation = intersectlocation;
                    }

                    length += sectionLength;
                }
            }

            return(Result.Create(closestPoint, closestPointDistance, closestPointLocation));
        }