private void MyMapViewOnGeoViewTapped_Line(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Get the tapped point, projected to WGS84.
            MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84);

            mapPoints.Add(destination);
            int len = mapPoints.Count();

            Esri.ArcGISRuntime.Geometry.PointCollection polylinePoints;
            Esri.ArcGISRuntime.Geometry.Geometry        pathGeometry;
            Esri.ArcGISRuntime.Geometry.Polyline        routeLine;
            if (len > 1)
            {
                polylinePoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84)
                {
                    mapPoints[len - 2],
                    destination
                };

                routeLine    = new Esri.ArcGISRuntime.Geometry.Polyline(polylinePoints);
                pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

                // 这是测地线的长度
                //double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
                double distance = GeometryEngine.Length(pathGeometry);
                //double distance = GeometryEngine.Length(routeLine);
                lengthList.Add(distance);
                myMeasureResult.Text += "\n" + distance + " (地图默认长度单位)";
            }
        }
示例#2
0
        /// <summary>
        /// Asynchronous task that splits the current sketch geometry into 100 segments of equal length.
        /// </summary>
        /// <returns>Task{bool}</returns>
        private async Task <bool> ExecuteDensify()
        {
            // get the current sketch geometry from the editing module
            var sketchGeometry = await EditingModule.GetSketchGeometryAsync();

            // check if geometry is valid
            bool isGeometryValid = await QueuingTaskFactory.StartNew <bool>(() =>
            {
                bool validGeometry = true;

                if (sketchGeometry == null || sketchGeometry.IsEmpty)
                {
                    validGeometry = false;
                }

                return(validGeometry);
            });

            if (!isGeometryValid)
            {
                return(false);
            }

            // get the currently selected features from the map
            // the selected feature uses the above selected geometry
            var currentlySelectedFeature = await MappingModule.ActiveMapView.Map.GetSelectionSetAsync();

            // set up an edit operation
            EditOperation editOperation = new EditOperation();

            editOperation.Name = "Densify selected geometry";

            Geometry densifiedGeometry = null;

            // modify the geometry in the sketch geometry
            // the geometry operation needs to run as it own task
            await QueuingTaskFactory.StartNew(() =>
            {
                // compute a length fur the current geometry when divided into 100 segments
                var segmentLength = GeometryEngine.Length(sketchGeometry) / 100;
                // compute a new densified geometry
                densifiedGeometry = GeometryEngine.Densify(sketchGeometry, segmentLength);
            });

            // for the currently selected feature go through the layers to which the feature belongs
            foreach (var mapMember in currentlySelectedFeature.MapMembers)
            {
                // for each of the selections in the layer (map member)
                foreach (var selectedOID in currentlySelectedFeature[mapMember])
                {
                    // provide the densified geometry for the selected feature as part of the modify operation
                    editOperation.Modify((Layer)mapMember, selectedOID, densifiedGeometry);
                }
            }

            // execute the edit operation and return
            return(await editOperation.ExecuteAsync());
        }
        private void buildFlightPath()
        {
            // Use geometry engine to create a circle around the center of the scene
            Geometry circle = GeometryEngine.EllipseGeodesic(new GeodesicEllipseParameters(centerPoint, 1700, 1700));

            // Create a path around the perimeter of the circle
            routePath = (Polyline)GeometryEngine.Boundary(circle);

            // Store the length of the route for use later
            routeLength = GeometryEngine.Length(routePath);
        }
