Select to view content in your preferred language

How to retrieve the coordinates of a polygon graphics?

922
3
07-12-2012 06:34 AM
FabienNAPPA
Regular Contributor
How to retrieve the coordinates of a polygon graphics?

    

   private void GetCoordonnatesPolygonGraphics(Graphic graphic)
        {
           // Here ????
        }


  private void AddPolygonGraphics()
       {
            string coordinateString1 = "130,5.59 118.42,3.92 117.3,23.3 143.2,22.9 130,5.59";

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            PointCollectionConverter pointConverter = new PointCollectionConverter();
            ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 =
                pointConverter.ConvertFromString(coordinateString1) as ESRI.ArcGIS.Client.Geometry.PointCollection;

            ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon();
            polygon1.Rings.Add(pointCollection1);

            Graphic graphic = new Graphic()
            {
                Geometry = mercator.FromGeographic(polygon1),
                Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol
            };

            graphicsLayer.Graphics.Add(graphic);
       }




Thank's
Fabiano
0 Kudos
3 Replies
JoeHershman
MVP Alum
0 Kudos
RKatz
by
Emerging Contributor

looks like the docs are deprecated

0 Kudos
FabienNAPPA
Regular Contributor
Thank you !

This is code :

        private static ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
     
        void ShowPolyCoords(Graphic graphic)
        {
            listBox1.Items.Clear();
            var polygon = graphic.Geometry as Polygon;
            if (polygon == null) return;
            PointCollection points = polygon.Rings[0];

            foreach (var point in points)
            {
                MapPoint pMapPointGeog = (MapPoint)mercator.ToGeographic(point);
                listBox1.Items.Add(String.Format("{0:0.00} | {1:0.00}", pMapPointGeog.X, pMapPointGeog.Y));
            }
        }

0 Kudos