コード例 #1
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;
        }
コード例 #2
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);
        }
コード例 #3
0
        private async Task DoCutPolygons()
        {
            SetupUI();
            if (graphicsLayer != null)
            {
                //Get the user's input
                var cutPolyLine = (await mapView1.Editor.RequestShapeAsync(DrawShape.Polyline)) as Polyline;

                //iterate over the graphics in the graphicsLayer. If the graphic intersects with the polyline we will cut it.
                //and then create Graphic objects from the results. Next we add those Graphics resulting to a new list (finalList).
                //if it doesn't we will add the graphic to the new list (finalList)
                var finalList = graphicsLayer.Graphics.ToList();
                foreach (var g in graphicsLayer.Graphics)
                {
                    if (GeometryEngine.Intersects(g.Geometry, cutPolyLine))
                    {
                        var cutPolygonGeometries = GeometryEngine.Cut(g.Geometry, cutPolyLine);
                        var cutPolygonGraphics   = cutPolygonGeometries.Select(x => new Graphic {
                            Geometry = x
                        });
                        finalList.AddRange(cutPolygonGraphics);
                    }
                    else
                    {
                        finalList.Add(g);
                    }
                }
                //add the results to the graphics layer
                graphicsLayer.Graphics.Clear();
                graphicsLayer.Graphics.AddRange(finalList);
            }
        }
コード例 #4
0
        private async Task DoCutPolygons()
        {
            if (statesOverlay != null && resultsOverlay != null)
            {
                resultsOverlay.Graphics.Clear();

                // Get the user's input
                var cutPolyLine = (await mapView1.Editor.RequestShapeAsync(DrawShape.Polyline)) as Polyline;

                // Normalize for WrapAround
                Polyline polyline = GeometryEngine.NormalizeCentralMeridian(cutPolyLine) as Polyline;

                // Iterate over the graphics in the GraphicsOverlay. If the graphic intersects with the polyline we will cut it
                // and create Graphic objects from the results. Next we add those Graphics resulting to a List<Graphic>.
                List <Graphic> cutGraphics = new List <Graphic>();
                foreach (var g in statesOverlay.Graphics)
                {
                    if (GeometryEngine.Intersects(g.Geometry, polyline))
                    {
                        var cutPolygonGeometries = GeometryEngine.Cut(g.Geometry, polyline);
                        var cutPolygonGraphics   = cutPolygonGeometries.Select(x => new Graphic {
                            Geometry = x
                        });
                        cutGraphics.AddRange(cutPolygonGraphics);
                    }
                }
                // Add the results to the GraphicsOverlay
                resultsOverlay.Graphics.AddRange(cutGraphics);
            }
        }
コード例 #5
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);
     }
 }
コード例 #6
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;
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: AbstractLayer.cs プロジェクト: mrc-glk/gsec
        public virtual List <T> ListByPosition(MapPoint point, double toleranceMeters = 0)
        {
            Geometry buf = (toleranceMeters > 0 ? GeometryEngine.BufferGeodetic(point, toleranceMeters, LinearUnits.Meters) : point);

            IEnumerable <T> elements = Elements.Where(r => GeometryEngine.Intersects(r.Graphic.Geometry, buf));

            return(elements.ToList());
        }
コード例 #8
0
ファイル: AbstractLayer.cs プロジェクト: mrc-glk/gsec
        public virtual T ByPosition(MapPoint point, double toleranceMeters = 0)
        {
            Geometry buf = (toleranceMeters > 0 ? GeometryEngine.BufferGeodetic(point, toleranceMeters, LinearUnits.Meters) : point);

            IEnumerable <T> elements = Elements.Where(r => GeometryEngine.Intersects(r.Graphic.Geometry, buf));

            //Console.WriteLine("ByPosition({0}) found {1} elements", typeof(T).Name, elements.Count());
            return(elements.FirstOrDefault());
        }
