ThinkGeo.com    |     Documentation    |     Premium Support

Get all points of a shape

What I am trying to do is, if you select a shape on a map, I want to be able to find the distance of each line of that shape and create a label from it.


Is there a way that i can get all the points that represent the selected shape?  What ive been trying to do is find the bounding box of that shape and then take the difference between the two but when I do so i get a GeometryCollection is not supported now exception. 


Is there any way to get all the points of a shape?


Thanks in advance,


Andy



Hi Andy, 
  
 you can use the vertices property, this gives you the collection of points. 
  
 ex: 
 LineShape ls = theMap.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape() as LineShape; 
 Console.writeln (ls.Vertices.Count); 
  
 Patrick.

Hi Patrick, 
  
 Thanks for the help.  When I try to use your idea the LineShape gets set to null.  Is there any way to get the vertices of a Multipolygon shape? 
  


Here is my code for a multipolygon; 
  
 MultipolygonShape mpl = aFeature.GetShape (); 
 foreach (PolygonShape mp in mpl.Polygons) 
 { 
    verticesCollection.AddRange (mp.OuterRing.Vertices); 
 } 
  
 As you can see, this code does not manage inner rings but can easily be changed to. 
  
 Patrick.

Andy, 
  
 I agree with Patrick’s idea, thanks for his sharing. 
  
 If you want to get all points of a shape, first you need to know which kind of shape you are using. And then get the points depend on different shape type, maybe you can not find the Vertices directly, such as MultipolygonShape, I think Patrick’s sample code can guide you to deal with this condition. 
  
 Please let me know if you have more questions. 
  
 Thanks 
  
 James 


Thanks for all the help, the multipolygon loop worked great.

Sounds good, any more questions please let us know. 
  
 Thanks, 
  
 Sun