ThinkGeo.com    |     Documentation    |     Premium Support

Convert line to polygon

I let my users to track a polygon line to measure a length.   If they get close to their starting point, I assume they wanted to draw a polygon and know the area as well.   Given a LineShape, how can I add the closing vertex and create a PolygonShape?


Thanks!



Never mind… I found it: 
  
     PolygonShape polygon = new PolygonShape(new RingShape(line.Vertices)); 
  
 Where line is a LineShape.

Ted, 
  
 Thanks for your post and sharing! 
  
 You are correct, while still I want to mention one thing is Ring Shape should be a closed area type shape, while line shape DONOT need to be closed, and it is line type shape. 
  
 Let me know if you have any more questions. 
  
 Thanks. 
  
 Yale 


Well, it was interesting.   When I first tested that, I guess I got lucky, and my beginning and ending vertices were coincidental.   And, when I added the resultant shape to the TrackOverlay.TrackShapeLayer, it drew as a polygon. 
  
 Later in the day, I could not get the resultant shapes to draw, however, the GetArea method returned a value that appears to be correct. 
  
 The light finally came on, and I added a closing vertex when original vertices were NOT coincidental, and then the shape draws. 
  
 Thanks for the confirmation.

Ted, 
  
 Thanks for your post and I am glad you fixed it! 
  
 Let me know if you have any more questions! 
  
 Thanks. 
  
 Yale