Exemplo n.º 1
0
        private async Task UpdateGeometry(MapPoint point)
        {
            if (_selectedFeature.Geometry is Polyline line)
            {
                // Get the nearest point on the selected line.
                ProximityResult nearestVertex = GeometryEngine.NearestVertex(line, point);

                // Create a new polyline.
                PolylineBuilder polylineBuilder = new PolylineBuilder(line);
                Part            part            = polylineBuilder.Parts[nearestVertex.PartIndex];

                // Replace the nearest point with the new point.
                part.SetPoint(nearestVertex.PointIndex, point);

                // Update the geometry of the feature.
                _selectedFeature.Geometry = GeometryEngine.Project(polylineBuilder.ToGeometry(), _selectedFeature.Geometry.SpatialReference);
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }
            else if (_selectedFeature.Geometry is MapPoint)
            {
                // Update the geometry of the feature.
                _selectedFeature.Geometry = point;
                await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);
            }

            // Clear the selection.
            (_selectedFeature.FeatureTable.Layer as FeatureLayer).ClearSelection();
            _selectedFeature = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the OnToolMouseDown event is handled. Allows the opportunity to perform asynchronous operations corresponding to the event.
        /// </summary>
        protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
        {
            //Get the instance of the ViewModel
            var vm = OverlayEmbeddableControl as EmbeddedControlViewModel;

            if (vm == null)
            {
                return(Task.FromResult(0));
            }

            //Get the map coordinates from the click point and set the property on the ViewModel.
            return(QueuedTask.Run(() =>
            {
                var mapPoint = ActiveMapView.ClientToMap(e.ClientPoint);
                var coords = GeometryEngine.Project(mapPoint, SpatialReferences.WGS84) as MapPoint;
                if (coords == null)
                {
                    return;
                }
                var sb = new StringBuilder();
                sb.AppendLine($"X: {coords.X:0.000}");
                sb.Append($"Y: {coords.Y:0.000}");
                if (coords.HasZ)
                {
                    sb.AppendLine();
                    sb.Append($"Z: {coords.Z:0.000}");
                }
                vm.Text = sb.ToString();
            }));
        }
        private async void MyMapView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (MyMapView != null)
            {
                Point screenPoint = e.GetPosition(MyMapView);

                MapPoint mapPoint = MyMapView.ScreenToLocation(screenPoint);

                if (mapPoint != null)
                {
                    // point = GetDesiredElevationLocation();
                    double result = await sceneSurface.GetElevationAsync(mapPoint);

                    if (MyMapView.IsWrapAroundEnabled)
                    {
                        mapPoint = GeometryEngine.Project(mapPoint, SpatialReferences.Wgs84) as MapPoint;

                        textBox.Text = String.Format("x: {0}, y: {1} | Lat:{2},Lon:{3} | Scale:{4} | Elevation : {5} m", screenPoint.X, screenPoint.Y, Math.Round(mapPoint.Y, 6), Math.Round(mapPoint.X, 6), MyMapView.MapScale, result);
                    }
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 4
0
        private List <Graphic> GenerateGraphics(Diamond14EntityLine line, string type, Color color)
        {
            var result = new List <Graphic>();

            var lineBuilder = new PolylineBuilder(SpatialReferences.WebMercator);

            foreach (var point in line.Items)
            {
                if (point.IsValid())
                {
                    var mapPointWgs84 = new MapPoint(point.Longitude, point.Latitude, SpatialReferences.Wgs84);
                    var mapPoint      = GeometryEngine.Project(mapPointWgs84, SpatialReferences.WebMercator) as MapPoint;
                    lineBuilder.AddPoint(mapPoint);
                }
            }

            var geometry   = lineBuilder.ToGeometry();
            var resultLine = new Graphic
            {
                Geometry = geometry,
                Symbol   = new SimpleLineSymbol
                {
                    Color = color,
                    Width = line.Width
                }
            };

            resultLine.Attributes[Diamond14Attributes.LineValue] = line.LabelValue?.ToString() ?? string.Empty;
            resultLine.Attributes[Diamond14Attributes.LineType]  = type;

            result.Add(resultLine);

            return(result);
        }
        private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e)
        {
            var normalizedPoint = GeometryEngine.NormalizeCentralMeridian(e.Location);
            var projectedCenter = GeometryEngine.Project(normalizedPoint, SpatialReferences.Wgs84) as MapPoint;

            _clickOverlay.DataContext = projectedCenter;
        }
        /// <summary>
        /// Called when the OnToolMouseDown event is handled. Allows the opportunity to perform asynchronous operations corresponding to the event.
        /// </summary>
        protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
        {
            //Get the instance of the ViewModel
            var symbolDockPaneViewModel = FrameworkApplication.DockPaneManager.Find("ProSymbolEditor_MilitarySymbolDockpane") as MilitarySymbolDockpaneViewModel;

            if (symbolDockPaneViewModel == null)
            {
                return(Task.FromResult(0));
            }

            //Get the map coordinates from the click point and set the property on the ViewModel.
            return(QueuedTask.Run(() =>
            {
                var tempMapPoint = MapView.Active.ClientToMap(e.ClientPoint);
                try
                {
                    // for now we will always project to WGS84
                    MapPoint projectedMapPoint = GeometryEngine.Project(tempMapPoint, SpatialReferences.WGS84) as MapPoint;

                    //Create a point with a z value, since the mil spec feature classes have z enabled (TODO: other way to do this?)
                    symbolDockPaneViewModel.MapGeometry = MapPointBuilder.CreateMapPoint(projectedMapPoint.X, projectedMapPoint.Y, 0, projectedMapPoint.SpatialReference);
                    symbolDockPaneViewModel.MapPointCoordinatesString = string.Format("{0:0.0####} {1:0.0####}", tempMapPoint.Y, tempMapPoint.X);
                }
                catch (Exception exception)
                {
                    System.Console.WriteLine(exception.Message);
                }
            }));
        }
        private void Initialize()
        {
            // Create a point geometry in NYC in WGS84.
            MapPoint startingPoint = new MapPoint(-73.984513, 40.748469, SpatialReferences.Wgs84);

            // Update the UI with the initial coordinates.
            _beforeLabel.Text = $"Before - x: {startingPoint.X}, y: {startingPoint.Y}";

            // Create a geographic transformation step for transform WKID 108055, WGS_1984_To_MSK_1942.
            GeographicTransformationStep geoStep = new GeographicTransformationStep(108055);

            // Create the transformation.
            GeographicTransformation geoTransform = new GeographicTransformation(geoStep);

            // Project to a coordinate system used in New York, NAD_1983_HARN_StatePlane_New_York_Central_FIPS_3102.
            MapPoint afterPoint = (MapPoint)GeometryEngine.Project(startingPoint, SpatialReference.Create(2829), geoTransform);

            // Update the UI with the projected coordinates.
            _afterLabel.Text = $"After (specific) - x: {afterPoint.X}, y: {afterPoint.Y}";

            // Perform the same projection without specified transformation.
            MapPoint unspecifiedTransformPoint = (MapPoint)GeometryEngine.Project(startingPoint, SpatialReference.Create(2829));

            // Update the UI with the projection done without specific transform for comparison purposes.
            _nonSpecificLabel.Text = $"After (non-specific) - x: {unspecifiedTransformPoint.X}, y: {unspecifiedTransformPoint.Y}";
        }
Exemplo n.º 8
0
        public override async void MapViewTapped(MapView mapView, MapViewInputEventArgs e, bool drawing)
        {
            if (!drawing)
            {
                var graphic = await GraphicsLayer.HitTestAsync(mapView, e.Position);

                if (graphic != null)
                {
                    OnItemTapped(int.Parse($"{graphic.Attributes[CURR_GEO]}"));
                }
                return;
            }

            MapPoint newPoint = (MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);

            if (_drawPointList.Count == 0)
            {
                AddGraphic(newPoint, DRAFT, MapShapeLayer.GetSymbol(GeoMarkerType.Point, GeoStatus.Hilight));
            }
            else
            {
                Polyline line = new Polyline(new MapPoint[] { _drawPointList.Last(), newPoint });
                AddGraphic(line, DRAFT, MapShapeLayer.GetSymbol(GeoMarkerType.Line, GeoStatus.Hilight));
            }

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

            // Update the destination graphic.
            _endLocationGraphic.Geometry = destination;

            // Get the points that define the route polyline.
            PointCollection polylinePoints = new PointCollection(SpatialReferences.Wgs84)
            {
                (MapPoint)_startLocationGraphic.Geometry,
                destination
            };

            // Create the polyline for the two points.
            Polyline routeLine = new Polyline(polylinePoints);

            // Densify the polyline to show the geodesic curve.
            Geometry pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

            // Apply the curved line to the path graphic.
            _pathGraphic.Geometry = pathGeometry;

            // Calculate and show the distance.
            double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

            ResultsLabel.Text = $"{(int)distance} kilometers";
        }
Exemplo n.º 10
0
        // Intersects feature geometries with a user defined polygon.
        private async void IntersectButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _resultsOverlay.Graphics.Clear();

                // wait for user to draw a polygon
                Polygon userpoly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon) as Polygon;

                Polygon poly = GeometryEngine.NormalizeCentralMeridian(userpoly) as Polygon;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(poly, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Intersect the feature geometries and add to graphics layer
                var states            = stateFeatures.Select(feature => feature.Geometry);
                var intersectGraphics = states
                                        .Select(state => GeometryEngine.Intersection(state, poly))
                                        .Select(geo => new Graphic(geo, _fillSymbol));

                _resultsOverlay.Graphics.AddRange(intersectGraphics);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Intersection Error: " + ex.Message, "Intersection Sample");
            }
        }
        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 + " (地图默认面积单位)";
            }
        }
