How to get polygon all coordinates

1379
7
Jump to solution
07-04-2012 06:12 AM
DevaKa
by
New Contributor
Hi All,

I want to know how to get polygon all coordinates? I have a situation to save all coordinates. If I draw a multi-line, I have to capture all coordinates for it. When I use Client.Graphic.Extent.toString(), I am getting only 4 coordinates (If I am not wrong it might be minx,miny, maxx,maxy) when I draw rectangle and point. But I want to capture all coordinates for polygon and multiline.

thanks in Advance.
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Regular Contributor
   if ( graphic.Geometry is Polygon )   {  .....   } 


Joe, how to get coordinates for each side of polygon? I am drawing only a polygon. I want to get all coordinates of polygon.


         private void ShowPolyCoords(Graphic graphic)         {             var polygon = graphic.Geometry as Polygon;             if ( polygon == null ) return;               PointCollection points = polygon.Rings[0];             foreach (var point in points)             {                 Debug.WriteLine("X: {0}, Y: {1}", point.X, point.Y);             }         } 
Thanks,
-Joe

View solution in original post

7 Replies
LanceCrumbliss
Occasional Contributor II
Hi All,

I want to know how to get polygon all coordinates? I have a situation to save all coordinates. If I draw a multi-line, I have to capture all coordinates for it. When I use Client.Graphic.Extent.toString(), I am getting only 4 coordinates (If I am not wrong it might be minx,miny, maxx,maxy) when I draw rectangle and point. But I want to capture all coordinates for polygon and multiline.

thanks in Advance.



Forgive me, as this is air-code, but the logic is:


if the graphic's geometry is a polygon then 
   For each ring in the polygon's rings
        for each mappoint in the ring's pointcollection
          do something with the mappoint (like get mappoint.X and mappoint.Y) 
       next mappoint
     next ring
End if
0 Kudos
DevaKa
by
New Contributor
Thanks for prompt response.

if the graphic's geometry is a polygon then 
   For each ring in the polygon's rings
        for each mappoint in the ring's pointcollection
          do something with the mappoint (like get mappoint.X and mappoint.Y) 
       next mappoint
     next ring
End if


I am new to this Silverlight viewer. I didn't find any rings or mappoint or pointcollections in graphics.
0 Kudos
JoeHershman
MVP Regular Contributor
A Graphic object has a Geometry property so what is described above is something like


  if ( graphic.Geometry is Polygon )
  { 
.....
  }

Thanks,
-Joe
0 Kudos
LanceCrumbliss
Occasional Contributor II
Thanks for prompt response.

I am new to this Silverlight viewer. I didn't find any rings or mappoint or pointcollections in graphics.


THe graphic's geometry.�??  not the graphic itself.
0 Kudos
DevaKa
by
New Contributor

  if ( graphic.Geometry is Polygon )
  { 
.....
  }



Joe, how to get coordinates for each side of polygon? I am drawing only a polygon. I want to get all coordinates of polygon.
0 Kudos
JoeHershman
MVP Regular Contributor
   if ( graphic.Geometry is Polygon )   {  .....   } 


Joe, how to get coordinates for each side of polygon? I am drawing only a polygon. I want to get all coordinates of polygon.


         private void ShowPolyCoords(Graphic graphic)         {             var polygon = graphic.Geometry as Polygon;             if ( polygon == null ) return;               PointCollection points = polygon.Rings[0];             foreach (var point in points)             {                 Debug.WriteLine("X: {0}, Y: {1}", point.X, point.Y);             }         } 
Thanks,
-Joe
DevaKa
by
New Contributor
Thanks Joe. It works fine.
0 Kudos