コード例 #9
0
 private Graphic FindRelatedCountry(MapPoint location)
 {
     // TODO: Use a spatial index!
     foreach (var country in _countryOverlay.Graphics)
     {
         var      countryGeometry         = country.Geometry;
         var      countrySpatialReference = countryGeometry.SpatialReference;
         Geometry locationGeometry;
         if (location.SpatialReference.Wkid != countrySpatialReference.Wkid)
         {
             locationGeometry = GeometryEngine.Project(location, countrySpatialReference);
         }
         else
         {
             locationGeometry = location;
         }
         if (GeometryEngine.Intersects(countryGeometry, locationGeometry))
         {
             return(country);
         }
     }
     return(null);
 }
コード例 #10
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;
        }
コード例 #11
0
        // REWORK ALL THIS LOGIC
        private void doFrameRanger(double elapsedSeconds)
        {
            // convert km/h to m/s
            double rangerSpeed = viewModel.RangerSpeed / 3.6;

            lock (rangerLayer.DataLock)
            {
                foreach (Ranger ranger in rangerLayer.Elements)
                {
                    MapPoint newPos = ranger.UpdateUiPosition(rangerSpeed, elapsedSeconds);

                    Geometry buf = GeoUtil.GetBuffer(newPos, Ranger.FineRange);

                    // catch interlopers nearby
                    lock (interloperLayer.DataLock)
                    {
                        List <Interloper> caught = interloperLayer.Elements.Where(x => GeometryEngine.Intersects(buf, x.EsriPosition) == true).ToList();
                        if (caught.Count > 0)
                        {
                            rangerLayer.ShowFineAnimation(ranger);
                            caught.ForEach(x => interloperLayer.RemoveElement(x));
                            ranger.Route = null;
                        }
                    }
                }
            }
        }
