public static void CloseSplittedPolygons(AreaBaseShape sourcePolygon, MultipolygonShape splitedPolygon, LineShape splitLine, GeographyUnit mapUnit, DistanceUnit distanceUnit, double distance)
        {
            var multiline = splitLine.GetIntersection(sourcePolygon);

            foreach (var vertex in multiline.Lines.SelectMany(l => l.Vertices))
            {
                var closeArea = new PointShape(vertex).Buffer(distance, mapUnit, distanceUnit).GetBoundingBox();
                foreach (var polygon in splitedPolygon.Polygons)
                {
                    CloseSplittedRing(vertex, closeArea, polygon.OuterRing);
                    foreach (var ring in polygon.InnerRings)
                    {
                        CloseSplittedRing(vertex, closeArea, ring);
                    }
                }
            }
        }
예제 #2
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            PointShape start = Points[((ComboBoxItem)cmbStart.SelectedItem).Content.ToString()];
            PointShape end   = Points[((ComboBoxItem)cmbEnd.SelectedItem).Content.ToString()];

            LineShape startSegment = GetNearestSegment(start);
            LineShape endSegment   = GetNearestSegment(end);

            LineShape route = new LineShape();

            if (startSegment.Id == endSegment.Id)
            {
                route = startSegment.GetLineOnALine(start, end) as LineShape;
            }
            else
            {
                double         tolerance        = double.Parse(txtTolerance.Text, CultureInfo.InvariantCulture);
                PolygonShape   bufferedPolygon  = endSegment.Buffer(tolerance, GeographyUnit.DecimalDegree, DistanceUnit.Meter).Polygons[0];
                MultilineShape intersectedLines = startSegment.GetIntersection(bufferedPolygon) as MultilineShape;
                if (intersectedLines.Lines.Count > 0)     // Just check the intersected within allowed tolerance.
                {
                    PointShape intersectedPoint = intersectedLines.Lines[0].GetCenterPoint();

                    PointShape nearestPointOnStart = intersectedPoint.GetClosestPointTo(startSegment, GeographyUnit.DecimalDegree);
                    PointShape nearestPointOnEnd   = intersectedPoint.GetClosestPointTo(endSegment, GeographyUnit.DecimalDegree);

                    LineShape routeSegmentOnStart = startSegment.GetLineOnALine(start, nearestPointOnStart) as LineShape;
                    LineShape routeSegmentOnEnd   = endSegment.GetLineOnALine(end, nearestPointOnEnd) as LineShape;

                    IEnumerable <Vertex> vertexs = route.Vertices;
                    int index = IndexOf(routeSegmentOnStart.Vertices, new Vertex(nearestPointOnStart));
                    if (index == 0)
                    {
                        vertexs = vertexs.Concat(routeSegmentOnStart.Vertices.Reverse());
                    }
                    else
                    {
                        vertexs = vertexs.Concat(routeSegmentOnStart.Vertices);
                    }

                    index = IndexOf(routeSegmentOnEnd.Vertices, new Vertex(nearestPointOnEnd));
                    if (index == 0)
                    {
                        vertexs = vertexs.Concat(routeSegmentOnEnd.Vertices);
                    }
                    else
                    {
                        vertexs = vertexs.Concat(routeSegmentOnEnd.Vertices.Reverse());
                    }

                    route = new LineShape(vertexs);
                }
            }

            routeResultLayer.InternalFeatures.Clear();
            if (route.Vertices.Count > 1)
            {
                routeResultLayer.InternalFeatures.Add(new Feature(route));
            }
            else
            {
                MessageBox.Show("No Route Found.");
            }

            Map1.Refresh();
        }