示例#4
0
        public static int GetMeters(this Geometry geometry)
        {
            try
            {
                var projectDistance = GeometryEngine.Length(GeometryEngine.Simplify(geometry as Polyline));

                double  projectDistanceMeter = LinearUnits.Meters.FromMeters(projectDistance);
                decimal insideItemArea       = Convert.ToDecimal(Math.Round(projectDistanceMeter, 2, MidpointRounding.AwayFromZero));

                return(Convert.ToInt32(Math.Truncate(insideItemArea)));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(0);
        }
示例#5
0
        /// <summary>
        /// Divide the first selected feature into equal parts or by map unit distance.
        /// </summary>
        /// <param name="numberOfParts">Number of parts to create.</param>
        /// <param name="value">Value for number or parts or distance.</param>
        /// <returns></returns>
        private static Task DivideLinesAsync(bool numberOfParts, double value)
        {
            //Run on MCT
            return(QueuedTask.Run(() =>
            {
                //get selected feature
                var selectedFeatures = MapView.Active.Map.GetSelection();

                //get the layer of the selected feature
                var featLayer = selectedFeatures.Keys.First() as FeatureLayer;
                var oid = selectedFeatures.Values.First().First();

                var feature = featLayer.Inspect(oid);

                //get geometry and length
                var origPolyLine = feature.Shape as Polyline;
                var origLength = GeometryEngine.Length(origPolyLine);

                //List of mappoint geometries for the split
                var splitPoints = new List <MapPoint>();

                var enteredValue = (numberOfParts) ? origLength / value : value;
                var splitAtDistance = 0 + enteredValue;

                while (splitAtDistance < origLength)
                {
                    //create a mapPoint at splitDistance and add to splitpoint list
                    splitPoints.Add(GeometryEngine.MovePointAlongLine(origPolyLine, splitAtDistance, false, 0));
                    splitAtDistance += enteredValue;
                }

                //create and execute the edit operation
                var op = new EditOperation();
                op.Name = "Divide Lines";
                op.SelectModifiedFeatures = false;
                op.SelectNewFeatures = false;
                op.SplitAtPoints(featLayer, oid, splitPoints);
                op.Execute();

                //clear selection
                //MapView.Active.Map.SetSelection(null);
                featLayer.ClearSelection();
            }));
        }
示例#6
0
        private async Task doCalculateAreaAndLength()
        {
            try
            {
                //Wait for user to draw
                var geom = await mapView1.Editor.RequestShapeAsync(DrawShape.Polygon);

                //show geometry on map
                _graphicsOverlay.Graphics.Clear();

                var g = new Graphic {
                    Geometry = geom, Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol
                };
                _graphicsOverlay.Graphics.Add(g);


                //Calculate results
                var areaPlanar = GeometryEngine.Area(geom);
                ResultsAreaPlanar.Text = string.Format("{0} millas cuad.", (areaPlanar * toSqMilesConversion).ToString("n3"));

                var perimPlanar = GeometryEngine.Length(geom);
                ResultsPerimeterPlanar.Text = string.Format("{0} millas", (perimPlanar * toMilesConversion).ToString("n3"));


                var areaGeodesic = GeometryEngine.GeodesicArea(geom);
                ResultsAreaGeodesic.Text = string.Format("{0} millas cuad.", (areaGeodesic * toSqMilesConversion).ToString("n3"));

                var perimGeodesic = GeometryEngine.GeodesicLength(geom);
                ResultsPerimeterGeodesic.Text = string.Format("{0} millas cuad.", (perimGeodesic * toMilesConversion).ToString("n3"));

                //Instructions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                Results.Visibility  = Windows.UI.Xaml.Visibility.Visible;
                Reiniciar.IsEnabled = true;
            }
            catch (System.Threading.Tasks.TaskCanceledException)
            {
                var dlg = new MessageDialog("El trazado actual ha sido cancelado.", "Tarea Cancelada!");
                var _x  = dlg.ShowAsync();
            }
        }
示例#7
0
        private async Task DoCalculateAreaAndLengthAsync()
        {
            try
            {
                //Wait for user to draw
                var geom = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon);

                //show geometry on map
                _graphicsOverlay.Graphics.Clear();

                var g = new Graphic
                {
                    Geometry = geom,
                    Symbol   = LayoutRoot.Resources["DefaultFillSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol
                };
                _graphicsOverlay.Graphics.Add(g);

                //Calculate results
                var areaPlanar = GeometryEngine.Area(geom);
                ResultsAreaPlanar.Text = string.Format("{0} sq. miles", (areaPlanar * toSqMilesConversion).ToString("n3"));

                var perimPlanar = GeometryEngine.Length(geom);
                ResultsPerimeterPlanar.Text = string.Format("{0} miles", (perimPlanar * toMilesConversion).ToString("n3"));

                var areaGeodesic = GeometryEngine.GeodesicArea(geom);
                ResultsAreaGeodesic.Text = string.Format("{0} sq. miles", (areaGeodesic * toSqMilesConversion).ToString("n3"));

                var perimGeodesic = GeometryEngine.GeodesicLength(geom);
                ResultsPerimeterGeodesic.Text = string.Format("{0} miles", (perimGeodesic * toMilesConversion).ToString("n3"));

                Instructions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                Results.Visibility      = Windows.UI.Xaml.Visibility.Visible;
            }
            catch (TaskCanceledException)
            {
                var _x = new MessageDialog("Current sketch has been canceled.", "Task Canceled!").ShowAsync();
            }
        }
        private async Task doCalculateAreaAndLength()
        {
            try
            {
                // Wait for user to draw
                var geom = await mapView.Editor.RequestShapeAsync(DrawShape.Polygon);

                // show geometry on map
                graphicsLayer.Graphics.Clear();

                var graphic = new Graphic {
                    Geometry = geom, Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol
                };
                graphicsLayer.Graphics.Add(graphic);

                // Calculate results
                var areaPlanar = GeometryEngine.Area(geom);
                ResultsAreaPlanar.Text = string.Format("{0} sq. miles", (areaPlanar * toSqMilesConversion).ToString("n3"));

                var perimPlanar = GeometryEngine.Length(geom);
                ResultsPerimeterPlanar.Text = string.Format("{0} miles", (perimPlanar * toMilesConversion).ToString("n3"));

                var areaGeodesic = GeometryEngine.GeodesicArea(geom);
                ResultsAreaGeodesic.Text = string.Format("{0} sq. miles", (areaGeodesic * toSqMilesConversion).ToString("n3"));

                var perimGeodesic = GeometryEngine.GeodesicLength(geom);
                ResultsPerimeterGeodesic.Text = string.Format("{0} miles", (perimGeodesic * toMilesConversion).ToString("n3"));

                Instructions.Visibility = Visibility.Collapsed;
                Results.Visibility      = Visibility.Visible;
            }
            catch (TaskCanceledException)
            {
                MessageBox.Show("Current sketch has been canceled.", "Task Canceled!");
            }
        }
示例#9
0
        public void Work(object obj)
        {
            int       type = Convert.ToInt32(obj);
            DrawShape drawType;

            _points          = null;
            _tempTextGraphic = null;
            totalLength      = 0;
            Symbol symbol = null;

            switch (type)
            {
            case 0:
                _points          = new List <MapPoint>();
                _tempTextGraphic = new List <Graphic>();
                symbol           = new SimpleLineSymbol();
                ((SimpleLineSymbol)symbol).Color = System.Windows.Media.Colors.Orange;
                ((SimpleLineSymbol)symbol).Style = SimpleLineStyle.Dash;
                ((SimpleLineSymbol)symbol).Width = 2;
                drawType = DrawShape.Polyline;
                break;

            case 1:
                symbol = new SimpleLineSymbol();
                ((SimpleLineSymbol)symbol).Color = System.Windows.Media.Colors.Orange;
                ((SimpleLineSymbol)symbol).Style = SimpleLineStyle.Dash;
                ((SimpleLineSymbol)symbol).Width = 2;
                drawType = DrawShape.Polygon;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            Geometry geo;

            if (symbol != null)
            {
                _map.Dispatcher.Invoke(
                    new Action(
                        async delegate
                {
                    if (_map.MapView.Editor.IsActive)
                    {
                        _map.MapView.Editor.Cancel.Execute(null);
                    }

                    try
                    {
                        geo = await _map.MapView.Editor.RequestShapeAsync(drawType, symbol);
                    }
                    catch
                    {
                        geo        = null;
                        IsObsolete = true;
                        //clearTextGraphic();
                        Callback?.Invoke(null);
                        return;
                    }

                    if (geo != null)
                    {
                        // create a new graphic; set the Geometry and Symbol
                        Graphic graphic = new Graphic
                        {
                            Geometry = geo,
                            Symbol   = symbol
                        };
                        MapPoint mp;
                        string text;
                        if (geo is Polyline)
                        {
                            mp   = (geo as Polyline).Parts.Last().Last().EndPoint;
                            text = distanceToStr(GeometryEngine.Length(geo) * 111000);
                        }
                        else
                        {
                            mp   = (geo as Polygon).Parts.Last().Last().EndPoint;
                            text = areaToStr(GeometryEngine.GeodesicArea(geo) * 111000 * 111000);
                        }
                        addTextSymbol(text, mp);
                        _map.GetGraphicLayer("Drawing").Graphics.Add(graphic);
                        IsObsolete = true;
                        Callback?.Invoke(text);
                    }
                }));
            }
        }
示例#10
0
        /// <summary>
        /// Divide the first selected feature into equal parts or by map unit distance.
        /// </summary>
        /// <param name="numberOfParts">Number of parts to create.</param>
        /// <param name="value">Value for number or parts or distance.</param>
        /// <returns></returns>
        private static Task DivideLinesAsync(bool numberOfParts, double value)
        {
            //Run on MCT
            return(QueuedTask.Run(() =>
            {
                //get selected feature
                var selectedFeatures = MapView.Active.Map.GetSelection();

                //get the layer of the selected feature
                var featLayer = selectedFeatures.Keys.First() as FeatureLayer;
                var oid = selectedFeatures.Values.First().First();

                var feature = featLayer.Inspect(oid);

                //get geometry and length
                var origPolyLine = feature.Shape as Polyline;
                var origLength = GeometryEngine.Length(origPolyLine);

                string xml = origPolyLine.ToXML();

                //List of mappoint geometries for the split
                var splitPoints = new List <MapPoint>();

                var enteredValue = (numberOfParts) ? origLength / value : value;
                var splitAtDistance = 0 + enteredValue;

                while (splitAtDistance < origLength)
                {
                    //create a mapPoint at splitDistance and add to splitpoint list
                    MapPoint pt = null;
                    try
                    {
                        pt = GeometryEngine.MovePointAlongLine(origPolyLine, splitAtDistance, false, 0, GeometryEngine.SegmentExtension.NoExtension);
                    }
                    catch (GeometryObjectException)
                    {
                        // line is an arc?
                    }

                    if (pt != null)
                    {
                        splitPoints.Add(pt);
                    }
                    splitAtDistance += enteredValue;
                }

                if (splitPoints.Count == 0)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Divide lines was unable to process your selected line. Please select another.", "Divide Lines");
                    return;
                }
                //create and execute the edit operation
                var op = new EditOperation();
                op.Name = "Divide Lines";
                op.SelectModifiedFeatures = false;
                op.SelectNewFeatures = false;
                op.SplitAtPoints(featLayer, oid, splitPoints);
                op.Execute();

                //clear selection
                featLayer.ClearSelection();
            }));
        }
        private void Update(ShapefileFeatureTable sf, CancellationToken ct, IProgress <int> p)
        {
            Task.Run(async() =>
            {
                var directory = Globals.Model.Assets.PathTo("BasinShapefile");
                if (String.IsNullOrWhiteSpace(directory))
                {
                    MessageBox.Show("You need to have imported a basin shapefile.");
                    Clear();
                    return;
                }

                var file = Directory.EnumerateFiles(directory, "*.shp").FirstOrDefault();
                if (String.IsNullOrWhiteSpace(file))
                {
                    MessageBox.Show("Error reading the basin shapefile.");
                    Clear();
                    return;
                }

                var ci      = Globals.Model.EcosystemVitality.FetchIndicator <ConnectivityIndicator>();
                var reaches = ci?.Reaches;
                if (reaches == null)
                {
                    MessageBox.Show(
                        "You must import a river network for the Connectivity Indicator in Ecosystem Vitality.");
                    Clear();
                    return;
                }

                var bsf      = await ShapefileFeatureTable.OpenAsync(file);
                var allQuery = new QueryParameters
                {
                    Geometry            = bsf.Extent,
                    SpatialRelationship = SpatialRelationship.Contains
                };
                ConservationAreaIndicator.TotalProtectedArea = 0;
                ConservationAreaIndicator.TotalArea          = 0;

                foreach (var mapFeature in await bsf.QueryFeaturesAsync(allQuery))
                {
                    if (ct.IsCancellationRequested)
                    {
                        Clear();
                        return;
                    }

                    ConservationAreaIndicator.TotalArea += GeometryEngine.AreaGeodetic(mapFeature.Geometry);

                    var areaFeatures = await sf.QueryFeaturesAsync(new QueryParameters
                    {
                        Geometry            = mapFeature.Geometry,
                        SpatialRelationship = SpatialRelationship.Contains
                    });
                    foreach (var feature in areaFeatures)
                    {
                        ConservationAreaIndicator.TotalProtectedArea += GeometryEngine.AreaGeodetic(feature.Geometry);
                        if (ct.IsCancellationRequested)
                        {
                            Clear();
                            return;
                        }
                    }
                }

                p.Report(25);

                // todo: this is not an efficient algorithm
                var pb = new PolylineBuilder(new SpatialReference(Model.Attributes.Wkid));
                foreach (var reach in reaches)
                {
                    pb.AddPart(
                        reach.Nodes.Select(node => new MapPoint(node.Location.Longitude, node.Location.Latitude)));
                }
                var mapGeometry = pb.ToGeometry();
                ConservationAreaIndicator.TotalLength = GeometryEngine.Length(mapGeometry);

                if (ct.IsCancellationRequested)
                {
                    Clear();
                    return;
                }

                var lengthFeatures = await sf.QueryFeaturesAsync(new QueryParameters
                {
                    Geometry            = sf.Extent,
                    SpatialRelationship = SpatialRelationship.Contains
                });

                var tpl         = 0.0;
                var reachNumber = 0;
                foreach (var reach in reaches)
                {
                    var poly = new PolylineBuilder(new SpatialReference(Model.Attributes.Wkid));
                    poly.AddPart(reach.Nodes.Select(node =>
                                                    new MapPoint(node.Location.Longitude, node.Location.Latitude)));
                    var pg = poly.ToGeometry();
                    foreach (var feature in lengthFeatures)
                    {
                        var intersection = GeometryEngine.Intersection(pg, feature.Geometry) as Polyline;
                        if (intersection?.Parts.Count > 0)
                        {
                            tpl += GeometryEngine.Length(pg);
                        }
                        if (ct.IsCancellationRequested)
                        {
                            Clear();
                            return;
                        }
                    }

                    p.Report(25 + (int)(75.0 * reachNumber++ / reaches.Count));
                }

                ConservationAreaIndicator.TotalProtectedLength = tpl;
            }, ct).Wait(ct);
        }