Exemplo n.º 12
0
        public static async Task <Scene> CreateBerlin(ARSceneView sv)
        {
            // URL for a scene service of buildings in Brest, France
            Uri buildingsService = new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Berlin/SceneServer");
            var iml = new ArcGISSceneLayer(buildingsService)
            {
                Opacity = 1
            };
            await iml.LoadAsync();

            var      observerCamera = new Esri.ArcGISRuntime.Mapping.Camera(new MapPoint(-4.49492, 48.3808, 48.2511, SpatialReferences.Wgs84), 344.488, 74.1212, 0.0);
            MapPoint center         = (MapPoint)GeometryEngine.Project(iml.FullExtent.GetCenter(), SpatialReferences.Wgs84);

            observerCamera = new Esri.ArcGISRuntime.Mapping.Camera(center.Y, center.X, 600, 120, 60, 0);
            var scene = new Scene(Basemap.CreateImagery());

            scene.InitialViewpoint = new Esri.ArcGISRuntime.Mapping.Viewpoint(observerCamera.Location, observerCamera);
            scene.OperationalLayers.Add(iml);
            scene.BaseSurface = new Surface();
            scene.BaseSurface.BackgroundGrid.IsVisible = false;
            scene.BaseSurface.ElevationSources.Add(new ArcGISTiledElevationSource(new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")));
            scene.BaseSurface.NavigationConstraint = NavigationConstraint.None;
            sv.TranslationFactor = 1000;
            return(scene);
        }
 public FindAnAddress()
 {
     this.InitializeComponent();
     mapView1.Map.InitialExtent = GeometryEngine.Project(new Envelope(-122.554, 37.615, -122.245, 37.884, SpatialReferences.Wgs84),
                                                         SpatialReferences.WebMercator) as Envelope;
     _candidateGraphicsLayer = mapView1.Map.Layers["CandidateGraphicsLayer"] as GraphicsLayer;
 }
        private void Initialize()
        {
            // Create a spatial reference that's suitable for creating planar buffers in north central Texas (State Plane).
            SpatialReference statePlaneNorthCentralTexas = new SpatialReference(32038);

            // Define a polygon that represents the valid area of use for the spatial reference.
            // This information is available at https://developers.arcgis.com/net/latest/wpf/guide/pdf/projected_coordinate_systems_rt100_3_0.pdf
            List <MapPoint> spatialReferenceExtentCoords = new List <MapPoint>
            {
                new MapPoint(-103.070, 31.720, SpatialReferences.Wgs84),
                new MapPoint(-103.070, 34.580, SpatialReferences.Wgs84),
                new MapPoint(-94.000, 34.580, SpatialReferences.Wgs84),
                new MapPoint(-94.00, 31.720, SpatialReferences.Wgs84)
            };

            _spatialReferenceArea = new Polygon(spatialReferenceExtentCoords);
            _spatialReferenceArea = GeometryEngine.Project(_spatialReferenceArea, statePlaneNorthCentralTexas) as Polygon;

            // Create a map that uses the North Central Texas state plane spatial reference.
            Map bufferMap = new Map(statePlaneNorthCentralTexas);

            // Add some base layers (counties, cities, and highways).
            Uri usaLayerSource           = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer");
            ArcGISMapImageLayer usaLayer = new ArcGISMapImageLayer(usaLayerSource);

            bufferMap.Basemap.BaseLayers.Add(usaLayer);

            // Use a new EnvelopeBuilder to expand the spatial reference extent 120%.
            EnvelopeBuilder envBuilder = new EnvelopeBuilder(_spatialReferenceArea.Extent);

            envBuilder.Expand(1.2);

            // Set the map's initial extent to the expanded envelope.
            Envelope startingEnvelope = envBuilder.ToGeometry();

            bufferMap.InitialViewpoint = new Viewpoint(startingEnvelope);

            // Assign the map to the MapView.
            _myMapView.Map = bufferMap;

            // Create a graphics overlay to show the buffer polygon graphics.
            GraphicsOverlay bufferGraphicsOverlay = new GraphicsOverlay
            {
                // Give the overlay an ID so it can be found later.
                Id = "buffers"
            };

            // Create a graphic to show the spatial reference's valid extent (envelope) with a dashed red line.
            SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Red, 5);
            Graphic          spatialReferenceExtentGraphic = new Graphic(_spatialReferenceArea, lineSymbol);

            // Add the graphic to a new overlay.
            GraphicsOverlay spatialReferenceGraphicsOverlay = new GraphicsOverlay();

            spatialReferenceGraphicsOverlay.Graphics.Add(spatialReferenceExtentGraphic);

            // Add the graphics overlays to the MapView.
            _myMapView.GraphicsOverlays.Add(bufferGraphicsOverlay);
            _myMapView.GraphicsOverlays.Add(spatialReferenceGraphicsOverlay);
        }
        private async void Initialize()
        {
            // Create a new Scene with an imagery basemap.
            Scene scene = new Scene(Basemap.CreateImagery());

            // Add a base surface with elevation data.
            Surface elevationSurface = new Surface();
            Uri     elevationService = new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");

            elevationSurface.ElevationSources.Add(new ArcGISTiledElevationSource(elevationService));
            scene.BaseSurface = elevationSurface;

            // Add a scene layer.
            Uri buildingsService            = new Uri("https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Berlin/SceneServer");
            ArcGISSceneLayer buildingsLayer = new ArcGISSceneLayer(buildingsService);

            scene.OperationalLayers.Add(buildingsLayer);

            // Assign the Scene to the SceneView.
            MySceneView.Scene = scene;

            // Create a camera with an interesting view.
            await buildingsLayer.LoadAsync();

            MapPoint center     = (MapPoint)GeometryEngine.Project(buildingsLayer.FullExtent.GetCenter(), SpatialReferences.Wgs84);
            Camera   viewCamera = new Camera(center.Y, center.X, 600, 120, 60, 0);

            // Set the viewpoint with the camera.
            await MySceneView.SetViewpointCameraAsync(viewCamera);
        }
Exemplo n.º 16
0
        public static AnimationHandle AnimatePointTo(Graphic graphic, MapPoint newLocation, TimeSpan duration, GraphicsOverlay animationLayer = null)
        {
            if (!(graphic.Geometry is MapPoint))
            {
                throw new ArgumentException("Graphic must have a point geometry");
            }

            var start = graphic.Geometry as MapPoint;

            if (start.SpatialReference != null && newLocation.SpatialReference != null && !start.SpatialReference.IsEqual(newLocation.SpatialReference))
            {
                start = GeometryEngine.Project(start, newLocation.SpatialReference) as MapPoint;
            }
            return(AnimationHandle.StartAnimation(
                       duration: duration,
                       onPulse: (normalizedTime) =>
            {
                double x = (newLocation.X - start.X) * normalizedTime + start.X;
                double y = (newLocation.Y - start.Y) * normalizedTime + start.Y;
                double z = double.NaN;
                bool animateZ = newLocation.HasZ && start.HasZ;
                if (animateZ)
                {
                    z = (newLocation.Z - start.Z) * normalizedTime + start.Z;
                }
                graphic.Geometry = animateZ ? new MapPoint(x, y, z, start.SpatialReference) : new MapPoint(x, y, start.SpatialReference);
            },
                       onStart: null,
                       onEnd: () => graphic.Geometry = newLocation,
                       repeat: false,
                       easing: null // new QuadraticEase() { EasingMode = EasingMode.EaseInOut }
                       ));
        }
Exemplo n.º 17
0
        static Constants()
        {
            MapPoint minLonLat = new MapPoint(Constants.LonMin, Constants.LatMin, SpatialReferences.Wgs84);
            MapPoint maxLonLat = new MapPoint(Constants.LonMax, Constants.LatMax, SpatialReferences.Wgs84);

            MapPoint minXY = GeometryEngine.Project(minLonLat, SpatialReferences.WebMercator) as MapPoint;
            MapPoint maxXY = GeometryEngine.Project(maxLonLat, SpatialReferences.WebMercator) as MapPoint;

            XMin = minXY.X;
            YMin = minXY.Y;
            XMax = maxXY.X;
            YMax = maxXY.Y;

            // make sure the snapshot can be ImageWidth / ImageHeight
            if ((maxXY.X - minXY.X) / (maxXY.Y - minXY.Y) > ImageWidth / ImageHeight)
            {
                double height = (maxXY.X - minXY.X) * ImageHeight / ImageWidth;
                YMin -= (height - (maxXY.Y - minXY.Y)) / 2;
                YMax += (height - (maxXY.Y - minXY.Y)) / 2;
            }
            else
            {
                double width = (maxXY.Y - minXY.Y) * ImageWidth / ImageHeight;
                XMin -= (width - (maxXY.X - minXY.X)) / 2;
                XMax += (width - (maxXY.X - minXY.X)) / 2;
            }
        }
        // Unions feature geometries with a user defined polygon.
        private async void UnionButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _resultGraphics.Graphics.Clear();

                // wait for user to draw a polygon
                var poly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon);

                // Take account of WrapAround
                var normalizedPoly = GeometryEngine.NormalizeCentralMeridian(poly) as Polygon;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(normalizedPoly, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Union the geometries and add to graphics layer
                var states     = stateFeatures.Select(feature => feature.Geometry);
                var unionPolys = states.ToList();


                var unionPoly    = GeometryEngine.Union(unionPolys);
                var unionGraphic = new Graphic(unionPoly, _fillSymbol);

                _resultGraphics.Graphics.Add(unionGraphic);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Union Error: " + ex.Message, "Union Sample");
            }
        }
        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 + " (地图默认长度单位)";
            }
        }
