ThinkGeo.com    |     Documentation    |     Premium Support

Finding the CenterPoint for Non-Rectangular Shapes

Anyone know how to get the correct centerpoint for non-rectangular shapes?


I'm trying to add markers to the center point of the shapes in my featureLayer, but they are land plots so some of them are angular.


This means the boundingBox centerPoint doesn't visually look like it's marking the actual feature, it's offset.


Is there a way to compensate?


I've tried playing with xOffset and yOffset, the problem is, I don't know how to determine if the shape is non-rectagular or angled.



Kirk, 
  
 Just wonder are you using the BoudingBox’s Center Point or the Polygon’s own Center Point? Try the polygon’s one as that’s more accurate. 
 
            PointShape centerPoint = polygonShape.GetCenterPoint();
 
 Thanks, 
  
 Ben

Awesome! 
 That’s what I was looking for. 
  
 Now, the trickier part, is there a way to ensure a marker is within the polygon bounds of a particular feature, while adding multiple (up to 5 markers) to a specific polygon while not having the markers overlap?

Kirk, 
  
 There is no direct ways for that. Maybe you can generate couples of satellite points around the center point first, and then check if every point is within the Polygon using Polygon.Contains(Point) method. You need a good algorithm to get the satellite points, for a small polygon, there are chances that the markers cannot fit in it unless they are partly overlapped on the map. 
  
 Let me know if you have any good ideas about it. 
  
 Thanks, 
  
 Ben