Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My application uses the ArcGIS Silverlight API to select polygons from a map layer. It uses the Geometry.Extent.GetCenter() method to get the centroid of the shape and add a thumbtack image at those coordinates.

The problem I'm having is that for some shapes (crescents, for example), the centroid will actually fall outside the bounds of the shape. In this case, the thumbtack will appear outside of the shape.

Is there any way that I can ensure that the coordinates I choose are actually inside of the polygon?

share|improve this question
add comment

2 Answers

You are basically looking for an equivalent to IArea.LabelPoint in ArcObjects. The Silverlight API does not have support for this directly, but you can leverage the REST API GeometryService to do that. See Label Points. The downside of using the geometry service is that you need to send a separate request to the server, which may (or may not) be an issue in your scenario.

You might also find this question useful: Algorithm for finding irregular polygon centroid (label point).

share|improve this answer
add comment

From http://resources.arcgis.com/content/kbase?fa=articleShow&d=19742

If the center of the polygon's bounding box does not fall inside the polygon itself (one example would be a crescent-shaped polygon), the point is moved in the X direction until it enters into the polygon (let's call this "Point1"). The point is then moved in the same direction, along the X axis, until it exits the polygon (let's call this "Point2"). The centroid is calculated to be halfway between Point1 and Point2, on the same X axis. For complex polygons that have more than one pair of polygon outlines that cross the X-axis, each pair of outlines is compared to see which pair creates the widest length along the X-axis. Then, the centroid is calculated to be halfway between the points where this pair of outlines crosses the X-axis.

The equivalent is somewhere in ArcMap since version 8, but I cannot find the equivalent in ArcObjects. I presume it would use the above method (which I guess you could implement yourself - it maybe as quick as searching through IGeometry5 interfaces..).

Update: It could be this - http://edndoc.esri.com/arcobjects/9.0/ComponentHelp/esriGeoprocessing/IGpDescribeGeometry_Centroid.htm

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.