private void UpdateGeometry(string operation, double segmentLength, double deviation)
        {
            // Start with the original polyline.
            Polyline polyline = _originalPolyline;

            // Apply the selected operation.
            if (operation == "Generalize")
            {
                // Reset the other slider.
                _segmentLengthSlider.Progress = 0;

                polyline = (Polyline)GeometryEngine.Generalize(polyline, deviation, true);

                // Update the result label.
                _resultLabel.Text = $"Operation: Generalize, Deviation: {deviation:f}";
            }
            else
            {
                // Reset the other slider.
                _deviationSlider.Progress = 0;

                polyline = (Polyline)GeometryEngine.Densify(polyline, segmentLength);

                // Update the result label.
                _resultLabel.Text = $"Operation: Densify, Segment length: {segmentLength:f}";
            }

            // Update the graphic geometries to show the results.
            _resultPolylineGraphic.Geometry = polyline;
            _resultPointGraphic.Geometry    = new Multipoint(polyline.Parts.SelectMany(m => m.Points));
        }
예제 #2
0
        private void OnUIChanged(object sender, EventArgs e)
        {
            // Start with the original polyline.
            Polyline polyline = _originalPolyline;

            // Reset the slider if the operation is changed.
            if (sender is UISegmentedControl)
            {
                _slider.Value = 100.0F;
            }

            // Apply the selected operation.
            if (_operationPicker.SelectedSegment == 0)
            {
                polyline = (Polyline)GeometryEngine.Densify(polyline, _slider.Value);

                // Update the result label.
                _resultLabel.Text = $"Densify - Segment length: {_slider.Value:f}";
            }
            else
            {
                polyline = (Polyline)GeometryEngine.Generalize(polyline, _slider.Value, true);

                // Update the result label.
                _resultLabel.Text = $"Generalize - Deviation: {_slider.Value:f}";
            }

            // Update the graphic geometries to show the results.
            _resultPolylineGraphic.Geometry = polyline;
            _resultPointGraphic.Geometry    = new Multipoint(polyline.Parts.SelectMany(m => m.Points));
        }
