<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On 14 juin 07, at 13:02, Matt Doughty wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"> <DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Hi,<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial">Can anybody explain how PostGIS calculates centroids? I’ve checked the manual but the relevant section doesn’t refer to an OGC Specification. From what I can understand, it takes an average of the coordinates of all the vertices of an entry, ignoring whether or not the centroid falls outside the polygons. Is this right? This differs from other GIS- GeoMedia, for example, when confronted with a multipolygon entry, always puts the centroid inside the largest polygon.<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial">Can anybody shed some light on this?<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial">Cheers,<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN lang="EN-GB" style="font-size: 10.0pt;font-family:Arial">Matt</SPAN></FONT></P></DIV></BLOCKQUOTE></DIV><BR><DIV><SPAN class="Apple-tab-span" style="white-space:pre">              </SPAN>Matt,</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">     </SPAN>I don't know the algorithm, but you're right, centroid is not necessary inside polygon if it is convex, with interior rings (centroid inside a interior ring) or a (i did not check myself) multi-polygon. As far as i can see, the centroid is a straight forward barycenter (mean of all points), and therefore you cannot really use it as a "center point" in a user interface (to place a GUI element for a polygon that is not inside polygon confuses the user). </DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN>I agree, having a function that would give a kind of centroid guaranteed to be inside the polygon, and in a "natural way" (eg equidistant from edges) would be very nice.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Regards</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV></BODY></HTML>