Exemplo n.º 1
0
        // REWORK ALL THIS LOGIC
        private void doFrameInterloper(double elapsedSeconds)
        {
            double interloperSpeed = viewModel.InterloperSpeed / 3.6;

            lock (interloperLayer.DataLock)
            {
                foreach (Interloper interloper in interloperLayer.Elements)
                {
                    MapPoint newPos = interloper.UpdateUiPosition(interloperSpeed, elapsedSeconds);

                    Sensor nearestSensor = sensorLayer.GetNearestTo(newPos);
                    if (nearestSensor == null)
                    {
                        continue;
                    }

                    if (GeometryEngine.Within(newPos, nearestSensor.RangeGraphic.Geometry) == true)
                    {
                        handleAlarm(nearestSensor);

                        interloper.Graphic.IsVisible = true;
                    }
                    else
                    {
                        interloper.Graphic.IsVisible = (interloperLayer.ShowOnlyWithinSensorRange == false);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Accepts two user shapes and adds them to the graphics layer
        private async Task AcceptShapeAsync()
        {
            // Shape One
            Geometry shapeOne = await mapView.Editor.RequestShapeAsync(
                (DrawShape)comboShapeOne.SelectedValue, _symbols[comboShapeOne.SelectedIndex]);

            _graphicsLayer.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex]));

            // Shape Two
            Geometry shapeTwo = await mapView.Editor.RequestShapeAsync(
                (DrawShape)comboShapeTwo.SelectedValue, _symbols[comboShapeTwo.SelectedIndex]);

            _graphicsLayer.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex]));

            var relations = new List <Tuple <string, bool> >();

            relations.Add(new Tuple <string, bool>("Contains", GeometryEngine.Contains(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Crosses", GeometryEngine.Crosses(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Disjoint", GeometryEngine.Disjoint(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Equals", GeometryEngine.Equals(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Intersects", GeometryEngine.Intersects(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Overlaps", GeometryEngine.Overlaps(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Touches", GeometryEngine.Touches(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Within", GeometryEngine.Within(shapeOne, shapeTwo)));
            resultsListView.ItemsSource = relations;

            resultsPanel.Visibility = Visibility.Visible;
        }
        // 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)
            {
                MessageBox.Show("Cut Error: " + ex.Message, "Cut Geometry");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a list of spatial relationships between two geometries
        /// </summary>
        /// <param name="a">The 'a' in "a contains b"</param>
        /// <param name="b">The 'b' in "a contains b"</param>
        /// <returns>A list of spatial relationships that are true for a and b.</returns>
        private static List <SpatialRelationship> GetSpatialRelationships(Geometry a, Geometry b)
        {
            List <SpatialRelationship> relationships = new List <SpatialRelationship>();

            if (GeometryEngine.Crosses(a, b))
            {
                relationships.Add(SpatialRelationship.Crosses);
            }
            if (GeometryEngine.Contains(a, b))
            {
                relationships.Add(SpatialRelationship.Contains);
            }
            if (GeometryEngine.Disjoint(a, b))
            {
                relationships.Add(SpatialRelationship.Disjoint);
            }
            if (GeometryEngine.Intersects(a, b))
            {
                relationships.Add(SpatialRelationship.Intersects);
            }
            if (GeometryEngine.Overlaps(a, b))
            {
                relationships.Add(SpatialRelationship.Overlaps);
            }
            if (GeometryEngine.Touches(a, b))
            {
                relationships.Add(SpatialRelationship.Touches);
            }
            if (GeometryEngine.Within(a, b))
            {
                relationships.Add(SpatialRelationship.Within);
            }
            return(relationships);
        }
        /// <summary>
        /// The methods retrieves the outer ring(s) of the input polygon.
        /// This method must be called on the MCT. Use QueuedTask.Run.
        /// </summary>
        /// <param name="inputPolygon">Input Polygon.</param>
        /// <returns>The outer most (exterior, clockwise) ring(s) of the polygon. If the input is null or empty, a null pointer is returned.</returns>
        /// <remarks>This method must be called on the MCT. Use QueuedTask.Run.</remarks>
        public Polygon GetOutermostRings(Polygon inputPolygon)
        {
            if (inputPolygon == null || inputPolygon.IsEmpty)
            {
                return(null);
            }

            PolygonBuilder outerRings    = new PolygonBuilder();
            List <Polygon> internalRings = new List <Polygon>();

            // explode the parts of the polygon into a list of individual geometries
            var parts = MultipartToSinglePart(inputPolygon);

            // get an enumeration of clockwise geometries (area > 0) ordered by the area
            var clockwiseParts = parts.Where(geom => ((Polygon)geom).Area > 0).OrderByDescending(geom => ((Polygon)geom).Area);

            // for each of the exterior rings
            foreach (var part in clockwiseParts)
            {
                // add the first (the largest) ring into the internal collection
                if (internalRings.Count == 0)
                {
                    internalRings.Add(part as Polygon);
                }

                // use flag to indicate if current part is within the already selection polygons
                bool isWithin = false;

                foreach (var item in internalRings)
                {
                    if (GeometryEngine.Within(part, item))
                    {
                        isWithin = true;
                    }
                }

                // if the current polygon is not within any polygon of the internal collection
                // then it is disjoint and needs to be added to
                if (isWithin == false)
                {
                    internalRings.Add(part as Polygon);
                }
            }

            // now assemble a new polygon geometry based on the internal polygon collection
            foreach (var ring in internalRings)
            {
                outerRings.AddParts(ring.Parts);
            }

            // return the final geometry of the outer rings
            return(outerRings.ToGeometry());
        }
Exemplo n.º 6
0
        // Accepts two user shapes and adds them to the graphics layer
        private async Task AcceptShapeAsync()
        {
            // Shape One
            DrawShape drawShape1 = (DrawShape)comboShapeOne.SelectedItem;
            Geometry  shapeOne   = null;

            if (drawShape1 == DrawShape.Point)
            {
                shapeOne = await mapView.Editor.RequestPointAsync();
            }
            else
            {
                shapeOne = await mapView.Editor.RequestShapeAsync(drawShape1, _symbols[comboShapeOne.SelectedIndex]);
            }

            graphicsLayer.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex]));

            // Shape Two
            Geometry shapeTwo = await mapView.Editor.RequestShapeAsync(
                (DrawShape)comboShapeTwo.SelectedItem, _symbols[comboShapeTwo.SelectedIndex]);

            graphicsLayer.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex]));

            Dictionary <string, bool> relations = new Dictionary <string, bool>();

            relations["Contains"]   = GeometryEngine.Contains(shapeOne, shapeTwo);
            relations["Crosses"]    = GeometryEngine.Crosses(shapeOne, shapeTwo);
            relations["Disjoint"]   = GeometryEngine.Disjoint(shapeOne, shapeTwo);
            relations["Equals"]     = GeometryEngine.Equals(shapeOne, shapeTwo);
            relations["Intersects"] = GeometryEngine.Intersects(shapeOne, shapeTwo);
            relations["Overlaps"]   = GeometryEngine.Overlaps(shapeOne, shapeTwo);
            relations["Touches"]    = GeometryEngine.Touches(shapeOne, shapeTwo);
            relations["Within"]     = GeometryEngine.Within(shapeOne, shapeTwo);

            resultsPanel.Visibility     = Visibility.Visible;
            resultsListView.ItemsSource = relations;
        }
