Select to view content in your preferred language

How to Get polygon points from Geometry.Ring

4436
4
Jump to solution
06-25-2012 07:18 PM
JulieBiju
Deactivated User
Hello...Advance thanks...Please help me to solve the issue specified below

I drw a polygon on my map using the function below.Now i want to save these polygon points to DB for future reference.How can i retrive polygon points?I try to access the ring values and failed with that .Help me for this Please

Private Sub MyDrawObject_DrawComplete(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.DrawEventArgs)                   'args.Geometry.rings              Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)         Dim graphic As New ESRI.ArcGIS.Client.Graphic() With           {             .Geometry = args.Geometry,             .Symbol = _activeSymbol           }         graphicsLayer.Graphics.Add(graphic)       End Sub
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Alum
You cast the geometry to a Polygon, which has a collection of Rings.  Each Ring is a PointCollection, for a user drawn polygon with the standard tools the polygon will only have one Ring.  In C# something like this

    if ( args.Geometry is Polygon )   {   PointCollection points = ((Polygon)geometry).Rings[0];   foreach ( MapPoint mapPoint in points )   {    //Save the points   }  } 


Hope that helps
Thanks,
-Joe

View solution in original post

0 Kudos
4 Replies
JoeHershman
MVP Alum
You cast the geometry to a Polygon, which has a collection of Rings.  Each Ring is a PointCollection, for a user drawn polygon with the standard tools the polygon will only have one Ring.  In C# something like this

    if ( args.Geometry is Polygon )   {   PointCollection points = ((Polygon)geometry).Rings[0];   foreach ( MapPoint mapPoint in points )   {    //Save the points   }  } 


Hope that helps
Thanks,
-Joe
0 Kudos
JulieBiju
Deactivated User
You cast the geometry to a Polygon, which has a collection of Rings.  Each Ring is a

if ( args.Geometry is Polygon )
  {
  PointCollection points = ((Polygon)geometry).Rings[0];
  foreach ( MapPoint mapPoint in points )
  {
   //Save the points
  }
}



I am getting errors like
'Polygon' is ambiguous, imported from the namespaces or types 'ESRI.ArcGIS.Client.Geometry, System.Windows.Shapes'.
'PointCollection' is ambiguous, imported from the namespaces or types 'ESRI.ArcGIS.Client.Geometry, System.Windows.Media'.

 If TypeOf args.Geometry Is Polygon Then
            Dim points As PointCollection = DirectCast(geometry, Polygon).Rings(0)
            'Save the points
            For Each mapPoint As MapPoint In points
            Next
        End If




					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
JulieBiju
Deactivated User
I am getting errors like
'Polygon' is ambiguous, imported from the namespaces or types 'ESRI.ArcGIS.Client.Geometry, System.Windows.Shapes'.
'PointCollection' is ambiguous, imported from the namespaces or types 'ESRI.ArcGIS.Client.Geometry, System.Windows.Media'.


Commented
'Imports System.Windows.Media
'Imports System.Windows.Shapes

Now working fine...Thankk UUUUU
0 Kudos
DavidMarley
Frequent Contributor
That "ambiguous...namespace" error is a very standard one and simply means there are multiple objects with name = <ObjectName> (e.g., Polygon) in the namespaces you have referenced via using statements. One solution is as you noted, to simply remove any using statements for namespaces you are not using anyway. The other solution is to fully qualify the object reference, for example "ESRI.ArcGIS.Client.Geometry.Polygon" instead of just "Polygon".  One last handy solution is to use the following using syntax to clarify which object you intend to use by default in your class:

using Polygon = ESRI.ArcGIS.Client.Geometry.Polygon;

Then in your code you can refer to Polygon without getting any ambiguous namespace error:

Polygon poly = new Polygon(); // no ambiguous error...


This is especially useful for something like Polygon which has naming conflicts even within the Esri namespaces (e.g., ESRI.ArcGIS.Client.Geometry.Polygon and ESRI.ArcGIS.Client.Bing.GeocodeService.Polygon)
0 Kudos