Esempio n. 1
0
        private void btnSplitLine_Click(object sender, EventArgs e)
        {
            LayerOverlay  layerOverLay  = (LayerOverlay)winformsMap1.Overlays[1];
            MapShapeLayer mapShapeLayer = (MapShapeLayer)layerOverLay.Layers[0];

            LineShape lineShape  = (LineShape)mapShapeLayer.MapShapes["Line1"].Feature.GetShape();
            LineShape lineShape2 = (LineShape)mapShapeLayer.MapShapes["Line2"].Feature.GetShape();

            //Gets the crossing MultipointShape with the PointShape that will be used to calculate the two split lines.
            MultipointShape multipointShape = lineShape.GetCrossing(lineShape2);

            //Uses the GetLineOnLine (Dynamic Segmentation) to get the two split lines from the intersection point.
            LineShape splitLineShape1 = (LineShape)lineShape.GetLineOnALine(StartingPoint.FirstPoint, multipointShape.Points[0]);
            LineShape splitLineShape2 = (LineShape)lineShape.GetLineOnALine(StartingPoint.LastPoint, multipointShape.Points[0]);

            //Displays the two split lines with different colors to distinguish them.
            MapShape splitMapShape1 = new MapShape(new Feature(splitLineShape1));

            splitMapShape1.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Orange, 3, true);
            splitMapShape1.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("SplitLine1", splitMapShape1);

            MapShape splitMapShape2 = new MapShape(new Feature(splitLineShape2));

            splitMapShape2.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Turquoise, 3, true);
            splitMapShape2.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("SplitLine2", splitMapShape2);

            //Displays the intersection point as a reference.
            MapShape pointMapShape = new MapShape(new Feature(multipointShape.Points[0]));

            pointMapShape.ZoomLevels.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle,
                                                                                                        GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 1, 9);
            pointMapShape.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("Point", pointMapShape);

            winformsMap1.Refresh(layerOverLay);

            btnSplitLine.Enabled = false;
        }
Esempio n. 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();
        }