コード例 #12
0
        private async void QueryFeatures(Geometry buffer, MapPoint location)
        {
            //create query
            var query = new QueryParameters();

            query.Geometry           = buffer;
            query.MaxAllowableOffset = 0;
            System.Diagnostics.Debug.WriteLine(buffer.ToJson());

            var layer   = MyMapView.Map.OperationalLayers[0] as FeatureLayer;
            var table   = layer.FeatureTable;
            var results = await table.QueryFeaturesAsync(query);

            layer.ClearSelection();


            /* // ===================================================================
             * //                       Single Closest Bar
             * // -------------------------------------------------------------------
             *
             * double shortDist = -1;
             * Feature feature = null;
             *
             * //check for closest bars within buffer
             * foreach (var item in results)
             * {
             *  var calcDistance = GeometryEngine.Distance(location, item.Geometry);
             *
             *  if (shortDist == -1)
             *  {
             *      shortDist = calcDistance;
             *      feature = item;
             *      continue;
             *  }
             *
             *  if (calcDistance < shortDist)
             *  {
             *      shortDist = calcDistance;
             *      feature = item;
             *  }
             * }
             *
             * //exit if no closest bar
             * if (feature == null)
             *  return;
             *
             * if (!(GeometryEngine.Intersects(buffer, feature.Geometry)))
             *  return;
             *
             * //highlight closest bar
             * layer.SelectFeature(feature);
             * layer.SelectionColor = Colors.DarkRed;
             *
             * //draw line to closest bar
             * var linePoints = new PolylineBuilder(SpatialReferences.WebMercator);
             * linePoints.AddPoint(location);
             * linePoints.AddPoint(feature.Geometry as MapPoint);
             * var line = linePoints.ToGeometry();
             *
             * var lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.DashDotDot, Colors.Maroon, 2);
             * var lineGraphic = new Graphic(line, lineSymbol);
             * MyOverlay.Graphics.Add(lineGraphic);
             *
             *
             * //create text symbol for distance at midpoint of line
             * var x = (line.Extent.XMin + line.Extent.XMax) / 2;
             * var y = (line.Extent.YMin + line.Extent.YMax) / 2;
             * var textPoint = new MapPoint(x, y);
             * var text = String.Format("{0:0.00}", shortDist / 1609.34) + " miles";
             * var textSymbol = new TextSymbol(text, Colors.Black, 15, Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Center, Esri.ArcGISRuntime.Symbology.VerticalAlignment.Baseline);
             * textSymbol.FontWeight = Esri.ArcGISRuntime.Symbology.FontWeight.Bold;
             * //textSymbol.BackgroundColor = Colors.Maroon;
             * //textSymbol.Angle = Math.Atan2(line.Extent.YMax - line.Extent.YMin, line.Extent.XMax - line.Extent.XMin) * 180.0 / Math.PI;
             * var textGraphic = new Graphic(textPoint, textSymbol);
             * MyOverlay.Graphics.Add(textGraphic);
             *
             * //===================================================================*/



            //==================================================================
            //                    Two Closest Bars
            //------------------------------------------------------------------

            double[]  shortDist = { -1, -1 };
            Feature[] feature   = new Feature[2];
            System.Diagnostics.Debug.WriteLine("#1: shortdist is at: " + shortDist[0].ToString() + " " + shortDist[1].ToString());

            //check for closest bars within buffer
            foreach (var item in results)
            {
                var calcDistance = GeometryEngine.Distance(location, item.Geometry);
                System.Diagnostics.Debug.WriteLine("feature distance: " + (calcDistance / 1609.34).ToString() + " meters; shordist = " + shortDist[0].ToString() + " " + shortDist[1].ToString());
                if (shortDist[0] == -1)
                {
                    shortDist[0] = calcDistance;
                    System.Diagnostics.Debug.WriteLine("setting first");
                    feature[0] = item;
                    continue;
                }
                if (shortDist[1] == -1)
                {
                    System.Diagnostics.Debug.WriteLine("setting second");
                    shortDist[1] = calcDistance;
                    feature[1]   = item;
                    continue;
                }

                if (calcDistance < shortDist[0])
                {
                    System.Diagnostics.Debug.WriteLine("less than first");
                    shortDist[1] = shortDist[0];
                    feature[1]   = feature[0];
                    shortDist[0] = calcDistance;
                    feature[0]   = item;
                }
                else if (calcDistance < shortDist[1])
                {
                    System.Diagnostics.Debug.WriteLine("less than second");
                    shortDist[1] = calcDistance;
                    feature[1]   = item;
                }
            }

            //exit if no closest bar
            if (feature[0] == null || feature[1] == null)
            {
                return;
            }

            if (!(GeometryEngine.Intersects(buffer, feature[0].Geometry)))
            {
                return;
            }

            //highlight closest bar
            for (int i = 0; i < 2; i++)
            {
                layer.SelectFeature(feature[i]);
                layer.SelectionColor = Colors.DarkRed;

                //draw line to closest bar
                var linePoints = new PolylineBuilder(SpatialReferences.WebMercator);
                linePoints.AddPoint(location);
                linePoints.AddPoint(feature[i].Geometry as MapPoint);
                var line = linePoints.ToGeometry();

                var lineSymbol  = new SimpleLineSymbol(SimpleLineSymbolStyle.DashDotDot, Colors.Maroon, 2);
                var lineGraphic = new Graphic(line, lineSymbol);
                MyOverlay.Graphics.Add(lineGraphic);

                //create text symbol for distance at midpoint of line
                var x          = (line.Extent.XMin + line.Extent.XMax) / 2;
                var y          = (line.Extent.YMin + line.Extent.YMax) / 2;
                var textPoint  = new MapPoint(x, y);
                var text       = String.Format("{0:0.00}", shortDist[i] / 1609.34) + " miles";
                var textSymbol = new TextSymbol(text, Colors.Black, 15, Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Center, Esri.ArcGISRuntime.Symbology.VerticalAlignment.Baseline);
                textSymbol.FontWeight = Esri.ArcGISRuntime.Symbology.FontWeight.Bold;
                //textSymbol.BackgroundColor = Colors.Maroon;
                //textSymbol.Angle = Math.Atan2(line.Extent.YMax - line.Extent.YMin, line.Extent.XMax - line.Extent.XMin) * 180.0 / Math.PI;
                var textGraphic = new Graphic(textPoint, textSymbol);
                MyOverlay.Graphics.Add(textGraphic);
            }
        }