예제 #3
0
        // Generalizes the original line graphic
        private void GeneralizeButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _generalizedGraphicsOverlay.Graphics.Clear();

                var offset = DistanceSlider.Value * 1000;
                var generalizedPolyline = GeometryEngine.Generalize(
                    _originalGraphicsOverlay.Graphics[0].Geometry, offset, false) as Polyline;

                if (generalizedPolyline != null)
                {
                    var graphic = new Graphic(generalizedPolyline, _generalizedLineSymbol);
                    _generalizedGraphicsOverlay.Graphics.Add(graphic);

                    foreach (var part in generalizedPolyline.Parts)
                    {
                        foreach (var point in part.GetPoints())
                        {
                            var vertex = new Graphic(point, _generalizedMarkerSymbol);
                            _generalizedGraphicsOverlay.Graphics.Add(vertex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error generalizing line: " + ex.Message, "Generalize Sample");
            }
        }
예제 #4
0
        private void UpdateGeometry(string operation, double value)
        {
            // Start with the original polyline.
            Polyline polyline = _originalPolyline;

            // Apply the selected operation.
            if (operation == "Generalize")
            {
                polyline = (Polyline)GeometryEngine.Generalize(polyline, value, true);

                // Update the result label.
                _resultLabel.Text = $"Generalize - Deviation: {value:f}";
            }
            else
            {
                polyline = (Polyline)GeometryEngine.Densify(polyline, value);

                // Update the result label.
                _resultLabel.Text = $"Densify - Segment length: {value:f}";
            }

            // Update the graphic geometries to show the results.
            _resultPolylineGraphic.Geometry = polyline;
            _resultPointGraphic.Geometry    = new Multipoint(polyline.Parts.SelectMany(m => m.Points));
        }
        private void GeneralizeButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                generalizedGraphicsLayer.Graphics.Clear();

                var offset = DistanceSlider.Value * 1000;

                var generalizedGeometry = GeometryEngine.Generalize(originalGraphicsLayer.Graphics[0].Geometry, offset, false);
                if (generalizedGeometry != null)
                {
                    var g = new Graphic(generalizedGeometry, generalizedLineSymbol);
                    generalizedGraphicsLayer.Graphics.Add(g);

                    foreach (var part in (generalizedGeometry as Polyline).Parts)
                    {
                        foreach (var point in part.GetPoints())
                        {
                            var vertex = new Graphic()
                            {
                                Symbol   = generalizedMarkerSymbol,
                                Geometry = point
                            };
                            generalizedGraphicsLayer.Graphics.Add(vertex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Error generalizing line: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
예제 #6
0
        // Generalizes the original line graphic
        private void GeneralizeButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _generalizedGraphicsLayer.Graphics.Clear();

                var offset = DistanceSlider.Value * 1000;
                var generalizedPolyline = GeometryEngine.Generalize(_originalGraphicsLayer.Graphics[0].Geometry, offset, false) as Polyline;

                if (generalizedPolyline != null)
                {
                    var graphic = new Graphic(generalizedPolyline, _generalizedLineSymbol);
                    _generalizedGraphicsLayer.Graphics.Add(graphic);

                    foreach (var path in generalizedPolyline)
                    {
                        foreach (var coord in path)
                        {
                            var vertex = new Graphic(new MapPoint(coord, mapView.SpatialReference), _generalizedMarkerSymbol);
                            _generalizedGraphicsLayer.Graphics.Add(vertex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog("Error generalizing line: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
        private void GeneralizeButton_Click(object sender, RoutedEventArgs e)
        {
            generalizedGraphicsLayer.Graphics.Clear();
            //GeneralizeButton.IsEnabled = false;


            var offset = DistanceSlider.Value * 1000;

            var generalizedGeometry = GeometryEngine.Generalize(originalGraphicsLayer.Graphics[0].Geometry, offset, false);

            generalizedGraphicsLayer.Graphics.Clear();
            if (generalizedGeometry != null)
            {
                var g = new Graphic();
                g.Symbol   = generalizedLineSymbol;
                g.Geometry = generalizedGeometry;
                g.Geometry.SpatialReference = mapView1.SpatialReference;
                generalizedGraphicsLayer.Graphics.Add(g);

                foreach (var pc in (generalizedGeometry as Polyline).Paths)
                {
                    foreach (var point in pc)
                    {
                        var vertice = new Graphic()
                        {
                            Symbol   = generalizedMarkerSymbol,
                            Geometry = new MapPoint(point.X, point.Y)
                        };
                        generalizedGraphicsLayer.Graphics.Add(vertice);
                    }
                }
            }
        }
예제 #8
0
        // myMapView 事件
        private async void MyMapView_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            IInputElement ie  = (IInputElement)(sender);
            MapPoint      loc = myMapView.ScreenToLocation(e.GetPosition(ie));

            switch (operation)
            {
            case OperateType.DrawPoint:     //画点
                Graphic pt = new Graphic(loc, pointSymbol);
                graphicsLayer.Graphics.Add(pt);
                break;

            case OperateType.DrawPolyline:    //画线
                pointCollection.Add(loc);
                if (pointCollection.Count >= 2)
                {
                    if (pointCollection.Count > 2)
                    {
                        Graphic         g  = graphicsLayer.Graphics[graphicsLayer.Graphics.Count - 1];
                        PolylineBuilder lb = new PolylineBuilder(pointCollection);
                        g.Geometry = lb.ToGeometry();
                    }
                    else
                    {
                        Esri.ArcGISRuntime.Geometry.Polyline l = new Esri.ArcGISRuntime.Geometry.Polyline(pointCollection);
                        Graphic lg = new Graphic(l, lineSymbol);
                        graphicsLayer.Graphics.Add(lg);
                    }
                }
                break;

            case OperateType.DrawPolygon:    //画多边形
                pointCollection.Add(loc);
                if (pointCollection.Count >= 3)
                {
                    if (pointCollection.Count > 3)
                    {
                        Graphic        g  = graphicsLayer.Graphics[graphicsLayer.Graphics.Count - 1];
                        PolygonBuilder pb = new PolygonBuilder(pointCollection);
                        g.Geometry = pb.ToGeometry();
                    }
                    else
                    {
                        Esri.ArcGISRuntime.Geometry.Polygon p = new Esri.ArcGISRuntime.Geometry.Polygon(pointCollection);
                        Graphic pg = new Graphic(p, fillSymbol);
                        graphicsLayer.Graphics.Add(pg);
                    }
                }
                break;

            case OperateType.None:    //缺省状态
                graphicsLayer.ClearSelection();
                IdentifyGraphicsOverlayResult result = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                //选择图形元素
                if (result.Graphics.Count < 1)
                {
                    curSelGraphic = null;
                    EditVertexMenuItem.IsEnabled   = false;
                    UneditVertexMenuItem.IsEnabled = false;
                    return;
                }
                curSelGraphic                = result.Graphics.First();
                curSelGraphic.IsSelected     = true;
                EditVertexMenuItem.IsEnabled = true;
                break;

            case OperateType.Cal_Clip:     //选择图形
                IdentifyGraphicsOverlayResult gResult = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResult.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphic = gResult.Graphics.First();
                selGraphic.IsSelected = true; listOfClipGraphics.Add(selGraphic); //记录所选图形
                if (listOfClipGraphics.Count == 2)                                //图形数目为2时,进行剪切计算
                {
                    Graphic g1 = listOfClipGraphics[0];
                    Graphic g2 = listOfClipGraphics[1];
                    if (g1.Geometry.GeometryType != GeometryType.Polygon || g2.Geometry.GeometryType != GeometryType.Polygon)     //如果所选图形不是多边形,则退出
                    {
                        MessageBox.Show("请选择两个多边形图形!");
                        listOfClipGraphics.Clear();
                        graphicsLayer.ClearSelection();
                        return;
                    }
                    Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Clip(g1.Geometry, g2.Geometry.Extent); //执行剪切操作
                    if (resultGeometry != null)                                                                                 //处理结果
                    {
                        graphicsLayer.Graphics.Remove(g1);                                                                      //从图形层中移除原图形
                        graphicsLayer.Graphics.Remove(g2);
                        Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol);                                        //利 用剪切结果构建新的图形
                        graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;

            case OperateType.Cal_Union:     // 联合
                IdentifyGraphicsOverlayResult gResultUnion = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResultUnion.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphicUnion = gResultUnion.Graphics.First();
                selGraphicUnion.IsSelected = true;
                listOfClipGraphics.Add(selGraphicUnion); //记录所选图形
                if (listOfClipGraphics.Count == 2)       //图形数目为2时,进行剪切计算
                {
                    Graphic g1 = listOfClipGraphics[0];
                    Graphic g2 = listOfClipGraphics[1];
                    if (g1.Geometry.GeometryType != GeometryType.Polygon || g2.Geometry.GeometryType != GeometryType.Polygon)     //如果所选图形不是多边形,则退出
                    {
                        MessageBox.Show("请选择两个多边形图形!");
                        listOfClipGraphics.Clear();
                        graphicsLayer.ClearSelection();
                        return;
                    }
                    Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Union(g1.Geometry, g2.Geometry.Extent); //执行剪切操作
                    if (resultGeometry != null)                                                                                  //处理结果
                    {
                        graphicsLayer.Graphics.Remove(g1);                                                                       //从图形层中移除原图形
                        graphicsLayer.Graphics.Remove(g2);
                        Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol);                                         //利 用剪切结果构建新的图形
                        graphicsLayer.Graphics.Add(clipedGraphic);
                        operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;

            case OperateType.Cal_Cut:     // 剪切
                IdentifyGraphicsOverlayResult gResult_Cut = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResult_Cut.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphic_Cut = gResult_Cut.Graphics.First();
                selGraphic_Cut.IsSelected = true;
                listOfClipGraphics.Add(selGraphic_Cut); //记录所选图形
                if (listOfClipGraphics.Count == 2)      //图形数目为1时,进行剪切计算
                {
                    Graphic g1 = listOfClipGraphics[0];
                    Graphic g2 = listOfClipGraphics[1];
                    if (g1.Geometry.GeometryType != GeometryType.Polygon || g2.Geometry.GeometryType != GeometryType.Polyline)     //如果所选图形不是多边形,则退出
                    {
                        MessageBox.Show("请先选择一个面要素后再选择一个线要素.");
                        listOfClipGraphics.Clear();
                        graphicsLayer.ClearSelection();
                        return;
                    }
                    Esri.ArcGISRuntime.Geometry.Polyline   polyLine       = (Esri.ArcGISRuntime.Geometry.Polyline)g2.Geometry;
                    Esri.ArcGISRuntime.Geometry.Geometry[] resultGeometry = GeometryEngine.Cut(g1.Geometry, polyLine); //执行剪切操作
                    if (resultGeometry != null)                                                                        //处理结果
                    {
                        graphicsLayer.Graphics.Remove(g1);
                        for (int z = 0; z < resultGeometry.Length; z++)
                        {
                            Graphic clipedGraphic = new Graphic(resultGeometry[z], fillSymbol);     //利 用剪切结果构建新的图形
                            graphicsLayer.Graphics.Add(clipedGraphic);
                        }
                        operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;

            case OperateType.Cal_Simplify:     // 拓扑纠正
                IdentifyGraphicsOverlayResult gResult_Simplify = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResult_Simplify.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphic_Simplify = gResult_Simplify.Graphics.First();
                selGraphic_Simplify.IsSelected = true;
                listOfClipGraphics.Add(selGraphic_Simplify); //记录所选图形
                if (listOfClipGraphics.Count == 1)           //图形数目为1时,进行剪切计算
                {
                    Graphic g1 = listOfClipGraphics[0];
                    if (g1.Geometry.GeometryType == GeometryType.Point)     //如果所选图形不是多边形,则退出
                    {
                        MessageBox.Show("请先选择一个面要素或线要素.");
                        listOfClipGraphics.Clear();
                        graphicsLayer.ClearSelection();
                        return;
                    }
                    Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Simplify(g1.Geometry); //执行剪切操作
                    if (resultGeometry != null)                                                                 //处理结果
                    {
                        graphicsLayer.Graphics.Remove(g1);                                                      //从图形层中移除原图形
                        Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol);                        //利 用剪切结果构建新的图形
                        graphicsLayer.Graphics.Add(clipedGraphic);
                        operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;

            case OperateType.Cal_Gene:     // 简化
                IdentifyGraphicsOverlayResult gResult_Gene = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResult_Gene.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphic_Gene = gResult_Gene.Graphics.First();
                selGraphic_Gene.IsSelected = true;
                listOfClipGraphics.Add(selGraphic_Gene); //记录所选图形
                if (listOfClipGraphics.Count == 1)       //图形数目为1时
                {
                    Graphic g1 = listOfClipGraphics[0];
                    if (g1.Geometry.GeometryType == GeometryType.Point)     //如果所选图形是点,则退出
                    {
                        MessageBox.Show("请先选择一个面要素或线要素.");
                        listOfClipGraphics.Clear();
                        graphicsLayer.ClearSelection();
                        return;
                    }
                    Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Generalize(g1.Geometry, 1000000.0, true); //执行剪切操作
                    if (resultGeometry != null)                                                                                    //处理结果
                    {
                        MessageBox.Show(resultGeometry.ToJson() + "\n" + resultGeometry.GeometryType);
                        graphicsLayer.Graphics.Remove(g1);                               //从图形层中移除原图形
                        Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利 用剪切结果构建新的图形
                        graphicsLayer.Graphics.Add(clipedGraphic);
                        operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;

            case OperateType.Cal_Buff:     // 缓冲
                IdentifyGraphicsOverlayResult gResult_Buff = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResult_Buff.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphic_Buff = gResult_Buff.Graphics.First();
                selGraphic_Buff.IsSelected = true;
                listOfClipGraphics.Add(selGraphic_Buff); //记录所选图形
                if (listOfClipGraphics.Count == 1)       //图形数目为1时,进行剪切计算
                {
                    Graphic g1 = listOfClipGraphics[0];
                    Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Buffer(g1.Geometry, 1000000.0);                                                                                                                           //执行剪切操作
                    if (resultGeometry != null)                                                                                                                                                                                                    //处理结果
                    {
                        graphicsLayer.Graphics.Remove(g1);                                                                                                                                                                                         //从图形层中移除原图形
                        Graphic clipedGraphic = new Graphic(resultGeometry, new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.FromArgb(125, 255, 250, 0), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.FromArgb(0, 0, 0), 4.0))); //利 用剪切结果构建新的图形
                        graphicsLayer.Graphics.Add(clipedGraphic);
                        operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;

            case OperateType.Cal_Jiaodian:     // 交点
                IdentifyGraphicsOverlayResult gResult_Jiaodian = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false);

                if (gResult_Jiaodian.Graphics.Count < 1)
                {
                    return;
                }
                Graphic selGraphic_Jiaodian = gResult_Jiaodian.Graphics.First();
                selGraphic_Jiaodian.IsSelected = true;
                listOfClipGraphics.Add(selGraphic_Jiaodian); //记录所选图形
                if (listOfClipGraphics.Count == 2)           //图形数目为1时,进行剪切计算
                {
                    Graphic g1 = listOfClipGraphics[0];
                    Graphic g2 = listOfClipGraphics[1];
                    IReadOnlyList <Geometry> resultGeometry = GeometryEngine.Intersections(g1.Geometry, g2.Geometry); //执行剪切操作
                    if (resultGeometry != null)                                                                       //处理结果
                    {
                        Graphic clipedGraphic = new Graphic(resultGeometry[0], pointSymbol);                          //利 用剪切结果构建新的图形
                        graphicsLayer.Graphics.Add(clipedGraphic);
                        operation = OperateType.None;
                    }
                    listOfClipGraphics.Clear();     //清空图形选择集合
                    graphicsLayer.ClearSelection(); //清空图形层所选
                }
                break;
            }
        }