Anyone know how to get the centroid of a "C", or "U" shape like polygon and the point need to be inside the polygon some where near the centre?
in most Arc* products this is referred to as a LabelPoint, so look for some incarnation of that term
ie
The point at which the label is located. The labelPoint is always located within or on a feature.
In Feature to Point Tool, choose "INSIDE" as the point location.
I need to use ArcGis Runtime SDK for Java API to code it. Feature to point is not available for me.
Oops... My mistake. Didn't notice the Space where it's posted.
did you look for labelpoint or not? it would be in a polygon class or methods section for your api
For the Java API, getLabelPointForPolygon in the GeometryEngine class.
like I said Joshua... they have to look for labelpoint stuff ... grief
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">boolean</SPAN> <SPAN class="token function">determineCentroid</SPAN><SPAN class="punctuation token">(</SPAN>Geometry polygon<SPAN class="punctuation token">,</SPAN> Point centroid<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getType</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> Geometry<SPAN class="punctuation token">.</SPAN>Type<SPAN class="punctuation token">.</SPAN>POLYGON<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> Point tempCentroid<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Get centroid of the polygon</SPAN> Envelope env <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Envelope</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> polygon<SPAN class="punctuation token">.</SPAN><SPAN class="token function">queryEnvelope</SPAN><SPAN class="punctuation token">(</SPAN>env<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> tempCentroid <SPAN class="operator token">=</SPAN> env<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCenter</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//If tempCentroid is within the polygon then centroid is valid, else look for nearest vertex</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>GeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">within</SPAN><SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">,</SPAN> tempCentroid<SPAN class="punctuation token">,</SPAN> featureServiceTable<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getSpatialReference</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> centroid<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setXY</SPAN><SPAN class="punctuation token">(</SPAN>tempCentroid<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getX</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> tempCentroid<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getY</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> Proximity2DResult proximity2DResult <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getNearestCoordinate</SPAN><SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">,</SPAN> tempCentroid<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> centroid<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setXY</SPAN><SPAN class="punctuation token">(</SPAN>proximity2DResult<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCoordinate</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">getX</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> proximity2DResult<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCoordinate</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">getY</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I did something as shown above to look for the centroid of a polygon whereby the centre is empty. Although the result it is not really plotted at the "centre" of the polygon but it did solved my problem.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.