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

            // 点集(mapPoints) ——记得清空
            mapPoints.Add(destination);
            int len = mapPoints.Count();

            Esri.ArcGISRuntime.Geometry.PointCollection polygonPoints;
            Esri.ArcGISRuntime.Geometry.Geometry        areaGeometry;
            Esri.ArcGISRuntime.Geometry.Polygon         routeArea;
            if (len > 2)
            {
                polygonPoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84)
                {
                    mapPoints[len - 3],
                    mapPoints[len - 2],
                    destination
                };

                routeArea = new Esri.ArcGISRuntime.Geometry.Polygon(polygonPoints);
                //pathGeometry = GeometryEngine.DensifyGeodetic(routeArea, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

                // 这是测地线的长度
                //double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
                double area = GeometryEngine.Area(routeArea);
                if (areaList.Count() != 0)
                {
                    area += areaList[areaList.Count() - 1];
                }
                areaList.Add(area);
                myMeasureResult.Text += "\n" + area + " (地图默认面积单位)";
            }
        }
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Identify the tapped graphics.
            IdentifyGraphicsOverlayResult result = null;

            try
            {
                result = await _myMapView.IdentifyGraphicsOverlayAsync(_graphicsOverlay, e.Position, 1, false);
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }

            // Return if there are no results.
            if (result == null || result.Graphics.Count < 1)
            {
                return;
            }

            // Get the smallest identified graphic.
            Graphic identifiedGraphic = result.Graphics.OrderBy(graphic => GeometryEngine.Area(graphic.Geometry)).First();

            // Clear any existing selection, then select the tapped graphic.
            _graphicsOverlay.ClearSelection();
            identifiedGraphic.IsSelected = true;

            // Get the selected graphic's geometry.
            Geometry selectedGeometry = identifiedGraphic.Geometry;

            // Perform the calculation and show the results.
            _resultTextView.Text = GetOutputText(selectedGeometry);
        }
Exemplo n.º 3
0
        public static decimal GetArea(this Geometry geometry)
        {
            try
            {
                var projectArea = GeometryEngine.Area(GeometryEngine.Simplify(geometry as Polygon));

                double  projectAreaHa  = AreaUnits.Hectares.FromSquareMeters(projectArea);
                decimal insideItemArea = Convert.ToDecimal(Math.Round(projectAreaHa, 2, MidpointRounding.AwayFromZero));

                return(insideItemArea);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(0);
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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!");
            }
        }
Exemplo n.º 7
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // First clear any existing selections
            ClearAllSelections();

            // Perform the identify operation
            IReadOnlyList <IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(e.Position, 5, false);

            // Return if there are no results
            if (results.Count < 1)
            {
                return;
            }

            // Get the results that are from ENC layers
            IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer);

            // Get the ENC results that have features
            IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0);

            // Get the first result with ENC features
            IdentifyLayerResult firstResult = encResultsWithFeatures.First();

            // Get the layer associated with this set of results
            EncLayer containingLayer = firstResult.LayerContent as EncLayer;

            // Select the smallest (area) feature in the layer.
            EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First();

            // Select the feature.
            containingLayer.SelectFeature(smallestFeature);

            // Create the callout definition.
            CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description);

            // Show the callout
            MyMapView.ShowCalloutAt(e.Location, definition);
        }
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // First clear any existing selections.
            ClearAllSelections();

            try
            {
                // Perform the identify operation.
                IReadOnlyList <IdentifyLayerResult> results = await _myMapView.IdentifyLayersAsync(e.Position, 5, false);

                // Return if there are no results.
                if (results.Count < 1)
                {
                    return;
                }

                // Get the results that are from ENC layers.
                IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer);

                // Get the ENC results that have features.
                IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0);

                // Get the first result with ENC features.
                IdentifyLayerResult firstResult = encResultsWithFeatures.First();

                // Get the layer associated with this set of results.
                EncLayer containingLayer = (EncLayer)firstResult.LayerContent;

                // Get the first identified ENC feature.
                EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First();

                // Select the feature.
                containingLayer.SelectFeature(smallestFeature);

                // Create the callout definition.
                CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description);

                // Show the callout.
                _myMapView.ShowCalloutAt(e.Location, definition);
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Exemplo n.º 9
0
        //renderResult.Miscellaneous.Add(Diamond14Attributes.LevelSetting, productDialog.LevelSetting);
        //renderResult.Miscellaneous.Add(Diamond14Attributes.ProductType, productDialog.Type);
        public GraphicsLayer Generate(RenderResult renderResult)
        {
            if (renderResult == null || renderResult.Miscellaneous == null || !renderResult.Miscellaneous.Keys.Contains(Diamond14Attributes.LevelSetting))
            {
                throw new Exception("找不到颜色配置");
            }
            if (string.IsNullOrEmpty(renderResult.Miscellaneous[Diamond14Attributes.LevelSetting].ToString()))
            {
                throw new ArgumentNullException("无效的颜色配置");
            }
            var sourceLayer = renderResult.Layer;
            var settings    = LevelValueManager.Settings[renderResult.Miscellaneous[Diamond14Attributes.LevelSetting].ToString()];

            var layer = new GraphicsLayer
            {
                DisplayName = sourceLayer.DisplayName
            };
            //layer.Opacity = 0.5;

            var dict = new SortedDictionary <double, Graphic>();

            foreach (var graphic in sourceLayer.Graphics)
            {
                if (graphic.Geometry is MapPoint)
                {
                    graphic.ZIndex = 5;
                    layer.Graphics.Add(graphic);
                }

                if (graphic.Geometry is Polyline)
                {
                    // Level value will be int. If null, value will be 0
                    int value = Convert.ToInt32(graphic.Attributes[Diamond14Attributes.LineValue]);

                    var polyline      = graphic.Geometry as Polyline;
                    var polygon       = ToPolygon(polyline);
                    var polygonSymbol = new SimpleFillSymbol
                    {
                        //Color = Color.FromArgb(0x66, 0xff, 0, 0)
                        Color = settings.GetValueColor(value)
                    };

                    var newGraphic = new Graphic
                    {
                        Geometry = polygon,
                        Symbol   = polygonSymbol
                    };
                    layer.Graphics.Add(newGraphic);

                    //double area = GeometryEngine.Area(polygon); clock wise will be positive
                    double area = Math.Abs(GeometryEngine.Area(polygon));
                    dict.Add(area, newGraphic);
                }
            }

            int zindex = dict.Keys.Count;

            foreach (var graphic in dict.Values)
            {
                graphic.ZIndex = zindex--;
            }

            return(layer);
        }