Exemplo n.º 20
0
 private void FindTagByPosition(Android.Graphics.PointF position)
 {
     try
     {
         if (null != listGraphicsOverlay && listGraphicsOverlay.Count > 0)
         {
             foreach (var item in listGraphicsOverlay)
             {
                 var      pointFind = new MapPoint(position.X, position.Y, mapView.LocationDisplay.Location.Position.SpatialReference);
                 var      simpleMarkerSymbolFind = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 10);
                 var      graphicFind            = new Graphic(pointFind, simpleMarkerSymbolFind);
                 Geometry geometryData           = GeometryEngine.Project(item.Value, mapView.LocationDisplay.Location.Position.SpatialReference);
                 Boolean  result          = GeometryEngine.Contains(geometryData, graphicFind.Geometry);
                 Boolean  resultIntersect = GeometryEngine.Intersects(geometryData, graphicFind.Geometry);
                 if (result && resultIntersect)
                 {
                     var intent = new Intent(this, typeof(ConsultarTap));
                     intent.PutExtra("codigoTag", item.Key);
                     StartActivity(intent);
                     SetContentView(Resource.Layout.Fragment_ConsultarTap);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Info("Error", ex.Message);
         throw new System.Exception(ex.Message);
     }
 }
        private async void Initialize()
        {
            // Add an imagery basemap
            MyMapView.Map = new Map(Basemap.CreateImagery());

            // Get the file name
            String filepath = GetRasterPath();

            // Load the raster file
            Raster myRasterFile = new Raster(filepath);

            // Create the layer
            RasterLayer myRasterLayer = new RasterLayer(myRasterFile);

            // Load the layer
            await myRasterLayer.LoadAsync();

            // Convert the layer's extent to the correct spatial reference
            Geometry convertedExtent = GeometryEngine.Project(myRasterLayer.FullExtent, SpatialReferences.WebMercator);

            // Get the raster's extent in a viewpoint
            Viewpoint myFullRasterExtent = new Viewpoint(convertedExtent);

            // Set the viewpoint
            MyMapView.SetViewpoint(myFullRasterExtent);

            // Add the layer to the map
            MyMapView.Map.OperationalLayers.Add(myRasterLayer);
        }
Exemplo n.º 22
0
        // Calculates a geometric difference between features and user defined geometry
        private async void DifferenceButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                differenceGraphics.Graphics.Clear();

                // wait for user to draw difference polygon
                var poly = await mapView.Editor.RequestShapeAsync(DrawShape.Polygon);

                // Adjust user polygon for backward digitization
                poly = GeometryEngine.Simplify(poly);

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(poly, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Calc difference between feature geometries and user polygon and add results to graphics layer
                var states = stateFeatures.Select(feature => feature.Geometry);

                var diffGraphics = states
                                   .Select(state => ((bool)useSymmetricDifference.IsChecked)
                        ? GeometryEngine.SymmetricDifference(state, poly)
                        : GeometryEngine.Difference(state, poly))
                                   .Select(geo => new Graphic(geo, _fillSymbol));

                differenceGraphics.Graphics.AddRange(diffGraphics);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Difference Error: " + ex.Message, "Geometry Difference Sample");
            }
        }
        // Cuts feature geometries with a user defined cut polyline.
        private async void CutButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _resultGraphics.Graphics.Clear();

                // wait for user to draw cut line
                var cutLine = await mapView.Editor.RequestShapeAsync(DrawShape.Polyline, _cutLineSymbol) as Polyline;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(cutLine, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Crosses;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Cut the feature geometries and add to graphics layer
                var states      = stateFeatures.Select(feature => feature.Geometry);
                var cutGraphics = states
                                  .Where(geo => !GeometryEngine.Within(cutLine, geo))
                                  .SelectMany(state => GeometryEngine.Cut(state, cutLine))
                                  .Select(geo => new Graphic(geo, _cutFillSymbol));

                _resultGraphics.Graphics.AddRange(cutGraphics);
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog("Cut Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
Exemplo n.º 24
0
        // Clips feature geometries with a user defined clipping rectangle.
        private async void ClipButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _clippedGraphicsOverlay.Graphics.Clear();

                // wait for user to draw clip rect
                var rect = await MyMapView.Editor.RequestShapeAsync(DrawShape.Rectangle);

                Polygon polygon = GeometryEngine.NormalizeCentralMeridian(rect) as Polygon;

                // get intersecting features from the feature layer
                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.Geometry            = GeometryEngine.Project(polygon, _statesLayer.FeatureTable.SpatialReference);
                filter.SpatialRelationship = SpatialRelationship.Intersects;
                filter.MaximumRows         = 52;
                var stateFeatures = await _statesLayer.FeatureTable.QueryAsync(filter);

                // Clip the feature geometries and add to graphics layer
                var states       = stateFeatures.Select(feature => feature.Geometry);
                var clipGraphics = states
                                   .Select(state => GeometryEngine.Clip(state, polygon.Extent))
                                   .Select(geo => new Graphic(geo, _clipSymbol));

                _clippedGraphicsOverlay.Graphics.AddRange(clipGraphics);
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                MessageBox.Show("Clip Error: " + ex.Message, "Clip Geometry");
            }
        }
Exemplo n.º 25
0
        private void OnView_Tapped(object sender, Esri.ArcGISRuntime.UI.GeoViewInputEventArgs e)
        {
            MapPoint geoPoint = getGeoPoint(e);

            geoPoint = (MapPoint)GeometryEngine.Project(geoPoint, SpatialReference.Create(3857));
            Polygon buffer = (Polygon)GeometryEngine.Buffer(geoPoint, 1000.0);

            GraphicCollection graphics = (threeD ? bufferAndQuerySceneGraphics : bufferAndQueryMapGraphics).Graphics;

            graphics.Clear();
            graphics.Add(new Graphic(buffer, BUFFER_SYMBOL));
            graphics.Add(new Graphic(geoPoint, CLICK_SYMBOL));

            Esri.ArcGISRuntime.Data.QueryParameters query = new Esri.ArcGISRuntime.Data.QueryParameters();
            query.Geometry = buffer;
            LayerCollection operationalLayers;

            if (threeD)
            {
                operationalLayers = sceneView.Scene.OperationalLayers;
            }
            else
            {
                operationalLayers = mapView.Map.OperationalLayers;
            }
            foreach (Layer layer in operationalLayers)
            {
                ((FeatureLayer)layer).SelectFeaturesAsync(query, SelectionMode.New);
            }
        }
        private async void Initialize()
        {
            // Create new Scene.
            Scene myScene = new Scene {
                Basemap = Basemap.CreateImagery()
            };

            // Create and add an elevation source for the Scene.
            ArcGISTiledElevationSource elevationSrc = new ArcGISTiledElevationSource(_elevationSourceUrl);

            myScene.BaseSurface.ElevationSources.Add(elevationSrc);

            // Create new scene layer from the URL.
            ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(_serviceUri);

            // Add created layer to the operational layers collection.
            myScene.OperationalLayers.Add(sceneLayer);

            // Load the layer.
            await sceneLayer.LoadAsync();

            // Get the center of the scene layer.
            MapPoint center = (MapPoint)GeometryEngine.Project(sceneLayer.FullExtent.GetCenter(), SpatialReferences.Wgs84);

            // Create a camera with coordinates showing layer data.
            Camera camera = new Camera(center.Y, center.X, 225, 220, 80, 0);

            // Assign the Scene to the SceneView.
            MySceneView.Scene = myScene;

            // Set view point of scene view using camera.
            await MySceneView.SetViewpointCameraAsync(camera);
        }
        //private void GraphicsLayer_PointerEntered_1(object sender, GraphicPointerRoutedEventArgs e)
        //{
        //    _mapTipGraphic = e.Graphic;
        //    RenderMapTip();
        //}

        private void RenderMapTip()
        {
            MapPoint anchor = _mapTipGraphic.Geometry as MapPoint;

            if (mapView1.SpatialReference != null)
            {
                if (_mapTipGraphic != null)
                {
                    mapView1tip.DataContext = _mapTipGraphic.Attributes;
                }
                //Convert anchor point to the spatial reference of the map
                var mp = GeometryEngine.Project(anchor, mapView1.SpatialReference) as MapPoint;

                //Convert anchor point to screen coordinate
                var screen = mapView1.LocationToScreen(mp);

                if (screen.X >= 0 && screen.Y >= 0 &&
                    screen.X < mapView1.ActualWidth && screen.Y < mapView1.ActualHeight)
                {
                    //Update location of map
                    MapTipTranslate.X      = screen.X;
                    MapTipTranslate.Y      = screen.Y - mapView1tip.ActualHeight;
                    mapView1tip.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
                else //Anchor is outside the display so close mapView1tip
                {
                    mapView1tip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                }
            }
        }
Exemplo n.º 28
0
        public async void SearchByMeterID(string searchString)
        {
            SimpleLineSymbol sls = new SimpleLineSymbol()
            {
                Color = System.Windows.Media.Colors.Red,
                Style = SimpleLineStyle.Solid,
                Width = 2
            };

            // get the layer and table
            FeatureLayer            featureLayer = this.mapView.Map.Layers[1] as FeatureLayer;
            GeodatabaseFeatureTable table        = featureLayer.FeatureTable as GeodatabaseFeatureTable;

            // Define an attribute query
            var filter = new Esri.ArcGISRuntime.Data.QueryFilter();

            filter.WhereClause = "POST_ID = '" + searchString + "'";     // 666-13080

            // Execute the query and await results
            IEnumerable <Feature> features = await table.QueryAsync(filter);

            // iterate the feature. Should be one in this case.
            foreach (Feature feature in features)
            {
                // Get the MapPoint, Project to Mercator so that we are working in meters
                MapPoint mapPoint      = feature.Geometry as MapPoint;
                MapPoint pointMercator = GeometryEngine.Project(mapPoint, SpatialReferences.WebMercator) as MapPoint;
                Geometry polygon       = GeometryEngine.Buffer(pointMercator, 200);

                // Re-project the polygon to WGS84 so that we can query against the layer which is in WGS84
                Polygon polygonWgs84 = GeometryEngine.Project(polygon, SpatialReferences.Wgs84) as Polygon;

                // add the circle (buffer)
                Graphic graphic = new Graphic();
                graphic.Symbol   = sls;
                graphic.Geometry = polygonWgs84;
                this.graphicsLayer.Graphics.Add(graphic);

                // Make sure the table supports querying
                if (table.SupportsQuery)
                {
                    // setup the query to use the polygon that's in WGS84
                    var query = new Esri.ArcGISRuntime.Data.SpatialQueryFilter();
                    query.Geometry            = polygonWgs84 as Geometry;
                    query.SpatialRelationship = SpatialRelationship.Intersects;

                    var result = await table.QueryAsync(query);

                    int i = 1;
                    // Loop through query results
                    foreach (Esri.ArcGISRuntime.Data.Feature f in result)
                    {
                        // do something with results
                        System.Diagnostics.Debug.WriteLine(i.ToString());
                        i++;
                    }
                }
            }
        }
Exemplo n.º 29
0
        private MapPoint GetLocation(Envelope viewpointExtent)
        {
            double x     = viewpointExtent.XMin + (_random.NextDouble() * viewpointExtent.Width);
            double y     = viewpointExtent.YMin + (_random.NextDouble() * viewpointExtent.Height);
            var    point = new MapPoint(x, y, viewpointExtent.SpatialReference);

            return((MapPoint)GeometryEngine.Project(point, SpatialReferences.Wgs84));
        }
Exemplo n.º 30
0
        public async void Initialize()
        {
            // Create a new scene with basemap
            var myScene = new Scene(Basemap.CreateImageryWithLabels());

            // create an elevation source
            ArcGISTiledElevationSource elevationSrc = new ArcGISTiledElevationSource(_elevationSourceUrl);

            myScene.BaseSurface.ElevationSources.Add(elevationSrc);

            // create additional layer
            ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(_serviceUri);

            myScene.OperationalLayers.Add(sceneLayer);

            // Set the surface placement mode for the overlay.
            graphicsOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Relative;

            // create a red "X" marker symbol
            SimpleMarkerSceneSymbol car = new SimpleMarkerSceneSymbol(SimpleMarkerSceneSymbolStyle.Cube, Color.Red, 20, 20, 20, SceneSymbolAnchorPosition.Bottom);

            // create a new graphic; assign the point and the symbol in the constructor


            try
            {
                // Load the layer.
                await sceneLayer.LoadAsync();

                // Get the center of the scene layer.
                MapPoint center = (MapPoint)GeometryEngine.Project(sceneLayer.FullExtent.GetCenter(), SpatialReferences.Wgs84);
                Console.WriteLine(center.ToString());
                var newPoint = new MapPoint(_positionPublisher.getX(), _positionPublisher.getY(), 0, SpatialReferences.Wgs84);

                graphic.Geometry = newPoint;
                graphic.Symbol   = car;

                graphicsOverlay.Graphics.Add(graphic);
                MainWindow.View.Map3D.GraphicsOverlays.Add(graphicsOverlay);

                // Assign the Scene to the SceneView.
                MainWindow.View.Map3D.Scene = myScene;

                ////  CAMERA ANGLE ////
                // Create a camera with coordinates showing layer data.
                // Camera camera = new Camera(center.Y, center.X, 225, 220, 80, 0);
                // Set view point of scene view using camera.
                //await Map3D.SetViewpointCameraAsync(camera);

                // create an OrbitGeoElementCameraController, pass in the target graphic and initial camera distance
                var orbitGraphicController = new OrbitGeoElementCameraController(graphic, 1000);
                MainWindow.View.Map3D.CameraController = orbitGraphicController;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error");
            }
        }