Exemplo n.º 7
0
        //SFS requires polygons to be ordered by outer and inner rings. Analyze multi polygons and split in individual polygons with one outer ring and internal rings
        internal static IEnumerable <Tuple <ReadOnlyPart, IList <ReadOnlyPart> > > SplitMultiPolygon(Polygon p)
        {
            List <Tuple <ReadOnlyPart, IList <ReadOnlyPart> > > outerRings =
                new List <Tuple <ReadOnlyPart, IList <ReadOnlyPart> > >();
            List <ReadOnlyPart> innerRings = new List <ReadOnlyPart>();

            foreach (var ring in p.Parts)
            {
                if (!IsCcw(ring.Points))
                {
                    outerRings.Add(new Tuple <ReadOnlyPart, IList <ReadOnlyPart> >(ring, new List <ReadOnlyPart>()));
                }
                else
                {
                    innerRings.Add(ring);
                }
            }
            foreach (var ring in innerRings)
            {
                var  inner          = new Polygon(ring);
                bool outerRingFound = false;
                foreach (var outerRing in outerRings)
                {
                    if (GeometryEngine.Within(inner, new Polygon(outerRing.Item1)))
                    {
                        outerRing.Item2.Add(ring);
                        outerRingFound = true;
                        break;
                    }
                }
                if (!outerRingFound)
                {
                    throw new System.IO.InvalidDataException("Ring orientations are wrong - please simplify geometry first");
                }
            }
            return(outerRings);
        }
        /// <summary>Get the Lat, Long from the Bing StreetSide View to set the location on the Pro Map</summary>
        public static Task SetMapLocationFromBing(double?longitude, double?latitude, int heading)
        {
            #region Process Heading

            var activeMapView = MapView.Active;
            if (activeMapView == null)
            {
                return(null);
            }

            #endregion

            return(QueuedTask.Run(() => {
                try
                {
                    var cam = activeMapView.Camera;
                    var bHeadingChange = Convert.ToInt32(cam.Heading) != heading;
                    cam.Heading = Convert.ToDouble(heading);
                    if (longitude.HasValue && latitude.HasValue)
                    {
                        var pt = MapPointBuilder.CreateMapPoint(longitude.Value, latitude.Value, SpatialReferences.WGS84);
                        var center = GeometryEngine.Project(pt, activeMapView.Map.SpatialReference) as MapPoint;
                        if (center == null)
                        {
                            return;
                        }
                        ShowCurrentBingMapCoord(center);

                        #region Update Map

                        // check if the center is outside the map view extent
                        var env = activeMapView.Extent.Expand(0.75, 0.75, true);
                        var bWithin = GeometryEngine.Within(center, env);
                        if (!bWithin)
                        {
                            cam.X = center.X;
                            cam.Y = center.Y;
                        }
                        if (_bFirst)
                        {
                            cam.Scale = 2000;
                            activeMapView.ZoomTo(cam, TimeSpan.FromMilliseconds(100));
                            _bFirst = false;
                        }
                        else
                        {
                            activeMapView.PanTo(cam, TimeSpan.FromMilliseconds(1000));
                        }
                        bHeadingChange = false;

                        #endregion
                    }
                    if (bHeadingChange)
                    {
                        activeMapView.PanTo(cam, TimeSpan.FromMilliseconds(300));
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($@"Error in SetMapLocationFromBing: {ex.Message}");
                }
            }));
        }
Exemplo n.º 9
0
 public static bool IsWithin(this MapPoint geometry, Envelope envelope)
 {
     return(GeometryEngine.Within(geometry, envelope));
 }
Exemplo n.º 10
0
        private void Geometry_OnviewTap(Graphic _graphic)
        {
            //var ree1 = graphic_collection.SelectMany(graphic => graphic.Attributes, (gr_key, gr_value) => new { gr_key, gr_value });
            var ere = _graphic.Geometry.GeometryType.ToString();
            List <GraphicsOverlay> grc = new List <GraphicsOverlay>();

            // GraphicCollection tempgrc=
            //  GraphicsOverlayCollection grc=new GraphicsOverlayCollection() ;
            foreach (var item in MyMapView.GraphicsOverlays)
            {
                if (item.Id != "seven")
                {
                    grc.Add(item);
                }
            }
            //var ree1 = grc.SelectMany(graphic => graphic.Attributes, (gr_key, gr_value) => new { gr_key, gr_value });

            if (ere == "Polyline")
            {
                foreach (var ter in grc)
                {
                    foreach (var item in ter.Graphics)
                    {
                        var textsymline = item.Symbol.ToString();
                        if (textsymline != "Esri.ArcGISRuntime.Symbology.TextSymbol")
                        {
                            if ((GeometryEngine.Intersects(item.Geometry, _graphic.Geometry) || GeometryEngine.Within(item.Geometry, _graphic.Geometry) || GeometryEngine.Overlaps(item.Geometry, _graphic.Geometry)))
                            {
                                item.IsSelected = true;
                            }
                        }
                        else
                        {
                            var se = item.Geometry;
                        }
                    }
                }
            }
            if (ere == "Polygon")
            {
                foreach (var ter in grc)
                {
                    foreach (var item in ter.Graphics)
                    {
                        var textsympolygon = item.Symbol.ToString();
                        if (textsympolygon != "Esri.ArcGISRuntime.Symbology.TextSymbol")
                        {
                            if ((GeometryEngine.Intersects(item.Geometry, _graphic.Geometry) || GeometryEngine.Within(item.Geometry, _graphic.Geometry) || GeometryEngine.Overlaps(item.Geometry, _graphic.Geometry)))
                            {
                                item.IsSelected = true;
                            }
                        }
                        else
                        {
                            var ett = item.Geometry;
                        }
                    }
                }
            }
        }